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

OMeta error handler #9

Closed
CMCDragonkai opened this issue Apr 9, 2015 · 1 comment
Closed

OMeta error handler #9

CMCDragonkai opened this issue Apr 9, 2015 · 1 comment

Comments

@CMCDragonkai
Copy link

In the error handler we currently get something like:

err.OMeta = { idx: 0, line: 1, col: 0 }

Is it possible to give us a way of knowing which production rule was the one that failed? Perhaps even a stack trace of the production rule, so we can know how deep the production rule went before failing?

@Page-
Copy link
Collaborator

Page- commented Apr 19, 2015

Sadly it's not that easy due to the backtracking nature of OMeta meaning that it's not possible to know which rule was the one that was meant to succeed (as there are usually multiple possible branches, and any of them might be "the one").

What you can do is to enable branch tracking and see what branches are tracked

grammar = OmetaGrammar.createInstance()
grammar.branches = {
    RuleName: true,
    AnotherRule: true
}
grammar._enableBranchTracking(grammar.branches);
grammar.matchAll(input, 'Process');
branches = grammar._getBranches()
console.log(branches[err.OMeta.idx])

You might well find that you need to backtrack from the idx that the error happened to find a tracked rule (since it tracks where the rule started matching). As for the grammar.branches object, you can use it with the hinter module to generate autocomplete (sadly I don't have an example available, but if this is useful to you I can try to get one sorted).

@Page- Page- closed this as completed Jan 18, 2016
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

2 participants