krl-parser
v1.3.0
Published
Parse KRL source code into an AST
Downloads
25
Readme
krl-parser
Parse KRL source code into an AST
Usage
var parser = require('krl-parser');
var src = ...//somehow get your krl string
var ast = parser(src);
AST Specification
A simple specification is found in spec.md
The AST type definitions are found in types.ts
API
ast = parser(src[, options])
src
- your krl source code stringoptions.filename
- If provided, it will be used on parsing errors so the user know what file failed to parse.
This function will throw errors when it can't parse. When applicable, the Error object may have a where
property. i.e.
var src = "function(a, b] { a + b }";
try {
ast = parser(src, { filename: "bad-function.krl" });
} catch (err) {
console.log(err.where);
}
{ filename: 'bad-function.krl',
line: 1,
col: 14,
excerpt: 'function(a, b] { a + b }\n ^' }
Developing
The technique used for this implementation is Top Down Operator Precedence, also called a Pratt parser.
When developing run this:
$ npm start
It will watch for file changes, rebuild the grammar and run tests.
To run tests once, run this:
$ npm test
To compile typescript, run this:
$ npm run build
License
MIT