Chevrotain / chevrotain

Parser Building Toolkit for JavaScript
https://chevrotain.io
Apache License 2.0
2.44k stars 199 forks source link

AT_LEAST_ONE doesn't include any children. #1990

Closed joelburget closed 9 months ago

joelburget commented 9 months ago

I created a minimal repro:

https://gist.github.com/joelburget/39199fefa7401ad3ff4f2654c5b58393

Output:

parser.test.ts:
Warning: Warning: No LINE_BREAKS Found.
    This Lexer has been defined to track line and column information,
    But none of the Token Types can be identified as matching a line terminator.
    See https://chevrotain.io/docs/guide/resolving_lexer_errors.html#LINE_BREAKS
    for details.
{
  literal_list: [
    {
      name: "literal_list",
      children: {}
    }
  ]
}
69 |
70 |   return visitor.visit(cst);
71 | }
72 |
73 | test("expr", () => {
74 |   expect(() => parseExpr("1")).not.toThrow();
      ^
error: expect(received).not.toThrow()

Error name: "TypeError"
Error message: "undefined is not an object (evaluating 'ctx.literal_list.map')"

      at /Users/joel/code/del/parser.test.ts:74:2
✗ expr [1.98ms]

As you can see, children: {}. Shouldn't there be children?

msujew commented 9 months ago

Your literal_list rule is invalid:

private literal_list = this.RULE("literal_list", () => {
-  this.AT_LEAST_ONE(this.literal);
+  this.AT_LEAST_ONE(() => this.SUBRULE(this.literal));
});

That should resolve the issue.