0.4.0 • Published 7 years ago

cheddar-parser v0.4.0

Weekly downloads
4
License
Apache-2.0
Repository
github
Last release
7 years ago

Installation

Install the CLI (includes REPL) using:

$ npm i -g cheddar-parser

Install for your project using:

$ npm i --save cheddar-parser

Usage

CLI

Simply running cheddar-parser will open up a REPL. Otherwise, if not a TTY, STDIN will be used as input to STDOUT. Various output formats exist, through flags.

--ast: Outputs an AST. Best for manually reading the parse tree --obj: Outputs an object. Provides in-depth data such as index & state --json: Outputs a JSON. Best for processing through another program --pretty: Pretty prints outputs. This includes syntax highlighting result & indenting JSON. Automatically assumed on the REPL.

In Node.js

One installed simply access the given parser using:

require('cheddar-parser/dist/path/to/item')

Alternatively, most common parsers are available through simply the module itself. example:

require('cheddar-parser').Expression

The full list of parsers is here.


To use a parser simply do:

let parserInstance = new parser(code, startIndex);
let result = parserInstance.exec();

result may be an instanceof CheddarLexer (ches.Lexer), in which case it succesfully parsed, a string, in which it errored, the string is the error description, or a symbol, in which it is a symbol which represents the given error.

An example, of the most common way a cheddar lexer is used:

let run = new parser(code, 0);
let res = run.exec();

if (!(res instanceof ches.Lexer)) {
    // Error, propogate the error
    return `Syntax Error: ${res} at ${run.Index}`;
} else {
    
}

You can also use the ches.Helper.Locate(code, index) to retrieve an array of [row, col, index] of the index in the code.

0.4.0

7 years ago

0.3.2

7 years ago

0.3.1

7 years ago

0.3.0

7 years ago

0.2.2

8 years ago

0.2.1

8 years ago

0.2.0

8 years ago

0.1.10

8 years ago

0.1.9

8 years ago

0.1.8

8 years ago

0.1.7

8 years ago

0.1.6

8 years ago

0.1.5

8 years ago

0.1.4

8 years ago

0.1.3

8 years ago

0.1.2

8 years ago