properly check for grammar/filename difference

This commit is contained in:
Terence Parr 2012-11-17 17:24:13 -08:00
parent 8631c143da
commit 80b1fa7acb
5 changed files with 8 additions and 8 deletions

View File

@ -4,6 +4,7 @@ November 17, 2012
* .tokens files goes in output dir like parser file.
* added check: action in lexer rules must be last element of outermost alt
* properly check for grammar/filename difference
November 11, 2012

View File

@ -1,8 +1,3 @@
grammar T;
s : A ;
s : EOF ;
A : 'a' ;
B : 'x' -> skip |'y' ;
WS : [ \t\r\n]+ -> skip ;

View File

@ -367,6 +367,7 @@ public class Tool {
if ( lexerAST!=null ) {
lexerg = new LexerGrammar(this, lexerAST);
lexerg.fileName = g.fileName;
lexerg.originalGrammar = g;
g.implicitLexer = lexerg;
lexerg.implicitLexerOwner = g;
processNonCombinedGrammar(lexerg, gencode);

View File

@ -248,10 +248,10 @@ public class BasicSemanticChecks extends GrammarTreeVisitor {
// They are triggered by the visitor methods above.
void checkGrammarName(Token nameToken) {
if ( g.implicitLexer==null ) return;
String fullyQualifiedName = nameToken.getInputStream().getSourceName();
File f = new File(fullyQualifiedName);
String fileName = f.getName();
if ( g.originalGrammar!=null ) return; // don't warn about diff if this is implicit lexer
if ( !Utils.stripFileExtension(fileName).equals(nameToken.getText()) &&
!fileName.equals(Grammar.GRAMMAR_FROM_STRING_NAME)) {
g.tool.errMgr.grammarError(ErrorType.FILE_AND_GRAMMAR_NAME_DIFFER,

View File

@ -121,10 +121,13 @@ public class Grammar implements AttributeResolver {
public String fileName;
/** Was this parser grammar created from a COMBINED grammar? If so,
* this is what we derived.
* this is what we extracted.
*/
public LexerGrammar implicitLexer;
/** If this is an extracted/implicit lexer, we point at original grammar */
public Grammar originalGrammar;
/** If we're imported, who imported us? If null, implies grammar is root */
public Grammar parent;
public List<Grammar> importedGrammars;