Skip to content

Commit

Permalink
- added the ability that one can add comments on an own line or inser…
Browse files Browse the repository at this point in the history
…t empty lines in a tokenVocab
  • Loading branch information
robstoll committed Jul 20, 2014
1 parent 823b8fd commit 20d859a
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 3 deletions.
3 changes: 3 additions & 0 deletions tool/src/main/java/org/antlr/tool/Grammar.java
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,9 @@ else if ( token == '\'' ) {
continue;
}
token = tokenizer.nextToken(); // skip newline
while(token == StreamTokenizer.TT_EOL ){
token = tokenizer.nextToken();
}
}
br.close();
}
Expand Down
28 changes: 25 additions & 3 deletions tool/src/test/java/org/antlr/test/TestCompositeGrammars.java
Original file line number Diff line number Diff line change
Expand Up @@ -535,13 +535,36 @@ public class TestCompositeGrammars extends BaseTest {
assertEquals("unexpected warnings: "+equeue, 0, equeue.warnings.size());
}

@Test public void testTokenVocabCommentsOnOwnLineNoWarningsLikeNoLexerRuleCorrespondingToToken()
@Test public void testTokenVocabCommentsOnOwnLineNoErrorNoWarnings()
throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);

mkdir(tmpdir);
writeFile(tmpdir, "Foo.tokens", "TokenFromTokenVocab=4\n//some comments on a new line\n'token'=4\n");
writeFile(tmpdir, "Foo.tokens", "TokenFromTokenVocab=4\n"
+ "//some comments on a new line\n'token'=4\n");

String grammar = "grammar Foo;\n"
+ "options {tokenVocab=Foo;}\n"
+ "tokens{TokenFromTokenVocab='token';}\n"
+ "a : TokenFromTokenVocab;\n"
+ "WS : (' '|'\\n') {$channel=HIDDEN;} ;\n";

writeFile(tmpdir, "Foo.g", grammar);
Tool antlr = newTool(new String[] {"-lib", tmpdir, tmpdir + "/Foo.g"});
antlr.process();

assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
assertEquals("unexpected warnings: "+equeue, 0, equeue.warnings.size());
}

@Test public void testTokenVocabWithEmptyLineNoErrorNoWarnings()
throws Exception {
ErrorQueue equeue = new ErrorQueue();
ErrorManager.setErrorListener(equeue);

mkdir(tmpdir);
writeFile(tmpdir, "Foo.tokens", "TokenFromTokenVocab=4\n\n'token'=4\n");

String grammar = "grammar Foo;\n"
+ "options {tokenVocab=Foo;}\n"
Expand Down Expand Up @@ -578,7 +601,6 @@ public class TestCompositeGrammars extends BaseTest {
assertEquals("unexpected errors: "+equeue, 0, equeue.errors.size());
assertEquals("unexpected warnings: "+equeue, 0, equeue.warnings.size());
}


@Test public void testSyntaxErrorsInImportsNotThrownOut() throws Exception {
ErrorQueue equeue = new ErrorQueue();
Expand Down

0 comments on commit 20d859a

Please sign in to comment.