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

0.4.1 • Public • Published

LavRia

TypeScript LALR(1) Parser Generator

install

requirement: npm

$ mkdir pg
$ cd pg
$ npm init
$ npm install lavriapg --save

sample

$ echo 1+1 | node ./node_modules/lavriapg/dist/sample.js

usage

edit language and run the following code:

// TypeScript
import {language_parser, ParserGenerator} from "lavriapg";
import {readFileSync} from "fs";
 
const input = readFileSync("/dev/stdin", "utf8") as string;
const language = language_parser.parse(readFileSync("./node_modules/lavriapg/language", "utf8") as string); // set the language file path
const parser = new ParserGenerator(language).getParser();
console.log(parser.parse(input));
// JavaScript(CommonJS)
const pg = require("lavriapg");
const fs = require("fs");
const input = fs.readFileSync("/dev/stdin", "utf8");
const language = pg.language_parser.parse(fs.readFileSync("./node_modules/lavriapg/language", "utf8")); // set the language file path
const parser = new pg.ParserGenerator(language).getParser();
console.log(parser.parse(input));

this program parses input (from stdin) that has the lex and grammar rules defined by language and shows its AST.

language is language file and it expresses itself.

Dependencies (0)

    Dev Dependencies (12)

    Package Sidebar

    Install

    npm i lavriapg

    Weekly Downloads

    0

    Version

    0.4.1

    License

    BSD-3-Clause

    Unpacked Size

    188 kB

    Total Files

    81

    Last publish

    Collaborators

    • tatamo