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.

Empty Alternative inside Nested Repetitions causes infinite loops on Parser initilization

See original GitHub issue

I’m sure this was a grammar error on my part, but just wanted to let you know it’s possible to get into a loop state while performing self-analysis.

The loop is like this:

 at possiblePathsFrom (/git/chevrotain/src/parse/grammar/interpreter.ts:287:14)
    at getAlternativesForProd (/git/chevrotain/src/parse/grammar/interpreter.ts:265:24)
    at possiblePathsFrom (/git/chevrotain/src/parse/grammar/interpreter.ts:322:16)
    at getAlternativesForProd (/git/chevrotain/src/parse/grammar/interpreter.ts:265:24)
    at possiblePathsFrom (/git/chevrotain/src/parse/grammar/interpreter.ts:322:16)
    at getAlternativesForProd (/git/chevrotain/src/parse/grammar/interpreter.ts:265:24)

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
bd82commented, Jun 22, 2020

The phase that causes the infinite loop does not take into account the GATEs at all. I hope to have time on the weekend to debug the reproduce-able example farther.

1reaction
bd82commented, Jun 12, 2020

I can reproduce the issue with this small example:

const { CstParser, createToken, EMPTY_ALT } = require("chevrotain")

// ----------------- lexer -----------------
const Comma = createToken({ name: "Comma", pattern: /,/ })

const allTokens = [
  Comma
]

class NestedManyEmptyAltBugParser extends CstParser {
  constructor() {
    super(allTokens)

    const $ = this

    // the parsing methods
    $.RULE("A", () => {
      $.MANY(() => {
        $.SUBRULE($.B)
      });
    });

    $.RULE("B", () => {
      $.MANY(() => {
        $.SUBRULE($.C)
      });
    });

    $.RULE("C", () => {
      $.OR([
        { ALT: () => $.CONSUME(Comma) },
        { ALT: () => EMPTY_ALT }
      ]);
    });

    this.performSelfAnalysis()
  }
}

const parser = new NestedManyEmptyAltBugParser()



Read more comments on GitHub >

github_iconTop Results From Across the Web

Empty Alternative inside Nested Repetitions causes infinite ...
Yes, it was fixable by changing grammar. I'm trying to think of the scenarios where I encountered this. It's happened to me a...
Read more >
Hibernate @OneToMany Relationship Causes Infinite Loop ...
Solution: Use. @JsonManagedReference annotation for the first objects instantiated. @JsonBackReference annotation for the second objects ...
Read more >
Top 4 Types of Statements in Python Infinite Loop - eduCBA
An Infinite Loop in Python is a continuous repetitive conditional loop that gets executed until an external factor interferes in the execution flow, ......
Read more >
Detecting and Escaping Infinite Loops with Jolt - Research
Specifi- cally, Jolt records the program state at the start of each loop iteration. If two consecutive loop iterations produce the same state,...
Read more >
changes/CHANGELOG.md - Chevrotain
Empty Alternative inside Nested Repetitions causes infinite loops on Parser ... Provides a ~20% performance boost to most parsers initialization time.
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