gram_ops
Globals / gram-ops
Package: gram-ops
(ast)-[ops]->(features)
Utility operations for extracting path features from gram
AST.
How to gram-ops
Install:
npm install @gram-data/gram-ops
Build a path
Use gram-builder to create a path.
import { node, edge } from '@gram-data/gram-builder';
const left = node('a');
const right = node('b');
const path = edge([left, right], 'right');
Extract features from the path
Extract a node list:
import { nodes } from '@gram-data/gram-ops';
const ns:GramPath[] = nodes(path);
Extract an edge list:
import { nodes } from '@gram-data/gram-ops';
const es:GramPath[] = edges(path);
Next Steps
- Write back to a string using gram-stringify
- Introspect the AST using gram-ast
Index
Functions
Functions
count
▸ Const
count(p
: GramPath): number
Defined in packages/gram-ops/src/index.ts:11
Parameters:
Name | Type |
---|---|
p |
GramPath |
Returns: number
edges
▸ Const
edges(p
: GramPath): GramEdge[]
Defined in packages/gram-ops/src/index.ts:70
Parameters:
Name | Type |
---|---|
p |
GramPath |
Returns: GramEdge[]
head
▸ Const
head(p
: GramPath): GramNode
Defined in packages/gram-ops/src/index.ts:18
Parameters:
Name | Type |
---|---|
p |
GramPath |
Returns: GramNode
identity
▸ Const
identity(p
: GramPath): undefined | string
Defined in packages/gram-ops/src/index.ts:35
Parameters:
Name | Type |
---|---|
p |
GramPath |
Returns: undefined | string
merge
▸ Const
merge(_
: GramPath, next
: GramPath): GramPath
Defined in packages/gram-ops/src/index.ts:30
Parameters:
Name | Type |
---|---|
_ |
GramPath |
next |
GramPath |
Returns: GramPath
nodes
▸ Const
nodes(p
: GramPath | GramPath[] | GramSeq): GramNode[]
Defined in packages/gram-ops/src/index.ts:44
Node set projected from within a path.
Parameters:
Name | Type | Description |
---|---|---|
p |
GramPath | GramPath[] | GramSeq | paths from which to project nodes |
Returns: GramNode[]
tail
▸ Const
tail(p
: GramPath): GramNode
Defined in packages/gram-ops/src/index.ts:24
Parameters:
Name | Type |
---|---|
p |
GramPath |
Returns: GramNode