pugneum-parser
v0.3.1
Published
Parses an array of pugneum tokens into an abstract syntax tree
Downloads
18
Readme
pugneum-parser
The pugneum parser transforms an array of tokens into an abstract syntax tree.
Installation
npm install pugneum-parser
Usage
var parse = require('pugneum-parser');
parse(tokens, options)
Convert pugneum tokens into an abstract syntax tree (AST).
options
can contain the following properties:
filename
(string): pugneum file name; included in AST nodes and used in error handlingplugins
(array): array of plugins in the order they should be appliedsource
(string): pugneum source code before tokenization; used in error handling
const lex = require('pugneum-lexer');
let filename = 'my-file.pg';
let source = 'div(data-foo="bar")';
let tokens = lex(source, {filename});
let ast = parse(tokens, {filename, source});
console.log(JSON.stringify(ast, null, ' '))
{
"type": "Block",
"nodes": [
{
"type": "Tag",
"name": "div",
"selfClosing": false,
"block": {
"type": "Block",
"nodes": [],
"line": 1,
"filename": "my-file.pg"
},
"attrs": [
{
"name": "data-foo",
"val": "bar",
"line": 1,
"column": 5,
"filename": "my-file.pg",
"mustEscape": true
}
],
"attributeBlocks": [],
"isInline": false,
"line": 1,
"column": 1,
"filename": "my-file.pg"
}
],
"line": 0,
"filename": "my-file.pg"
}
License
MIT