Fixes #1317
This commit is contained in:
parent
39ddd0da3a
commit
4e6e7edf0d
|
@ -69,7 +69,19 @@ public class TestCompositeGrammars extends BaseJavaTest {
|
|||
"WS : (' '|'\\n') -> skip ;\n" ;
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
ErrorQueue equeue = antlr("M.g4", false, "-lib", subdir);
|
||||
assertEquals(equeue.size(), 0);
|
||||
assertEquals(0, equeue.size());
|
||||
}
|
||||
|
||||
// Test for https://github.com/antlr/antlr4/issues/1317
|
||||
@Test public void testImportSelfLoop() throws Exception {
|
||||
mkdir(tmpdir);
|
||||
String master =
|
||||
"grammar M;\n" +
|
||||
"import M;\n" +
|
||||
"s : 'a' ;\n";
|
||||
writeFile(tmpdir, "M.g4", master);
|
||||
ErrorQueue equeue = antlr("M.g4", false, "-lib", tmpdir);
|
||||
assertEquals(0, equeue.size());
|
||||
}
|
||||
|
||||
@Test public void testDelegatesSeeSameTokenType() throws Exception {
|
||||
|
|
|
@ -392,6 +392,8 @@ public class Grammar implements AttributeResolver {
|
|||
if ( ast==null ) return;
|
||||
GrammarAST i = (GrammarAST)ast.getFirstChildWithType(ANTLRParser.IMPORT);
|
||||
if ( i==null ) return;
|
||||
Set<String> visited = new HashSet<>();
|
||||
visited.add(this.name);
|
||||
importedGrammars = new ArrayList<Grammar>();
|
||||
for (Object c : i.getChildren()) {
|
||||
GrammarAST t = (GrammarAST)c;
|
||||
|
@ -403,6 +405,9 @@ public class Grammar implements AttributeResolver {
|
|||
else if ( t.getType()==ANTLRParser.ID ) {
|
||||
importedGrammarName = t.getText();
|
||||
}
|
||||
if ( visited.contains(importedGrammarName) ) { // ignore circular refs
|
||||
continue;
|
||||
}
|
||||
Grammar g;
|
||||
try {
|
||||
g = tool.loadImportedGrammar(this, t);
|
||||
|
|
Loading…
Reference in New Issue