tsunami

log in
history

Debugging tsunami ANTLR syntax

Luke Breuer
2008-12-22 22:11 UTC

grammar
grammar tsunami;
options {
        language=CSharp2;
        backtrack=true;
}

document: para+;

para    : (ESCAPED | OTHER | bold | italic | strike)+;

bold    : STAR    para STAR;
italic  : UNDER   para UNDER;
strike  : TWODASH para TWODASH;

end     : NEWLINE*;

// NOT_OTHER BEGIN
NEWLINE : '\r'? '\n' { $channel=HIDDEN; };

// ESCAPE_ABLE BEGIN
STAR      : '*';
UNDER     : '_';
TWODASH   : '--';
BACKSLASH : '\\';
// ESCAPE_ABLE END
// NOT_OTHER END

// the following characters are excluded: [\r\n*_\-\\]
OTHER   : ('\u0000'..'\u0009' |
           '\u000B'..'\u000C' |
           '\u000E'..'\u0029' |
           '\u002B'..'\u002C' |
           '\u002E'..'\u005B' |
           '\u005D'..'\u005E' |
           '\u0060'..'\u00FF');

// the following characters can be escaped: [*_\-\\]
ESCAPED : BACKSLASH STAR      |
          BACKSLASH UNDER     |
          BACKSLASH TWODASH   |
          BACKSLASH BACKSLASH;
test input
*bb*
testing grammar against input
(no errors)