[antlr-interest] first steps with a lexer/parser

Harald Mueller harald_m_mueller at gmx.de
Fri Jan 4 08:38:36 PST 2008


> ... and it made the grammar much simpler without losing ...

That's what we all strive for, isn't it? :-)

> 
> here's a question - what would i have to change if i had escaped
> quotes inside of the string (\")? then surely i would have to use .*
> to match the string, and then do something different inside of it.

The following works ... I would like to have a little more standard string handling in ANTLR 3 lexers (I liked ANTLR 2 more here ...):

STRING @init { string result = ""; }        // we build the text "manually"
    : '"'
      ( c=~('"')   { result += (char) $c; } // a non-" char
      | '\\' '"'   { result += '\"'; }      // an escaped "
      )*
      '"'          { $text = result; }
    ;

Regards
Harald

-- 
Psssst! Schon vom neuen GMX MultiMessenger gehört?
Der kann`s mit allen: http://www.gmx.net/de/go/multimessenger?did=10


More information about the antlr-interest mailing list