[antlr-interest] part of comment-open in regular text

Rolf Schumacher mailinglist at august.de
Thu Apr 15 13:32:51 PDT 2004


While using the option 'greedy' the first time I solve (and understood)
one problem,
but generated me a new one:

How to match a k=2 left part of the comment-opening string as regular 
text in case this is not a comment-open string?

Rolf

---------
The appended gramma leads to 'nondeterminism'
between comments (CMT) and the rest (TEXT).
Do you know how to avoid that?
---------
class BParser extends Parser;

blocks: ( TEXT | CMT )+;

class BLexer extends Lexer;
options {
     k=3;
     charVocabulary = '\u000a' | '\u0020' .. '\u007e';
}

CMT
     :   "{{{"
         (   options { greedy=false; }
             :   '\n' { newline(); }
             |   .
         )*
         "}}}"
         {System.out.println("["+getText()+"]");}
     ;
WS
     :   (   ' '
         |   '\n' { newline(); }
         )
         { _ttype = Token.SKIP; }
     ;
protected TEXTCHAR
     :   '\u0021'..'\u007a'
     |   (   { LA(2) != '{' }? '{'
         |   { LA(3) != '{' }? "{{"
         )
     |   '\u007c'..'\u007e'
     ;
TEXT
     :   ( TEXTCHAR )+ {System.out.println(">"+getText()+"<");}
     ;

By the way: I wasn't able to include the usual DOS-MAC-end-of-line
syntax in CMT in order to maintain newline() in those cases as well.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/x-pkcs7-signature
Size: 1730 bytes
Desc: S/MIME Cryptographic Signature
Url : http://www.antlr.org/pipermail/antlr-interest/attachments/20040415/18452ee8/smime.bin


More information about the antlr-interest mailing list