question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Online Playground: unknown parser error type ->13<-

See original GitHub issue

I’m trying to build my grammar from the ground up now, making strange and super simplified versions to make sure that is working and then extend from there. I started with the json example. Below I post a working example, with one line commented out. If you turn it one you get the following error: unknown parser error type ->13<-

If you comment the line above out and then uncomment the other I get the error Cannot read property chunkSize of undefined

Im not sure how to continue to build the grammer or why this won’t work.

(function jsonGrammarOnlyExample() {
  // ----------------- Lexer -----------------
  const createToken = chevrotain.createToken;
  const Lexer = chevrotain.Lexer;

    const This = createToken({name: "This", pattern: /this/});
    const New = createToken({name: "New", pattern: /new/});
    const LParen = createToken({name: "LParen", pattern: /\(/});
    const RParen = createToken({name: "RParen", pattern: /\)/});
    const LCurly = createToken({name: "LCurly", pattern: /{/});
    const RCurly = createToken({name: "RCurly", pattern: /}/});
    const LSquare = createToken({name: "LSquare", pattern: /\[/});
    const RSquare = createToken({name: "RSquare", pattern: /]/});
    const Comma = createToken({name: "Comma", pattern: /,/});
    const Period = createToken({name: "Period", pattern: /\./});
    const Colon = createToken({name: "Colon", pattern: /:/});
    const SemiColon = createToken({name: "SemiColon", pattern: /;/});
    const Equals = createToken({name: "Equals", pattern: /=/});
  
  const Literal = createToken({
        name: "Literal", pattern: /\"[^\"^\n]*\"/
    });
    const Number = createToken({
        name: "Number", pattern: /[0-9]+(?:\.[0-9]+)?[^\s]+\b/
    });
    const Label = createToken({
        name: "Label", pattern: /([a-zA-Z]{1})([a-zA-Z0-9\-_]+)?/
    });
    const WhiteSpace = createToken({
        name: "WhiteSpace",
        pattern: /\s+/,
        group: Lexer.SKIPPED
    });
  
  const StringLiteral = createToken({
    name: "StringLiteral", pattern: /"(:?[^\\"\n\r]+|\\(:?[bfnrtv"\\/]|u[0-9a-fA-F]{4}))*"/
  });
  const NumberLiteral = createToken({
    name: "NumberLiteral", pattern: /-?(0|[1-9]\d*)(\.\d+)?([eE][+-]?\d+)?/
  });

  const jsonTokens = [WhiteSpace,
        This,
        New,
        LParen,
        RParen,
        LCurly,
        RCurly,
        LSquare,
        RSquare,
        Comma,
        Period,
        Colon,
        SemiColon,
        Equals,
        Number,
        Literal,
        Label];

  const JsonLexer = new Lexer(jsonTokens, {
    // Less position info tracked, reduces verbosity of the playground output.
    positionTracking: "onlyStart"
  });

  // Labels only affect error messages and Diagrams.
  LCurly.LABEL = "'{'";
  RCurly.LABEL = "'}'";
  LSquare.LABEL = "'['";
  RSquare.LABEL = "']'";
  Comma.LABEL = "','";
  Colon.LABEL = "':'";
 LParen.LABEL = "'('";
    RParen.LABEL = "')'";
    Period.LABEL = "'.'";
    SemiColon.LABEL = "';'";
    Equals.LABEL = "'='";

  // ----------------- parser -----------------
  const Parser = chevrotain.Parser;

  class JsonParser extends Parser {
    constructor(input) {
      super(input, jsonTokens, {
        recoveryEnabled: true,
        // This will automatically create a Concrete Syntax Tree
        // You can inspect this structure in the output window.
        outputCst: true
      })

      const $ = this;

      $.RULE("Expression", () => {
        $.SUBRULE($.PropertyDefinition)
      });
      
		$.RULE("PropertyCall", () => {
                $.SUBRULE($.UriResource),
                $.CONSUME(Period),
                $.SUBRULE2($.UriResource)              
            });
      
       $.RULE("Evaluation", () => {
                $.OR([
                    {ALT: () => { $.CONSUME(Number) }},
                    //{ALT: () => { $.SUBRULE($.UriResource) }},
                    //turn this line on and you get unknown parser error type 13
                    //turn it on and turn the line above off and you get Cannot read property chunkSize of undefined
                    {ALT: () => { $.SUBRULE($.PropertyCall) }}
                ]);
            });
      
      $.RULE("PropertyDefinition", () => {
                $.SUBRULE($.PropertyCall),
                $.OR([
                    {ALT: () => { $.CONSUME(Colon) }},
                    {ALT: () => { $.CONSUME(Equals) }}
                ]),
                $.SUBRULE2($.Evaluation)
            });
      
      
     
     $.RULE("UriResource", () => {
                $.CONSUME(Label)
            });


      // very important to call this after all the rules have been setup.
      // otherwise the parser may not work correctly as it will lack information
      // derived from the self analysis.
      this.performSelfAnalysis();
    }

  }

  // for the playground to work the returned object must contain these fields
  return {
    lexer: JsonLexer,
    parser: JsonParser,
    defaultRule: "Expression"
  };
}())

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
flyoncommented, Sep 17, 2018

Hi @bd82 , thanks for quick reply. Right, I was just trying to get something working online before installing via npm, but I see what you mean now, it would have saved me time to just try things right from my IDE and I would have had better / more clear errors. Thanks for the tips, I will continue trying things out in the IDE

0reactions
bd82commented, Sep 17, 2018

I am leaving this open to investigate the playground not showing the correct error message.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Online Playground: unknown parser error type ->13<- #814
I'm trying to build my grammar from the ground up now, making strange and super simplified versions to make sure that is working...
Read more >
TS Playground - An online editor for exploring TypeScript and ...
The Playground lets you write TypeScript or JavaScript online in a safe and sharable way.
Read more >
Xcode 13.2 - Internal error : Miss… | Apple Developer Forums
Same issue, "Internal error: missingPackageDescriptionModule". Tried removing / re-adding the package dependencies but xcode13.2 is stuck in the "Preparing to ...
Read more >
"Expression failed to parse, unknown error" only in Xcode 10.2 ...
Hello! I was experimenting with the VIPER architecture in a Xcode playground, and I encountered this error: Expression failed to parse, ...
Read more >
Go Playground - The Go Programming Language
... Error: failed to parse log level (main:info,state:info,statesync:info,*:error): Unknown Level String: 'main:info,state:info,statesync:info,*:error', ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found