Skip to content
Snippets Groups Projects
Commit 3ce9a0ab authored by Paweł Kędzia's avatar Paweł Kędzia
Browse files

Single and multi line comment handling added to lexicon grammar

parent 2fd075c6
No related branches found
No related tags found
No related merge requests found
......@@ -28,7 +28,7 @@ options {
// ----------------------------------------------------------------------------
class ANTLRLexiconParser extends Parser;
options {
k = 1;
k = 2;
buildAST = false;
exportVocab = ANTLRLexicons;
defaultErrorHandler = false;
......@@ -113,3 +113,36 @@ NEWLINE
| '\n'
) { newline(); $setType(antlr::Token::SKIP); }
;
COMMENT
options {
paraphrase = "Single line comment";
}
: "//" (~('\n'|'\r'))* { $setType(antlr::Token::SKIP); }
;
ML_COMMENT
options {
paraphrase = "Multi line comment";
}
: "/*"
( // TODO: test it and add reference to the site it's taken from!
/* This actually works OK despite the ambiguity that
'\r' '\n' can be matched in one alternative or by matching
'\r' in one iteration and '\n' in another.. But
this is really matched just by one rule per (...)*
loop iteration, so it's OK.
This is exactly how they do it all over the web - just
turn off the warning for this particular token.*/
options {
generateAmbigWarnings = false;
}
: { LA(2)!='/' }? '*'
| '\r' '\n' { newline(); }
| '\r' { newline(); }
| '\n' { newline(); }
| ~('*'|'\n'|'\r')
)*
"*/"
{ $setType(antlr::Token::SKIP); }
;
/**
* ML COMMENT
*/
// Single line comment
by part
och interj
ach interj
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment