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.
The
pushState
orbegin
method of the lexer pushes a key onto theconditionStack
. Whenever the current rule set is looked up (internally), this key is looked up in theconditions
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.
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.