Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Fix issue with infinite loop due to the rule that doesn't consume and gets pushed and popped - #47

Merged
zcbenz merged 1 commit into
atom:masterfrom
alexdima:infinite-loop-rule
Sep 21, 2015
Merged

zcbenz merged 1 commit into
atom:masterfrom
alexdima:infinite-loop-rule

Conversation

@alexdima

Copy link
Copy Markdown
Contributor

We have found in the wild a grammar that triggers an infinite loop in tokenization. The problem was due to a rule that would enter without advancing the input and would leave also without advancing the input (see infinite-loop-rules.json for a simplified example).

Thinking about it, I think the while(true) loop of grammar.tokenizeLine can end up in an infinite loop with the following rule stack patterns:

  • ABC, ABC, ABC, ... [this was already protected against]
  • ABC, ABCC, ABCCC, ... [this was already protected against]
  • ABC, AB, ABC, AB, ... [<---this is the one being addressed in this PR]
  • ABC, ABCD, ABCDE, ABCDEC, ABCDECD, ABCDECDE ... [<---this one is not yet addressed]

The change I propose for the third looping pattern is to keep track in a boolean (currentRuleHasAdvanced) if the last pushed rule has advanced whatsoever, and if it did not, then skip the entire line if the rule is being popped.

For the fourth looping pattern, I'm afraid I don't have enough TMbundle knowledge to produce a simple grammar demonstrating it, nor do I understand grammar.tokenizeLine sufficiently to propose a fix.

@zcbenz

zcbenz commented Sep 21, 2015

Copy link
Copy Markdown
Contributor

Sorry for the late reply, the looks good to me, thanks!

zcbenz added a commit that referenced this pull request Sep 21, 2015
Fix issue with infinite loop due to the rule that doesn't consume and gets pushed and popped
@zcbenz
zcbenz merged commit b5af109 into atom:master Sep 21, 2015
@zcbenz

zcbenz commented Sep 21, 2015

Copy link
Copy Markdown
Contributor

Oops I just realized #49 already fixed this, so I'm reverting this change.

@alexdima

Copy link
Copy Markdown
Contributor Author

np :)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants