Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private List<List<String>> processGrammarFiles(
String tokensFileName = grammarFile.getName().split("\\.")[0] + ".tokens";
File outputFile = new File(outputDirectory, tokensFileName);
if ( (! outputFile.exists()) ||
outputFile.lastModified() < grammarFile.lastModified() ||
outputFile.lastModified() <= grammarFile.lastModified() ||
dependencies.isDependencyChanged(grammarFile)) {
grammarFilesToProcess.add(grammarFile);
}
Expand All @@ -412,10 +412,7 @@ private List<List<String>> processGrammarFiles(
// Iterate each grammar file we were given and add it into the tool's list of
// grammars to process.
for (File grammarFile : grammarFiles) {
if (!buildContext.hasDelta(grammarFile)) {
continue;
}

buildContext.refresh(grammarFile);
buildContext.removeMessages(grammarFile);

getLog().debug("Grammar file '" + grammarFile.getPath() + "' detected.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,14 +216,14 @@ private void analyse(File grammarFile, Collection<File> grammarFiles, Tool tool)
return;

for (GrammarAST importDecl : grammar.getAllChildrenWithType(ANTLRParser.IMPORT)) {
Tree id = importDecl.getFirstChildWithType(ANTLRParser.ID);
for (Tree id: importDecl.getAllChildrenWithType(ANTLRParser.ID)) {
// missing id is not valid, but we don't want to prevent the root cause from
// being reported by the ANTLR tool
if (id != null) {
String grammarPath = getRelativePath(grammarFile);

// missing id is not valid, but we don't want to prevent the root cause from
// being reported by the ANTLR tool
if (id != null) {
String grammarPath = getRelativePath(grammarFile);

graph.addEdge(id.getText() + ".g4", grammarPath);
graph.addEdge(id.getText() + ".g4", grammarPath);
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ public void importsStandardLayout() throws Exception {
Path genHello = generatedSources.resolve("test/HelloParser.java");

Path baseGrammar = antlrDir.resolve("imports/TestBaseLexer.g4");
Path baseGrammar2 = antlrDir.resolve("imports/TestBaseLexer2.g4");
Path lexerGrammar = antlrDir.resolve("test/TestLexer.g4");
Path parserGrammar = antlrDir.resolve("test/TestParser.g4");

Expand All @@ -222,21 +223,20 @@ public void importsStandardLayout() throws Exception {
assertTrue(Files.exists(genHello));
assertTrue(Files.exists(genTestParser));
assertTrue(Files.exists(genTestLexer));
byte[] origTestLexerSum = checksum(genTestLexer);
byte[] origTestParserSum = checksum(genTestParser);
byte[] origHelloSum = checksum(genHello);

////////////////////////////////////////////////////////////////////////
// 2nd - nothing has been modified, no grammars have to be processed
////////////////////////////////////////////////////////////////////////

{
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);

maven.executeMojo(session, project, exec);

assertTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}

////////////////////////////////////////////////////////////////////////
Expand All @@ -245,50 +245,71 @@ public void importsStandardLayout() throws Exception {

// modify the grammar to make checksum comparison detect a change
try(Change change = Change.of(baseGrammar, "DOT: '.' ;")) {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);

maven.executeMojo(session, project, exec);

assertFalse(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));

////////////////////////////////////////////////////////////////////////
// 4th - the lexer grammar changed, the parser grammar has to be processed as well
// 4th - the second imported grammar changed, every dependency has to be processed
////////////////////////////////////////////////////////////////////////

// modify the grammar to make checksum comparison detect a change
try(Change change = Change.of(lexerGrammar)) {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);
try(Change change = Change.of(baseGrammar2, "BANG: '!' ;")) {
maven.executeMojo(session, project, exec);

assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));

////////////////////////////////////////////////////////////////////////
// 5th - the lexer grammar changed, the parser grammar has to be processed as well
////////////////////////////////////////////////////////////////////////

// modify the grammar to make checksum comparison detect a change
try(Change change = Change.of(lexerGrammar, "FOO: 'foo' ;")) {
maven.executeMojo(session, project, exec);

assertFalse(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
assertFalse(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));

////////////////////////////////////////////////////////////////////////
// 5th - the parser grammar changed, no other grammars have to be processed
// 6th - the parser grammar changed, no other grammars have to be processed
////////////////////////////////////////////////////////////////////////

// modify the grammar to make checksum comparison detect a change
try(Change change = Change.of(parserGrammar, " t : WS* ;")) {
byte[] testLexerSum = checksum(genTestLexer);
byte[] testParserSum = checksum(genTestParser);
byte[] helloSum = checksum(genHello);

maven.executeMojo(session, project, exec);

assertTrue(Arrays.equals(testLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(testParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(helloSum, checksum(genHello)));
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertFalse(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}
// Restore file and confirm it was restored.
maven.executeMojo(session, project, exec);
assertTrue(Arrays.equals(origTestLexerSum, checksum(genTestLexer)));
assertTrue(Arrays.equals(origTestParserSum, checksum(genTestParser)));
assertTrue(Arrays.equals(origHelloSum, checksum(genHello)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,4 @@ fragment
Whitespace : ' ' | '\n' | '\t' | '\r' ;

fragment
Hexdigit : [a-fA-F0-9] ;

fragment
Digit : [0-9] ;
Hexdigit : [a-fA-F0-9] ;
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
lexer grammar TestBaseLexer2;

fragment
Digit : [0-9] ;
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
lexer grammar TestLexer;

import TestBaseLexer;
import TestBaseLexer, TestBaseLexer2;

WS : Whitespace+ -> skip;
TEXT : ~[<&]+ ; // match any 16 bit char other than < and &
TEXT : ~[<&]+ ; // match any 16 bit char other than < and &
3 changes: 2 additions & 1 deletion contributors.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,5 @@ YYYY/MM/DD, github id, Full name, email
2017/05/29, kosak, Corey Kosak, [email protected]
2017/06/11, erikbra, Erik A. Brandstadmoen, [email protected]
2017/06/10, jm-mikkelsen, Jan Martin Mikkelsen, [email protected]
2017/06/25, alimg, Alim Gökkaya, [email protected]
2017/06/25, alimg, Alim Gökkaya, [email protected]
2017/07/11, dhalperi, Daniel Halperin, [email protected]