got actions/scopes into grammar

[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 6690]
This commit is contained in:
parrt 2010-02-12 17:19:47 -08:00
parent 66f179823d
commit b108a7cf2a
16 changed files with 415 additions and 393 deletions

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRLexer.g 2010-02-12 14:08:47
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRLexer.g 2010-02-12 16:46:34
/*
[The "BSD licence"]
@ -263,7 +263,7 @@ public class ANTLRLexer extends Lexer {
if ( (( input.LA(2) != '/')) ) {
alt3=1;
}
else if ( ((( true )||(( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') )))) ) {
else if ( (((( true )&&( !(input.LA(1) == '*' && input.LA(2) == '/') ))||( true ))) ) {
alt3=2;
}
else {

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRParser.g 2010-02-12 14:08:49
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ANTLRParser.g 2010-02-12 16:46:36
/*
[The "BSD licence"]
@ -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: id, ASSIGN, STRING_LITERAL
// elements: STRING_LITERAL, id, ASSIGN
// token labels:
// rule labels: retval
// token list labels:
@ -1699,7 +1699,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: SCOPE, ACTION, id
// elements: ACTION, SCOPE, id
// token labels:
// rule labels: retval
// token list labels:
@ -1853,7 +1853,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: AT, ACTION, id, actionScopeName
// elements: AT, actionScopeName, id, ACTION
// token labels:
// rule labels: retval
// token list labels:
@ -2353,7 +2353,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ARG_ACTION, ruleModifiers, DOC_COMMENT, rulePrequel, altListAsBlock, ruleReturns, exceptionGroup, id
// elements: exceptionGroup, DOC_COMMENT, id, ARG_ACTION, rulePrequel, altListAsBlock, ruleReturns, ruleModifiers
// token labels:
// rule labels: retval
// token list labels:
@ -2579,7 +2579,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ACTION, CATCH, ARG_ACTION
// elements: ARG_ACTION, CATCH, ACTION
// token labels:
// rule labels: retval
// token list labels:
@ -2662,7 +2662,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: FINALLY, ACTION
// elements: ACTION, FINALLY
// token labels:
// rule labels: retval
// token list labels:
@ -2976,7 +2976,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: THROWS, qid
// elements: qid, THROWS
// token labels:
// rule labels: retval
// token list labels:
@ -3800,7 +3800,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: rewrite, elements
// elements: elements, rewrite
// token labels:
// rule labels: retval
// token list labels:
@ -4165,7 +4165,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ebnfSuffix, labeledElement
// elements: labeledElement, ebnfSuffix
// token labels:
// rule labels: retval
// token list labels:
@ -4279,7 +4279,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: atom, ebnfSuffix
// elements: ebnfSuffix, atom
// token labels:
// rule labels: retval
// token list labels:
@ -4504,7 +4504,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ebnfSuffix, treeSpec
// elements: treeSpec, ebnfSuffix
// token labels:
// rule labels: retval
// token list labels:
@ -4944,7 +4944,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: blockSuffixe, block
// elements: block, blockSuffixe
// token labels:
// rule labels: retval
// token list labels:
@ -5508,7 +5508,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: id, DOT, terminal
// elements: terminal, id, DOT
// 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:
@ -5750,7 +5750,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: NOT, block
// elements: block, NOT
// token labels:
// rule labels: retval
// token list labels:
@ -5984,7 +5984,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ra, optionsSpec, altList
// elements: altList, ra, optionsSpec
// token labels:
// rule labels: retval
// token list labels:
@ -6512,7 +6512,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: ARG_ACTION, TOKEN_REF, elementOptions
// elements: ARG_ACTION, elementOptions, TOKEN_REF
// token labels:
// rule labels: retval
// token list labels:
@ -6704,7 +6704,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: terminal, ROOT
// elements: ROOT, terminal
// token labels:
// rule labels: retval
// token list labels:
@ -7281,7 +7281,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: rewriteAlt, rewriteAlt, SEMPRED, SEMPRED
// elements: SEMPRED, SEMPRED, rewriteAlt, 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:
@ -7823,7 +7823,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: rewriteTree, ebnfSuffix
// elements: ebnfSuffix, rewriteTree
// token labels:
// rule labels: retval
// token list labels:
@ -8303,7 +8303,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: rewriteTreeAlt, ebnfSuffix
// elements: ebnfSuffix, rewriteTreeAlt
// token labels:
// rule labels: retval
// token list labels:
@ -8595,7 +8595,7 @@ public class ANTLRParser extends Parser {
// AST REWRITE
// elements: TEMPLATE, rewriteTemplateArgs, str
// elements: rewriteTemplateArgs, str, TEMPLATE
// token labels: str
// rule labels: retval
// token list labels:

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ASTVerifier.g 2010-02-12 14:08:50
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ASTVerifier.g 2010-02-12 16:46:37
/*
[The "BSD license"]

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ActionSplitter.g 2010-02-12 14:08:50
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 ActionSplitter.g 2010-02-12 16:46:37
package org.antlr.v4.parse;
@ -1990,6 +1990,20 @@ public class ActionSplitter extends Lexer {
state.failed=false;
return success;
}
public final boolean synpred12_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred12_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 synpred17_ActionSplitter() {
state.backtracking++;
int start = input.mark();
@ -2018,20 +2032,6 @@ public class ActionSplitter extends Lexer {
state.failed=false;
return success;
}
public final boolean synpred12_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred12_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 synpred9_ActionSplitter() {
state.backtracking++;
int start = input.mark();
@ -2102,20 +2102,6 @@ public class ActionSplitter extends Lexer {
state.failed=false;
return success;
}
public final boolean synpred18_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred18_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 synpred1_ActionSplitter() {
state.backtracking++;
int start = input.mark();
@ -2130,11 +2116,11 @@ public class ActionSplitter extends Lexer {
state.failed=false;
return success;
}
public final boolean synpred2_ActionSplitter() {
public final boolean synpred18_ActionSplitter() {
state.backtracking++;
int start = input.mark();
try {
synpred2_ActionSplitter_fragment(); // can never throw exception
synpred18_ActionSplitter_fragment(); // can never throw exception
} catch (RecognitionException re) {
System.err.println("impossible: "+re);
}
@ -2158,6 +2144,20 @@ public class ActionSplitter extends 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();
@ -2296,20 +2296,19 @@ public class ActionSplitter extends Lexer {
static final String DFA29_eofS =
"\27\uffff";
static final String DFA29_minS =
"\1\44\1\0\3\uffff\1\0\12\uffff\1\0\6\uffff";
"\1\44\1\0\2\uffff\1\0\7\uffff\1\0\12\uffff";
static final String DFA29_maxS =
"\1\134\1\0\3\uffff\1\0\12\uffff\1\0\6\uffff";
"\1\134\1\0\2\uffff\1\0\7\uffff\1\0\12\uffff";
static final String DFA29_acceptS =
"\2\uffff\1\1\1\2\1\23\1\uffff\1\3\1\4\1\5\1\6\1\7\1\10\1\11\1\12"+
"\1\13\1\14\1\uffff\1\15\1\16\1\17\1\20\1\21\1\22";
"\2\uffff\1\1\1\2\1\uffff\1\15\1\16\1\17\1\20\1\21\1\22\1\23\1\uffff"+
"\1\3\1\4\1\5\1\6\1\7\1\10\1\11\1\12\1\13\1\14";
static final String DFA29_specialS =
"\1\uffff\1\0\3\uffff\1\1\12\uffff\1\2\6\uffff}>";
"\1\uffff\1\0\2\uffff\1\1\7\uffff\1\2\12\uffff}>";
static final String[] DFA29_transitionS = {
"\1\5\1\20\11\uffff\1\1\54\uffff\1\4",
"\1\14\1\4\11\uffff\1\1\54\uffff\1\13",
"\1\uffff",
"",
"",
"",
"\1\uffff",
"",
"",
@ -2318,15 +2317,16 @@ public class ActionSplitter extends Lexer {
"",
"",
"",
"",
"",
"",
"\1\uffff",
"",
"",
"",
"",
"",
"",
"",
"",
"",
""
};
@ -2382,57 +2382,57 @@ public class ActionSplitter extends Lexer {
if ( s>=0 ) return s;
break;
case 1 :
int LA29_5 = input.LA(1);
int LA29_4 = input.LA(1);
int index29_5 = input.index();
int index29_4 = input.index();
input.rewind();
s = -1;
if ( (synpred3_ActionSplitter()) ) {s = 6;}
if ( (synpred13_ActionSplitter()) ) {s = 5;}
else if ( (synpred4_ActionSplitter()) ) {s = 7;}
else if ( (synpred14_ActionSplitter()) ) {s = 6;}
else if ( (synpred5_ActionSplitter()) ) {s = 8;}
else if ( (synpred15_ActionSplitter()) ) {s = 7;}
else if ( (synpred6_ActionSplitter()) ) {s = 9;}
else if ( (synpred16_ActionSplitter()) ) {s = 8;}
else if ( (synpred7_ActionSplitter()) ) {s = 10;}
else if ( (synpred17_ActionSplitter()) ) {s = 9;}
else if ( (synpred8_ActionSplitter()) ) {s = 11;}
else if ( (synpred9_ActionSplitter()) ) {s = 12;}
else if ( (synpred10_ActionSplitter()) ) {s = 13;}
else if ( (synpred11_ActionSplitter()) ) {s = 14;}
else if ( (synpred12_ActionSplitter()) ) {s = 15;}
else if ( (synpred18_ActionSplitter()) ) {s = 10;}
input.seek(index29_5);
input.seek(index29_4);
if ( s>=0 ) return s;
break;
case 2 :
int LA29_16 = input.LA(1);
int LA29_12 = input.LA(1);
int index29_16 = input.index();
int index29_12 = input.index();
input.rewind();
s = -1;
if ( (synpred13_ActionSplitter()) ) {s = 17;}
if ( (synpred3_ActionSplitter()) ) {s = 13;}
else if ( (synpred14_ActionSplitter()) ) {s = 18;}
else if ( (synpred4_ActionSplitter()) ) {s = 14;}
else if ( (synpred15_ActionSplitter()) ) {s = 19;}
else if ( (synpred5_ActionSplitter()) ) {s = 15;}
else if ( (synpred16_ActionSplitter()) ) {s = 20;}
else if ( (synpred6_ActionSplitter()) ) {s = 16;}
else if ( (synpred17_ActionSplitter()) ) {s = 21;}
else if ( (synpred7_ActionSplitter()) ) {s = 17;}
else if ( (synpred18_ActionSplitter()) ) {s = 22;}
else if ( (synpred8_ActionSplitter()) ) {s = 18;}
else if ( (synpred9_ActionSplitter()) ) {s = 19;}
else if ( (synpred10_ActionSplitter()) ) {s = 20;}
else if ( (synpred11_ActionSplitter()) ) {s = 21;}
else if ( (synpred12_ActionSplitter()) ) {s = 22;}
input.seek(index29_16);
input.seek(index29_12);
if ( s>=0 ) return s;
break;
}

View File

@ -24,8 +24,13 @@ public class AttributeChecks implements ActionSplitterListener {
this.action = action;
}
public static void checkAllAttributeExpressions(Grammar g, List<Rule> rules) {
for (Rule r : rules) {
public static void checkAllAttributeExpressions(Grammar g) {
for (ActionAST act : g.actions.values()) {
AttributeChecks checker = new AttributeChecks(g, null, null, act, act.getText());
checker.examineAction();
}
for (Rule r : g.rules.values()) {
for (ActionAST a : r.namedActions.values()) {
AttributeChecks checker = new AttributeChecks(g, r, null, a, a.getText());
checker.examineAction();
@ -57,7 +62,7 @@ public class AttributeChecks implements ActionSplitterListener {
// LISTENER METHODS
public void setQualifiedAttr(String expr, Token x, Token y, Token rhs) {
if ( !node.space.resolves(x.getText(), y.getText(), node) ) {
if ( !node.resolver.resolves(x.getText(), y.getText(), node) ) {
ErrorManager.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE, // TODO; not right error
g.fileName, x, x.getText(), expr);
}
@ -65,7 +70,7 @@ public class AttributeChecks implements ActionSplitterListener {
}
public void qualifiedAttr(String expr, Token x, Token y) {
if ( !node.space.resolves(x.getText(), node) ) {
if ( !node.resolver.resolves(x.getText(), node) ) {
ErrorManager.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE,
g.fileName, x, x.getText(), expr);
return;
@ -73,8 +78,8 @@ public class AttributeChecks implements ActionSplitterListener {
// ???if y is not prop of x, we don't care; we'll ignore and leave as simple attr
if ( !node.space.resolves(x.getText(), y.getText(), node) ) {
if ( node.space.resolveToRuleRef(x.getText(), node) ) {
if ( !node.resolver.resolves(x.getText(), y.getText(), node) ) {
if ( node.resolver.resolveRefToRule(x.getText(), node)!=null ) {
ErrorManager.grammarError(ErrorType.INVALID_RULE_PARAMETER_REF,
g.fileName, y, y.getText(), expr);
}
@ -86,7 +91,7 @@ public class AttributeChecks implements ActionSplitterListener {
}
public void setAttr(String expr, Token x, Token rhs) {
if ( !node.space.resolves(x.getText(), node) ) {
if ( !node.resolver.resolves(x.getText(), node) ) {
ErrorManager.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE,
g.fileName, x, x.getText(), expr);
}
@ -95,12 +100,12 @@ public class AttributeChecks implements ActionSplitterListener {
public void attr(String expr, Token x) { // arg, retval, predefined, token ref, rule ref, current rule
// TODO: check for isolated rule ref "+x+" in "+expr);
if ( node.space.resolveToRuleRef(x.getText(), node) ) {
if ( node.resolver.resolveRefToRule(x.getText(), node)!=null ) {
ErrorManager.grammarError(ErrorType.ISOLATED_RULE_SCOPE,
g.fileName, x, x.getText(), expr);
return;
}
if ( !node.space.resolves(x.getText(), node) ) {
if ( !node.resolver.resolves(x.getText(), node) ) {
ErrorManager.grammarError(ErrorType.UNKNOWN_SIMPLE_ATTRIBUTE,
g.fileName, x, x.getText(), expr);
}

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 BasicSemanticTriggers.g 2010-02-12 14:54:09
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 BasicSemanticTriggers.g 2010-02-12 17:18:11
/*
[The "BSD license"]

View File

@ -80,7 +80,7 @@ public List<GrammarAST> terminals = new ArrayList<GrammarAST>();
public List<GrammarAST> tokenIDRefs = new ArrayList<GrammarAST>();
public List<GrammarAST> strings = new ArrayList<GrammarAST>();
public List<GrammarAST> tokensDefs = new ArrayList<GrammarAST>();
public List<GrammarAST> scopes = new ArrayList<GrammarAST>();
public List<AttributeScope> scopes = new ArrayList<AttributeScope>();
public List<GrammarAST> actions = new ArrayList<GrammarAST>();
Grammar g; // which grammar are we checking
public CollectSymbols(TreeNodeStream input, Grammar g) {
@ -114,12 +114,17 @@ bottomup
;
globalScope
: {inContext("GRAMMAR")}? ^(SCOPE ID ACTION) {scopes.add($SCOPE);}
: {inContext("GRAMMAR")}? ^(SCOPE ID ACTION)
{
AttributeScope s = ScopeParser.parseDynamicScope($ACTION.text);
s.ast = $ACTION;
scopes.add(s);
}
;
globalNamedAction
: {inContext("GRAMMAR")}? ^(AT ID? ID ACTION)
{actions.add($AT);}
{actions.add($AT); ((ActionAST)$ACTION).resolver = g;}
;
tokensSection
@ -151,11 +156,11 @@ finishRule
: RULE {currentRule = null;}
;
rulelNamedAction
ruleNamedAction
: {inContext("RULE")}? ^(AT ID ACTION)
{
currentRule.namedActions.put($ID.text,(ActionAST)$ACTION);
((ActionAST)$ACTION).space = currentRule;
((ActionAST)$ACTION).resolver = currentRule;
}
;
@ -165,7 +170,7 @@ ruleAction
ACTION
{
currentRule.alt[currentAlt].actions.add((ActionAST)$ACTION);
((ActionAST)$ACTION).space = currentRule.alt[currentAlt];
((ActionAST)$ACTION).resolver = currentRule.alt[currentAlt];
}
;
@ -173,7 +178,7 @@ exceptionHandler
: ^(CATCH ARG_ACTION ACTION)
{
currentRule.exceptionActions.add((ActionAST)$ACTION);
((ActionAST)$ACTION).space = currentRule;
((ActionAST)$ACTION).resolver = currentRule;
}
;
@ -181,7 +186,7 @@ finallyClause
: ^(FINALLY ACTION)
{
currentRule.exceptionActions.add((ActionAST)$ACTION);
((ActionAST)$ACTION).space = currentRule;
((ActionAST)$ACTION).resolver = currentRule;
}
;

View File

@ -1,4 +1,4 @@
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 CollectSymbols.g 2010-02-12 14:54:08
// $ANTLR 3.2.1-SNAPSHOT Jan 26, 2010 15:12:28 CollectSymbols.g 2010-02-12 17:18:11
/*
[The "BSD license"]
@ -167,7 +167,7 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
public List<GrammarAST> tokenIDRefs = new ArrayList<GrammarAST>();
public List<GrammarAST> strings = new ArrayList<GrammarAST>();
public List<GrammarAST> tokensDefs = new ArrayList<GrammarAST>();
public List<GrammarAST> scopes = new ArrayList<GrammarAST>();
public List<AttributeScope> scopes = new ArrayList<AttributeScope>();
public List<GrammarAST> actions = new ArrayList<GrammarAST>();
Grammar g; // which grammar are we checking
public CollectSymbols(TreeNodeStream input, Grammar g) {
@ -394,7 +394,7 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "globalScope"
// CollectSymbols.g:116:1: globalScope : {...}? ^( SCOPE ID ACTION ) ;
public final void globalScope() throws RecognitionException {
GrammarAST SCOPE1=null;
GrammarAST ACTION1=null;
try {
// CollectSymbols.g:117:2: ({...}? ^( SCOPE ID ACTION ) )
@ -404,15 +404,19 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
if (state.backtracking>0) {state.failed=true; return ;}
throw new FailedPredicateException(input, "globalScope", "inContext(\"GRAMMAR\")");
}
SCOPE1=(GrammarAST)match(input,SCOPE,FOLLOW_SCOPE_in_globalScope247); if (state.failed) return ;
match(input,SCOPE,FOLLOW_SCOPE_in_globalScope247); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
match(input,ID,FOLLOW_ID_in_globalScope249); if (state.failed) return ;
match(input,ACTION,FOLLOW_ACTION_in_globalScope251); if (state.failed) return ;
ACTION1=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_globalScope251); if (state.failed) return ;
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
scopes.add(SCOPE1);
AttributeScope s = ScopeParser.parseDynamicScope((ACTION1!=null?ACTION1.getText():null));
s.ast = ACTION1;
scopes.add(s);
}
}
@ -430,22 +434,23 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "globalNamedAction"
// CollectSymbols.g:120:1: globalNamedAction : {...}? ^( AT ( ID )? ID ACTION ) ;
// CollectSymbols.g:125:1: globalNamedAction : {...}? ^( AT ( ID )? ID ACTION ) ;
public final void globalNamedAction() throws RecognitionException {
GrammarAST AT2=null;
GrammarAST ACTION3=null;
try {
// CollectSymbols.g:121:2: ({...}? ^( AT ( ID )? ID ACTION ) )
// CollectSymbols.g:121:4: {...}? ^( AT ( ID )? ID ACTION )
// CollectSymbols.g:126:2: ({...}? ^( AT ( ID )? ID ACTION ) )
// CollectSymbols.g:126:4: {...}? ^( AT ( ID )? ID ACTION )
{
if ( !((inContext("GRAMMAR"))) ) {
if (state.backtracking>0) {state.failed=true; return ;}
throw new FailedPredicateException(input, "globalNamedAction", "inContext(\"GRAMMAR\")");
}
AT2=(GrammarAST)match(input,AT,FOLLOW_AT_in_globalNamedAction268); if (state.failed) return ;
AT2=(GrammarAST)match(input,AT,FOLLOW_AT_in_globalNamedAction270); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
// CollectSymbols.g:121:33: ( ID )?
// CollectSymbols.g:126:33: ( ID )?
int alt2=2;
int LA2_0 = input.LA(1);
@ -458,21 +463,21 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
}
switch (alt2) {
case 1 :
// CollectSymbols.g:121:33: ID
// CollectSymbols.g:126:33: ID
{
match(input,ID,FOLLOW_ID_in_globalNamedAction270); if (state.failed) return ;
match(input,ID,FOLLOW_ID_in_globalNamedAction272); if (state.failed) return ;
}
break;
}
match(input,ID,FOLLOW_ID_in_globalNamedAction273); if (state.failed) return ;
match(input,ACTION,FOLLOW_ACTION_in_globalNamedAction275); if (state.failed) return ;
match(input,ID,FOLLOW_ID_in_globalNamedAction275); if (state.failed) return ;
ACTION3=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_globalNamedAction277); if (state.failed) return ;
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
actions.add(AT2);
actions.add(AT2); ((ActionAST)ACTION3).resolver = g;
}
}
@ -490,21 +495,21 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "tokensSection"
// CollectSymbols.g:125:1: tokensSection : {...}? ( ^( ASSIGN t= ID STRING_LITERAL ) | t= ID ) ;
// CollectSymbols.g:130:1: tokensSection : {...}? ( ^( ASSIGN t= ID STRING_LITERAL ) | t= ID ) ;
public final void tokensSection() throws RecognitionException {
GrammarAST t=null;
GrammarAST ASSIGN3=null;
GrammarAST STRING_LITERAL4=null;
GrammarAST ASSIGN4=null;
GrammarAST STRING_LITERAL5=null;
try {
// CollectSymbols.g:126:2: ({...}? ( ^( ASSIGN t= ID STRING_LITERAL ) | t= ID ) )
// CollectSymbols.g:126:4: {...}? ( ^( ASSIGN t= ID STRING_LITERAL ) | t= ID )
// CollectSymbols.g:131:2: ({...}? ( ^( ASSIGN t= ID STRING_LITERAL ) | t= ID ) )
// CollectSymbols.g:131:4: {...}? ( ^( ASSIGN t= ID STRING_LITERAL ) | t= ID )
{
if ( !((inContext("TOKENS"))) ) {
if (state.backtracking>0) {state.failed=true; return ;}
throw new FailedPredicateException(input, "tokensSection", "inContext(\"TOKENS\")");
}
// CollectSymbols.g:127:3: ( ^( ASSIGN t= ID STRING_LITERAL ) | t= ID )
// CollectSymbols.g:132:3: ( ^( ASSIGN t= ID STRING_LITERAL ) | t= ID )
int alt3=2;
int LA3_0 = input.LA(1);
@ -523,26 +528,26 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
}
switch (alt3) {
case 1 :
// CollectSymbols.g:127:5: ^( ASSIGN t= ID STRING_LITERAL )
// CollectSymbols.g:132:5: ^( ASSIGN t= ID STRING_LITERAL )
{
ASSIGN3=(GrammarAST)match(input,ASSIGN,FOLLOW_ASSIGN_in_tokensSection298); if (state.failed) return ;
ASSIGN4=(GrammarAST)match(input,ASSIGN,FOLLOW_ASSIGN_in_tokensSection300); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
t=(GrammarAST)match(input,ID,FOLLOW_ID_in_tokensSection302); if (state.failed) return ;
STRING_LITERAL4=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_tokensSection304); if (state.failed) return ;
t=(GrammarAST)match(input,ID,FOLLOW_ID_in_tokensSection304); if (state.failed) return ;
STRING_LITERAL5=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_tokensSection306); if (state.failed) return ;
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
terminals.add(t); tokenIDRefs.add(t);
tokensDefs.add(ASSIGN3); strings.add(STRING_LITERAL4);
tokensDefs.add(ASSIGN4); strings.add(STRING_LITERAL5);
}
}
break;
case 2 :
// CollectSymbols.g:130:5: t= ID
// CollectSymbols.g:135:5: t= ID
{
t=(GrammarAST)match(input,ID,FOLLOW_ID_in_tokensSection318); if (state.failed) return ;
t=(GrammarAST)match(input,ID,FOLLOW_ID_in_tokensSection320); if (state.failed) return ;
if ( state.backtracking==1 ) {
terminals.add(t); tokenIDRefs.add(t); tokensDefs.add(t);
}
@ -568,20 +573,20 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "rule"
// CollectSymbols.g:135:1: rule : ^( RULE name= ID ( . )+ ) ;
// CollectSymbols.g:140:1: rule : ^( RULE name= ID ( . )+ ) ;
public final void rule() throws RecognitionException {
GrammarAST name=null;
GrammarAST RULE5=null;
GrammarAST RULE6=null;
try {
// CollectSymbols.g:135:5: ( ^( RULE name= ID ( . )+ ) )
// CollectSymbols.g:135:9: ^( RULE name= ID ( . )+ )
// CollectSymbols.g:140:5: ( ^( RULE name= ID ( . )+ ) )
// CollectSymbols.g:140:9: ^( RULE name= ID ( . )+ )
{
RULE5=(GrammarAST)match(input,RULE,FOLLOW_RULE_in_rule340); if (state.failed) return ;
RULE6=(GrammarAST)match(input,RULE,FOLLOW_RULE_in_rule342); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
name=(GrammarAST)match(input,ID,FOLLOW_ID_in_rule344); if (state.failed) return ;
// CollectSymbols.g:135:25: ( . )+
name=(GrammarAST)match(input,ID,FOLLOW_ID_in_rule346); if (state.failed) return ;
// CollectSymbols.g:140:25: ( . )+
int cnt4=0;
loop4:
do {
@ -598,7 +603,7 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
switch (alt4) {
case 1 :
// CollectSymbols.g:135:25: .
// CollectSymbols.g:140:25: .
{
matchAny(input); if (state.failed) return ;
@ -619,8 +624,8 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
int numAlts = RULE5.getFirstChildWithType(BLOCK).getChildCount();
Rule r = new Rule(g, (name!=null?name.getText():null), (GrammarASTWithOptions)RULE5, numAlts);
int numAlts = RULE6.getFirstChildWithType(BLOCK).getChildCount();
Rule r = new Rule(g, (name!=null?name.getText():null), (GrammarASTWithOptions)RULE6, numAlts);
rules.add(r);
currentRule = r;
currentAlt = 1;
@ -644,14 +649,14 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
};
// $ANTLR start "setAlt"
// CollectSymbols.g:145:1: setAlt : {...}? ( ALT | ALT_REWRITE ) ;
// CollectSymbols.g:150:1: setAlt : {...}? ( ALT | ALT_REWRITE ) ;
public final CollectSymbols.setAlt_return setAlt() throws RecognitionException {
CollectSymbols.setAlt_return retval = new CollectSymbols.setAlt_return();
retval.start = input.LT(1);
try {
// CollectSymbols.g:146:2: ({...}? ( ALT | ALT_REWRITE ) )
// CollectSymbols.g:146:4: {...}? ( ALT | ALT_REWRITE )
// CollectSymbols.g:151:2: ({...}? ( ALT | ALT_REWRITE ) )
// CollectSymbols.g:151:4: {...}? ( ALT | ALT_REWRITE )
{
if ( !((inContext("RULE BLOCK"))) ) {
if (state.backtracking>0) {state.failed=true; return retval;}
@ -686,13 +691,13 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "finishRule"
// CollectSymbols.g:150:1: finishRule : RULE ;
// CollectSymbols.g:155:1: finishRule : RULE ;
public final void finishRule() throws RecognitionException {
try {
// CollectSymbols.g:151:2: ( RULE )
// CollectSymbols.g:151:4: RULE
// CollectSymbols.g:156:2: ( RULE )
// CollectSymbols.g:156:4: RULE
{
match(input,RULE,FOLLOW_RULE_in_finishRule392); if (state.failed) return ;
match(input,RULE,FOLLOW_RULE_in_finishRule394); if (state.failed) return ;
if ( state.backtracking==1 ) {
currentRule = null;
}
@ -711,31 +716,31 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR end "finishRule"
// $ANTLR start "rulelNamedAction"
// CollectSymbols.g:154:1: rulelNamedAction : {...}? ^( AT ID ACTION ) ;
public final void rulelNamedAction() throws RecognitionException {
GrammarAST ID6=null;
GrammarAST ACTION7=null;
// $ANTLR start "ruleNamedAction"
// CollectSymbols.g:159:1: ruleNamedAction : {...}? ^( AT ID ACTION ) ;
public final void ruleNamedAction() throws RecognitionException {
GrammarAST ID7=null;
GrammarAST ACTION8=null;
try {
// CollectSymbols.g:155:2: ({...}? ^( AT ID ACTION ) )
// CollectSymbols.g:155:4: {...}? ^( AT ID ACTION )
// CollectSymbols.g:160:2: ({...}? ^( AT ID ACTION ) )
// CollectSymbols.g:160:4: {...}? ^( AT ID ACTION )
{
if ( !((inContext("RULE"))) ) {
if (state.backtracking>0) {state.failed=true; return ;}
throw new FailedPredicateException(input, "rulelNamedAction", "inContext(\"RULE\")");
throw new FailedPredicateException(input, "ruleNamedAction", "inContext(\"RULE\")");
}
match(input,AT,FOLLOW_AT_in_rulelNamedAction408); if (state.failed) return ;
match(input,AT,FOLLOW_AT_in_ruleNamedAction410); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
ID6=(GrammarAST)match(input,ID,FOLLOW_ID_in_rulelNamedAction410); if (state.failed) return ;
ACTION7=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_rulelNamedAction412); if (state.failed) return ;
ID7=(GrammarAST)match(input,ID,FOLLOW_ID_in_ruleNamedAction412); if (state.failed) return ;
ACTION8=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_ruleNamedAction414); if (state.failed) return ;
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
currentRule.namedActions.put((ID6!=null?ID6.getText():null),(ActionAST)ACTION7);
((ActionAST)ACTION7).space = currentRule;
currentRule.namedActions.put((ID7!=null?ID7.getText():null),(ActionAST)ACTION8);
((ActionAST)ACTION8).resolver = currentRule;
}
@ -750,28 +755,28 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
}
return ;
}
// $ANTLR end "rulelNamedAction"
// $ANTLR end "ruleNamedAction"
// $ANTLR start "ruleAction"
// CollectSymbols.g:162:1: ruleAction : {...}? ACTION ;
// CollectSymbols.g:167:1: ruleAction : {...}? ACTION ;
public final void ruleAction() throws RecognitionException {
GrammarAST ACTION8=null;
GrammarAST ACTION9=null;
try {
// CollectSymbols.g:163:2: ({...}? ACTION )
// CollectSymbols.g:163:4: {...}? ACTION
// CollectSymbols.g:168:2: ({...}? ACTION )
// CollectSymbols.g:168:4: {...}? ACTION
{
if ( !((inContext("RULE ...")&&!inContext("SCOPE")&&
!inContext("CATCH")&&!inContext("FINALLY"))) ) {
if (state.backtracking>0) {state.failed=true; return ;}
throw new FailedPredicateException(input, "ruleAction", "inContext(\"RULE ...\")&&!inContext(\"SCOPE\")&&\n\t\t !inContext(\"CATCH\")&&!inContext(\"FINALLY\")");
}
ACTION8=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_ruleAction432); if (state.failed) return ;
ACTION9=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_ruleAction434); if (state.failed) return ;
if ( state.backtracking==1 ) {
currentRule.alt[currentAlt].actions.add((ActionAST)ACTION8);
((ActionAST)ACTION8).space = currentRule.alt[currentAlt];
currentRule.alt[currentAlt].actions.add((ActionAST)ACTION9);
((ActionAST)ACTION9).resolver = currentRule.alt[currentAlt];
}
@ -790,25 +795,25 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "exceptionHandler"
// CollectSymbols.g:172:1: exceptionHandler : ^( CATCH ARG_ACTION ACTION ) ;
// CollectSymbols.g:177:1: exceptionHandler : ^( CATCH ARG_ACTION ACTION ) ;
public final void exceptionHandler() throws RecognitionException {
GrammarAST ACTION9=null;
GrammarAST ACTION10=null;
try {
// CollectSymbols.g:173:2: ( ^( CATCH ARG_ACTION ACTION ) )
// CollectSymbols.g:173:4: ^( CATCH ARG_ACTION ACTION )
// CollectSymbols.g:178:2: ( ^( CATCH ARG_ACTION ACTION ) )
// CollectSymbols.g:178:4: ^( CATCH ARG_ACTION ACTION )
{
match(input,CATCH,FOLLOW_CATCH_in_exceptionHandler448); if (state.failed) return ;
match(input,CATCH,FOLLOW_CATCH_in_exceptionHandler450); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_exceptionHandler450); if (state.failed) return ;
ACTION9=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_exceptionHandler452); if (state.failed) return ;
match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_exceptionHandler452); if (state.failed) return ;
ACTION10=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_exceptionHandler454); if (state.failed) return ;
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
currentRule.exceptionActions.add((ActionAST)ACTION9);
((ActionAST)ACTION9).space = currentRule;
currentRule.exceptionActions.add((ActionAST)ACTION10);
((ActionAST)ACTION10).resolver = currentRule;
}
@ -827,24 +832,24 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "finallyClause"
// CollectSymbols.g:180:1: finallyClause : ^( FINALLY ACTION ) ;
// CollectSymbols.g:185:1: finallyClause : ^( FINALLY ACTION ) ;
public final void finallyClause() throws RecognitionException {
GrammarAST ACTION10=null;
GrammarAST ACTION11=null;
try {
// CollectSymbols.g:181:2: ( ^( FINALLY ACTION ) )
// CollectSymbols.g:181:4: ^( FINALLY ACTION )
// CollectSymbols.g:186:2: ( ^( FINALLY ACTION ) )
// CollectSymbols.g:186:4: ^( FINALLY ACTION )
{
match(input,FINALLY,FOLLOW_FINALLY_in_finallyClause469); if (state.failed) return ;
match(input,FINALLY,FOLLOW_FINALLY_in_finallyClause471); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
ACTION10=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_finallyClause471); if (state.failed) return ;
ACTION11=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_finallyClause473); if (state.failed) return ;
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
currentRule.exceptionActions.add((ActionAST)ACTION10);
((ActionAST)ACTION10).space = currentRule;
currentRule.exceptionActions.add((ActionAST)ACTION11);
((ActionAST)ACTION11).resolver = currentRule;
}
@ -863,23 +868,23 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "ruleArg"
// CollectSymbols.g:188:1: ruleArg : {...}? ARG_ACTION ;
// CollectSymbols.g:193:1: ruleArg : {...}? ARG_ACTION ;
public final void ruleArg() throws RecognitionException {
GrammarAST ARG_ACTION11=null;
GrammarAST ARG_ACTION12=null;
try {
// CollectSymbols.g:189:2: ({...}? ARG_ACTION )
// CollectSymbols.g:189:4: {...}? ARG_ACTION
// CollectSymbols.g:194:2: ({...}? ARG_ACTION )
// CollectSymbols.g:194:4: {...}? ARG_ACTION
{
if ( !((inContext("RULE"))) ) {
if (state.backtracking>0) {state.failed=true; return ;}
throw new FailedPredicateException(input, "ruleArg", "inContext(\"RULE\")");
}
ARG_ACTION11=(GrammarAST)match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleArg491); if (state.failed) return ;
ARG_ACTION12=(GrammarAST)match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleArg493); if (state.failed) return ;
if ( state.backtracking==1 ) {
currentRule.args = ScopeParser.parseTypeList((ARG_ACTION11!=null?ARG_ACTION11.getText():null));
currentRule.args.ast = ARG_ACTION11;
currentRule.args = ScopeParser.parseTypeList((ARG_ACTION12!=null?ARG_ACTION12.getText():null));
currentRule.args.ast = ARG_ACTION12;
}
@ -898,24 +903,24 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "ruleReturns"
// CollectSymbols.g:196:1: ruleReturns : ^( RETURNS ARG_ACTION ) ;
// CollectSymbols.g:201:1: ruleReturns : ^( RETURNS ARG_ACTION ) ;
public final void ruleReturns() throws RecognitionException {
GrammarAST ARG_ACTION12=null;
GrammarAST ARG_ACTION13=null;
try {
// CollectSymbols.g:197:2: ( ^( RETURNS ARG_ACTION ) )
// CollectSymbols.g:197:4: ^( RETURNS ARG_ACTION )
// CollectSymbols.g:202:2: ( ^( RETURNS ARG_ACTION ) )
// CollectSymbols.g:202:4: ^( RETURNS ARG_ACTION )
{
match(input,RETURNS,FOLLOW_RETURNS_in_ruleReturns508); if (state.failed) return ;
match(input,RETURNS,FOLLOW_RETURNS_in_ruleReturns510); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
ARG_ACTION12=(GrammarAST)match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleReturns510); if (state.failed) return ;
ARG_ACTION13=(GrammarAST)match(input,ARG_ACTION,FOLLOW_ARG_ACTION_in_ruleReturns512); if (state.failed) return ;
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
currentRule.retvals = ScopeParser.parseTypeList((ARG_ACTION12!=null?ARG_ACTION12.getText():null));
currentRule.retvals.ast = ARG_ACTION12;
currentRule.retvals = ScopeParser.parseTypeList((ARG_ACTION13!=null?ARG_ACTION13.getText():null));
currentRule.retvals.ast = ARG_ACTION13;
}
@ -934,21 +939,21 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "ruleScopeSpec"
// CollectSymbols.g:204:1: ruleScopeSpec : {...}? ( ^( SCOPE ACTION ) | ^( SCOPE (ids+= ID )+ ) ) ;
// CollectSymbols.g:209:1: ruleScopeSpec : {...}? ( ^( SCOPE ACTION ) | ^( SCOPE (ids+= ID )+ ) ) ;
public final void ruleScopeSpec() throws RecognitionException {
GrammarAST ACTION13=null;
GrammarAST ACTION14=null;
GrammarAST ids=null;
List list_ids=null;
try {
// CollectSymbols.g:205:2: ({...}? ( ^( SCOPE ACTION ) | ^( SCOPE (ids+= ID )+ ) ) )
// CollectSymbols.g:205:4: {...}? ( ^( SCOPE ACTION ) | ^( SCOPE (ids+= ID )+ ) )
// CollectSymbols.g:210:2: ({...}? ( ^( SCOPE ACTION ) | ^( SCOPE (ids+= ID )+ ) ) )
// CollectSymbols.g:210:4: {...}? ( ^( SCOPE ACTION ) | ^( SCOPE (ids+= ID )+ ) )
{
if ( !((inContext("RULE"))) ) {
if (state.backtracking>0) {state.failed=true; return ;}
throw new FailedPredicateException(input, "ruleScopeSpec", "inContext(\"RULE\")");
}
// CollectSymbols.g:206:3: ( ^( SCOPE ACTION ) | ^( SCOPE (ids+= ID )+ ) )
// CollectSymbols.g:211:3: ( ^( SCOPE ACTION ) | ^( SCOPE (ids+= ID )+ ) )
int alt6=2;
int LA6_0 = input.LA(1);
@ -989,30 +994,30 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
}
switch (alt6) {
case 1 :
// CollectSymbols.g:206:5: ^( SCOPE ACTION )
// CollectSymbols.g:211:5: ^( SCOPE ACTION )
{
match(input,SCOPE,FOLLOW_SCOPE_in_ruleScopeSpec533); if (state.failed) return ;
match(input,SCOPE,FOLLOW_SCOPE_in_ruleScopeSpec535); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
ACTION13=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_ruleScopeSpec535); if (state.failed) return ;
ACTION14=(GrammarAST)match(input,ACTION,FOLLOW_ACTION_in_ruleScopeSpec537); if (state.failed) return ;
match(input, Token.UP, null); if (state.failed) return ;
if ( state.backtracking==1 ) {
currentRule.scope = ScopeParser.parseDynamicScope((ACTION13!=null?ACTION13.getText():null));
currentRule.scope.ast = ACTION13;
currentRule.scope = ScopeParser.parseDynamicScope((ACTION14!=null?ACTION14.getText():null));
currentRule.scope.ast = ACTION14;
}
}
break;
case 2 :
// CollectSymbols.g:211:5: ^( SCOPE (ids+= ID )+ )
// CollectSymbols.g:216:5: ^( SCOPE (ids+= ID )+ )
{
match(input,SCOPE,FOLLOW_SCOPE_in_ruleScopeSpec548); if (state.failed) return ;
match(input,SCOPE,FOLLOW_SCOPE_in_ruleScopeSpec550); if (state.failed) return ;
match(input, Token.DOWN, null); if (state.failed) return ;
// CollectSymbols.g:211:16: (ids+= ID )+
// CollectSymbols.g:216:16: (ids+= ID )+
int cnt5=0;
loop5:
do {
@ -1026,9 +1031,9 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
switch (alt5) {
case 1 :
// CollectSymbols.g:211:16: ids+= ID
// CollectSymbols.g:216:16: ids+= ID
{
ids=(GrammarAST)match(input,ID,FOLLOW_ID_in_ruleScopeSpec552); if (state.failed) return ;
ids=(GrammarAST)match(input,ID,FOLLOW_ID_in_ruleScopeSpec554); if (state.failed) return ;
if (list_ids==null) list_ids=new ArrayList();
list_ids.add(ids);
@ -1075,14 +1080,14 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
};
// $ANTLR start "rewriteElement"
// CollectSymbols.g:215:1: rewriteElement : {...}? ( TOKEN_REF | RULE_REF | STRING_LITERAL | LABEL ) ;
// CollectSymbols.g:220:1: rewriteElement : {...}? ( TOKEN_REF | RULE_REF | STRING_LITERAL | LABEL ) ;
public final CollectSymbols.rewriteElement_return rewriteElement() throws RecognitionException {
CollectSymbols.rewriteElement_return retval = new CollectSymbols.rewriteElement_return();
retval.start = input.LT(1);
try {
// CollectSymbols.g:217:2: ({...}? ( TOKEN_REF | RULE_REF | STRING_LITERAL | LABEL ) )
// CollectSymbols.g:218:6: {...}? ( TOKEN_REF | RULE_REF | STRING_LITERAL | LABEL )
// CollectSymbols.g:222:2: ({...}? ( TOKEN_REF | RULE_REF | STRING_LITERAL | LABEL ) )
// CollectSymbols.g:223:6: {...}? ( TOKEN_REF | RULE_REF | STRING_LITERAL | LABEL )
{
if ( !((inContext("RESULT ..."))) ) {
if (state.backtracking>0) {state.failed=true; return retval;}
@ -1119,7 +1124,7 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
};
// $ANTLR start "labeledElement"
// CollectSymbols.g:222:1: labeledElement : {...}? ( ^( ASSIGN id= ID e= . ) | ^( PLUS_ASSIGN id= ID e= . ) ) ;
// CollectSymbols.g:227:1: labeledElement : {...}? ( ^( ASSIGN id= ID e= . ) | ^( PLUS_ASSIGN id= ID e= . ) ) ;
public final CollectSymbols.labeledElement_return labeledElement() throws RecognitionException {
CollectSymbols.labeledElement_return retval = new CollectSymbols.labeledElement_return();
retval.start = input.LT(1);
@ -1128,14 +1133,14 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
GrammarAST e=null;
try {
// CollectSymbols.g:228:2: ({...}? ( ^( ASSIGN id= ID e= . ) | ^( PLUS_ASSIGN id= ID e= . ) ) )
// CollectSymbols.g:228:4: {...}? ( ^( ASSIGN id= ID e= . ) | ^( PLUS_ASSIGN id= ID e= . ) )
// CollectSymbols.g:233:2: ({...}? ( ^( ASSIGN id= ID e= . ) | ^( PLUS_ASSIGN id= ID e= . ) ) )
// CollectSymbols.g:233:4: {...}? ( ^( ASSIGN id= ID e= . ) | ^( PLUS_ASSIGN id= ID e= . ) )
{
if ( !((inContext("RULE ..."))) ) {
if (state.backtracking>0) {state.failed=true; return retval;}
throw new FailedPredicateException(input, "labeledElement", "inContext(\"RULE ...\")");
}
// CollectSymbols.g:229:3: ( ^( ASSIGN id= ID e= . ) | ^( PLUS_ASSIGN id= ID e= . ) )
// CollectSymbols.g:234:3: ( ^( ASSIGN id= ID e= . ) | ^( PLUS_ASSIGN id= ID e= . ) )
int alt7=2;
int LA7_0 = input.LA(1);
@ -1154,12 +1159,12 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
}
switch (alt7) {
case 1 :
// CollectSymbols.g:229:5: ^( ASSIGN id= ID e= . )
// CollectSymbols.g:234:5: ^( ASSIGN id= ID e= . )
{
match(input,ASSIGN,FOLLOW_ASSIGN_in_labeledElement616); if (state.failed) return retval;
match(input,ASSIGN,FOLLOW_ASSIGN_in_labeledElement618); if (state.failed) return retval;
match(input, Token.DOWN, null); if (state.failed) return retval;
id=(GrammarAST)match(input,ID,FOLLOW_ID_in_labeledElement620); if (state.failed) return retval;
id=(GrammarAST)match(input,ID,FOLLOW_ID_in_labeledElement622); if (state.failed) return retval;
e=(GrammarAST)input.LT(1);
matchAny(input); if (state.failed) return retval;
@ -1168,12 +1173,12 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
}
break;
case 2 :
// CollectSymbols.g:230:5: ^( PLUS_ASSIGN id= ID e= . )
// CollectSymbols.g:235:5: ^( PLUS_ASSIGN id= ID e= . )
{
match(input,PLUS_ASSIGN,FOLLOW_PLUS_ASSIGN_in_labeledElement632); if (state.failed) return retval;
match(input,PLUS_ASSIGN,FOLLOW_PLUS_ASSIGN_in_labeledElement634); if (state.failed) return retval;
match(input, Token.DOWN, null); if (state.failed) return retval;
id=(GrammarAST)match(input,ID,FOLLOW_ID_in_labeledElement636); if (state.failed) return retval;
id=(GrammarAST)match(input,ID,FOLLOW_ID_in_labeledElement638); if (state.failed) return retval;
e=(GrammarAST)input.LT(1);
matchAny(input); if (state.failed) return retval;
@ -1209,16 +1214,16 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
};
// $ANTLR start "terminal"
// CollectSymbols.g:234:1: terminal : ({...}? STRING_LITERAL | TOKEN_REF );
// CollectSymbols.g:239:1: terminal : ({...}? STRING_LITERAL | TOKEN_REF );
public final CollectSymbols.terminal_return terminal() throws RecognitionException {
CollectSymbols.terminal_return retval = new CollectSymbols.terminal_return();
retval.start = input.LT(1);
GrammarAST STRING_LITERAL14=null;
GrammarAST TOKEN_REF15=null;
GrammarAST STRING_LITERAL15=null;
GrammarAST TOKEN_REF16=null;
try {
// CollectSymbols.g:235:5: ({...}? STRING_LITERAL | TOKEN_REF )
// CollectSymbols.g:240:5: ({...}? STRING_LITERAL | TOKEN_REF )
int alt8=2;
int LA8_0 = input.LA(1);
@ -1237,19 +1242,19 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
}
switch (alt8) {
case 1 :
// CollectSymbols.g:235:7: {...}? STRING_LITERAL
// CollectSymbols.g:240:7: {...}? STRING_LITERAL
{
if ( !((!inContext("TOKENS ASSIGN"))) ) {
if (state.backtracking>0) {state.failed=true; return retval;}
throw new FailedPredicateException(input, "terminal", "!inContext(\"TOKENS ASSIGN\")");
}
STRING_LITERAL14=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal662); if (state.failed) return retval;
STRING_LITERAL15=(GrammarAST)match(input,STRING_LITERAL,FOLLOW_STRING_LITERAL_in_terminal664); if (state.failed) return retval;
if ( state.backtracking==1 ) {
terminals.add(((GrammarAST)retval.start));
strings.add(STRING_LITERAL14);
strings.add(STRING_LITERAL15);
if ( currentRule!=null ) {
currentRule.alt[currentAlt].tokenRefs.map((STRING_LITERAL14!=null?STRING_LITERAL14.getText():null), STRING_LITERAL14);
currentRule.alt[currentAlt].tokenRefs.map((STRING_LITERAL15!=null?STRING_LITERAL15.getText():null), STRING_LITERAL15);
}
}
@ -1257,15 +1262,15 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
}
break;
case 2 :
// CollectSymbols.g:243:7: TOKEN_REF
// CollectSymbols.g:248:7: TOKEN_REF
{
TOKEN_REF15=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal677); if (state.failed) return retval;
TOKEN_REF16=(GrammarAST)match(input,TOKEN_REF,FOLLOW_TOKEN_REF_in_terminal679); if (state.failed) return retval;
if ( state.backtracking==1 ) {
terminals.add(TOKEN_REF15);
tokenIDRefs.add(TOKEN_REF15);
terminals.add(TOKEN_REF16);
tokenIDRefs.add(TOKEN_REF16);
if ( currentRule!=null ) {
currentRule.alt[currentAlt].tokenRefs.map((TOKEN_REF15!=null?TOKEN_REF15.getText():null), TOKEN_REF15);
currentRule.alt[currentAlt].tokenRefs.map((TOKEN_REF16!=null?TOKEN_REF16.getText():null), TOKEN_REF16);
}
}
@ -1287,20 +1292,20 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
// $ANTLR start "ruleref"
// CollectSymbols.g:253:1: ruleref : RULE_REF ;
// CollectSymbols.g:258:1: ruleref : RULE_REF ;
public final void ruleref() throws RecognitionException {
GrammarAST RULE_REF16=null;
GrammarAST RULE_REF17=null;
try {
// CollectSymbols.g:255:5: ( RULE_REF )
// CollectSymbols.g:255:7: RULE_REF
// CollectSymbols.g:260:5: ( RULE_REF )
// CollectSymbols.g:260:7: RULE_REF
{
RULE_REF16=(GrammarAST)match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref702); if (state.failed) return ;
RULE_REF17=(GrammarAST)match(input,RULE_REF,FOLLOW_RULE_REF_in_ruleref704); if (state.failed) return ;
if ( state.backtracking==1 ) {
rulerefs.add(RULE_REF16);
rulerefs.add(RULE_REF17);
if ( currentRule!=null ) {
currentRule.alt[currentAlt].ruleRefs.map((RULE_REF16!=null?RULE_REF16.getText():null), RULE_REF16);
currentRule.alt[currentAlt].ruleRefs.map((RULE_REF17!=null?RULE_REF17.getText():null), RULE_REF17);
}
}
@ -1495,41 +1500,41 @@ public class CollectSymbols extends org.antlr.v4.runtime.tree.TreeFilter {
public static final BitSet FOLLOW_SCOPE_in_globalScope247 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_globalScope249 = new BitSet(new long[]{0x0000000000010000L});
public static final BitSet FOLLOW_ACTION_in_globalScope251 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_AT_in_globalNamedAction268 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_globalNamedAction270 = new BitSet(new long[]{0x0000000000000000L,0x0000000000800000L});
public static final BitSet FOLLOW_ID_in_globalNamedAction273 = new BitSet(new long[]{0x0000000000010000L});
public static final BitSet FOLLOW_ACTION_in_globalNamedAction275 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ASSIGN_in_tokensSection298 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_tokensSection302 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000008L});
public static final BitSet FOLLOW_STRING_LITERAL_in_tokensSection304 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ID_in_tokensSection318 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RULE_in_rule340 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_rule344 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_set_in_setAlt368 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RULE_in_finishRule392 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_AT_in_rulelNamedAction408 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_rulelNamedAction410 = new BitSet(new long[]{0x0000000000010000L});
public static final BitSet FOLLOW_ACTION_in_rulelNamedAction412 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ACTION_in_ruleAction432 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_CATCH_in_exceptionHandler448 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_exceptionHandler450 = new BitSet(new long[]{0x0000000000010000L});
public static final BitSet FOLLOW_ACTION_in_exceptionHandler452 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_FINALLY_in_finallyClause469 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ACTION_in_finallyClause471 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleArg491 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RETURNS_in_ruleReturns508 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleReturns510 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_SCOPE_in_ruleScopeSpec533 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ACTION_in_ruleScopeSpec535 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_SCOPE_in_ruleScopeSpec548 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_ruleScopeSpec552 = new BitSet(new long[]{0x0000000000000008L,0x0000000000800000L});
public static final BitSet FOLLOW_set_in_rewriteElement580 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ASSIGN_in_labeledElement616 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_labeledElement620 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_PLUS_ASSIGN_in_labeledElement632 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_labeledElement636 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal662 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal677 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref702 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_AT_in_globalNamedAction270 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_globalNamedAction272 = new BitSet(new long[]{0x0000000000000000L,0x0000000000800000L});
public static final BitSet FOLLOW_ID_in_globalNamedAction275 = new BitSet(new long[]{0x0000000000010000L});
public static final BitSet FOLLOW_ACTION_in_globalNamedAction277 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ASSIGN_in_tokensSection300 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_tokensSection304 = new BitSet(new long[]{0x0000000000000000L,0x0000000000000008L});
public static final BitSet FOLLOW_STRING_LITERAL_in_tokensSection306 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ID_in_tokensSection320 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RULE_in_rule342 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_rule346 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_set_in_setAlt370 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RULE_in_finishRule394 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_AT_in_ruleNamedAction410 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_ruleNamedAction412 = new BitSet(new long[]{0x0000000000010000L});
public static final BitSet FOLLOW_ACTION_in_ruleNamedAction414 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ACTION_in_ruleAction434 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_CATCH_in_exceptionHandler450 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_exceptionHandler452 = new BitSet(new long[]{0x0000000000010000L});
public static final BitSet FOLLOW_ACTION_in_exceptionHandler454 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_FINALLY_in_finallyClause471 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ACTION_in_finallyClause473 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleArg493 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RETURNS_in_ruleReturns510 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ARG_ACTION_in_ruleReturns512 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_SCOPE_in_ruleScopeSpec535 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ACTION_in_ruleScopeSpec537 = new BitSet(new long[]{0x0000000000000008L});
public static final BitSet FOLLOW_SCOPE_in_ruleScopeSpec550 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_ruleScopeSpec554 = new BitSet(new long[]{0x0000000000000008L,0x0000000000800000L});
public static final BitSet FOLLOW_set_in_rewriteElement582 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_ASSIGN_in_labeledElement618 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_labeledElement622 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_PLUS_ASSIGN_in_labeledElement634 = new BitSet(new long[]{0x0000000000000004L});
public static final BitSet FOLLOW_ID_in_labeledElement638 = new BitSet(new long[]{0xFFFFFFFFFFFFFFF0L,0x0000003FFFFFFFFFL});
public static final BitSet FOLLOW_STRING_LITERAL_in_terminal664 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_TOKEN_REF_in_terminal679 = new BitSet(new long[]{0x0000000000000002L});
public static final BitSet FOLLOW_RULE_REF_in_ruleref704 = new BitSet(new long[]{0x0000000000000002L});
}

View File

@ -4,9 +4,7 @@ import org.antlr.runtime.RecognitionException;
import org.antlr.runtime.tree.BufferedTreeNodeStream;
import org.antlr.v4.parse.ASTVerifier;
import org.antlr.v4.parse.GrammarASTAdaptor;
import org.antlr.v4.tool.ErrorManager;
import org.antlr.v4.tool.Grammar;
import org.antlr.v4.tool.Rule;
import org.antlr.v4.tool.*;
/** */
public class SemanticPipeline {
@ -49,11 +47,17 @@ public class SemanticPipeline {
SymbolChecks symcheck = new SymbolChecks(g, collector);
symcheck.examine(); // side-effect: strip away redef'd rules.
// STORE RULES IN GRAMMAR
// don't continue if we get symbol errors
if ( false ) return;
// STORE RULES/ACTIONS/SCOPES IN GRAMMAR
for (Rule r : collector.rules) g.defineRule(r);
for (AttributeScope s : collector.scopes) g.defineScope(s);
for (GrammarAST a : collector.actions) g.defineAction(a);
// TODO: named actions
// CHECK ATTRIBUTE EXPRESSIONS FOR SEMANTIC VALIDITY
AttributeChecks.checkAllAttributeExpressions(g, collector.rules);
AttributeChecks.checkAllAttributeExpressions(g);
// ASSIGN TOKEN TYPES
}

View File

@ -50,8 +50,6 @@ public class SymbolChecks {
public void checkForRuleConflicts(List<Rule> rules) {
if ( rules==null ) return;
int i = 0;
List<Integer> toRemove = new ArrayList<Integer>();
for (Rule r : collector.rules) {
if ( nameToRuleMap.get(r.name)==null ) {
nameToRuleMap.put(r.name, r);
@ -60,29 +58,27 @@ public class SymbolChecks {
GrammarAST idNode = (GrammarAST)r.ast.getChild(0);
ErrorManager.grammarError(ErrorType.RULE_REDEFINITION,
g.fileName, idNode.token, r.name);
toRemove.add(i);
}
if ( globalScopeNames.contains(r.name) ) {
GrammarAST idNode = (GrammarAST)r.ast.getChild(0);
ErrorManager.grammarError(ErrorType.SYMBOL_CONFLICTS_WITH_GLOBAL_SCOPE,
g.fileName, idNode.token, r.name);
}
i++;
}
collector.rules.removeAll(toRemove);
}
public void checkScopeRedefinitions(List<GrammarAST> scopes) {
public void checkScopeRedefinitions(List<AttributeScope> scopes) {
if ( scopes==null ) return;
for (int i=0; i< scopes.size(); i++) {
GrammarAST s = scopes.get(i);
GrammarAST idNode = (GrammarAST)s.getChild(0);
if ( !globalScopeNames.contains(idNode.getText()) ) {
globalScopeNames.add(idNode.getText());
AttributeScope s = scopes.get(i);
//GrammarAST idNode = (GrammarAST)s.getChild(0);
if ( !globalScopeNames.contains(s.getName()) ) {
globalScopeNames.add(s.getName());
}
else {
Token idNode = ((GrammarAST) s.ast.getChild(0)).token;
ErrorManager.grammarError(ErrorType.SCOPE_REDEFINITION,
g.fileName, idNode.token, idNode.getText());
g.fileName, idNode, s.getName());
}
}
}

View File

@ -4,7 +4,8 @@ import org.antlr.runtime.Token;
public class ActionAST extends GrammarAST {
// Alt, rule, grammar space
public AttributeResolver space;
public AttributeResolver resolver;
public ActionAST(Token t) { super(t); }
public ActionAST(int type) { super(type); }
public ActionAST(int type, Token t) { super(type, t); }

View File

@ -33,9 +33,7 @@ public class Alternative implements AttributeResolver {
public Alternative(Rule r) { this.rule = r; }
public AttributeResolver getParent() {
return null;
}
public AttributeResolver getParent() { return rule; }
/** Is isolated x a token/rule/label ref? */
public boolean resolves(String x, ActionAST node) {
@ -44,7 +42,7 @@ public class Alternative implements AttributeResolver {
ruleRefs.get(x)!=null ||
labelDefs.get(x)!=null;
if ( inAlt ) return inAlt;
return rule.resolves(x, node);
return getParent().resolves(x, node);
}
/** Find x as token/rule/label ref then find y in properties list. */
@ -56,26 +54,32 @@ public class Alternative implements AttributeResolver {
// look up rule, ask it to resolve y (must be retval or predefined)
return rule.g.getRule(x).resolvesAsRetvalOrProperty(y);
}
List<LabelElementPair> labels = labelDefs.get(x); // label?
if ( labels!=null ) {
// it's a label ref, compute scope from label type and grammar type
LabelElementPair anyLabelDef = labels.get(0);
if ( rule.getPredefinedScope(anyLabelDef.type).get(y)!=null) return true;
if ( anyLabelDef.type==LabelType.RULE_LABEL ) {
Rule ref = rule.g.getRule(anyLabelDef.element.getText());
return ref.resolvesAsRetvalOrProperty(y);
}
}
return false;
Rule r = resolveRefToRule(x, node);
if ( r!=null ) return r.resolvesAsRetvalOrProperty(y);
return getParent().resolves(x, y, node);
//
// List<LabelElementPair> labels = labelDefs.get(x); // label?
// if ( labels!=null ) {
// // it's a label ref, compute scope from label type and grammar type
// LabelElementPair anyLabelDef = labels.get(0);
// if ( rule.getPredefinedScope(anyLabelDef.type).get(y)!=null) return true;
// if ( anyLabelDef.type==LabelType.RULE_LABEL ) {
// Rule ref = rule.g.getRule(anyLabelDef.element.getText());
// return ref.resolvesAsRetvalOrProperty(y);
// }
// }
// return false;
}
public boolean resolveToRuleRef(String x, ActionAST node) {
if ( ruleRefs.get(x)!=null ) return true;
public Rule resolveRefToRule(String x, ActionAST node) {
if ( ruleRefs.get(x)!=null ) return rule.g.getRule(x);
List<LabelElementPair> labels = labelDefs.get(x);
if ( labels!=null ) { // it's a label ref. is it a rule label?
LabelElementPair anyLabelDef = labels.get(0);
if ( anyLabelDef.type==LabelType.RULE_LABEL ) return true;
if ( anyLabelDef.type==LabelType.RULE_LABEL ) {
return rule.g.getRule(anyLabelDef.element.getText());
}
}
return false;
return getParent().resolveRefToRule(x, node);
}
}

View File

@ -9,5 +9,5 @@ public interface AttributeResolver {
public AttributeResolver getParent();
public boolean resolves(String x, ActionAST node);
public boolean resolves(String x, String y, ActionAST node);
public boolean resolveToRuleRef(String x, ActionAST node);
public Rule resolveRefToRule(String x, ActionAST node);
}

View File

@ -31,11 +31,11 @@ public class AttributeScope {
add(new Attribute("int"));
}};
public static enum Type {
ARG, RET, TOKEN, PREDEFINED_RULE, PREDEFINED_LEXER_RULE,
GLOBAL_SCOPE, // scope symbols { ...}
RULE_SCOPE; // scope { int i; int j; }
}
// public static enum Type {
// ARG, RET, TOKEN, PREDEFINED_RULE, PREDEFINED_LEXER_RULE,
// GLOBAL_SCOPE, // scope symbols { ...}
// RULE_SCOPE; // scope { int i; int j; }
// }
/** The list of Attribute objects */

View File

@ -48,15 +48,17 @@ public class Grammar implements AttributeResolver {
public List<Grammar> importedGrammars;
public Map<String, Rule> rules = new LinkedHashMap<String, Rule>();
/** Map a scope to a map of name:action pairs.
/** Map a name to an action.
* The code generator will use this to fill holes in the output files.
* I track the AST node for the action in case I need the line number
* for errors.
*/
Map<String, Map<String,GrammarAST>> actions = new HashMap<String, Map<String,GrammarAST>>();
public Map<String,ActionAST> actions = new HashMap<String,ActionAST>();
/** A list of options specified at the grammar level such as language=Java. */
protected Map<String, String> options;
public Map<String, String> options;
public Map<String, AttributeScope> scopes = new LinkedHashMap<String, AttributeScope>();
public Grammar(Tool tool, GrammarRootAST ast) {
if ( ast==null ) throw new IllegalArgumentException("can't pass null tree");
@ -107,16 +109,14 @@ public class Grammar implements AttributeResolver {
}
}
public void defineAction(GrammarAST ampersandAST) {
String scope = null;
String name = null;
if ( ampersandAST.getChildCount()==1 ) {
name = ampersandAST.getChild(0).getText();
public void defineAction(GrammarAST atAST) {
if ( atAST.getChildCount()==2 ) {
String name = atAST.getChild(0).getText();
actions.put(name, (ActionAST)atAST.getChild(1));
}
else {
scope = ampersandAST.getChild(0).getText();
name = ampersandAST.getChild(1).getText();
Map<String,GrammarAST> f = actions.get(scope);
String name = atAST.getChild(1).getText();
actions.put(name, (ActionAST)atAST.getChild(2));
}
}
@ -124,6 +124,8 @@ public class Grammar implements AttributeResolver {
public Rule getRule(String name) { return rules.get(name); }
public void defineScope(AttributeScope s) { scopes.put(s.getName(), s); }
/** Get list of all delegates from all grammars in the delegate subtree of g.
* The grammars are in delegation tree preorder. Don't include ourselves
* in list as we're not a delegate of ourselves.
@ -212,17 +214,17 @@ public class Grammar implements AttributeResolver {
public AttributeResolver getParent() { return null; }
/** $x in grammar action can only be scope name */
public boolean resolves(String x, ActionAST node) {
return false;
return scopes.get(x)!=null;
}
public boolean resolves(String x, String y, ActionAST node) {
return false;
}
/** $x.y makes no sense in grammar action; Rule.resolves()
* shouldn't call this.
*/
public boolean resolves(String x, String y, ActionAST node) { return false; }
public boolean resolveToRuleRef(String x, ActionAST node) {
return false;
}
public Rule resolveRefToRule(String x, ActionAST node) { return getRule(x); }
/** Given a grammar type, what should be the default action scope?
* If I say @members in a COMBINED grammar, for example, the

View File

@ -64,8 +64,8 @@ public class Rule implements AttributeResolver {
/** Labels are visible to all alts in a rule. Record all defs here.
* We need to ensure labels are used to track same kind of symbols.
* Tracks all label defs for a label.
public MultiMap<String, LabelElementPair> labelDefs =
new MultiMap<String, LabelElementPair>();
public MultiMap<String, LabelElementPair> labelDefs =
new MultiMap<String, LabelElementPair>();
*/
public Alternative[] alt;
@ -86,51 +86,51 @@ public class Rule implements AttributeResolver {
if ( resolvesAsRetvalOrProperty(x) ) return true;
if ( args.get(x)!=null ) return true;
// resolve outside of an alt?
if ( node.space instanceof Alternative ) return getParent().resolves(x, node);
return getLabelNames().contains(x); // can see all labels if not in alt
if ( node.resolver instanceof Alternative ) return getParent().resolves(x, node);
if ( getLabelNames().contains(x) ) return true; // can see all labels if not in alt
return getParent().resolves(x, node);
}
/** For $x.y, is x an arg, retval, predefined prop, token/rule/label ref?
* If so, make sure y resolves within that perspective.
*/
public boolean resolves(String x, String y, ActionAST node) {
if ( x.equals(this.name) ) { // $x.y ref in rule x is same as $y
return resolves(y, node);
}
Rule r = resolveRefToRule(x, node);
if ( r!=null ) r.resolvesAsRetvalOrProperty(y);
return getParent().resolves(x,y,node);
MultiMap<String, LabelElementPair> labelDefs = null;
if ( node.space instanceof Alternative) {
labelDefs = ((Alternative)node.space).labelDefs;
}
else labelDefs = getLabelDefs();
List<LabelElementPair> labels = labelDefs.get(x); // label?
if ( labels!=null ) {
// it's a label ref, compute scope from label type and grammar type
LabelElementPair anyLabelDef = labels.get(0);
// predefined?
if ( getPredefinedScope(anyLabelDef.type).get(y)!=null) return true;
if ( anyLabelDef.type==LabelType.RULE_LABEL ) {
Rule ref = g.getRule(anyLabelDef.element.getText());
return ref.resolvesAsRetvalOrProperty(y);
}
}
return false;
// if ( x.equals(this.name) ) { // $x.y ref in rule x is same as $y
// return resolves(y, node);
// }
//
// if ( node.resolver == this ) { // action not in alt (attr space is this rule)
// List<LabelElementPair> labels = getLabelDefs().get(x);
// if ( labels!=null ) {
// // it's a label ref, compute scope from label type and grammar type
// LabelElementPair anyLabelDef = labels.get(0);
// // predefined?
// if ( getPredefinedScope(anyLabelDef.type).get(y)!=null) return true;
// if ( anyLabelDef.type==LabelType.RULE_LABEL ) {
// Rule ref = g.getRule(anyLabelDef.element.getText());
// return ref.resolvesAsRetvalOrProperty(y);
// }
// }
// }
// return false;
}
public boolean resolveToRuleRef(String x, ActionAST node) {
if ( x.equals(this.name) ) return true;
MultiMap<String, LabelElementPair> labelDefs = null;
if ( node.space instanceof Alternative) {
labelDefs = ((Alternative)node.space).labelDefs;
public Rule resolveRefToRule(String x, ActionAST node) {
if ( x.equals(this.name) ) return this;
if ( node.resolver == this ) { // action not in alt (attr space is this rule)
List<LabelElementPair> labels = getLabelDefs().get(x);
if ( labels!=null ) { // it's a label ref. is it a rule label?
LabelElementPair anyLabelDef = labels.get(0);
if ( anyLabelDef.type==LabelType.RULE_LABEL ) {
return g.getRule(anyLabelDef.element.getText());
}
}
}
else labelDefs = getLabelDefs();
List<LabelElementPair> labels = labelDefs.get(x);
if ( labels!=null ) { // it's a label ref. is it a rule label?
LabelElementPair anyLabelDef = labels.get(0);
if ( anyLabelDef.type==LabelType.RULE_LABEL ) return true;
}
return false;
return null; // don't look for general rule (not one ref'd in this rule)
}
public boolean resolvesAsRetvalOrProperty(String y) {