From 36425dd59cf538c0a50d8f86666fe7bb9272a13c Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Sun, 29 Jun 2014 21:39:15 -0700 Subject: [PATCH 1/3] Big change to error messages themselves by removing single quotes for non input text stuff. Made cannot_find_tokens_file more specific (split it). Added offending token information to a lot of the messages. It now only prints the file name and not the full path to the file in error messages. Re-factored the ANTLRMessage hierarchy to share fields. Getting the offending token required number of methods to take different arguments. removed the default ST listener in the error manager as it is apparently unused. Cannot find imported grammar is now a grammar error not a tool error. --- tool/src/org/antlr/v4/Tool.java | 10 +- .../v4/analysis/LeftRecursionDetector.java | 4 +- .../analysis/LeftRecursiveRuleAnalyzer.java | 2 +- .../LeftRecursiveRuleTransformer.java | 6 +- .../antlr/v4/automata/ParserATNFactory.java | 2 +- .../antlr/v4/codegen/model/RuleFunction.java | 3 +- tool/src/org/antlr/v4/parse/ScopeParser.java | 13 +- .../org/antlr/v4/parse/TokenVocabParser.java | 41 +- .../org/antlr/v4/semantics/RuleCollector.java | 6 +- tool/src/org/antlr/v4/tool/ANTLRMessage.java | 21 +- tool/src/org/antlr/v4/tool/ErrorManager.java | 50 +-- tool/src/org/antlr/v4/tool/ErrorType.java | 374 +++++++++--------- tool/src/org/antlr/v4/tool/Grammar.java | 15 +- .../v4/tool/GrammarSemanticsMessage.java | 29 +- .../antlr/v4/tool/GrammarSyntaxMessage.java | 6 +- .../v4/tool/LeftRecursionCyclesMessage.java | 9 +- tool/src/org/antlr/v4/tool/ToolMessage.java | 6 +- .../antlr/v4/test/TestAttributeChecks.java | 190 ++++----- .../v4/test/TestBasicSemanticErrors.java | 38 +- .../org/antlr/v4/test/TestLeftRecursion.java | 4 +- .../org/antlr/v4/test/TestScopeParsing.java | 6 +- tool/test/org/antlr/v4/test/TestSets.java | 2 +- .../org/antlr/v4/test/TestSymbolIssues.java | 38 +- .../antlr/v4/test/TestToolSyntaxErrors.java | 34 +- 24 files changed, 462 insertions(+), 447 deletions(-) diff --git a/tool/src/org/antlr/v4/Tool.java b/tool/src/org/antlr/v4/Tool.java index 59d88d30d..4714a9ea4 100644 --- a/tool/src/org/antlr/v4/Tool.java +++ b/tool/src/org/antlr/v4/Tool.java @@ -593,9 +593,10 @@ public class Tool { /** * Try current dir then dir of g then lib dir * @param g - * @param name The imported grammar name. + * @param nameNode The node associated with the imported grammar name. */ - public Grammar loadImportedGrammar(Grammar g, String name) throws IOException { + public Grammar loadImportedGrammar(Grammar g, GrammarAST nameNode) throws IOException { + String name = nameNode.getText(); g.tool.log("grammar", "load " + name + " from " + g.fileName); File importedFile = null; for (String extension : ALL_GRAMMAR_EXTENSIONS) { @@ -606,12 +607,15 @@ public class Tool { } if ( importedFile==null ) { - errMgr.toolError(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, name, g.fileName); + errMgr.grammarError(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, g.fileName, nameNode.getToken(), name); return null; } ANTLRFileStream in = new ANTLRFileStream(importedFile.getAbsolutePath(), grammarEncoding); GrammarRootAST root = parse(g.fileName, in); + if ( root==null ) { + return null; + } Grammar imported = createGrammar(root); imported.fileName = importedFile.getAbsolutePath(); return imported; diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java b/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java index 44e4b4a85..61e0309a7 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java @@ -74,7 +74,9 @@ public class LeftRecursionDetector { } //System.out.println("cycles="+listOfRecursiveCycles); if ( !listOfRecursiveCycles.isEmpty() ) { - g.tool.errMgr.leftRecursionCycles(g.fileName, listOfRecursiveCycles); + RuleStartState firstRuleStartState = atn.ruleToStartState[0]; + Rule r = g.getRule(firstRuleStartState.ruleIndex); + g.tool.errMgr.leftRecursionCycles(g.fileName, r.ast.getToken(), listOfRecursiveCycles); } } diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java index faf5f4ab3..09100ed5d 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java @@ -131,7 +131,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { assoc = ASSOC.left; } else { - tool.errMgr.toolError(ErrorType.ILLEGAL_OPTION_VALUE, "assoc", assoc); + tool.errMgr.toolError(ErrorType.ILLEGAL_OPTION_VALUE, t.getToken(), "assoc", assoc); } } } diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java index 3d8ac1779..60b060c4d 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleTransformer.java @@ -34,6 +34,7 @@ import org.antlr.runtime.ANTLRStringStream; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.ParserRuleReturnScope; import org.antlr.runtime.RecognitionException; +import org.antlr.runtime.Token; import org.antlr.v4.Tool; import org.antlr.v4.misc.OrderedHashMap; import org.antlr.v4.parse.ANTLRLexer; @@ -177,7 +178,7 @@ public class LeftRecursiveRuleTransformer { // update Rule to just one alt and add prec alt ActionAST arg = (ActionAST)r.ast.getFirstChildWithType(ANTLRParser.ARG_ACTION); if ( arg!=null ) { - r.args = ScopeParser.parseTypedArgList(arg, arg.getText(), g.tool.errMgr); + r.args = ScopeParser.parseTypedArgList(arg, arg.getText(), g); r.args.type = AttributeDict.DictType.ARG; r.args.ast = arg; arg.resolver = r.alt[1]; // todo: isn't this Rule or something? @@ -206,15 +207,18 @@ public class LeftRecursiveRuleTransformer { lexer.tokens = tokens; ToolANTLRParser p = new ToolANTLRParser(tokens, tool); p.setTreeAdaptor(adaptor); + Token ruleStart = null; try { ParserRuleReturnScope r = p.rule(); RuleAST tree = (RuleAST)r.getTree(); + ruleStart = (Token)r.getStart(); GrammarTransformPipeline.setGrammarPtr(g, tree); GrammarTransformPipeline.augmentTokensWithOriginalPosition(g, tree); return tree; } catch (Exception e) { tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, + ruleStart, "error parsing rule created during left-recursion detection: "+ruleText, e); } diff --git a/tool/src/org/antlr/v4/automata/ParserATNFactory.java b/tool/src/org/antlr/v4/automata/ParserATNFactory.java index b87772fba..183962bed 100644 --- a/tool/src/org/antlr/v4/automata/ParserATNFactory.java +++ b/tool/src/org/antlr/v4/automata/ParserATNFactory.java @@ -306,7 +306,7 @@ public class ParserATNFactory implements ATNFactory { public Handle _ruleRef(@NotNull GrammarAST node) { Rule r = g.getRule(node.getText()); if ( r==null ) { - g.tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, "Rule "+node.getText()+" undefined"); + g.tool.errMgr.grammarError(ErrorType.INTERNAL_ERROR, g.fileName, node.getToken(), "Rule "+node.getText()+" undefined"); return null; } RuleStartState start = atn.ruleToStartState[r.index]; diff --git a/tool/src/org/antlr/v4/codegen/model/RuleFunction.java b/tool/src/org/antlr/v4/codegen/model/RuleFunction.java index fc1182d1c..22aedd98d 100644 --- a/tool/src/org/antlr/v4/codegen/model/RuleFunction.java +++ b/tool/src/org/antlr/v4/codegen/model/RuleFunction.java @@ -235,7 +235,8 @@ public class RuleFunction extends OutputModelObject { } return visitor.frequencies.peek(); - } catch (RecognitionException ex) { + } + catch (RecognitionException ex) { factory.getGrammar().tool.errMgr.toolError(ErrorType.INTERNAL_ERROR, ex); return new FrequencySet(); } diff --git a/tool/src/org/antlr/v4/parse/ScopeParser.java b/tool/src/org/antlr/v4/parse/ScopeParser.java index 7eec947ca..4323d6908 100644 --- a/tool/src/org/antlr/v4/parse/ScopeParser.java +++ b/tool/src/org/antlr/v4/parse/ScopeParser.java @@ -39,6 +39,7 @@ import org.antlr.v4.tool.Attribute; import org.antlr.v4.tool.AttributeDict; import org.antlr.v4.tool.ErrorManager; import org.antlr.v4.tool.ErrorType; +import org.antlr.v4.tool.Grammar; import org.antlr.v4.tool.ast.ActionAST; import java.util.ArrayList; @@ -62,17 +63,17 @@ public class ScopeParser { * * convert to an attribute scope. */ - public static AttributeDict parseTypedArgList(@Nullable ActionAST action, String s, ErrorManager errMgr) { - return parse(action, s, ',', errMgr); + public static AttributeDict parseTypedArgList(@Nullable ActionAST action, String s, Grammar g) { + return parse(action, s, ',', g); } - public static AttributeDict parse(@Nullable ActionAST action, String s, char separator, ErrorManager errMgr) { + public static AttributeDict parse(@Nullable ActionAST action, String s, char separator, Grammar g) { AttributeDict dict = new AttributeDict(); List> decls = splitDecls(s, separator); for (Pair decl : decls) { // System.out.println("decl="+decl); if ( decl.a.trim().length()>0 ) { - Attribute a = parseAttributeDef(action, decl, errMgr); + Attribute a = parseAttributeDef(action, decl, g); dict.add(a); } } @@ -84,7 +85,7 @@ public class ScopeParser { * but if the separator is ',' you cannot use ',' in the initvalue * unless you escape use "\," escape. */ - public static Attribute parseAttributeDef(@Nullable ActionAST action, @NotNull Pair decl, ErrorManager errMgr) { + public static Attribute parseAttributeDef(@Nullable ActionAST action, @NotNull Pair decl, Grammar g) { if ( decl.a==null ) return null; Attribute attr = new Attribute(); boolean inID = false; @@ -113,7 +114,7 @@ public class ScopeParser { start = 0; } if ( start<0 ) { - errMgr.toolError(ErrorType.CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL,decl); + g.tool.errMgr.grammarError(ErrorType.CANNOT_FIND_ATTRIBUTE_NAME_IN_DECL, g.fileName, action.token, decl); } // walk forwards looking for end of an ID int stop=-1; diff --git a/tool/src/org/antlr/v4/parse/TokenVocabParser.java b/tool/src/org/antlr/v4/parse/TokenVocabParser.java index 934a40a68..85398e6ec 100644 --- a/tool/src/org/antlr/v4/parse/TokenVocabParser.java +++ b/tool/src/org/antlr/v4/parse/TokenVocabParser.java @@ -34,6 +34,8 @@ import org.antlr.runtime.Token; import org.antlr.v4.Tool; import org.antlr.v4.codegen.CodeGenerator; import org.antlr.v4.tool.ErrorType; +import org.antlr.v4.tool.Grammar; +import org.antlr.v4.tool.ast.GrammarAST; import java.io.BufferedReader; import java.io.File; @@ -48,12 +50,10 @@ import java.util.regex.Pattern; /** */ public class TokenVocabParser { - protected final Tool tool; - protected final String vocabName; + protected final Grammar g; - public TokenVocabParser(Tool tool, String vocabName) { - this.tool = tool; - this.vocabName = vocabName; + public TokenVocabParser(Grammar g) { + this.g = g; } /** Load a vocab file {@code .tokens} and return mapping. */ @@ -63,6 +63,8 @@ public class TokenVocabParser { File fullFile = getImportedVocabFile(); FileInputStream fis = null; BufferedReader br = null; + Tool tool = g.tool; + String vocabName = g.getOptionString("tokenVocab"); try { Pattern tokenDefPattern = Pattern.compile("([^\n]+?)[ \\t]*?=[ \\t]*?([0-9]+)"); fis = new FileInputStream(fullFile); @@ -102,7 +104,7 @@ public class TokenVocabParser { if ( tokenDef.length()>0 ) { // ignore blank lines tool.errMgr.toolError(ErrorType.TOKENS_FILE_SYNTAX_ERROR, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION, - " bad token def: "+tokenDef, + " bad token def: " + tokenDef, lineNum); } } @@ -110,13 +112,25 @@ public class TokenVocabParser { } } catch (FileNotFoundException fnfe) { - tool.errMgr.toolError(ErrorType.CANNOT_FIND_TOKENS_FILE, - fullFile); + GrammarAST inTree = g.ast.getOptionAST("tokenVocab"); + String inTreeValue = inTree.getToken().getText(); + if ( vocabName.equals(inTreeValue) ) { + tool.errMgr.grammarError(ErrorType.CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR, + g.fileName, + inTree.getToken(), + fullFile); + } + else { // must be from -D option on cmd-line not token in tree + tool.errMgr.toolError(ErrorType.CANNOT_FIND_TOKENS_FILE_GIVEN_ON_CMDLINE, + fullFile, + g.name); + } } catch (Exception e) { tool.errMgr.toolError(ErrorType.ERROR_READING_TOKENS_FILE, + e, fullFile, - e); + e.getMessage()); } finally { try { @@ -124,8 +138,9 @@ public class TokenVocabParser { } catch (IOException ioe) { tool.errMgr.toolError(ErrorType.ERROR_READING_TOKENS_FILE, + ioe, fullFile, - ioe); + ioe.getMessage()); } } return tokens; @@ -141,8 +156,8 @@ public class TokenVocabParser { * was no output directory specified. */ public File getImportedVocabFile() { - - File f = new File(tool.libDirectory, + String vocabName = g.getOptionString("tokenVocab"); + File f = new File(g.tool.libDirectory, File.separator + vocabName + CodeGenerator.VOCAB_FILE_EXTENSION); @@ -154,7 +169,7 @@ public class TokenVocabParser { // to look for it in the output directory which is where .tokens // files are generated (in the base, not relative to the input // location.) - f = new File(tool.outputDirectory, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION); + f = new File(g.tool.outputDirectory, vocabName + CodeGenerator.VOCAB_FILE_EXTENSION); return f; } } diff --git a/tool/src/org/antlr/v4/semantics/RuleCollector.java b/tool/src/org/antlr/v4/semantics/RuleCollector.java index 7791dcfe9..17cae5415 100644 --- a/tool/src/org/antlr/v4/semantics/RuleCollector.java +++ b/tool/src/org/antlr/v4/semantics/RuleCollector.java @@ -81,20 +81,20 @@ public class RuleCollector extends GrammarTreeVisitor { rules.put(r.name, r); if ( arg!=null ) { - r.args = ScopeParser.parseTypedArgList(arg, arg.getText(), g.tool.errMgr); + r.args = ScopeParser.parseTypedArgList(arg, arg.getText(), g); r.args.type = AttributeDict.DictType.ARG; r.args.ast = arg; arg.resolver = r.alt[currentOuterAltNumber]; } if ( returns!=null ) { - r.retvals = ScopeParser.parseTypedArgList(returns, returns.getText(), g.tool.errMgr); + r.retvals = ScopeParser.parseTypedArgList(returns, returns.getText(), g); r.retvals.type = AttributeDict.DictType.RET; r.retvals.ast = returns; } if ( locals!=null ) { - r.locals = ScopeParser.parseTypedArgList(locals, locals.getText(), g.tool.errMgr); + r.locals = ScopeParser.parseTypedArgList(locals, locals.getText(), g); r.locals.type = AttributeDict.DictType.LOCAL; r.locals.ast = locals; } diff --git a/tool/src/org/antlr/v4/tool/ANTLRMessage.java b/tool/src/org/antlr/v4/tool/ANTLRMessage.java index 403d25432..bbeda2f4f 100644 --- a/tool/src/org/antlr/v4/tool/ANTLRMessage.java +++ b/tool/src/org/antlr/v4/tool/ANTLRMessage.java @@ -30,6 +30,7 @@ package org.antlr.v4.tool; +import org.antlr.runtime.Token; import org.antlr.v4.runtime.misc.NotNull; import org.antlr.v4.runtime.misc.Nullable; import org.stringtemplate.v4.ST; @@ -50,18 +51,25 @@ public class ANTLRMessage { public int line = -1; public int charPosition = -1; - public ANTLRMessage(@NotNull ErrorType errorType) { - this(errorType, (Throwable)null); + public Grammar g; + /** Most of the time, we'll have a token such as an undefined rule ref + * and so this will be set. + */ + public Token offendingToken; + + public ANTLRMessage(@NotNull ErrorType errorType) { + this(errorType, (Throwable)null, Token.INVALID_TOKEN); } - public ANTLRMessage(@NotNull ErrorType errorType, Object... args) { - this(errorType, null, args); - } + public ANTLRMessage(@NotNull ErrorType errorType, Token offendingToken, Object... args) { + this(errorType, null, offendingToken, args); + } - public ANTLRMessage(@NotNull ErrorType errorType, @Nullable Throwable e, Object... args) { + public ANTLRMessage(@NotNull ErrorType errorType, @Nullable Throwable e, Token offendingToken, Object... args) { this.errorType = errorType; this.e = e; this.args = args; + this.offendingToken = offendingToken; } @NotNull @@ -80,6 +88,7 @@ public class ANTLRMessage { public ST getMessageTemplate(boolean verbose) { ST messageST = new ST(getErrorType().msg); + messageST.impl.name = errorType.name(); messageST.add("verbose", verbose); Object[] args = getArgs(); diff --git a/tool/src/org/antlr/v4/tool/ErrorManager.java b/tool/src/org/antlr/v4/tool/ErrorManager.java index 9601aabe9..364316e21 100644 --- a/tool/src/org/antlr/v4/tool/ErrorManager.java +++ b/tool/src/org/antlr/v4/tool/ErrorManager.java @@ -30,14 +30,14 @@ package org.antlr.v4.tool; +import org.antlr.runtime.Token; import org.antlr.v4.Tool; import org.stringtemplate.v4.ST; -import org.stringtemplate.v4.STErrorListener; import org.stringtemplate.v4.STGroup; import org.stringtemplate.v4.STGroupFile; import org.stringtemplate.v4.misc.ErrorBuffer; -import org.stringtemplate.v4.misc.STMessage; +import java.io.File; import java.net.URL; import java.util.Collection; import java.util.EnumSet; @@ -63,29 +63,6 @@ public class ErrorManager { ErrorBuffer initSTListener = new ErrorBuffer(); - STErrorListener theDefaultSTListener = - new STErrorListener() { - @Override - public void compileTimeError(STMessage msg) { - ErrorManager.internalError(msg.toString()); - } - - @Override - public void runTimeError(STMessage msg) { - ErrorManager.internalError(msg.toString()); - } - - @Override - public void IOError(STMessage msg) { - ErrorManager.internalError(msg.toString()); - } - - @Override - public void internalError(STMessage msg) { - ErrorManager.internalError(msg.toString()); - } - }; - public ErrorManager(Tool tool) { this.tool = tool; } @@ -111,7 +88,13 @@ public class ErrorManager { locationValid = true; } if (msg.fileName != null) { - locationST.add("file", msg.fileName); + File f = new File(msg.fileName); + // Don't show path to file in messages; too long. + String displayFileName = msg.fileName; + if ( f.exists() ) { + displayFileName = f.getName(); + } + locationST.add("file", displayFileName); locationValid = true; } @@ -181,12 +164,15 @@ public class ErrorManager { * @param args The arguments to pass to the StringTemplate */ public void toolError(ErrorType errorType, Object... args) { - ToolMessage msg = new ToolMessage(errorType, args); - emit(errorType, msg); + toolError(errorType, null, Token.INVALID_TOKEN, args); } - public void toolError(ErrorType errorType, Throwable e, Object... args) { - ToolMessage msg = new ToolMessage(errorType, e, args); + public void toolError(ErrorType errorType, Token offendingToken, Object... args) { + toolError(errorType, null, offendingToken, args); + } + + public void toolError(ErrorType errorType, Throwable e, Token offendingToken, Object... args) { + ToolMessage msg = new ToolMessage(errorType, e, offendingToken, args); emit(errorType, msg); } @@ -200,9 +186,9 @@ public class ErrorManager { } - public void leftRecursionCycles(String fileName, Collection> cycles) { + public void leftRecursionCycles(String fileName, Token startTokenOfFirstRuleInCycle, Collection> cycles) { errors++; - ANTLRMessage msg = new LeftRecursionCyclesMessage(fileName, cycles); + ANTLRMessage msg = new LeftRecursionCyclesMessage(fileName, startTokenOfFirstRuleInCycle, cycles); tool.error(msg); } diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index e77649aed..56b4a12f5 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -16,7 +16,7 @@ * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, @@ -50,27 +50,27 @@ public enum ErrorType { /** * Compiler Error 1. * - *

cannot write file 'filename': reason

+ *

cannot write file filename: reason

*/ - CANNOT_WRITE_FILE(1, "cannot write file '': ", ErrorSeverity.ERROR), + CANNOT_WRITE_FILE(1, "cannot write file : ", ErrorSeverity.ERROR), /** * Compiler Error 2. * - *

unknown command-line option 'option'

+ *

unknown command-line option option

*/ - INVALID_CMDLINE_ARG(2, "unknown command-line option ''", ErrorSeverity.ERROR), + INVALID_CMDLINE_ARG(2, "unknown command-line option ", ErrorSeverity.ERROR), /** * Compiler Error 3. * - *

cannot find tokens file 'filename'

+ *

cannot find tokens file filename

*/ - CANNOT_FIND_TOKENS_FILE(3, "cannot find tokens file ''", ErrorSeverity.ERROR), + CANNOT_FIND_TOKENS_FILE_GIVEN_ON_CMDLINE(3, "cannot find tokens file given for ", ErrorSeverity.ERROR), /** * Compiler Error 4. * - *

cannot find tokens file 'filename': reason

+ *

cannot find tokens file filename: reason

*/ - ERROR_READING_TOKENS_FILE(4, "cannot find tokens file '': ", ErrorSeverity.ERROR), + ERROR_READING_TOKENS_FILE(4, "error reading tokens file : ", ErrorSeverity.ERROR), /** * Compiler Error 5. * @@ -93,21 +93,27 @@ public enum ErrorType { * Compiler Error 8. * *

- * grammar name 'name' and file name 'filename' differ

+ * grammar name name and file name filename differ

*/ - FILE_AND_GRAMMAR_NAME_DIFFER(8, "grammar name '' and file name '' differ", ErrorSeverity.ERROR), + FILE_AND_GRAMMAR_NAME_DIFFER(8, "grammar name and file name differ", ErrorSeverity.ERROR), /** * Compiler Error 9. * - *

invalid {@code -Dname=value} syntax: 'syntax'

+ *

invalid {@code -Dname=value} syntax: syntax

*/ - BAD_OPTION_SET_SYNTAX(9, "invalid -Dname=value syntax: ''", ErrorSeverity.ERROR), + BAD_OPTION_SET_SYNTAX(9, "invalid -Dname=value syntax: ", ErrorSeverity.ERROR), /** * Compiler Error 10. * *

warning treated as error

*/ WARNING_TREATED_AS_ERROR(10, "warning treated as error", ErrorSeverity.ERROR_ONE_OFF), + /** + * Compiler Error 11. + * + *

cannot find tokens file filename: reason

+ */ + ERROR_READING_IMPORTED_GRAMMAR(11, "error reading imported grammar referenced in ", ErrorSeverity.ERROR), /** * Compiler Error 20. @@ -144,35 +150,35 @@ public enum ErrorType { * Compiler Error 31. * *

- * ANTLR cannot generate 'language' code as of version + * ANTLR cannot generate language code as of version * version

*/ - CANNOT_CREATE_TARGET_GENERATOR(31, "ANTLR cannot generate '' code as of version "+ Tool.VERSION, ErrorSeverity.ERROR), + CANNOT_CREATE_TARGET_GENERATOR(31, "ANTLR cannot generate code as of version "+ Tool.VERSION, ErrorSeverity.ERROR), /** * Compiler Error 32. * *

- * code generation template 'template' has missing, misnamed, or - * incomplete arg list; missing 'field'

+ * code generation template template has missing, misnamed, or + * incomplete arg list; missing field

*/ - CODE_TEMPLATE_ARG_ISSUE(32, "code generation template '' has missing, misnamed, or incomplete arg list; missing ''", ErrorSeverity.ERROR), + CODE_TEMPLATE_ARG_ISSUE(32, "code generation template has missing, misnamed, or incomplete arg list; missing ", ErrorSeverity.ERROR), /** * Compiler Error 33. * - *

missing code generation template 'template'

+ *

missing code generation template template

*/ - CODE_GEN_TEMPLATES_INCOMPLETE(33, "missing code generation template ''", ErrorSeverity.ERROR), + CODE_GEN_TEMPLATES_INCOMPLETE(33, "missing code generation template ", ErrorSeverity.ERROR), /** * Compiler Error 34. * *

- * no mapping to template name for output model class 'class'

+ * no mapping to template name for output model class class

*/ - NO_MODEL_TO_TEMPLATE_MAPPING(34, "no mapping to template name for output model class ''", ErrorSeverity.ERROR), + NO_MODEL_TO_TEMPLATE_MAPPING(34, "no mapping to template name for output model class ", ErrorSeverity.ERROR), /** * Compiler Error 35. * - *

templates/target and tool aren't compatible

+ *

templates/target and tool arent compatible

*/ INCOMPATIBLE_TOOL_AND_TEMPLATES(35, " code generation target requires ANTLR ; it can't be loaded by the current ANTLR ", ErrorSeverity.ERROR), @@ -189,21 +195,21 @@ public enum ErrorType { /** * Compiler Error 51. * - *

rule 'rule' redefinition; previous at line line

+ *

rule rule redefinition; previous at line line

*/ - RULE_REDEFINITION(51, "rule '' redefinition; previous at line ", ErrorSeverity.ERROR), + RULE_REDEFINITION(51, "rule redefinition; previous at line ", ErrorSeverity.ERROR), /** * Compiler Error 52. * - *

lexer rule 'rule' not allowed in parser

+ *

lexer rule rule not allowed in parser

*/ - LEXER_RULES_NOT_ALLOWED(52, "lexer rule '' not allowed in parser", ErrorSeverity.ERROR), + LEXER_RULES_NOT_ALLOWED(52, "lexer rule not allowed in parser", ErrorSeverity.ERROR), /** * Compiler Error 53. * - *

parser rule 'rule' not allowed in lexer

+ *

parser rule rule not allowed in lexer

*/ - PARSER_RULES_NOT_ALLOWED(53, "parser rule '' not allowed in lexer", ErrorSeverity.ERROR), + PARSER_RULES_NOT_ALLOWED(53, "parser rule not allowed in lexer", ErrorSeverity.ERROR), /** * Compiler Error 54. * @@ -222,10 +228,10 @@ public enum ErrorType { * Compiler Error 57. * *

- * reference to undefined rule 'rule' in non-local ref - * 'reference'

+ * reference to undefined rule rule in non-local ref + * reference

*/ - UNDEFINED_RULE_IN_NONLOCAL_REF(57, "reference to undefined rule '' in non-local ref ''", ErrorSeverity.ERROR), + UNDEFINED_RULE_IN_NONLOCAL_REF(57, "reference to undefined rule in non-local ref ", ErrorSeverity.ERROR), /** * Compiler Error 60. * @@ -236,87 +242,87 @@ public enum ErrorType { * Compiler Error 63. * *

- * unknown attribute reference 'attribute' in - * 'expression'

+ * unknown attribute reference attribute in + * expression

*/ - UNKNOWN_SIMPLE_ATTRIBUTE(63, "unknown attribute reference '' in ''", ErrorSeverity.ERROR), + UNKNOWN_SIMPLE_ATTRIBUTE(63, "unknown attribute reference in ", ErrorSeverity.ERROR), /** * Compiler Error 64. * *

- * parameter 'parameter' of rule 'rule' is not accessible + * parameter parameter of rule rule is not accessible * in this scope: expression

*/ - INVALID_RULE_PARAMETER_REF(64, "parameter '' of rule '' is not accessible in this scope: ", ErrorSeverity.ERROR), + INVALID_RULE_PARAMETER_REF(64, "parameter of rule is not accessible in this scope: ", ErrorSeverity.ERROR), /** * Compiler Error 65. * *

- * unknown attribute 'attribute' for rule 'rule' in - * 'expression'

+ * unknown attribute attribute for rule rule in + * expression

*/ - UNKNOWN_RULE_ATTRIBUTE(65, "unknown attribute '' for rule '' in ''", ErrorSeverity.ERROR), + UNKNOWN_RULE_ATTRIBUTE(65, "unknown attribute for rule in ", ErrorSeverity.ERROR), /** * Compiler Error 66. * *

- * attribute 'attribute' isn't a valid property in - * 'expression'

+ * attribute attribute isn't a valid property in + * expression

*/ - UNKNOWN_ATTRIBUTE_IN_SCOPE(66, "attribute '' isn't a valid property in ''", ErrorSeverity.ERROR), + UNKNOWN_ATTRIBUTE_IN_SCOPE(66, "attribute isn't a valid property in ", ErrorSeverity.ERROR), /** * Compiler Error 67. * *

- * missing attribute access on rule reference 'rule' in - * 'expression'

+ * missing attribute access on rule reference rule in + * expression

*/ - ISOLATED_RULE_REF(67, "missing attribute access on rule reference '' in ''", ErrorSeverity.ERROR), + ISOLATED_RULE_REF(67, "missing attribute access on rule reference in ", ErrorSeverity.ERROR), /** * Compiler Error 69. * - *

label 'label' conflicts with rule with same name

+ *

label label conflicts with rule with same name

*/ - LABEL_CONFLICTS_WITH_RULE(69, "label '' conflicts with rule with same name", ErrorSeverity.ERROR), + LABEL_CONFLICTS_WITH_RULE(69, "label conflicts with rule with same name", ErrorSeverity.ERROR), /** * Compiler Error 70. * - *

label 'label' conflicts with token with same name

+ *

label label conflicts with token with same name

*/ - LABEL_CONFLICTS_WITH_TOKEN(70, "label '' conflicts with token with same name", ErrorSeverity.ERROR), + LABEL_CONFLICTS_WITH_TOKEN(70, "label conflicts with token with same name", ErrorSeverity.ERROR), /** * Compiler Error 72. * - *

label 'label' conflicts with parameter with same name

+ *

label label conflicts with parameter with same name

*/ - LABEL_CONFLICTS_WITH_ARG(72, "label '' conflicts with parameter with same name", ErrorSeverity.ERROR), + LABEL_CONFLICTS_WITH_ARG(72, "label conflicts with parameter with same name", ErrorSeverity.ERROR), /** * Compiler Error 73. * - *

label 'label' conflicts with return value with same name

+ *

label label conflicts with return value with same name

*/ - LABEL_CONFLICTS_WITH_RETVAL(73, "label '' conflicts with return value with same name", ErrorSeverity.ERROR), + LABEL_CONFLICTS_WITH_RETVAL(73, "label conflicts with return value with same name", ErrorSeverity.ERROR), /** * Compiler Error 74. * - *

label 'label' conflicts with local with same name

+ *

label label conflicts with local with same name

*/ - LABEL_CONFLICTS_WITH_LOCAL(74, "label '' conflicts with local with same name", ErrorSeverity.ERROR), + LABEL_CONFLICTS_WITH_LOCAL(74, "label conflicts with local with same name", ErrorSeverity.ERROR), /** * Compiler Error 75. * *

- * label 'label' type mismatch with previous definition: + * label label type mismatch with previous definition: * message

*/ - LABEL_TYPE_CONFLICT(75, "label '' type mismatch with previous definition: ", ErrorSeverity.ERROR), + LABEL_TYPE_CONFLICT(75, "label type mismatch with previous definition: ", ErrorSeverity.ERROR), /** * Compiler Error 76. * *

- * return value 'name' conflicts with parameter with same name

+ * return value name conflicts with parameter with same name

*/ - RETVAL_CONFLICTS_WITH_ARG(76, "return value '' conflicts with parameter with same name", ErrorSeverity.ERROR), + RETVAL_CONFLICTS_WITH_ARG(76, "return value conflicts with parameter with same name", ErrorSeverity.ERROR), /** * Compiler Error 79. * @@ -326,38 +332,38 @@ public enum ErrorType { /** * Compiler Error 80. * - *

rule 'rule' has no defined parameters

+ *

rule rule has no defined parameters

*/ - RULE_HAS_NO_ARGS(80, "rule '' has no defined parameters", ErrorSeverity.ERROR), + RULE_HAS_NO_ARGS(80, "rule has no defined parameters", ErrorSeverity.ERROR), /** * Compiler Warning 83. * - *

unsupported option 'option'

+ *

unsupported option option

*/ - ILLEGAL_OPTION(83, "unsupported option ''", ErrorSeverity.WARNING), + ILLEGAL_OPTION(83, "unsupported option ", ErrorSeverity.WARNING), /** * Compiler Warning 84. * - *

unsupported option value 'name=value'

+ *

unsupported option value name=value

*/ - ILLEGAL_OPTION_VALUE(84, "unsupported option value '='", ErrorSeverity.WARNING), + ILLEGAL_OPTION_VALUE(84, "unsupported option value =", ErrorSeverity.WARNING), /** * Compiler Error 94. * - *

redefinition of 'action' action

+ *

redefinition of action action

*/ - ACTION_REDEFINITION(94, "redefinition of '' action", ErrorSeverity.ERROR), + ACTION_REDEFINITION(94, "redefinition of action", ErrorSeverity.ERROR), /** * Compiler Error 99. * *

This error may take any of the following forms.

* *
    - *
  • grammar 'grammar' has no rules
  • - *
  • implicitly generated grammar 'grammar' has no rules
  • + *
  • grammar grammar has no rules
  • + *
  • implicitly generated grammar grammar has no rules
  • *
*/ - NO_RULES(99, "implicitly generated grammar '' has no rules", ErrorSeverity.ERROR), + NO_RULES(99, "implicitly generated grammar has no rules", ErrorSeverity.ERROR), /** * Compiler Error 105. * @@ -369,54 +375,60 @@ public enum ErrorType { /** * Compiler Error 106. * - *

rule 'rule' is not defined in grammar 'grammar'

+ *

rule rule is not defined in grammar grammar

*/ - NO_SUCH_RULE_IN_SCOPE(106, "rule '' is not defined in grammar ''", ErrorSeverity.ERROR), + NO_SUCH_RULE_IN_SCOPE(106, "rule is not defined in grammar ", ErrorSeverity.ERROR), /** * Compiler Warning 108. * - *

token name 'Token' is already defined

+ *

token name Token is already defined

*/ - TOKEN_NAME_REASSIGNMENT(108, "token name '' is already defined", ErrorSeverity.WARNING), + TOKEN_NAME_REASSIGNMENT(108, "token name is already defined", ErrorSeverity.WARNING), /** * Compiler Warning 109. * - *

options ignored in imported grammar 'grammar'

+ *

options ignored in imported grammar grammar

*/ - OPTIONS_IN_DELEGATE(109, "options ignored in imported grammar ''", ErrorSeverity.WARNING), + OPTIONS_IN_DELEGATE(109, "options ignored in imported grammar ", ErrorSeverity.WARNING), /** * Compiler Error 110. * *

- * can't find or load grammar 'grammar' from - * 'filename'

+ * can't find or load grammar grammar from + * filename

*/ - CANNOT_FIND_IMPORTED_GRAMMAR(110, "can't find or load grammar '' from ''", ErrorSeverity.ERROR), + CANNOT_FIND_IMPORTED_GRAMMAR(110, "can't find or load grammar ", ErrorSeverity.ERROR), /** * Compiler Error 111. * *

- * grammartype grammar 'grammar1' cannot import - * grammartype grammar 'grammar2'

+ * grammartype grammar grammar1 cannot import + * grammartype grammar grammar2

*/ - INVALID_IMPORT(111, " grammar '' cannot import grammar ''", ErrorSeverity.ERROR), + INVALID_IMPORT(111, " grammar cannot import grammar ", ErrorSeverity.ERROR), /** * Compiler Error 113. * *

- * grammartype grammar 'grammar1' and imported - * grammartype grammar 'grammar2' both generate - * 'recognizer'

+ * grammartype grammar grammar1 and imported + * grammartype grammar grammar2 both generate + * recognizer

*/ - IMPORT_NAME_CLASH(113, " grammar '' and imported grammar '' both generate ''", ErrorSeverity.ERROR), + IMPORT_NAME_CLASH(113, " grammar and imported grammar both generate ", ErrorSeverity.ERROR), + /** + * Compiler Error 160. + * + *

cannot find tokens file filename

+ */ + CANNOT_FIND_TOKENS_FILE_REFD_IN_GRAMMAR(160, "cannot find tokens file ", ErrorSeverity.ERROR), /** * Compiler Warning 118. * *

- * all operators of alt 'alt' of left-recursive rule must have same + * all operators of alt alt of left-recursive rule must have same * associativity

*/ - ALL_OPS_NEED_SAME_ASSOC(118, "all operators of alt '' of left-recursive rule must have same associativity", ErrorSeverity.WARNING), + ALL_OPS_NEED_SAME_ASSOC(118, "all operators of alt of left-recursive rule must have same associativity", ErrorSeverity.WARNING), /** * Compiler Error 119. * @@ -440,30 +452,30 @@ public enum ErrorType { /** * Compiler Error 122. * - *

rule 'rule': must label all alternatives or none

+ *

rule rule: must label all alternatives or none

*/ - RULE_WITH_TOO_FEW_ALT_LABELS(122, "rule '': must label all alternatives or none", ErrorSeverity.ERROR), + RULE_WITH_TOO_FEW_ALT_LABELS(122, "rule : must label all alternatives or none", ErrorSeverity.ERROR), /** * Compiler Error 123. * *

- * rule alt label 'label' redefined in rule 'rule1', - * originally in rule 'rule2'

+ * rule alt label label redefined in rule rule1, + * originally in rule rule2

*/ - ALT_LABEL_REDEF(123, "rule alt label '' redefined in rule '', originally in rule ''", ErrorSeverity.ERROR), + ALT_LABEL_REDEF(123, "rule alt label redefined in rule , originally in rule ", ErrorSeverity.ERROR), /** * Compiler Error 124. * *

- * rule alt label 'label' conflicts with rule 'rule'

+ * rule alt label label conflicts with rule rule

*/ - ALT_LABEL_CONFLICTS_WITH_RULE(124, "rule alt label '' conflicts with rule ''", ErrorSeverity.ERROR), + ALT_LABEL_CONFLICTS_WITH_RULE(124, "rule alt label conflicts with rule ", ErrorSeverity.ERROR), /** * Compiler Warning 125. * - *

implicit definition of token 'Token' in parser

+ *

implicit definition of token Token in parser

*/ - IMPLICIT_TOKEN_DEFINITION(125, "implicit definition of token '' in parser", ErrorSeverity.WARNING), + IMPLICIT_TOKEN_DEFINITION(125, "implicit definition of token in parser", ErrorSeverity.WARNING), /** * Compiler Error 126. * @@ -483,9 +495,9 @@ public enum ErrorType { /** * Compiler Error 130. * - *

label 'label' assigned to a block which is not a set

+ *

label label assigned to a block which is not a set

*/ - LABEL_BLOCK_NOT_A_SET(130, "label '' assigned to a block which is not a set", ErrorSeverity.ERROR), + LABEL_BLOCK_NOT_A_SET(130, "label assigned to a block which is not a set", ErrorSeverity.ERROR), /** * Compiler Warning 131. * @@ -501,97 +513,97 @@ public enum ErrorType { * Compiler Error 132. * *

- * action in lexer rule 'rule' must be last element of single + * action in lexer rule rule must be last element of single * outermost alt

* * @deprecated This error is no longer issued by ANTLR 4.2. */ @Deprecated - LEXER_ACTION_PLACEMENT_ISSUE(132, "action in lexer rule '' must be last element of single outermost alt", ErrorSeverity.ERROR), + LEXER_ACTION_PLACEMENT_ISSUE(132, "action in lexer rule must be last element of single outermost alt", ErrorSeverity.ERROR), /** * Compiler Error 133. * *

- * {@code ->command} in lexer rule 'rule' must be last element of + * {@code ->command} in lexer rule rule must be last element of * single outermost alt

*/ - LEXER_COMMAND_PLACEMENT_ISSUE(133, "->command in lexer rule '' must be last element of single outermost alt", ErrorSeverity.ERROR), + LEXER_COMMAND_PLACEMENT_ISSUE(133, "->command in lexer rule must be last element of single outermost alt", ErrorSeverity.ERROR), /** * Compiler Error 134. * *

- * symbol 'symbol' conflicts with generated code in target language + * symbol symbol conflicts with generated code in target language * or runtime

* *

* Note: This error has the same number as the unrelated error * {@link #UNSUPPORTED_REFERENCE_IN_LEXER_SET}.

*/ - USE_OF_BAD_WORD(134, "symbol '' conflicts with generated code in target language or runtime", ErrorSeverity.ERROR), + USE_OF_BAD_WORD(134, "symbol conflicts with generated code in target language or runtime", ErrorSeverity.ERROR), /** * Compiler Error 134. * - *

rule reference 'rule' is not currently supported in a set

+ *

rule reference rule is not currently supported in a set

* *

* Note: This error has the same number as the unrelated error * {@link #USE_OF_BAD_WORD}.

*/ - UNSUPPORTED_REFERENCE_IN_LEXER_SET(134, "rule reference '' is not currently supported in a set", ErrorSeverity.ERROR), + UNSUPPORTED_REFERENCE_IN_LEXER_SET(134, "rule reference is not currently supported in a set", ErrorSeverity.ERROR), /** * Compiler Error 135. * - *

cannot assign a value to list label 'label'

+ *

cannot assign a value to list label label

*/ - ASSIGNMENT_TO_LIST_LABEL(135, "cannot assign a value to list label ''", ErrorSeverity.ERROR), + ASSIGNMENT_TO_LIST_LABEL(135, "cannot assign a value to list label ", ErrorSeverity.ERROR), /** * Compiler Error 136. * - *

return value 'name' conflicts with rule with same name

+ *

return value name conflicts with rule with same name

*/ - RETVAL_CONFLICTS_WITH_RULE(136, "return value '' conflicts with rule with same name", ErrorSeverity.ERROR), + RETVAL_CONFLICTS_WITH_RULE(136, "return value conflicts with rule with same name", ErrorSeverity.ERROR), /** * Compiler Error 137. * - *

return value 'name' conflicts with token with same name

+ *

return value name conflicts with token with same name

*/ - RETVAL_CONFLICTS_WITH_TOKEN(137, "return value '' conflicts with token with same name", ErrorSeverity.ERROR), + RETVAL_CONFLICTS_WITH_TOKEN(137, "return value conflicts with token with same name", ErrorSeverity.ERROR), /** * Compiler Error 138. * - *

parameter 'parameter' conflicts with rule with same name

+ *

parameter parameter conflicts with rule with same name

*/ - ARG_CONFLICTS_WITH_RULE(138, "parameter '' conflicts with rule with same name", ErrorSeverity.ERROR), + ARG_CONFLICTS_WITH_RULE(138, "parameter conflicts with rule with same name", ErrorSeverity.ERROR), /** * Compiler Error 139. * - *

parameter 'parameter' conflicts with token with same name

+ *

parameter parameter conflicts with token with same name

*/ - ARG_CONFLICTS_WITH_TOKEN(139, "parameter '' conflicts with token with same name", ErrorSeverity.ERROR), + ARG_CONFLICTS_WITH_TOKEN(139, "parameter conflicts with token with same name", ErrorSeverity.ERROR), /** * Compiler Error 140. * - *

local 'local' conflicts with rule with same name

+ *

local local conflicts with rule with same name

*/ - LOCAL_CONFLICTS_WITH_RULE(140, "local '' conflicts with rule with same name", ErrorSeverity.ERROR), + LOCAL_CONFLICTS_WITH_RULE(140, "local conflicts with rule with same name", ErrorSeverity.ERROR), /** * Compiler Error 141. * - *

local 'local' conflicts with rule token same name

+ *

local local conflicts with rule token same name

*/ - LOCAL_CONFLICTS_WITH_TOKEN(141, "local '' conflicts with rule token same name", ErrorSeverity.ERROR), + LOCAL_CONFLICTS_WITH_TOKEN(141, "local conflicts with rule token same name", ErrorSeverity.ERROR), /** * Compiler Error 142. * - *

local 'local' conflicts with parameter with same name

+ *

local local conflicts with parameter with same name

*/ - LOCAL_CONFLICTS_WITH_ARG(142, "local '' conflicts with parameter with same name", ErrorSeverity.ERROR), + LOCAL_CONFLICTS_WITH_ARG(142, "local conflicts with parameter with same name", ErrorSeverity.ERROR), /** * Compiler Error 143. * - *

local 'local' conflicts with return value with same name

+ *

local local conflicts with return value with same name

*/ - LOCAL_CONFLICTS_WITH_RETVAL(143, "local '' conflicts with return value with same name", ErrorSeverity.ERROR), + LOCAL_CONFLICTS_WITH_RETVAL(143, "local conflicts with return value with same name", ErrorSeverity.ERROR), /** * Compiler Error 144. * @@ -604,18 +616,18 @@ public enum ErrorType { * Compiler Error 145. * *

- * lexer mode 'mode' must contain at least one non-fragment + * lexer mode mode must contain at least one non-fragment * rule

* *

* Every lexer mode must contain at least one rule which is not declared * with the {@code fragment} modifier.

*/ - MODE_WITHOUT_RULES(145, "lexer mode '' must contain at least one non-fragment rule", ErrorSeverity.ERROR), + MODE_WITHOUT_RULES(145, "lexer mode must contain at least one non-fragment rule", ErrorSeverity.ERROR), /** * Compiler Warning 146. * - *

non-fragment lexer rule 'rule' can match the empty string

+ *

non-fragment lexer rule rule can match the empty string

* *

All non-fragment lexer rules must match at least one character.

* @@ -630,12 +642,12 @@ public enum ErrorType { * Whitespace : [ \t]*; // error 146 * */ - EPSILON_TOKEN(146, "non-fragment lexer rule '' can match the empty string", ErrorSeverity.WARNING), + EPSILON_TOKEN(146, "non-fragment lexer rule can match the empty string", ErrorSeverity.WARNING), /** * Compiler Error 147. * *

- * left recursive rule 'rule' must contain an alternative which is + * left recursive rule rule must contain an alternative which is * not left recursive

* *

Left-recursive rules must contain at least one alternative which is not @@ -650,12 +662,12 @@ public enum ErrorType { * ; * */ - NO_NON_LR_ALTS(147, "left recursive rule '' must contain an alternative which is not left recursive", ErrorSeverity.ERROR), + NO_NON_LR_ALTS(147, "left recursive rule must contain an alternative which is not left recursive", ErrorSeverity.ERROR), /** * Compiler Error 148. * *

- * left recursive rule 'rule' contains a left recursive alternative + * left recursive rule rule contains a left recursive alternative * which can be followed by the empty string

* *

In left-recursive rules, all left-recursive alternatives must match at @@ -670,12 +682,12 @@ public enum ErrorType { * ; * */ - EPSILON_LR_FOLLOW(148, "left recursive rule '' contains a left recursive alternative which can be followed by the empty string", ErrorSeverity.ERROR), + EPSILON_LR_FOLLOW(148, "left recursive rule contains a left recursive alternative which can be followed by the empty string", ErrorSeverity.ERROR), /** * Compiler Error 149. * *

- * lexer command 'command' does not exist or is not supported by + * lexer command command does not exist or is not supported by * the current target

* *

Each lexer command requires an explicit implementation in the target @@ -685,34 +697,34 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * X : 'foo' -> type(Foo);  // ok
-	 * Y : 'foo' -> token(Foo); // error 149 (token is not a supported lexer command)
+	 * X : foo -> type(Foo);  // ok
+	 * Y : foo -> token(Foo); // error 149 (token is not a supported lexer command)
 	 * 
* * @since 4.1 */ - INVALID_LEXER_COMMAND(149, "lexer command '' does not exist or is not supported by the current target", ErrorSeverity.ERROR), + INVALID_LEXER_COMMAND(149, "lexer command does not exist or is not supported by the current target", ErrorSeverity.ERROR), /** * Compiler Error 150. * - *

missing argument for lexer command 'command'

+ *

missing argument for lexer command command

* *

Some lexer commands require an argument.

* *

The following rule produces this error.

* *
-	 * X : 'foo' -> type(Foo); // ok
-	 * Y : 'foo' -> type;      // error 150 (the type command requires an argument)
+	 * X : foo -> type(Foo); // ok
+	 * Y : foo -> type;      // error 150 (the type command requires an argument)
 	 * 
* * @since 4.1 */ - MISSING_LEXER_COMMAND_ARGUMENT(150, "missing argument for lexer command ''", ErrorSeverity.ERROR), + MISSING_LEXER_COMMAND_ARGUMENT(150, "missing argument for lexer command ", ErrorSeverity.ERROR), /** * Compiler Error 151. * - *

lexer command 'command' does not take any arguments

+ *

lexer command command does not take any arguments

* *

A lexer command which does not take parameters was invoked with an * argument.

@@ -720,13 +732,13 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * X : 'foo' -> popMode;    // ok
-	 * Y : 'foo' -> popMode(A); // error 151 (the popMode command does not take an argument)
+	 * X : foo -> popMode;    // ok
+	 * Y : foo -> popMode(A); // error 151 (the popMode command does not take an argument)
 	 * 
* * @since 4.1 */ - UNWANTED_LEXER_COMMAND_ARGUMENT(151, "lexer command '' does not take any arguments", ErrorSeverity.ERROR), + UNWANTED_LEXER_COMMAND_ARGUMENT(151, "lexer command does not take any arguments", ErrorSeverity.ERROR), /** * Compiler Error 152. * @@ -737,8 +749,8 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * x : 'x'; // ok
-	 * y : 'y;  // error 152
+	 * x : x; // ok
+	 * y : y;  // error 152
 	 * 
* * @since 4.1 @@ -748,7 +760,7 @@ public enum ErrorType { * Compiler Error 153. * *

- * rule 'rule' contains a closure with at least one alternative + * rule rule contains a closure with at least one alternative * that can match an empty string

* *

A rule contains a closure ({@code (...)*}) or positive closure @@ -759,18 +771,18 @@ public enum ErrorType { *

 	 * x  : ;
 	 * y  : x+;                                // error 153
-	 * z1 : ('foo' | 'bar'? 'bar2'?)*;         // error 153
-	 * z2 : ('foo' | 'bar' 'bar2'? | 'bar2')*; // ok
+	 * z1 : (foo | bar? bar2?)*;         // error 153
+	 * z2 : (foo | bar bar2? | bar2)*; // ok
 	 * 
* * @since 4.1 */ - EPSILON_CLOSURE(153, "rule '' contains a closure with at least one alternative that can match an empty string", ErrorSeverity.ERROR), + EPSILON_CLOSURE(153, "rule contains a closure with at least one alternative that can match an empty string", ErrorSeverity.ERROR), /** * Compiler Warning 154. * *

- * rule 'rule' contains an optional block with at least one + * rule rule contains an optional block with at least one * alternative that can match an empty string

* *

A rule contains an optional block ({@code (...)?}) around an empty @@ -781,18 +793,18 @@ public enum ErrorType { *

 	 * x  : ;
 	 * y  : x?;                                // warning 154
-	 * z1 : ('foo' | 'bar'? 'bar2'?)?;         // warning 154
-	 * z2 : ('foo' | 'bar' 'bar2'? | 'bar2')?; // ok
+	 * z1 : (foo | bar? bar2?)?;         // warning 154
+	 * z2 : (foo | bar bar2? | bar2)?; // ok
 	 * 
* * @since 4.1 */ - EPSILON_OPTIONAL(154, "rule '' contains an optional block with at least one alternative that can match an empty string", ErrorSeverity.WARNING), + EPSILON_OPTIONAL(154, "rule contains an optional block with at least one alternative that can match an empty string", ErrorSeverity.WARNING), /** * Compiler Warning 155. * *

- * rule 'rule' contains a lexer command with an unrecognized + * rule rule contains a lexer command with an unrecognized * constant value; lexer interpreters may produce incorrect output

* *

A lexer rule contains a standard lexer command, but the constant value @@ -808,13 +820,13 @@ public enum ErrorType { * public static final int CUSTOM = HIDDEN + 1; * } * - * X : 'foo' -> channel(HIDDEN); // ok - * Y : 'bar' -> channel(CUSTOM); // warning 155 + * X : foo -> channel(HIDDEN); // ok + * Y : bar -> channel(CUSTOM); // warning 155 * * * @since 4.2 */ - UNKNOWN_LEXER_CONSTANT(155, "rule '' contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output", ErrorSeverity.WARNING), + UNKNOWN_LEXER_CONSTANT(155, "rule contains a lexer command with an unrecognized constant value; lexer interpreters may produce incorrect output", ErrorSeverity.WARNING), /** * Compiler Error 156. * @@ -825,8 +837,8 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * x : 'x';  // ok
-	 * y : '\u005Cu'; // error 156
+	 * x : x;  // ok
+	 * y : \u005Cu; // error 156
 	 * 
* * @since 4.2.1 @@ -835,7 +847,7 @@ public enum ErrorType { /** * Compiler Warning 157. * - *

rule 'rule' contains an 'assoc' element option in an + *

rule rule contains an assoc element option in an * unrecognized location

* *

@@ -849,19 +861,19 @@ public enum ErrorType { *

The following rule produces this warning.

* *
-	 * x : 'x'
-	 *   | x '+'<assoc=right> x   // warning 157
-	 *   |<assoc=right> x '*' x   // ok
+	 * x : x
+	 *   | x +<assoc=right> x   // warning 157
+	 *   |<assoc=right> x * x   // ok
 	 *   ;
 	 * 
* * @since 4.2.1 */ - UNRECOGNIZED_ASSOC_OPTION(157, "rule '' contains an 'assoc' terminal option in an unrecognized location", ErrorSeverity.WARNING), + UNRECOGNIZED_ASSOC_OPTION(157, "rule contains an assoc terminal option in an unrecognized location", ErrorSeverity.WARNING), /** * Compiler Warning 158. * - *

fragment rule 'rule' contains an action or command which can + *

fragment rule rule contains an action or command which can * never be executed

* *

A lexer rule which is marked with the {@code fragment} modifier @@ -874,38 +886,38 @@ public enum ErrorType { *

The following rule produces this warning.

* *
-	 * X1 : 'x' -> more    // ok
+	 * X1 : x -> more    // ok
 	 *    ;
-	 * Y1 : 'x' {more();}  // ok
+	 * Y1 : x {more();}  // ok
 	 *    ;
 	 * fragment
-	 * X2 : 'x' -> more    // warning 158
+	 * X2 : x -> more    // warning 158
 	 *    ;
 	 * fragment
-	 * Y2 : 'x' {more();}  // warning 158
+	 * Y2 : x {more();}  // warning 158
 	 *    ;
 	 * 
* * @since 4.2.1 */ - FRAGMENT_ACTION_IGNORED(158, "fragment rule '' contains an action or command which can never be executed", ErrorSeverity.WARNING), + FRAGMENT_ACTION_IGNORED(158, "fragment rule contains an action or command which can never be executed", ErrorSeverity.WARNING), /** * Compiler Error 159. * - *

cannot declare a rule with reserved name 'rule'

+ *

cannot declare a rule with reserved name rule

* *

A rule was declared with a reserved name.

* *

The following rule produces this error.

* *
-	 * EOF : ' '   // error 159 (EOF is a reserved name)
+	 * EOF :     // error 159 (EOF is a reserved name)
 	 *     ;
 	 * 
* * @since 4.2.1 */ - RESERVED_RULE_NAME(159, "cannot declare a rule with reserved name ''", ErrorSeverity.ERROR), + RESERVED_RULE_NAME(159, "cannot declare a rule with reserved name ", ErrorSeverity.ERROR), /* * Backward incompatibility errors @@ -944,7 +956,7 @@ public enum ErrorType { * Compiler Warning 202. * *

- * '{@code tokens {A; B;}}' syntax is now '{@code tokens {A, B}}' in ANTLR + * {@code tokens {A; B;}} syntax is now {@code tokens {A, B}} in ANTLR * 4

* *

@@ -956,13 +968,13 @@ public enum ErrorType { * NOTE: ANTLR 4 does not allow a trailing comma to appear following the * last token declared in the {@code tokens{}} block.

*/ - V3_TOKENS_SYNTAX(202, "'tokens {A; B;}' syntax is now 'tokens {A, B}' in ANTLR 4", ErrorSeverity.WARNING), + V3_TOKENS_SYNTAX(202, "tokens {A; B;} syntax is now tokens {A, B} in ANTLR 4", ErrorSeverity.WARNING), /** * Compiler Error 203. * *

* assignments in {@code tokens{}} are not supported in ANTLR 4; use lexical - * rule 'TokenName : LiteralValue;' instead

+ * rule TokenName : LiteralValue; instead

* *

* ANTLR 3 allowed literal tokens to be declared and assigned a value within @@ -971,7 +983,7 @@ public enum ErrorType { * value declared in the {@code tokens{}} block should be converted to * standard lexer rules.

*/ - V3_ASSIGN_IN_TOKENS(203, "assignments in tokens{} are not supported in ANTLR 4; use lexical rule ' : ;' instead", ErrorSeverity.ERROR), + V3_ASSIGN_IN_TOKENS(203, "assignments in tokens{} are not supported in ANTLR 4; use lexical rule : ; instead", ErrorSeverity.ERROR), /** * Compiler Warning 204. * @@ -993,7 +1005,7 @@ public enum ErrorType { *

{@code (...)=>} syntactic predicates are not supported in ANTLR 4

* *

- * ANTLR 4's improved lookahead algorithms do not require the use of + * ANTLR 4s improved lookahead algorithms do not require the use of * syntactic predicates to disambiguate long lookahead sequences. The * syntactic predicates should be removed when migrating a grammar from * ANTLR 3 to ANTLR 4.

diff --git a/tool/src/org/antlr/v4/tool/Grammar.java b/tool/src/org/antlr/v4/tool/Grammar.java index fbdcbdf17..a716ebc72 100644 --- a/tool/src/org/antlr/v4/tool/Grammar.java +++ b/tool/src/org/antlr/v4/tool/Grammar.java @@ -30,6 +30,7 @@ package org.antlr.v4.tool; +import org.antlr.runtime.tree.Tree; import org.antlr.v4.Tool; import org.antlr.v4.analysis.LeftRecursiveRuleTransformer; import org.antlr.v4.misc.CharSupport; @@ -355,7 +356,8 @@ public class Grammar implements AttributeResolver { GrammarAST t = (GrammarAST)c; String importedGrammarName = null; if ( t.getType()==ANTLRParser.ASSIGN ) { - importedGrammarName = t.getChild(1).getText(); + t = (GrammarAST)t.getChild(1); + importedGrammarName = t.getText(); tool.log("grammar", "import "+ importedGrammarName); } else if ( t.getType()==ANTLRParser.ID ) { @@ -364,11 +366,14 @@ public class Grammar implements AttributeResolver { } Grammar g; try { - g = tool.loadImportedGrammar(this, importedGrammarName); + g = tool.loadImportedGrammar(this, t); } catch (IOException ioe) { - tool.errMgr.toolError(ErrorType.CANNOT_FIND_IMPORTED_GRAMMAR, ioe, - importedGrammarName); + tool.errMgr.grammarError(ErrorType.ERROR_READING_IMPORTED_GRAMMAR, + importedGrammarName, + t.getToken(), + importedGrammarName, + name); continue; } // did it come back as error node or missing? @@ -811,7 +816,7 @@ public class Grammar implements AttributeResolver { public void importTokensFromTokensFile() { String vocab = getOptionString("tokenVocab"); if ( vocab!=null ) { - TokenVocabParser vparser = new TokenVocabParser(tool, vocab); + TokenVocabParser vparser = new TokenVocabParser(this); Map tokens = vparser.load(); tool.log("grammar", "tokens=" + tokens); for (String t : tokens.keySet()) { diff --git a/tool/src/org/antlr/v4/tool/GrammarSemanticsMessage.java b/tool/src/org/antlr/v4/tool/GrammarSemanticsMessage.java index 9f1475a96..72e750122 100644 --- a/tool/src/org/antlr/v4/tool/GrammarSemanticsMessage.java +++ b/tool/src/org/antlr/v4/tool/GrammarSemanticsMessage.java @@ -33,40 +33,17 @@ package org.antlr.v4.tool; import org.antlr.runtime.Token; /** A problem with the symbols and/or meaning of a grammar such as rule - * redefinition. + * redefinition. Any msg where we can point to a location in the grammar. */ public class GrammarSemanticsMessage extends ANTLRMessage { - public Grammar g; - /** Most of the time, we'll have a token such as an undefined rule ref - * and so this will be set. - */ - public Token offendingToken; - - /* - public GrammarSemanticsMessage(ErrorType etype, - Grammar g, - Token offendingToken, - Object... args) - { - super(etype,args); - this.g = g; - if ( g!=null ) fileName = g.fileName; - this.offendingToken = offendingToken; - if ( offendingToken!=null ) { - line = offendingToken.getLine(); - charPosition = offendingToken.getCharPositionInLine(); - } - } -*/ public GrammarSemanticsMessage(ErrorType etype, String fileName, Token offendingToken, Object... args) { - super(etype,args); + super(etype,offendingToken,args); this.fileName = fileName; - this.offendingToken = offendingToken; - if ( offendingToken!=null ) { + if ( offendingToken!=null ) { line = offendingToken.getLine(); charPosition = offendingToken.getCharPositionInLine(); } diff --git a/tool/src/org/antlr/v4/tool/GrammarSyntaxMessage.java b/tool/src/org/antlr/v4/tool/GrammarSyntaxMessage.java index 8c4767c29..4648a84d1 100644 --- a/tool/src/org/antlr/v4/tool/GrammarSyntaxMessage.java +++ b/tool/src/org/antlr/v4/tool/GrammarSyntaxMessage.java @@ -37,17 +37,13 @@ import org.antlr.runtime.Token; * "The '{' came as a complete surprise to me at this point in your program" */ public class GrammarSyntaxMessage extends ANTLRMessage { - public Grammar g; - /** Most of the time, we'll have a token and so this will be set. */ - public Token offendingToken; - public GrammarSyntaxMessage(ErrorType etype, String fileName, Token offendingToken, RecognitionException antlrException, Object... args) { - super(etype, antlrException, args); + super(etype, antlrException, offendingToken, args); this.fileName = fileName; this.offendingToken = offendingToken; if ( offendingToken!=null ) { diff --git a/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java b/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java index c04d6e515..5e352d3bf 100644 --- a/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java +++ b/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java @@ -30,14 +30,13 @@ package org.antlr.v4.tool; +import org.antlr.runtime.Token; + import java.util.Collection; public class LeftRecursionCyclesMessage extends ANTLRMessage { - public Collection> cycles; - - public LeftRecursionCyclesMessage(String fileName, Collection> cycles) { - super(ErrorType.LEFT_RECURSION_CYCLES, cycles); - this.cycles = cycles; + public LeftRecursionCyclesMessage(String fileName, Token startTokenOfFirstRuleInCycle, Collection> cycles) { + super(ErrorType.LEFT_RECURSION_CYCLES, startTokenOfFirstRuleInCycle, cycles); this.fileName = fileName; } } diff --git a/tool/src/org/antlr/v4/tool/ToolMessage.java b/tool/src/org/antlr/v4/tool/ToolMessage.java index 3283d4bde..422eda232 100644 --- a/tool/src/org/antlr/v4/tool/ToolMessage.java +++ b/tool/src/org/antlr/v4/tool/ToolMessage.java @@ -30,6 +30,8 @@ package org.antlr.v4.tool; +import org.antlr.runtime.Token; + /** A generic message from the tool such as "file not found" type errors; there * is no reason to create a special object for each error unlike the grammar * errors, which may be rather complex. @@ -43,9 +45,9 @@ public class ToolMessage extends ANTLRMessage { super(errorType); } public ToolMessage(ErrorType errorType, Object... args) { - super(errorType, null, args); + super(errorType, null, Token.INVALID_TOKEN, args); } public ToolMessage(ErrorType errorType, Throwable e, Object... args) { - super(errorType, e, args); + super(errorType, e, Token.INVALID_TOKEN, args); } } diff --git a/tool/test/org/antlr/v4/test/TestAttributeChecks.java b/tool/test/org/antlr/v4/test/TestAttributeChecks.java index a3b23700d..7cb8fed61 100644 --- a/tool/test/org/antlr/v4/test/TestAttributeChecks.java +++ b/tool/test/org/antlr/v4/test/TestAttributeChecks.java @@ -16,7 +16,7 @@ * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, @@ -55,8 +55,8 @@ public class TestAttributeChecks extends BaseTest { "c : ;\n"; String[] membersChecks = { - "$a", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference 'a' in '$a'\n", - "$a.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference 'a' in '$a.y'\n", + "$a", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a\n", + "$a.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference a in $a.y\n", }; String[] initChecks = { @@ -68,8 +68,8 @@ public class TestAttributeChecks extends BaseTest { "$ids", "", "$labs", "", - "$c", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference 'c' in '$c'\n", - "$a.q", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:10: unknown attribute 'q' for rule 'a' in '$a.q'\n", + "$c", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference c in $c\n", + "$a.q", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:10: unknown attribute q for rule a in $a.q\n", }; String[] inlineChecks = { @@ -92,21 +92,21 @@ public class TestAttributeChecks extends BaseTest { }; String[] bad_inlineChecks = { - "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference 'lab' in '$lab'\n", - "$q", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q'\n", - "$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q.y'\n", - "$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q'\n", - "$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q = 3;'\n", - "$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q.y'\n", - "$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'q' in '$q = $blort;'\n" + - "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:9: unknown attribute reference 'blort' in '$blort'\n", - "$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute 'ick' for rule 'a' in '$a.ick'\n", - "$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute 'ick' for rule 'a' in '$a.ick'\n", - "$b.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:6: parameter 'd' of rule 'b' is not accessible in this scope: $b.d\n", // can't see rule ref's arg - "$d.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'd' in '$d.text'\n", // valid rule, but no ref - "$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:8: parameter 'd' of rule 'b' is not accessible in this scope: $lab.d\n", - "$ids = null;", "error(" + ErrorType.ASSIGNMENT_TO_LIST_LABEL.code + "): A.g4:7:4: cannot assign a value to list label 'ids'\n", - "$labs = null;","error(" + ErrorType.ASSIGNMENT_TO_LIST_LABEL.code + "): A.g4:7:4: cannot assign a value to list label 'labs'\n", + "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference lab in $lab\n", + "$q", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q\n", + "$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q.y\n", + "$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q\n", + "$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q = 3;\n", + "$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q.y\n", + "$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference q in $q = $blort;\n" + + "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:9: unknown attribute reference blort in $blort\n", + "$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute ick for rule a in $a.ick\n", + "$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:6: unknown attribute ick for rule a in $a.ick\n", + "$b.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:6: parameter d of rule b is not accessible in this scope: $b.d\n", // cant see rule refs arg + "$d.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference d in $d.text\n", // valid rule, but no ref + "$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:7:8: parameter d of rule b is not accessible in this scope: $lab.d\n", + "$ids = null;", "error(" + ErrorType.ASSIGNMENT_TO_LIST_LABEL.code + "): A.g4:7:4: cannot assign a value to list label ids\n", + "$labs = null;","error(" + ErrorType.ASSIGNMENT_TO_LIST_LABEL.code + "): A.g4:7:4: cannot assign a value to list label labs\n", }; String[] finallyChecks = { @@ -121,97 +121,97 @@ public class TestAttributeChecks extends BaseTest { "$ids", "", "$labs", "", - "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference 'lab' in '$lab'\n", - "$q", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q'\n", - "$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q.y'\n", - "$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q'\n", - "$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q = 3;'\n", - "$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q.y'\n", - "$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'q' in '$q = $blort;'\n" + - "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:19: unknown attribute reference 'blort' in '$blort'\n", - "$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute 'ick' for rule 'a' in '$a.ick'\n", - "$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute 'ick' for rule 'a' in '$a.ick'\n", - "$b.e", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'b' in '$b.e'\n", // can't see rule refs outside alts - "$b.d", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'b' in '$b.d'\n", - "$c.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'c' in '$c.text'\n", - "$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:10:18: parameter 'd' of rule 'b' is not accessible in this scope: $lab.d\n", + "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference lab in $lab\n", + "$q", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q\n", + "$q.y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q.y\n", + "$q = 3", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q\n", + "$q = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q = 3;\n", + "$q.y = 3;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q.y\n", + "$q = $blort;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference q in $q = $blort;\n" + + "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:19: unknown attribute reference blort in $blort\n", + "$a.ick", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute ick for rule a in $a.ick\n", + "$a.ick = 3;", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:16: unknown attribute ick for rule a in $a.ick\n", + "$b.e", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference b in $b.e\n", // cant see rule refs outside alts + "$b.d", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference b in $b.d\n", + "$c.text", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference c in $c.text\n", + "$lab.d", "error(" + ErrorType.INVALID_RULE_PARAMETER_REF.code + "): A.g4:10:18: parameter d of rule b is not accessible in this scope: $lab.d\n", }; String[] dynMembersChecks = { - "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference 'S' in '$S'\n", - "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::i'\n", - "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::i'\n" + - "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:17: reference to undefined rule 'S' in non-local ref '$S::i'\n", + "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:2:11: unknown attribute reference S in $S\n", + "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::i\n", + "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::i\n" + + "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:17: reference to undefined rule S in non-local ref $S::i\n", - "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:2:14: unknown attribute 'f' for rule 'b' in '$b::f'\n", - "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::j'\n", - "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::j = 3;'\n", - "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule 'S' in non-local ref '$S::j = $S::k;'\n", + "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:2:14: unknown attribute f for rule b in $b::f\n", + "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::j\n", + "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::j = 3;\n", + "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:2:11: reference to undefined rule S in non-local ref $S::j = $S::k;\n", }; String[] dynInitChecks = { - "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:5:8: missing attribute access on rule reference 'a' in '$a'\n", - "$b", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference 'b' in '$b'\n", - "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:5:8: missing attribute access on rule reference 'lab' in '$lab'\n", - "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:11: unknown attribute 'f' for rule 'b' in '$b::f'\n", - "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::i'\n", - "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::i'\n" + - "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:14: reference to undefined rule 'S' in non-local ref '$S::i'\n", - "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:11: unknown attribute 'z' for rule 'a' in '$a::z'\n", - "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference 'S' in '$S'\n", + "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:5:8: missing attribute access on rule reference a in $a\n", + "$b", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference b in $b\n", + "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:5:8: missing attribute access on rule reference lab in $lab\n", + "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:11: unknown attribute f for rule b in $b::f\n", + "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::i\n", + "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::i\n" + + "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:14: reference to undefined rule S in non-local ref $S::i\n", + "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:5:11: unknown attribute z for rule a in $a::z\n", + "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:5:8: unknown attribute reference S in $S\n", - "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::j'\n", - "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::j = 3;'\n", - "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule 'S' in non-local ref '$S::j = $S::k;'\n", + "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::j\n", + "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::j = 3;\n", + "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:5:8: reference to undefined rule S in non-local ref $S::j = $S::k;\n", }; String[] dynInlineChecks = { - "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference 'a' in '$a'\n", - "$b", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference 'b' in '$b'\n", - "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference 'lab' in '$lab'\n", - "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:7: unknown attribute 'f' for rule 'b' in '$b::f'\n", - "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::i'\n", - "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::i'\n" + - "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:10: reference to undefined rule 'S' in non-local ref '$S::i'\n", - "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:7: unknown attribute 'z' for rule 'a' in '$a::z'\n", + "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference a in $a\n", + "$b", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference b in $b\n", + "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:7:4: missing attribute access on rule reference lab in $lab\n", + "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:7: unknown attribute f for rule b in $b::f\n", + "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::i\n", + "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::i\n" + + "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:10: reference to undefined rule S in non-local ref $S::i\n", + "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:7:7: unknown attribute z for rule a in $a::z\n", - "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::j'\n", - "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::j = 3;'\n", - "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule 'S' in non-local ref '$S::j = $S::k;'\n", - "$Q[-1]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n", - "$Q[-i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n", - "$Q[i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n", - "$Q[0]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n", - "$Q[-1]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n", - "$Q[-i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n", - "$Q[i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n", - "$Q[0]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'Q' in '$Q'\n", - "$S[-1]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n", - "$S[-i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n", - "$S[i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n", - "$S[0]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n", - "$S[-1]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n", - "$S[-i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n", - "$S[i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n", - "$S[0]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n", - "$S[$S::y]::i", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference 'S' in '$S'\n" + - "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:7: reference to undefined rule 'S' in non-local ref '$S::y'\n" + "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::j\n", + "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::j = 3;\n", + "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:4: reference to undefined rule S in non-local ref $S::j = $S::k;\n", + "$Q[-1]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n", + "$Q[-i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n", + "$Q[i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n", + "$Q[0]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n", + "$Q[-1]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n", + "$Q[-i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n", + "$Q[i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n", + "$Q[0]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference Q in $Q\n", + "$S[-1]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n", + "$S[-i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n", + "$S[i]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n", + "$S[0]::y", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n", + "$S[-1]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n", + "$S[-i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n", + "$S[i]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n", + "$S[0]::y = 23;", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n", + "$S[$S::y]::i", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:7:4: unknown attribute reference S in $S\n" + + "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:7:7: reference to undefined rule S in non-local ref $S::y\n" }; String[] dynFinallyChecks = { - "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference 'a' in '$a'\n", - "$b", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'b' in '$b'\n", - "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference 'lab' in '$lab'\n", - "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:17: unknown attribute 'f' for rule 'b' in '$b::f'\n", - "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference 'S' in '$S'\n", - "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::i'\n", - "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::i'\n" + - "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:20: reference to undefined rule 'S' in non-local ref '$S::i'\n", - "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:17: unknown attribute 'z' for rule 'a' in '$a::z'\n", + "$a", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference a in $a\n", + "$b", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference b in $b\n", + "$lab", "error(" + ErrorType.ISOLATED_RULE_REF.code + "): A.g4:10:14: missing attribute access on rule reference lab in $lab\n", + "$b::f", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:17: unknown attribute f for rule b in $b::f\n", + "$S", "error(" + ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE.code + "): A.g4:10:14: unknown attribute reference S in $S\n", + "$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::i\n", + "$S::i=$S::i", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::i\n" + + "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:20: reference to undefined rule S in non-local ref $S::i\n", + "$a::z", "error(" + ErrorType.UNKNOWN_RULE_ATTRIBUTE.code + "): A.g4:10:17: unknown attribute z for rule a in $a::z\n", - "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::j'\n", - "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::j = 3;'\n", - "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule 'S' in non-local ref '$S::j = $S::k;'\n", + "$S::j", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::j\n", + "$S::j = 3;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::j = 3;\n", + "$S::j = $S::k;", "error(" + ErrorType.UNDEFINED_RULE_IN_NONLOCAL_REF.code + "): A.g4:10:14: reference to undefined rule S in non-local ref $S::j = $S::k;\n", }; @Test public void testMembersActions() throws RecognitionException { diff --git a/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java b/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java index 697c47017..1b376f6a0 100644 --- a/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java +++ b/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java @@ -54,17 +54,17 @@ public class TestBasicSemanticErrors extends BaseTest { "b : ( options { ick=bar; greedy=true; } : ID )+ ;\n" + "c : ID ID ;", // YIELDS - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:2:10: unsupported option 'foo'\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:2:19: unsupported option 'k'\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:2:10: unsupported option foo\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:2:19: unsupported option k\n" + "error(" + ErrorType.TOKEN_NAMES_MUST_START_UPPER.code + "): U.g4:5:8: token names must start with an uppercase letter: f\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:9:10: unsupported option 'x'\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:9:10: unsupported option x\n" + "error(" + ErrorType.REPEATED_PREQUEL.code + "): U.g4:9:0: repeated grammar prequel spec (options, tokens, or import); please merge\n" + "error(" + ErrorType.REPEATED_PREQUEL.code + "): U.g4:8:0: repeated grammar prequel spec (options, tokens, or import); please merge\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:12:10: unsupported option 'blech'\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:12:21: unsupported option 'greedy'\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:15:16: unsupported option 'ick'\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:15:25: unsupported option 'greedy'\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:16:16: unsupported option 'x'\n", + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:12:10: unsupported option blech\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:12:21: unsupported option greedy\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:15:16: unsupported option ick\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:15:25: unsupported option greedy\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): U.g4:16:16: unsupported option x\n", }; @Test public void testU() { super.testErrors(U, false); } @@ -82,7 +82,7 @@ public class TestBasicSemanticErrors extends BaseTest { ""; String expected = - "error(" + ErrorType.LABEL_BLOCK_NOT_A_SET.code + "): T.g4:2:5: label 'op' assigned to a block which is not a set\n"; + "error(" + ErrorType.LABEL_BLOCK_NOT_A_SET.code + "): T.g4:2:5: label op assigned to a block which is not a set\n"; testErrors(new String[] { grammar, expected }, false); } @@ -97,16 +97,16 @@ public class TestBasicSemanticErrors extends BaseTest { "expr : '=';\n"; String expected = - "error(" + ErrorType.ARG_CONFLICTS_WITH_RULE.code + "): T.g4:2:7: parameter 'expr' conflicts with rule with same name\n" + - "error(" + ErrorType.RETVAL_CONFLICTS_WITH_RULE.code + "): T.g4:2:26: return value 'expr' conflicts with rule with same name\n" + - "error(" + ErrorType.LOCAL_CONFLICTS_WITH_RULE.code + "): T.g4:3:12: local 'expr' conflicts with rule with same name\n" + - "error(" + ErrorType.RETVAL_CONFLICTS_WITH_ARG.code + "): T.g4:2:26: return value 'expr' conflicts with parameter with same name\n" + - "error(" + ErrorType.LOCAL_CONFLICTS_WITH_ARG.code + "): T.g4:3:12: local 'expr' conflicts with parameter with same name\n" + - "error(" + ErrorType.LOCAL_CONFLICTS_WITH_RETVAL.code + "): T.g4:3:12: local 'expr' conflicts with return value with same name\n" + - "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): T.g4:4:4: label 'expr' conflicts with rule with same name\n" + - "error(" + ErrorType.LABEL_CONFLICTS_WITH_ARG.code + "): T.g4:4:4: label 'expr' conflicts with parameter with same name\n" + - "error(" + ErrorType.LABEL_CONFLICTS_WITH_RETVAL.code + "): T.g4:4:4: label 'expr' conflicts with return value with same name\n" + - "error(" + ErrorType.LABEL_CONFLICTS_WITH_LOCAL.code + "): T.g4:4:4: label 'expr' conflicts with local with same name\n"; + "error(" + ErrorType.ARG_CONFLICTS_WITH_RULE.code + "): T.g4:2:7: parameter expr conflicts with rule with same name\n" + + "error(" + ErrorType.RETVAL_CONFLICTS_WITH_RULE.code + "): T.g4:2:26: return value expr conflicts with rule with same name\n" + + "error(" + ErrorType.LOCAL_CONFLICTS_WITH_RULE.code + "): T.g4:3:12: local expr conflicts with rule with same name\n" + + "error(" + ErrorType.RETVAL_CONFLICTS_WITH_ARG.code + "): T.g4:2:26: return value expr conflicts with parameter with same name\n" + + "error(" + ErrorType.LOCAL_CONFLICTS_WITH_ARG.code + "): T.g4:3:12: local expr conflicts with parameter with same name\n" + + "error(" + ErrorType.LOCAL_CONFLICTS_WITH_RETVAL.code + "): T.g4:3:12: local expr conflicts with return value with same name\n" + + "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): T.g4:4:4: label expr conflicts with rule with same name\n" + + "error(" + ErrorType.LABEL_CONFLICTS_WITH_ARG.code + "): T.g4:4:4: label expr conflicts with parameter with same name\n" + + "error(" + ErrorType.LABEL_CONFLICTS_WITH_RETVAL.code + "): T.g4:4:4: label expr conflicts with return value with same name\n" + + "error(" + ErrorType.LABEL_CONFLICTS_WITH_LOCAL.code + "): T.g4:4:4: label expr conflicts with local with same name\n"; ST grammarST = new ST(grammarTemplate); grammarST.add("args", "int expr"); grammarST.add("retvals", "int expr"); diff --git a/tool/test/org/antlr/v4/test/TestLeftRecursion.java b/tool/test/org/antlr/v4/test/TestLeftRecursion.java index dbf161cba..9a3ed59c2 100644 --- a/tool/test/org/antlr/v4/test/TestLeftRecursion.java +++ b/tool/test/org/antlr/v4/test/TestLeftRecursion.java @@ -491,7 +491,7 @@ public class TestLeftRecursion extends BaseTest { "ID : 'a'..'z'+ ;\n" + "WS : (' '|'\\n') -> skip ;\n"; String expected = - "error(" + ErrorType.NO_NON_LR_ALTS.code + "): T.g4:3:0: left recursive rule 'a' must contain an alternative which is not left recursive\n"; + "error(" + ErrorType.NO_NON_LR_ALTS.code + "): T.g4:3:0: left recursive rule a must contain an alternative which is not left recursive\n"; testErrors(new String[] { grammar, expected }, false); } @@ -505,7 +505,7 @@ public class TestLeftRecursion extends BaseTest { "ID : 'a'..'z'+ ;\n" + "WS : (' '|'\\n') -> skip ;\n"; String expected = - "error(" + ErrorType.EPSILON_LR_FOLLOW.code + "): T.g4:3:0: left recursive rule 'a' contains a left recursive alternative which can be followed by the empty string\n"; + "error(" + ErrorType.EPSILON_LR_FOLLOW.code + "): T.g4:3:0: left recursive rule a contains a left recursive alternative which can be followed by the empty string\n"; testErrors(new String[] { grammar, expected }, false); } diff --git a/tool/test/org/antlr/v4/test/TestScopeParsing.java b/tool/test/org/antlr/v4/test/TestScopeParsing.java index 98fe29a75..851bd4817 100644 --- a/tool/test/org/antlr/v4/test/TestScopeParsing.java +++ b/tool/test/org/antlr/v4/test/TestScopeParsing.java @@ -32,6 +32,7 @@ package org.antlr.v4.test; import org.antlr.v4.parse.ScopeParser; import org.antlr.v4.tool.ErrorManager; +import org.antlr.v4.tool.Grammar; import org.junit.Test; import static org.junit.Assert.*; @@ -55,11 +56,12 @@ public class TestScopeParsing extends BaseTest { "i,j, k", "{i=null i, j=null j, k=null k}", }; - @Test public void testArgs() { + @Test public void testArgs() throws Exception { for (int i = 0; i < argPairs.length; i+=2) { String input = argPairs[i]; String expected = argPairs[i+1]; - String actual = ScopeParser.parseTypedArgList(null, input, new ErrorManager(null)).attributes.toString(); + Grammar dummy = new Grammar("grammar T; a:'a';"); + String actual = ScopeParser.parseTypedArgList(null, input, dummy).attributes.toString(); assertEquals(expected, actual); } } diff --git a/tool/test/org/antlr/v4/test/TestSets.java b/tool/test/org/antlr/v4/test/TestSets.java index da9ef1c28..12f5a00d8 100644 --- a/tool/test/org/antlr/v4/test/TestSets.java +++ b/tool/test/org/antlr/v4/test/TestSets.java @@ -238,7 +238,7 @@ public class TestSets extends BaseTest { "a : A {System.out.println($A.text);} ;\n" + "A : ~('a'|B) ;\n" + "B : 'b' ;\n", - "error(" + ErrorType.UNSUPPORTED_REFERENCE_IN_LEXER_SET.code + "): T.g4:3:10: rule reference 'B' is not currently supported in a set\n" + "error(" + ErrorType.UNSUPPORTED_REFERENCE_IN_LEXER_SET.code + "): T.g4:3:10: rule reference B is not currently supported in a set\n" }; super.testErrors(pair, true); } diff --git a/tool/test/org/antlr/v4/test/TestSymbolIssues.java b/tool/test/org/antlr/v4/test/TestSymbolIssues.java index f863687ab..7d6d8f92c 100644 --- a/tool/test/org/antlr/v4/test/TestSymbolIssues.java +++ b/tool/test/org/antlr/v4/test/TestSymbolIssues.java @@ -54,15 +54,15 @@ public class TestSymbolIssues extends BaseTest { "\n" + "ID : 'a'..'z'+ ID ;", // YIELDS - "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:5:1: redefinition of 'members' action\n" + - "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:7:1: redefinition of 'header' action\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): A.g4:2:10: unsupported option 'opt'\n" + - "warning(" + ErrorType.ILLEGAL_OPTION.code + "): A.g4:2:21: unsupported option 'k'\n" + - "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:5:1: redefinition of 'members' action\n" + - "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:9:27: implicit definition of token 'X' in parser\n" + - "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:10:20: implicit definition of token 'Y' in parser\n" + - "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:11:4: implicit definition of token 'FJKD' in parser\n" + - "error(" + ErrorType.RULE_HAS_NO_ARGS.code + "): A.g4:9:37: rule 'b' has no defined parameters\n" + + "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:5:1: redefinition of members action\n" + + "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:7:1: redefinition of header action\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): A.g4:2:10: unsupported option opt\n" + + "warning(" + ErrorType.ILLEGAL_OPTION.code + "): A.g4:2:21: unsupported option k\n" + + "error(" + ErrorType.ACTION_REDEFINITION.code + "): A.g4:5:1: redefinition of members action\n" + + "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:9:27: implicit definition of token X in parser\n" + + "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:10:20: implicit definition of token Y in parser\n" + + "warning(" + ErrorType.IMPLICIT_TOKEN_DEFINITION.code + "): A.g4:11:4: implicit definition of token FJKD in parser\n" + + "error(" + ErrorType.RULE_HAS_NO_ARGS.code + "): A.g4:9:37: rule b has no defined parameters\n" + "error(" + ErrorType.MISSING_RULE_ARGS.code + "): A.g4:10:31: missing arguments(s) on rule reference: a\n" }; @@ -77,10 +77,10 @@ public class TestSymbolIssues extends BaseTest { "\n" + "s : FOO ;", // YIELDS - "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): B.g4:4:4: label 's' conflicts with rule with same name\n" + - "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): B.g4:4:9: label 'b' conflicts with rule with same name\n" + - "error(" + ErrorType.LABEL_CONFLICTS_WITH_TOKEN.code + "): B.g4:4:15: label 'X' conflicts with token with same name\n" + - "error(" + ErrorType.LABEL_TYPE_CONFLICT.code + "): B.g4:6:9: label 'x' type mismatch with previous definition: TOKEN_LIST_LABEL!=TOKEN_LABEL\n" + + "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): B.g4:4:4: label s conflicts with rule with same name\n" + + "error(" + ErrorType.LABEL_CONFLICTS_WITH_RULE.code + "): B.g4:4:9: label b conflicts with rule with same name\n" + + "error(" + ErrorType.LABEL_CONFLICTS_WITH_TOKEN.code + "): B.g4:4:15: label X conflicts with token with same name\n" + + "error(" + ErrorType.LABEL_TYPE_CONFLICT.code + "): B.g4:6:9: label x type mismatch with previous definition: TOKEN_LIST_LABEL!=TOKEN_LABEL\n" + "error(" + ErrorType.IMPLICIT_STRING_DEFINITION.code + "): B.g4:4:20: cannot create implicit token for string literal in non-combined grammar: '.'\n" }; @@ -97,8 +97,8 @@ public class TestSymbolIssues extends BaseTest { " : ID ;", // YIELDS - "error(" + ErrorType.LABEL_CONFLICTS_WITH_ARG.code + "): D.g4:4:21: label 'j' conflicts with parameter with same name\n" + - "error(" + ErrorType.RETVAL_CONFLICTS_WITH_ARG.code + "): D.g4:6:22: return value 'i' conflicts with parameter with same name\n" + "error(" + ErrorType.LABEL_CONFLICTS_WITH_ARG.code + "): D.g4:4:21: label j conflicts with parameter with same name\n" + + "error(" + ErrorType.RETVAL_CONFLICTS_WITH_ARG.code + "): D.g4:6:22: return value i conflicts with parameter with same name\n" }; static String[] E = { @@ -112,7 +112,7 @@ public class TestSymbolIssues extends BaseTest { "a : A ;\n", // YIELDS - "warning(" + ErrorType.TOKEN_NAME_REASSIGNMENT.code + "): E.g4:3:4: token name 'A' is already defined\n" + "warning(" + ErrorType.TOKEN_NAME_REASSIGNMENT.code + "): E.g4:3:4: token name A is already defined\n" }; @Test public void testA() { super.testErrors(A, false); } @@ -147,7 +147,7 @@ public class TestSymbolIssues extends BaseTest { "mode X;\n" + "fragment B : 'b';", - "error(" + ErrorType.MODE_WITHOUT_RULES.code + "): L.g4:3:5: lexer mode 'X' must contain at least one non-fragment rule\n" + "error(" + ErrorType.MODE_WITHOUT_RULES.code + "): L.g4:3:5: lexer mode X must contain at least one non-fragment rule\n" }; testErrors(test, false); @@ -162,8 +162,8 @@ public class TestSymbolIssues extends BaseTest { " B : C;\n" + " fragment C : A | (A C)?;", - "warning(" + ErrorType.EPSILON_TOKEN.code + "): L.g4:3:0: non-fragment lexer rule 'WS' can match the empty string\n" + - "warning(" + ErrorType.EPSILON_TOKEN.code + "): L.g4:5:2: non-fragment lexer rule 'B' can match the empty string\n" + "warning(" + ErrorType.EPSILON_TOKEN.code + "): L.g4:3:0: non-fragment lexer rule WS can match the empty string\n" + + "warning(" + ErrorType.EPSILON_TOKEN.code + "): L.g4:5:2: non-fragment lexer rule B can match the empty string\n" }; testErrors(test, false); diff --git a/tool/test/org/antlr/v4/test/TestToolSyntaxErrors.java b/tool/test/org/antlr/v4/test/TestToolSyntaxErrors.java index 995b9d3e6..1b79140fa 100644 --- a/tool/test/org/antlr/v4/test/TestToolSyntaxErrors.java +++ b/tool/test/org/antlr/v4/test/TestToolSyntaxErrors.java @@ -39,7 +39,7 @@ public class TestToolSyntaxErrors extends BaseTest { "grammar A;\n" + "", // YIELDS - "error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar 'A' has no rules\n", + "error(" + ErrorType.NO_RULES.code + "): A.g4::: grammar A has no rules\n", "A;", "error(" + ErrorType.SYNTAX_ERROR.code + "): A.g4:1:0: syntax error: 'A' came as a complete surprise to me\n", @@ -273,8 +273,8 @@ public class TestToolSyntaxErrors extends BaseTest { "X : 'foo' -> popmode;\n" + // "meant" to use -> popMode "Y : 'foo' -> token(Foo);", // "meant" to use -> type(Foo) - "error(" + ErrorType.INVALID_LEXER_COMMAND.code + "): A.g4:4:13: lexer command 'popmode' does not exist or is not supported by the current target\n" + - "error(" + ErrorType.INVALID_LEXER_COMMAND.code + "): A.g4:5:13: lexer command 'token' does not exist or is not supported by the current target\n" + "error(" + ErrorType.INVALID_LEXER_COMMAND.code + "): A.g4:4:13: lexer command popmode does not exist or is not supported by the current target\n" + + "error(" + ErrorType.INVALID_LEXER_COMMAND.code + "): A.g4:5:13: lexer command token does not exist or is not supported by the current target\n" }; super.testErrors(pair, true); } @@ -287,8 +287,8 @@ public class TestToolSyntaxErrors extends BaseTest { "X : 'foo' -> popMode(Foo);\n" + // "meant" to use -> popMode "Y : 'foo' -> type;", // "meant" to use -> type(Foo) - "error(" + ErrorType.UNWANTED_LEXER_COMMAND_ARGUMENT.code + "): A.g4:4:13: lexer command 'popMode' does not take any arguments\n" + - "error(" + ErrorType.MISSING_LEXER_COMMAND_ARGUMENT.code + "): A.g4:5:13: missing argument for lexer command 'type'\n" + "error(" + ErrorType.UNWANTED_LEXER_COMMAND_ARGUMENT.code + "): A.g4:4:13: lexer command popMode does not take any arguments\n" + + "error(" + ErrorType.MISSING_LEXER_COMMAND_ARGUMENT.code + "): A.g4:5:13: missing argument for lexer command type\n" }; super.testErrors(pair, true); } @@ -303,7 +303,7 @@ public class TestToolSyntaxErrors extends BaseTest { "A : 'a' ;\n" + "B : 'b' ;\n", - "error(" + ErrorType.RULE_REDEFINITION.code + "): Oops.g4:4:0: rule 'ret_ty' redefinition; previous at line 3\n" + "error(" + ErrorType.RULE_REDEFINITION.code + "): Oops.g4:4:0: rule ret_ty redefinition; previous at line 3\n" }; super.testErrors(pair, true); } @@ -317,15 +317,15 @@ public class TestToolSyntaxErrors extends BaseTest { + "z1 : ('foo' | 'bar'? 'bar2'?)*;\n" + "z2 : ('foo' | 'bar' 'bar2'? | 'bar2')*;\n"; String expected = - "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:3:0: rule 'y1' contains a closure with at least one alternative that can match an empty string\n" + - "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:4:0: rule 'y2' contains a closure with at least one alternative that can match an empty string\n" + - "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:5:0: rule 'z1' contains a closure with at least one alternative that can match an empty string\n"; + "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:3:0: rule y1 contains a closure with at least one alternative that can match an empty string\n" + + "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:4:0: rule y2 contains a closure with at least one alternative that can match an empty string\n" + + "error(" + ErrorType.EPSILON_CLOSURE.code + "): A.g4:5:0: rule z1 contains a closure with at least one alternative that can match an empty string\n"; String[] pair = new String[] { grammar, expected }; - + super.testErrors(pair, true); } @@ -337,8 +337,8 @@ public class TestToolSyntaxErrors extends BaseTest { + "z1 : ('foo' | 'bar'? 'bar2'?)?;\n" + "z2 : ('foo' | 'bar' 'bar2'? | 'bar2')?;\n"; String expected = - "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): A.g4:3:0: rule 'y' contains an optional block with at least one alternative that can match an empty string\n" + - "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): A.g4:4:0: rule 'z1' contains an optional block with at least one alternative that can match an empty string\n"; + "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): A.g4:3:0: rule y contains an optional block with at least one alternative that can match an empty string\n" + + "warning(" + ErrorType.EPSILON_OPTIONAL.code + "): A.g4:4:0: rule z1 contains an optional block with at least one alternative that can match an empty string\n"; String[] pair = new String[] { grammar, @@ -373,7 +373,7 @@ public class TestToolSyntaxErrors extends BaseTest { "WS : [ \\r\\t\\n]+ -> skip ;\n"; String expected = ""; - + String[] pair = new String[] { grammar, expected }; super.testErrors(pair, true); } @@ -464,7 +464,7 @@ public class TestToolSyntaxErrors extends BaseTest { " | x '*' x // ok\n" + " ;\n"; String expected = - "warning(" + ErrorType.UNRECOGNIZED_ASSOC_OPTION.code + "): A.g4:3:10: rule 'x' contains an 'assoc' terminal option in an unrecognized location\n"; + "warning(" + ErrorType.UNRECOGNIZED_ASSOC_OPTION.code + "): A.g4:3:10: rule x contains an assoc terminal option in an unrecognized location\n"; String[] pair = new String[] { grammar, @@ -492,8 +492,8 @@ public class TestToolSyntaxErrors extends BaseTest { "Y2 : 'x' {more();} // warning 158\n" + " ;\n"; String expected = - "warning(" + ErrorType.FRAGMENT_ACTION_IGNORED.code + "): A.g4:7:12: fragment rule 'X2' contains an action or command which can never be executed\n" + - "warning(" + ErrorType.FRAGMENT_ACTION_IGNORED.code + "): A.g4:10:9: fragment rule 'Y2' contains an action or command which can never be executed\n"; + "warning(" + ErrorType.FRAGMENT_ACTION_IGNORED.code + "): A.g4:7:12: fragment rule X2 contains an action or command which can never be executed\n" + + "warning(" + ErrorType.FRAGMENT_ACTION_IGNORED.code + "): A.g4:10:9: fragment rule Y2 contains an action or command which can never be executed\n"; String[] pair = new String[] { grammar, @@ -514,7 +514,7 @@ public class TestToolSyntaxErrors extends BaseTest { "WS : ' ';\n" + " EOF : 'a';\n"; String expected = - "error(" + ErrorType.RESERVED_RULE_NAME.code + "): A.g4:3:1: cannot declare a rule with reserved name 'EOF'\n"; + "error(" + ErrorType.RESERVED_RULE_NAME.code + "): A.g4:3:1: cannot declare a rule with reserved name EOF\n"; String[] pair = new String[] { grammar, From f0ab9b1415d6e20cf634b6fe62b457733c01443d Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Mon, 30 Jun 2014 09:26:02 -0700 Subject: [PATCH 2/3] use assoc value's token. --- tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java index 09100ed5d..19b3f9a79 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursiveRuleAnalyzer.java @@ -131,7 +131,7 @@ public class LeftRecursiveRuleAnalyzer extends LeftRecursiveRuleWalker { assoc = ASSOC.left; } else { - tool.errMgr.toolError(ErrorType.ILLEGAL_OPTION_VALUE, t.getToken(), "assoc", assoc); + tool.errMgr.toolError(ErrorType.ILLEGAL_OPTION_VALUE, t.getOptionAST("assoc").getToken(), "assoc", assoc); } } } From e3fc04bda1ce8bafaa55a2a584f26f2238c910c8 Mon Sep 17 00:00:00 2001 From: Terence Parr Date: Mon, 30 Jun 2014 15:16:20 -0700 Subject: [PATCH 3/3] put good quotes back in. rm unneeded arg to left-recur msg. --- .../v4/analysis/LeftRecursionDetector.java | 4 +- tool/src/org/antlr/v4/tool/ErrorManager.java | 4 +- tool/src/org/antlr/v4/tool/ErrorType.java | 52 +++++++++---------- .../v4/tool/LeftRecursionCyclesMessage.java | 23 +++++++- 4 files changed, 50 insertions(+), 33 deletions(-) diff --git a/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java b/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java index 61e0309a7..44e4b4a85 100644 --- a/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java +++ b/tool/src/org/antlr/v4/analysis/LeftRecursionDetector.java @@ -74,9 +74,7 @@ public class LeftRecursionDetector { } //System.out.println("cycles="+listOfRecursiveCycles); if ( !listOfRecursiveCycles.isEmpty() ) { - RuleStartState firstRuleStartState = atn.ruleToStartState[0]; - Rule r = g.getRule(firstRuleStartState.ruleIndex); - g.tool.errMgr.leftRecursionCycles(g.fileName, r.ast.getToken(), listOfRecursiveCycles); + g.tool.errMgr.leftRecursionCycles(g.fileName, listOfRecursiveCycles); } } diff --git a/tool/src/org/antlr/v4/tool/ErrorManager.java b/tool/src/org/antlr/v4/tool/ErrorManager.java index 364316e21..fc196af20 100644 --- a/tool/src/org/antlr/v4/tool/ErrorManager.java +++ b/tool/src/org/antlr/v4/tool/ErrorManager.java @@ -186,9 +186,9 @@ public class ErrorManager { } - public void leftRecursionCycles(String fileName, Token startTokenOfFirstRuleInCycle, Collection> cycles) { + public void leftRecursionCycles(String fileName, Collection> cycles) { errors++; - ANTLRMessage msg = new LeftRecursionCyclesMessage(fileName, startTokenOfFirstRuleInCycle, cycles); + ANTLRMessage msg = new LeftRecursionCyclesMessage(fileName, cycles); tool.error(msg); } diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index 56b4a12f5..4eb8dc2f6 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -16,7 +16,7 @@ * 3. The name of the author may not be used to endorse or promote products * derived from this software without specific prior written permission. * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS AND ANY EXPRESS OR + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, @@ -178,7 +178,7 @@ public enum ErrorType { /** * Compiler Error 35. * - *

templates/target and tool arent compatible

+ *

templates/target and tool aren't compatible

*/ INCOMPATIBLE_TOOL_AND_TEMPLATES(35, " code generation target requires ANTLR ; it can't be loaded by the current ANTLR ", ErrorSeverity.ERROR), @@ -697,8 +697,8 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * X : foo -> type(Foo);  // ok
-	 * Y : foo -> token(Foo); // error 149 (token is not a supported lexer command)
+	 * X : 'foo' -> type(Foo);  // ok
+	 * Y : 'foo' -> token(Foo); // error 149 (token is not a supported lexer command)
 	 * 
* * @since 4.1 @@ -714,8 +714,8 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * X : foo -> type(Foo); // ok
-	 * Y : foo -> type;      // error 150 (the type command requires an argument)
+	 * X : 'foo' -> type(Foo); // ok
+	 * Y : 'foo' -> type;      // error 150 (the type command requires an argument)
 	 * 
* * @since 4.1 @@ -732,8 +732,8 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * X : foo -> popMode;    // ok
-	 * Y : foo -> popMode(A); // error 151 (the popMode command does not take an argument)
+	 * X : 'foo' -> popMode;    // ok
+	 * Y : 'foo' -> popMode(A); // error 151 (the popMode command does not take an argument)
 	 * 
* * @since 4.1 @@ -749,8 +749,8 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * x : x; // ok
-	 * y : y;  // error 152
+	 * x : 'x'; // ok
+	 * y : 'y';  // error 152
 	 * 
* * @since 4.1 @@ -771,8 +771,8 @@ public enum ErrorType { *
 	 * x  : ;
 	 * y  : x+;                                // error 153
-	 * z1 : (foo | bar? bar2?)*;         // error 153
-	 * z2 : (foo | bar bar2? | bar2)*; // ok
+	 * z1 : ('foo' | 'bar'? 'bar2'?)*;         // error 153
+	 * z2 : ('foo' | 'bar' 'bar2'? | 'bar2')*; // ok
 	 * 
* * @since 4.1 @@ -793,8 +793,8 @@ public enum ErrorType { *
 	 * x  : ;
 	 * y  : x?;                                // warning 154
-	 * z1 : (foo | bar? bar2?)?;         // warning 154
-	 * z2 : (foo | bar bar2? | bar2)?; // ok
+	 * z1 : ('foo' | 'bar'? 'bar2'?)?;         // warning 154
+	 * z2 : ('foo' | 'bar' 'bar2'? | 'bar2')?; // ok
 	 * 
* * @since 4.1 @@ -820,8 +820,8 @@ public enum ErrorType { * public static final int CUSTOM = HIDDEN + 1; * } * - * X : foo -> channel(HIDDEN); // ok - * Y : bar -> channel(CUSTOM); // warning 155 + * X : 'foo' -> channel(HIDDEN); // ok + * Y : 'bar' -> channel(CUSTOM); // warning 155 * * * @since 4.2 @@ -837,8 +837,8 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * x : x;  // ok
-	 * y : \u005Cu; // error 156
+	 * x : 'x';  // ok
+	 * y : '\u005Cu'; // error 156
 	 * 
* * @since 4.2.1 @@ -861,8 +861,8 @@ public enum ErrorType { *

The following rule produces this warning.

* *
-	 * x : x
-	 *   | x +<assoc=right> x   // warning 157
+	 * x : 'x'
+	 *   | x '+'<assoc=right> x   // warning 157
 	 *   |<assoc=right> x * x   // ok
 	 *   ;
 	 * 
@@ -886,15 +886,15 @@ public enum ErrorType { *

The following rule produces this warning.

* *
-	 * X1 : x -> more    // ok
+	 * X1 : 'x' -> more    // ok
 	 *    ;
-	 * Y1 : x {more();}  // ok
+	 * Y1 : 'x' {more();}  // ok
 	 *    ;
 	 * fragment
-	 * X2 : x -> more    // warning 158
+	 * X2 : 'x' -> more    // warning 158
 	 *    ;
 	 * fragment
-	 * Y2 : x {more();}  // warning 158
+	 * Y2 : 'x' {more();}  // warning 158
 	 *    ;
 	 * 
* @@ -911,7 +911,7 @@ public enum ErrorType { *

The following rule produces this error.

* *
-	 * EOF :     // error 159 (EOF is a reserved name)
+	 * EOF :  ' '   // error 159 (EOF is a reserved name)
 	 *     ;
 	 * 
* @@ -1005,7 +1005,7 @@ public enum ErrorType { *

{@code (...)=>} syntactic predicates are not supported in ANTLR 4

* *

- * ANTLR 4s improved lookahead algorithms do not require the use of + * ANTLR 4's improved lookahead algorithms do not require the use of * syntactic predicates to disambiguate long lookahead sequences. The * syntactic predicates should be removed when migrating a grammar from * ANTLR 3 to ANTLR 4.

diff --git a/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java b/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java index 5e352d3bf..3e0740b2a 100644 --- a/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java +++ b/tool/src/org/antlr/v4/tool/LeftRecursionCyclesMessage.java @@ -35,8 +35,27 @@ import org.antlr.runtime.Token; import java.util.Collection; public class LeftRecursionCyclesMessage extends ANTLRMessage { - public LeftRecursionCyclesMessage(String fileName, Token startTokenOfFirstRuleInCycle, Collection> cycles) { - super(ErrorType.LEFT_RECURSION_CYCLES, startTokenOfFirstRuleInCycle, cycles); + public LeftRecursionCyclesMessage(String fileName, Collection> cycles) { + super(ErrorType.LEFT_RECURSION_CYCLES, getStartTokenOfFirstRule(cycles), cycles); this.fileName = fileName; } + + protected static Token getStartTokenOfFirstRule(Collection> cycles) { + if (cycles == null) { + return null; + } + + for (Collection collection : cycles) { + if (collection == null) { + return null; + } + + for (Rule rule : collection) { + if (rule.ast != null) { + return rule.ast.getToken(); + } + } + } + return null; + } }