[antlr-interest] Fuzzy parsing ('filter' option)

Jean-Christophe Bach jeanchristophe.bach at inria.fr
Wed Aug 11 07:54:30 PDT 2010


Hi antlr users,

I have a combined grammar and I would like to do fuzzy parsing. I know that the
filter option is designed for the lexer part, but is there any way to use this
option by keeping my combined grammar ?
In our old  parser (antlr2), we used this option like this (in a combined
grammar) :

class HostParser extends Parser;
...
// returns the current goal language code
private String getCode() {
  String result = targetlexer.target.toString();
  targetlexer.clearTarget();
  return result;
}
...
and parser rules

...
class HostLexer extends Lexer;
options {
  ...
  filter=TARGET;
  ...
 }

public StringBuilder target = new StringBuilder("");
// clear the buffer
public void clearTarget() { target.delete(0,target.length()); }

...

protected
TARGET : (.) { target.append($getText); } ;


It was very easy to do fuzzy parsing and to use what was parsed : when needed,
we only had to call getCode() function to get a HostBlock code and to put it in
a node of our tree.  But with antlr3, I'm not sure to understand how to proceed.
I tried to give the option 'filter=true;' directly to my fragment TARGET rule,
but it does not seem to be a good idea (I obtain errors).
Would someone have any idea ?

Regards,

JC


More information about the antlr-interest mailing list