Permalink
Browse files

Fix parsing of single-line comments without text.

If the '//' was followed by newline immediately, without any text, that
it wasn't parsed as a comment correctly, instead emitting hard to
understand errors further down in the text.

Fixed by using the same approach to describing // comments as is used in
ANTLR3's example C preprocessor grammar.

Fixes #6.
  • Loading branch information...
1 parent 1518d80 commit 4419320948cd8a554927657e9c5f96c2e289112f @vslavik committed Apr 6, 2012
Showing with 3 additions and 1 deletion.
  1. +1 −1 src/bkl/parser/Bakefile.g
  2. +2 −0 tests/test_parsing/comments/single_line.bkl
View
2 src/bkl/parser/Bakefile.g
@@ -215,7 +215,7 @@ TEXT: ('a'..'z' | 'A'..'Z' | '0'..'9' | '-' | '_' | '.' | '/' | '@')+;
// ---------------------------------------------------------------------------
COMMENT
- : '//' ~'\n'* { $channel = HIDDEN };
+ : '//' ~('\n'|'\r')* '\r'? '\n' { $channel = HIDDEN };
ML_COMMENT
: '/*' (options{greedy=false;}:.)* '*/' { $channel = HIDDEN };
View
2 tests/test_parsing/comments/single_line.bkl
@@ -3,3 +3,5 @@
exe foo {
my_var = 42; // the meaning of life, the universe, and everything
}
+//
+///

0 comments on commit 4419320

Please sign in to comment.