handle invalid template syntax %x.y = 3

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6701]
This commit is contained in:
parrt 2010-02-16 17:55:48 -08:00
parent c08812ea54
commit 1a5dfde6b5
7 changed files with 120 additions and 119 deletions

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} ANTLRLexer.g 2010-02-15 16:36:15
// $ANTLR ${project.version} ${buildNumber} ANTLRLexer.g 2010-02-16 17:54:23
/*
[The "BSD licence"]

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} ANTLRParser.g 2010-02-15 16:36:18
// $ANTLR ${project.version} ${buildNumber} ANTLRParser.g 2010-02-16 17:54:25
/*
[The "BSD licence"]
@ -284,7 +284,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: prequelConstruct, grammarType, DOC_COMMENT, id, rules
// elements: prequelConstruct, DOC_COMMENT, grammarType, id, rules
// token labels:
// rule labels: retval
// token list labels:
@ -1123,7 +1123,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: delegateGrammar, IMPORT
// elements: IMPORT, delegateGrammar
// token labels:
// rule labels: retval
// token list labels:
@ -1404,7 +1404,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: tokenSpec, TOKENS
// elements: TOKENS, tokenSpec
// token labels:
// rule labels: retval
// token list labels:
@ -1559,7 +1559,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: STRING_LITERAL, id, ASSIGN
// elements: STRING_LITERAL, ASSIGN, id
// token labels:
// rule labels: retval
// token list labels:
@ -1699,7 +1699,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: id, SCOPE, ACTION
// elements: SCOPE, id, ACTION
// token labels:
// rule labels: retval
// token list labels:
@ -1853,7 +1853,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: actionScopeName, AT, ACTION, id
// elements: actionScopeName, id, AT, ACTION
// token labels:
// rule labels: retval
// token list labels:
@ -2353,7 +2353,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ruleReturns, ARG_ACTION, ruleModifiers, altListAsBlock, exceptionGroup, id, rulePrequel, DOC_COMMENT
// elements: exceptionGroup, altListAsBlock, ruleModifiers, id, ARG_ACTION, DOC_COMMENT, rulePrequel, ruleReturns
// token labels:
// rule labels: retval
// token list labels:
@ -2579,7 +2579,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ARG_ACTION, CATCH, ACTION
// elements: CATCH, ARG_ACTION, ACTION
// token labels:
// rule labels: retval
// token list labels:
@ -3106,7 +3106,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: SCOPE, ACTION
// elements: ACTION, SCOPE
// token labels:
// rule labels: retval
// token list labels:
@ -3284,7 +3284,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: id, AT, ACTION
// elements: ACTION, AT, id
// token labels:
// rule labels: retval
// token list labels:
@ -4504,7 +4504,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: treeSpec, ebnfSuffix
// elements: ebnfSuffix, treeSpec
// token labels:
// rule labels: retval
// token list labels:
@ -4829,7 +4829,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: element, TREE_BEGIN
// elements: TREE_BEGIN, element
// token labels:
// rule labels: retval
// token list labels:
@ -5450,7 +5450,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: id, DOT, ruleref
// elements: id, ruleref, DOT
// token labels:
// rule labels: retval
// token list labels:
@ -5508,7 +5508,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: DOT, terminal, id
// elements: id, DOT, terminal
// token labels:
// rule labels: retval
// token list labels:
@ -5707,7 +5707,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: notTerminal, NOT
// elements: NOT, notTerminal
// token labels:
// rule labels: retval
// token list labels:
@ -5984,7 +5984,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: altList, optionsSpec, ra
// elements: optionsSpec, altList, ra
// token labels:
// rule labels: retval
// token list labels:
@ -6159,7 +6159,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ARG_ACTION, RULE_REF, op
// elements: op, ARG_ACTION, RULE_REF
// token labels: op
// rule labels: retval
// token list labels:
@ -6206,7 +6206,7 @@ public class ANTLRParser extends Parser {
{
// AST REWRITE
// elements: RULE_REF, ARG_ACTION
// elements: ARG_ACTION, RULE_REF
// token labels:
// rule labels: retval
// token list labels:
@ -6512,7 +6512,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: TOKEN_REF, elementOptions, ARG_ACTION
// elements: elementOptions, ARG_ACTION, TOKEN_REF
// token labels:
// rule labels: retval
// token list labels:
@ -6704,7 +6704,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ROOT, terminal
// elements: terminal, ROOT
// token labels:
// rule labels: retval
// token list labels:
@ -7193,7 +7193,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: predicatedRewrite, nakedRewrite
// elements: nakedRewrite, predicatedRewrite
// token labels:
// rule labels: retval
// token list labels:
@ -7281,7 +7281,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: SEMPRED, rewriteAlt, SEMPRED, rewriteAlt
// elements: rewriteAlt, SEMPRED, SEMPRED, rewriteAlt
// token labels:
// rule labels: retval
// token list labels:
@ -7740,7 +7740,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ebnfSuffix, rewriteTreeAtom
// elements: rewriteTreeAtom, ebnfSuffix
// token labels:
// rule labels: retval
// token list labels:
@ -8062,7 +8062,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ARG_ACTION, elementOptions, TOKEN_REF
// elements: TOKEN_REF, ARG_ACTION, elementOptions
// token labels:
// rule labels: retval
// token list labels:
@ -8440,7 +8440,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: TREE_BEGIN, rewriteTreeAtom, rewriteTreeElement
// elements: rewriteTreeElement, TREE_BEGIN, rewriteTreeAtom
// token labels:
// rule labels: retval
// token list labels:
@ -8595,7 +8595,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: rewriteTemplateArgs, str, TEMPLATE
// elements: rewriteTemplateArgs, TEMPLATE, str
// token labels: str
// rule labels: retval
// token list labels:

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} ASTVerifier.g 2010-02-15 16:36:19
// $ANTLR ${project.version} ${buildNumber} ASTVerifier.g 2010-02-16 17:54:26
/*
[The "BSD license"]

View File

@ -132,7 +132,7 @@ TEMPLATE_EXPR
;
UNKNOWN_SYNTAX
@after {delegate.unknownSyntax($text);}
@after {delegate.unknownSyntax(emit());}
: '%' (ID|'.'|'('|')'|','|'{'|'}'|'"')*
;

View File

@ -1,4 +1,4 @@
// $ANTLR ${project.version} ${buildNumber} ActionSplitter.g 2010-02-15 16:36:19
// $ANTLR ${project.version} ${buildNumber} ActionSplitter.g 2010-02-16 17:54:26
package org.antlr.v4.parse;
@ -1388,7 +1388,7 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
state.type = _type;
state.channel = _channel;
if ( state.backtracking==1 ) {
delegate.unknownSyntax(getText());
delegate.unknownSyntax(emit());
} }
finally {
}
@ -2301,20 +2301,6 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
state.failed=false;
return success;
}
public final boolean synpred1_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred1_ActionSplitter_fragment(); // can never throw exception
} catch (RecognitionException re) {
System.err.println("impossible: "+re);
}
boolean success = !state.failed;
input.rewind(start);
state.backtracking--;
state.failed=false;
return success;
}
public final boolean synpred18_ActionSplitter() {
state.backtracking++;
int start = input.mark();
@ -2329,11 +2315,11 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
state.failed=false;
return success;
}
public final boolean synpred2_ActionSplitter() {
public final boolean synpred1_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred2_ActionSplitter_fragment(); // can never throw exception
synpred1_ActionSplitter_fragment(); // can never throw exception
} catch (RecognitionException re) {
System.err.println("impossible: "+re);
}
@ -2357,6 +2343,20 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
state.failed=false;
return success;
}
public final boolean synpred2_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred2_ActionSplitter_fragment(); // can never throw exception
} catch (RecognitionException re) {
System.err.println("impossible: "+re);
}
boolean success = !state.failed;
input.rewind(start);
state.backtracking--;
state.failed=false;
return success;
}
public final boolean synpred6_ActionSplitter() {
state.backtracking++;
int start = input.mark();
@ -2399,11 +2399,11 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
state.failed=false;
return success;
}
public final boolean synpred3_ActionSplitter() {
public final boolean synpred15_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred3_ActionSplitter_fragment(); // can never throw exception
synpred15_ActionSplitter_fragment(); // can never throw exception
} catch (RecognitionException re) {
System.err.println("impossible: "+re);
}
@ -2413,11 +2413,11 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
state.failed=false;
return success;
}
public final boolean synpred15_ActionSplitter() {
public final boolean synpred3_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred15_ActionSplitter_fragment(); // can never throw exception
synpred3_ActionSplitter_fragment(); // can never throw exception
} catch (RecognitionException re) {
System.err.println("impossible: "+re);
}
@ -2491,23 +2491,21 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
}
}
static final String DFA29_eotS =
"\32\uffff";
"\31\uffff";
static final String DFA29_eofS =
"\32\uffff";
"\31\uffff";
static final String DFA29_minS =
"\2\0\3\uffff\1\0\6\uffff\1\0\12\uffff\1\0\2\uffff";
"\1\0\1\uffff\1\0\6\uffff\1\0\2\uffff\1\0\1\uffff\1\0\12\uffff";
static final String DFA29_maxS =
"\1\uffff\1\0\3\uffff\1\0\6\uffff\1\0\12\uffff\1\0\2\uffff";
"\1\uffff\1\uffff\1\0\6\uffff\1\0\2\uffff\1\0\1\uffff\1\0\12\uffff";
static final String DFA29_acceptS =
"\2\uffff\1\1\1\2\1\24\1\uffff\1\16\1\17\1\20\1\21\1\22\1\23\1\uffff"+
"\1\4\1\5\1\6\1\7\1\10\1\11\1\12\1\13\1\14\1\15\1\uffff\1\3\1\24";
"\1\uffff\1\24\1\uffff\1\16\1\17\1\20\1\21\1\22\1\23\1\uffff\1\1"+
"\1\2\1\uffff\1\3\1\uffff\1\4\1\5\1\6\1\7\1\10\1\11\1\12\1\13\1\14"+
"\1\15";
static final String DFA29_specialS =
"\1\0\1\1\3\uffff\1\2\6\uffff\1\3\12\uffff\1\4\2\uffff}>";
"\1\0\1\uffff\1\1\6\uffff\1\2\2\uffff\1\3\1\uffff\1\4\12\uffff}>";
static final String[] DFA29_transitionS = {
"\44\31\1\14\1\5\11\31\1\1\54\31\1\27\uffa3\31",
"\1\uffff",
"",
"",
"\44\1\1\16\1\2\11\1\1\11\54\1\1\14\uffa3\1",
"",
"\1\uffff",
"",
@ -2519,16 +2517,18 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
"\1\uffff",
"",
"",
"",
"",
"",
"",
"",
"",
"",
"\1\uffff",
"",
"\1\uffff",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
};
@ -2572,56 +2572,56 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
int LA29_0 = input.LA(1);
s = -1;
if ( (LA29_0=='/') ) {s = 1;}
if ( ((LA29_0>='\u0000' && LA29_0<='#')||(LA29_0>='&' && LA29_0<='.')||(LA29_0>='0' && LA29_0<='[')||(LA29_0>=']' && LA29_0<='\uFFFF')) ) {s = 1;}
else if ( (LA29_0=='%') ) {s = 5;}
else if ( (LA29_0=='%') ) {s = 2;}
else if ( (LA29_0=='$') ) {s = 12;}
else if ( (LA29_0=='/') ) {s = 9;}
else if ( (LA29_0=='\\') ) {s = 23;}
else if ( (LA29_0=='\\') ) {s = 12;}
else if ( ((LA29_0>='\u0000' && LA29_0<='#')||(LA29_0>='&' && LA29_0<='.')||(LA29_0>='0' && LA29_0<='[')||(LA29_0>=']' && LA29_0<='\uFFFF')) ) {s = 25;}
else if ( (LA29_0=='$') ) {s = 14;}
if ( s>=0 ) return s;
break;
case 1 :
int LA29_1 = input.LA(1);
int LA29_2 = input.LA(1);
int index29_1 = input.index();
int index29_2 = input.index();
input.rewind();
s = -1;
if ( (synpred1_ActionSplitter()) ) {s = 2;}
if ( (synpred14_ActionSplitter()) ) {s = 3;}
else if ( (synpred2_ActionSplitter()) ) {s = 3;}
else if ( (synpred15_ActionSplitter()) ) {s = 4;}
else if ( (true) ) {s = 4;}
else if ( (synpred16_ActionSplitter()) ) {s = 5;}
else if ( (synpred17_ActionSplitter()) ) {s = 6;}
else if ( (synpred18_ActionSplitter()) ) {s = 7;}
else if ( (synpred19_ActionSplitter()) ) {s = 8;}
input.seek(index29_1);
input.seek(index29_2);
if ( s>=0 ) return s;
break;
case 2 :
int LA29_5 = input.LA(1);
int LA29_9 = input.LA(1);
int index29_5 = input.index();
int index29_9 = input.index();
input.rewind();
s = -1;
if ( (synpred14_ActionSplitter()) ) {s = 6;}
if ( (synpred1_ActionSplitter()) ) {s = 10;}
else if ( (synpred15_ActionSplitter()) ) {s = 7;}
else if ( (synpred2_ActionSplitter()) ) {s = 11;}
else if ( (synpred16_ActionSplitter()) ) {s = 8;}
else if ( (synpred17_ActionSplitter()) ) {s = 9;}
else if ( (synpred18_ActionSplitter()) ) {s = 10;}
else if ( (synpred19_ActionSplitter()) ) {s = 11;}
else if ( (true) ) {s = 1;}
input.seek(index29_5);
input.seek(index29_9);
if ( s>=0 ) return s;
break;
case 3 :
@ -2631,43 +2631,43 @@ public class ActionSplitter extends org.antlr.v4.runtime.Lexer {
int index29_12 = input.index();
input.rewind();
s = -1;
if ( (synpred4_ActionSplitter()) ) {s = 13;}
if ( (synpred3_ActionSplitter()) ) {s = 13;}
else if ( (synpred5_ActionSplitter()) ) {s = 14;}
else if ( (synpred6_ActionSplitter()) ) {s = 15;}
else if ( (synpred7_ActionSplitter()) ) {s = 16;}
else if ( (synpred8_ActionSplitter()) ) {s = 17;}
else if ( (synpred9_ActionSplitter()) ) {s = 18;}
else if ( (synpred10_ActionSplitter()) ) {s = 19;}
else if ( (synpred11_ActionSplitter()) ) {s = 20;}
else if ( (synpred12_ActionSplitter()) ) {s = 21;}
else if ( (synpred13_ActionSplitter()) ) {s = 22;}
else if ( (true) ) {s = 1;}
input.seek(index29_12);
if ( s>=0 ) return s;
break;
case 4 :
int LA29_23 = input.LA(1);
int LA29_14 = input.LA(1);
int index29_23 = input.index();
int index29_14 = input.index();
input.rewind();
s = -1;
if ( (synpred3_ActionSplitter()) ) {s = 24;}
if ( (synpred4_ActionSplitter()) ) {s = 15;}
else if ( (true) ) {s = 4;}
else if ( (synpred5_ActionSplitter()) ) {s = 16;}
else if ( (synpred6_ActionSplitter()) ) {s = 17;}
else if ( (synpred7_ActionSplitter()) ) {s = 18;}
else if ( (synpred8_ActionSplitter()) ) {s = 19;}
else if ( (synpred9_ActionSplitter()) ) {s = 20;}
else if ( (synpred10_ActionSplitter()) ) {s = 21;}
else if ( (synpred11_ActionSplitter()) ) {s = 22;}
else if ( (synpred12_ActionSplitter()) ) {s = 23;}
else if ( (synpred13_ActionSplitter()) ) {s = 24;}
input.seek(index29_23);
input.seek(index29_14);
if ( s>=0 ) return s;
break;
}

View File

@ -22,6 +22,6 @@ public interface ActionSplitterListener {
void setAttribute(String expr);
void templateExpr(String expr);
void unknownSyntax(String text);
void unknownSyntax(Token t);
void text(String text);
}

View File

@ -167,8 +167,9 @@ public class AttributeChecks implements ActionSplitterListener {
new AttributeChecks(g, r, alt, node, index).examineAction();
}
public void unknownSyntax(String text) {
System.err.println("unknown: "+text);
public void unknownSyntax(Token t) {
ErrorManager.grammarError(ErrorType.INVALID_TEMPLATE_ACTION,
g.fileName, t, t.getText());
}
public void text(String text) { }