How do I trap exceptions generated from any lexical rule using a single exception handler?

Terence Parr

Currently there is no way to specify an exception handler for the generated nextToken method (since you don't specify the rule itself). The best way to handle this problem is to use the filter option. You can specify a rule that is to be invoked by the lexer when no other rule is matched. If you just say "filter=true" then everything but your rules will be ignored like UNIX's sed. Better to use a rule like this:

        :       '<' (~'>')* '>' {System.out.println("invalid tag: "+$getText);}
        |       ( "
" | '
' | '
' ) {newline();}
        |       .
About | Sitemap | Contact