0.3.1 • Published 8 months ago

pugneum-parser v0.3.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

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 handling
  • plugins (array): array of plugins in the order they should be applied
  • source (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

0.3.0

8 months ago

0.3.1

8 months ago

0.2.0

8 months ago

0.1.1

8 months ago

0.1.0

9 months ago