@gram-data/gram-ast
Advanced tools
Comparing version 0.2.7 to 0.2.8
@@ -9,3 +9,3 @@ { | ||
], | ||
"version": "0.2.7", | ||
"version": "0.2.8", | ||
"license": "MIT", | ||
@@ -69,3 +69,3 @@ "repository": { | ||
}, | ||
"gitHead": "68f323250363f0ab629388565880339d5c94ed5e", | ||
"gitHead": "3d28a7b7186d406e75bfd22aac54cd1b4ba0dbfa", | ||
"publishConfig": { | ||
@@ -72,0 +72,0 @@ "access": "public" |
@@ -1,8 +0,36 @@ | ||
# Gram AST | ||
Gram abstract syntax tree definitions and utilities like type guards. | ||
An abstract syntax tree for data graphs. | ||
## How to gram-ast | ||
A [unist](https://github.com/syntax-tree/unist) compatible AST for | ||
Gram's text literal format. | ||
### Install: | ||
``` | ||
npm install @gram-data/gram-ast | ||
``` | ||
### Use [[gram-parse]] to create an AST, then introspect with gram-ast: | ||
``` | ||
import { toAST } from '@gram-data/gram-parse'; | ||
const src = '(a)-->(b)'; | ||
const parsed = toAST(src); | ||
// the top-level of the AST is a sequence of paths | ||
console.assert(isGramPathSequence(parsed)); | ||
// the first path should be an edge | ||
const firstPath = parsed.children[0]; | ||
console.assert(isGramEdge(firstPath)); | ||
// the children of an edge are nodes | ||
console.assert(isGramNode(firstPath.children[0])); | ||
console.assert(isGramNode(firstPath.children[1])); | ||
``` | ||
## Next Steps | ||
- Transform to js objects using [[gram-value]] | ||
- Write a [unist](https://github.com/syntax-tree/unist) plugin for processing the AST | ||
176401
37