From f37d99bc92a4eb533d3c2f0eec314c62be246ab1 Mon Sep 17 00:00:00 2001 From: Sam Harwell Date: Wed, 16 Jan 2013 13:45:08 -0600 Subject: [PATCH] Updated error messages and documentation --- tool/src/org/antlr/v4/tool/ErrorType.java | 44 ++++++++++++++++++- .../v4/test/TestBasicSemanticErrors.java | 16 +++---- .../org/antlr/v4/test/TestSymbolIssues.java | 4 +- 3 files changed, 52 insertions(+), 12 deletions(-) diff --git a/tool/src/org/antlr/v4/tool/ErrorType.java b/tool/src/org/antlr/v4/tool/ErrorType.java index 3fcb9075d..9eede2fb1 100644 --- a/tool/src/org/antlr/v4/tool/ErrorType.java +++ b/tool/src/org/antlr/v4/tool/ErrorType.java @@ -90,8 +90,8 @@ public enum ErrorType { RETVAL_CONFLICTS_WITH_ARG(76, "return value '' conflicts with parameter with same name", ErrorSeverity.ERROR), MISSING_RULE_ARGS(79, "missing arguments(s) on rule reference: ", ErrorSeverity.ERROR), RULE_HAS_NO_ARGS(80, "rule '' has no defined parameters", ErrorSeverity.ERROR), - ILLEGAL_OPTION(83, "illegal option ''", ErrorSeverity.WARNING), - ILLEGAL_OPTION_VALUE(84, "illegal option value '='", ErrorSeverity.WARNING), + ILLEGAL_OPTION(83, "unsupported option ''", ErrorSeverity.WARNING), + ILLEGAL_OPTION_VALUE(84, "unsupported option value '='", ErrorSeverity.WARNING), ACTION_REDEFINITION(94, "redefinition of '' action", ErrorSeverity.ERROR), NO_RULES(99, "implicitly generated grammar '' has no rules", ErrorSeverity.ERROR), NO_SUCH_GRAMMAR_SCOPE(105, "reference to undefined grammar in rule reference: .", ErrorSeverity.ERROR), @@ -128,8 +128,48 @@ public enum ErrorType { LOCAL_CONFLICTS_WITH_RETVAL(143, "local '' conflicts with return value with same name", ErrorSeverity.ERROR), INVALID_LITERAL_IN_LEXER_SET(144, "multi-character literals are not allowed in lexer sets: ", ErrorSeverity.ERROR), MODE_WITHOUT_RULES(145, "lexer mode '' must contain at least one non-fragment rule", ErrorSeverity.ERROR), + /** + * All non-fragment lexer rules must match at least one character. + *

+ * The following example shows this error. + * + *

+	 * Whitespace : [ \t]+;  // ok
+	 * Whitespace : [ \t];   // ok
+	 *
+	 * fragment WS : [ \t]*; // ok
+	 *
+	 * Whitespace : [ \t]*;  // error 146
+	 * 
+ */ EPSILON_TOKEN(146, "non-fragment lexer rule '' can match the empty string", ErrorSeverity.ERROR), + /** + * Left-recursive rules must contain at least one alternative which is not + * left recursive. + *

+ * The following rule produces this error. + * + *

+	 * // error 147:
+	 * a : a ID
+	 *   | a INT
+	 *   ;
+	 * 
+ */ NO_NON_LR_ALTS(147, "left recursive rule '' must contain an alternative which is not left recursive", ErrorSeverity.ERROR), + /** + * In left-recursive rules, all left-recursive alternatives must match at + * least one symbol following the recursive rule invocation. + *

+ * The following rule produces this error. + * + *

+	 * a : ID    // ok        (alternative is not left recursive)
+	 *   | a INT // ok        (a must be follow by INT)
+	 *   | a ID? // error 148 (the ID following a is optional)
+	 *   ;
+	 * 
+ */ EPSILON_LR_FOLLOW(148, "left recursive rule '' contains a left recursive alternative which can be followed by the empty string", ErrorSeverity.ERROR), // Backward incompatibility errors diff --git a/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java b/tool/test/org/antlr/v4/test/TestBasicSemanticErrors.java index e894bf571..bf3a01045 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(83): U.g4:2:10: illegal option 'foo'\n" + - "warning(83): U.g4:2:19: illegal option 'k'\n" + + "warning(83): U.g4:2:10: unsupported option 'foo'\n" + + "warning(83): U.g4:2:19: unsupported option 'k'\n" + "error(60): U.g4:5:8: token names must start with an uppercase letter: f\n" + - "warning(83): U.g4:9:10: illegal option 'x'\n" + + "warning(83): U.g4:9:10: unsupported option 'x'\n" + "error(54): U.g4:9:0: repeated grammar prequel spec (option, token, or import); please merge\n" + "error(54): U.g4:8:0: repeated grammar prequel spec (option, token, or import); please merge\n" + - "warning(83): U.g4:12:10: illegal option 'blech'\n" + - "warning(83): U.g4:12:21: illegal option 'greedy'\n" + - "warning(83): U.g4:15:16: illegal option 'ick'\n" + - "warning(83): U.g4:15:25: illegal option 'greedy'\n" + - "warning(83): U.g4:16:16: illegal option 'x'\n", + "warning(83): U.g4:12:10: unsupported option 'blech'\n" + + "warning(83): U.g4:12:21: unsupported option 'greedy'\n" + + "warning(83): U.g4:15:16: unsupported option 'ick'\n" + + "warning(83): U.g4:15:25: unsupported option 'greedy'\n" + + "warning(83): U.g4:16:16: unsupported option 'x'\n", }; @Test public void testU() { super.testErrors(U, false); } diff --git a/tool/test/org/antlr/v4/test/TestSymbolIssues.java b/tool/test/org/antlr/v4/test/TestSymbolIssues.java index d4abe1a72..0e3226d64 100644 --- a/tool/test/org/antlr/v4/test/TestSymbolIssues.java +++ b/tool/test/org/antlr/v4/test/TestSymbolIssues.java @@ -56,8 +56,8 @@ public class TestSymbolIssues extends BaseTest { // YIELDS "error(94): A.g4:5:1: redefinition of 'members' action\n" + "error(94): A.g4:7:1: redefinition of 'header' action\n" + - "warning(83): A.g4:2:10: illegal option 'opt'\n" + - "warning(83): A.g4:2:21: illegal option 'k'\n" + + "warning(83): A.g4:2:10: unsupported option 'opt'\n" + + "warning(83): A.g4:2:21: unsupported option 'k'\n" + "error(94): A.g4:5:1: redefinition of 'members' action\n" + "warning(125): A.g4:9:27: implicit definition of token 'X' in parser\n" + "warning(125): A.g4:10:20: implicit definition of token 'Y' in parser\n" +