I'm looking for some help implementing a custom error recovery strategy.

Consider the following grammar which accepts strings of the form
"ab--ab--cd--"..., and generates flat AST's of the form: GROUP["ab"]
GROUP["ab"] GROUP["cd"]...

grammar Test;

options {
  output=AST;
}

tokens {
  GROUP;
}

foo
  : (bar '--')+ -> bar+
  ;

bar
  : (('a' 'b') | ('c' 'd')) -> GROUP[$bar.text]
  ;

Now suppose we feed the parser the input string "ab--ac--cd--".  I
would like the resulting AST to look like: GROUP["ab"] GROUP["cd"]
corresponding to the first "ab" and the last "cd" of the input string.
 In other words, when the parser starts to match a bar rule but fails
(as it will when it encounters the first 'c' token in our example
input,) I'd like to scan past all tokens until the next '--' token,
and then tell the parser to back up to the state it was in just after
encountering the first 'b' token.

I'm able to over-ride what I think to be the appropriate methods of
BaseRecognizer, and I understand how to scan past and consume the
tokens I don't care about, but I'm unsure of how to direct the parser
back to the previous state (or if it's even possible.)

Any help would be appreciated.

 - Joe

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe: 
http://www.antlr.org/mailman/options/antlr-interest/your-email-address

-- 
You received this message because you are subscribed to the Google Groups 
"il-antlr-interest" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/il-antlr-interest?hl=en.

Reply via email to