krl-parser
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

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 string
  • options.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

Readme

Keywords

Package Sidebar

Install

npm i krl-parser

Weekly Downloads

11

Version

1.3.0

License

MIT

Unpacked Size

134 kB

Total Files

21

Last publish

Collaborators

  • b1conrad
  • farskipper
  • windley