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

Line number in "rule is not defined" error #19

Open
shamrin opened this issue Apr 12, 2012 · 3 comments · May be fixed by #21
Open

Line number in "rule is not defined" error #19

shamrin opened this issue Apr 12, 2012 · 3 comments · May be fixed by #21

Comments

@shamrin
Copy link

shamrin commented Apr 12, 2012

When referencing undefined symbol in the grammar rule, the following is throwed:


It's nice, but line number would be even better.

I tried implementing this, but got stuck at traverseRulesAnchoredAtName. At that point information about rule syntax nodes is lost. The function also seems to be highly optimized: uses its own stack instead of recursion.

Any suggestions on how to implement it?

@tolmasky
Copy link
Owner

If you look at SyntaxNode.prototype.message you will see a way to calculate a lineNumber for a given SyntaxNode. This should probably be factored out into something like SyntaxNode.prototype.lineNumber.

After this you would want to add the defining node to the rule object in buildRulesFromSyntaxTree. This would actually go into the individual rule builders (e.g. https://github.com/tolmasky/language/blob/master/lib/compiledgrammar.js#L251 ). You would just add node:aNode to that object creation line.

Now finally in traverseRulesAnchoredAtName when you throw you can just use rule.node.lineNumber() to get the line number in question.

@shamrin
Copy link
Author

shamrin commented Apr 12, 2012

Thanks! The problem with your suggestion is that rule is undefined at this point... And no easy way to find out what rule produced the hash...

I decided to do it the other way, with firstUsageNodes object:

#20

Here's how the message looks like:

multiplicative = primary ([*/] miltiplicative)?
                               ^^^^^^^^^^^^^^
ERROR line 6: Rule "miltiplicative" is not defined.

What do you think?

@shamrin
Copy link
Author

shamrin commented Apr 25, 2012

Francisco, could you please comment on my patch? Is idea good or bad? I can completely rewrite my patch if needed.

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

Successfully merging a pull request may close this issue.

2 participants