Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lexer.pushState does not work as expected (or intended?) #317

Open
rubenvereecken opened this issue Jan 12, 2016 · 0 comments
Open

lexer.pushState does not work as expected (or intended?) #317

rubenvereecken opened this issue Jan 12, 2016 · 0 comments

Comments

@rubenvereecken
Copy link

The pushState or begin method of the lexer pushes a key onto the conditionStack. Whenever the current rule set is looked up (internally), this key is looked up in the conditions object. However, this object is never changed so this lookup will always fail, resulting in no rules and a crash.

I found myself having to overwrite the method in a very simple manner.

    lexer.pushState = function(key, condition) {
      if (!condition) {
        condition = {
          ctx: key, 
          rules: lexer._currentRules()
        };
      }
      lexer.conditions[key] = condition;
      lexer.conditionStack.push(key); // This line is the body of the original function
    };

As you can see, it's backwards compatible since the condition parameter would just be undefined. The if-statement is just to make it easier, the only big change is that the conditions object gets the rules added.

Shall I send a PR with this functionality? I found it really useful to have some context-dependent logic in the lexer so I can minimize my grammar.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant