From a74005972d9f3c97f593aae9c4607304a5ee8304 Mon Sep 17 00:00:00 2001 From: Kyle Kingsbury Date: Tue, 18 Mar 2014 16:43:32 -0700 Subject: [PATCH] BasicSemanticChecks.checkGrammarName: allow null filenames. checkGrammarName assumes that all grammars come from actual files, but grammars loaded using Tool.parseGrammarFromString use input streams without source file names. This patch changes checkGrammarName to only verify that grammar names and file names correspond when a file name is available. --- tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java b/tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java index 91ebc32ce..0540189d2 100644 --- a/tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java +++ b/tool/src/org/antlr/v4/semantics/BasicSemanticChecks.java @@ -290,6 +290,11 @@ public class BasicSemanticChecks extends GrammarTreeVisitor { void checkGrammarName(Token nameToken) { String fullyQualifiedName = nameToken.getInputStream().getSourceName(); + if (fullyQualifiedName == null) { + // This wasn't read from a file. + return; + } + File f = new File(fullyQualifiedName); String fileName = f.getName(); if ( g.originalGrammar!=null ) return; // don't warn about diff if this is implicit lexer