How to use the chevrotain.Parser function in chevrotain

To help you get started, we’ve selected a few chevrotain examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SAP / chevrotain / examples / grammars / xml / xml_es6.js View on Github external
SLASH,
            EQUALS,
            STRING,
            Name,
            S
        ]
    }
}

var XmlLexer = new Lexer(XmlLexerDefinition)
var allTokens = XmlLexerDefinition.modes.INSIDE.concat(
    XmlLexerDefinition.modes.OUTSIDE
)

// ----------------- parser -----------------
class XmlParserES6 extends chevrotain.Parser {
    // Unfortunately no support for class fields with initializer in ES2015, only in ES2016...
    // so the parsing rules are defined inside the constructor, as each parsing rule must be initialized by
    // invoking RULE(...)
    // see: https://github.com/jeffmo/es-class-fields-and-static-properties
    constructor(input) {
        super(
            input,
            allTokens,
            // by default the error recovery / fault tolerance capabilities are disabled
            // use this flag to enable them
            { recoveryEnabled: true }
        )

        // not mandatory, using $ (or any other sign) to reduce verbosity (this. this. this. this. .......)
        var $ = this
github SAP / chevrotain / examples / jison_lex / jsonParser.js View on Github external
var chevrotain = require("chevrotain");
var JisonLex = require('jison-lex');

// ----------------- lexer -----------------
var Parser = chevrotain.Parser;
var extendToken = chevrotain.extendToken;


// In ES6, custom inheritance implementation (such as the one above) can be replaced with simple "class X extends Y"...
var True = extendToken("True");
var False = extendToken("False");
var Null = extendToken("Null");
var LCurly = extendToken("LCurly");
var RCurly = extendToken("RCurly");
var LSquare = extendToken("LSquare");
var RSquare = extendToken("RSquare");
var Comma = extendToken("Comma");
var Colon = extendToken("Colon");
var StringLiteral = extendToken("StringLiteral");
var NumberLiteral = extendToken("NumberLiteral");
github SAP / chevrotain / examples / parser / large_lookahead / large_lookahead.js View on Github external
var chevrotain = require("chevrotain");

// ----------------- lexer -----------------
var extendToken = chevrotain.extendToken;
var Lexer = chevrotain.Lexer;
var Parser = chevrotain.Parser;

var Assign = extendToken("Assign", /=/);
var Export = extendToken("Export", /export/);
var Interface = extendToken("Interface", /interface/);
var Identifier = extendToken("Identifier", /\w+/);

var WhiteSpace = extendToken("WhiteSpace", /\s+/);
WhiteSpace.GROUP = Lexer.SKIPPED; // marking WhiteSpace as 'SKIPPED' makes the lexer skip it.

var allTokens = [
    WhiteSpace, // whitespace is normally very common so it should be placed first to speed up the lexer's performance
    Assign,
    Export,
    Interface,
    Identifier
];
github SAP / chevrotain / examples / grammars / json / json_es6.js View on Github external
"use strict"
var chevrotain = require("chevrotain")

// ----------------- lexer -----------------
var Token = chevrotain.Token
var Lexer = chevrotain.Lexer
var Parser = chevrotain.Parser

// Unfortunately no support for static class properties in ES2015, only in ES2016...
// so the PATTERN/GROUP static props are defined outside the class declarations.
// see: https://github.com/jeffmo/es-class-fields-and-static-properties
class True {}

True.PATTERN = /true/

class False {}
False.PATTERN = /false/

class Null {}
Null.PATTERN = /null/

class LCurly {}
LCurly.PATTERN = /{/
github jhipster / jhipster-core / lib / dsl / poc / parser.js View on Github external
const Parser = require('chevrotain').Parser;
const tokensVocabulary = require('./lexer').tokens;

// short name to reduce grammar's verbosity
const t = tokensVocabulary;


class JDLParser extends Parser {
  // Our Parser only gets initialized once, new inputs will be transferred via
  // the ".input" setter.
  constructor() {
    super([], tokensVocabulary, { recoveryEnabled: true, outputCst: true });

    const $ = this;

    // HIGHLIGHTS1: Any rule may be used as a start rule, there is no artificial limit
    // like in pegjs. This capability is useful for partial parsing, e.g.:
github SAP / chevrotain / examples / grammars / xml / xml_es6.js View on Github external
"use strict"
var chevrotain = require("chevrotain")
var XRegExp = require("xregexp")

// ----------------- lexer -----------------
var Token = chevrotain.Token
var Lexer = chevrotain.Lexer
var Parser = chevrotain.Parser

// A little mini DSL for easier lexer definition using xRegExp.
var fragments = {}

function FRAGMENT(name, def) {
    fragments[name] = XRegExp.build(def, fragments)
}

function MAKE_PATTERN(def, flags) {
    return XRegExp.build(def, fragments, flags)
}

FRAGMENT(
    "NameStartChar",
    "([a-zA-Z]|\\u2070-\\u218F|\\u2C00-\\u2FEF|\\u3001-\\uD7FF|\\uF900-\\uFDCF|\\uFDF0-\\uFFFD)"
)
github witheve / Eve / src / runtime / parser.ts View on Github external
}
  }

  subBlock() {
    let neue = new ParseBlock(`${this.id}|sub${this.nodeId++}`, this.variableLookup);
    neue.parent = this;
    return neue;
  }
}


//-----------------------------------------------------------
// Parser
//-----------------------------------------------------------

export class Parser extends chev.Parser {
  block: ParseBlock;
  activeScopes: string[];
  currentAction: string;

  // Parser patterns
  doc: any;
  codeBlock: any;
  fencedBlock: any;
  section: any;
  searchSection: any;
  actionSection: any;
  value: any;
  bool: any;
  num: any;
  scopeDeclaration: any;
  name: any;
github SAP / chevrotain / examples / grammars / json / json_es6.js View on Github external
StringLiteral,
    LCurly,
    RCurly,
    LSquare,
    RSquare,
    Comma,
    Colon,
    True,
    False,
    Null
]
var JsonLexer = new Lexer(allTokens)

// ----------------- parser -----------------

class JsonParserES6 extends chevrotain.Parser {
    // Unfortunately no support for class fields with initializer in ES2015, only in ES2016...
    // so the parsing rules are defined inside the constructor, as each parsing rule must be initialized by
    // invoking RULE(...)
    // see: https://github.com/jeffmo/es-class-fields-and-static-properties
    constructor(input) {
        super(input, allTokens)

        // not mandatory, using $ (or any other sign) to reduce verbosity (this. this. this. this. .......)
        const $ = this

        $.RULE("json", () => {
            // prettier-ignore
            $.OR([
                {ALT: () => {$.SUBRULE($.object)}},
                {ALT: () => {$.SUBRULE($.array)}}
            ])
github christianvoigt / argdown / packages / argdown-parser / src / ArgdownParser.js View on Github external
'use strict';

import chevrotain, {
    Parser,
    Token,
    getTokenConstructor
} from 'chevrotain';
import {ArgdownLexer} from './ArgdownLexer.js';

class ArgdownParser extends chevrotain.Parser {

    constructor(input, lexer) {
        super(input, lexer.tokens);
        let $ = this;
        $.lexer = lexer;

        $.argdown = $.RULE("argdown", () => {
            let atLeastOne = $.AT_LEAST_ONE_SEP({
                SEP: lexer.Emptyline,
                DEF: () => $.OR([{
                    ALT: () => $.SUBRULE($.heading)
                }, {
                    ALT: () => $.SUBRULE($.statement)
                },  {
                    ALT: () => $.SUBRULE($.argument)
                },  {
github dapetcu21 / atom-autocomplete-lua / js / parser.js View on Github external
const Parser = require('chevrotain').Parser
const { tokenVocabulary, lex } = require('./lexer')

const {
  Name, BlockString, Number, String,
  And, Break, Do, Else, Elseif, End, False, For, Function, Goto, If, In, Local,
  Nil, Not, Or, Repeat, Return, Then, True, Until, While,
  Plus, Minus, Times, Div, FloorDiv, Mod, Pow, Length,
  Equal, NotEqual, LessThanEqual, GreaterThanEqual, LessThan, GreaterThan,
  Assign, LeftParen, RightParen, LeftBrace, RightBrace, LeftBracket, RightBracket,
  Label, Semicolon, Colon, Comma, Vararg, Concat, Period,
  BitwiseNot, BitwiseOr, BitwiseAnd, LeftShift, RightShift
} = tokenVocabulary

const {
  arithmetic, relational,
  and_, or_,