change ruleElementOption back to elementOption

This commit is contained in:
Terence Parr 2013-08-08 16:12:01 -07:00
parent 531afe5af8
commit 19fce5dd7d
5 changed files with 44 additions and 44 deletions

View File

@ -658,8 +658,8 @@ alternative
paraphrases.pop(); paraphrases.pop();
Grammar.setNodeOptions($tree, $o.tree); Grammar.setNodeOptions($tree, $o.tree);
} }
: o=ruleElementOptions? : o=elementOptions?
e+=element+ -> ^(ALT<AltAST> ruleElementOptions? $e+) e+=element+ -> ^(ALT<AltAST> elementOptions? $e+)
| -> ^(ALT<AltAST> EPSILON) // empty alt | -> ^(ALT<AltAST> EPSILON) // empty alt
; ;
@ -715,9 +715,9 @@ actionElement
} }
} }
: ACTION<ActionAST> : ACTION<ActionAST>
| ACTION ruleElementOptions -> ^(ACTION<ActionAST> ruleElementOptions) | ACTION elementOptions -> ^(ACTION<ActionAST> elementOptions)
| SEMPRED<PredAST> | SEMPRED<PredAST>
| SEMPRED ruleElementOptions -> ^(SEMPRED<PredAST> ruleElementOptions) | SEMPRED elementOptions -> ^(SEMPRED<PredAST> elementOptions)
; ;
labeledElement labeledElement
@ -794,8 +794,8 @@ wildcard
// Because the terminal rule is allowed to be the node // Because the terminal rule is allowed to be the node
// specification for the start of a tree rule, we must // specification for the start of a tree rule, we must
// later check that wildcard was not used for that. // later check that wildcard was not used for that.
DOT ruleElementOptions? DOT elementOptions?
-> ^(WILDCARD<TerminalAST>[$DOT] ruleElementOptions?) -> ^(WILDCARD<TerminalAST>[$DOT] elementOptions?)
; ;
// -------------------- // --------------------
@ -876,13 +876,13 @@ if ( options!=null ) {
Grammar.setNodeOptions($tree, options); Grammar.setNodeOptions($tree, options);
} }
} }
: TOKEN_REF ruleElementOptions? -> ^(TOKEN_REF<TerminalAST> ruleElementOptions?) : TOKEN_REF elementOptions? -> ^(TOKEN_REF<TerminalAST> elementOptions?)
| STRING_LITERAL ruleElementOptions? -> ^(STRING_LITERAL<TerminalAST> ruleElementOptions?) | STRING_LITERAL elementOptions? -> ^(STRING_LITERAL<TerminalAST> elementOptions?)
; ;
// Terminals may be adorned with certain options when // Terminals may be adorned with certain options when
// reference in the grammar: TOK<,,,> // reference in the grammar: TOK<,,,>
ruleElementOptions elementOptions
: LT (elementOption (COMMA elementOption)*)? GT : LT (elementOption (COMMA elementOption)*)? GT
-> ^(ELEMENT_OPTIONS[$LT,"ELEMENT_OPTIONS"] elementOption*) -> ^(ELEMENT_OPTIONS[$LT,"ELEMENT_OPTIONS"] elementOption*)
; ;

View File

@ -148,7 +148,7 @@ public void finishAlt(AltAST alt) { }
public void ruleRef(GrammarAST ref, ActionAST arg) { } public void ruleRef(GrammarAST ref, ActionAST arg) { }
public void tokenRef(TerminalAST ref) { } public void tokenRef(TerminalAST ref) { }
public void ruleElementOption(GrammarASTWithOptions t, GrammarAST ID, GrammarAST valueAST) { } public void elementOption(GrammarASTWithOptions t, GrammarAST ID, GrammarAST valueAST) { }
public void stringRef(TerminalAST ref) { } public void stringRef(TerminalAST ref) { }
public void wildcardRef(GrammarAST ref) { } public void wildcardRef(GrammarAST ref) { }
public void actionInAlt(ActionAST action) { } public void actionInAlt(ActionAST action) { }
@ -703,8 +703,8 @@ lexerElement
| lexerSubrule | lexerSubrule
| ACTION {actionInAlt((ActionAST)$ACTION);} | ACTION {actionInAlt((ActionAST)$ACTION);}
| SEMPRED {sempredInAlt((PredAST)$SEMPRED);} | SEMPRED {sempredInAlt((PredAST)$SEMPRED);}
| ^(ACTION ruleElementOptions) {actionInAlt((ActionAST)$ACTION);} | ^(ACTION elementOptions) {actionInAlt((ActionAST)$ACTION);}
| ^(SEMPRED ruleElementOptions) {sempredInAlt((PredAST)$SEMPRED);} | ^(SEMPRED elementOptions) {sempredInAlt((PredAST)$SEMPRED);}
| EPSILON | EPSILON
; ;
@ -738,7 +738,7 @@ lexerAtom
: terminal : terminal
| ^(NOT blockSet) | ^(NOT blockSet)
| blockSet | blockSet
| ^(WILDCARD ruleElementOptions) | ^(WILDCARD elementOptions)
| WILDCARD | WILDCARD
| LEXER_CHAR_SET | LEXER_CHAR_SET
| range | range
@ -752,9 +752,9 @@ actionElement
exitActionElement($start); exitActionElement($start);
} }
: ACTION : ACTION
| ^(ACTION ruleElementOptions) | ^(ACTION elementOptions)
| SEMPRED | SEMPRED
| ^(SEMPRED ruleElementOptions) | ^(SEMPRED elementOptions)
; ;
alternative alternative
@ -766,7 +766,7 @@ alternative
finishAlt((AltAST)$start); finishAlt((AltAST)$start);
exitAlternative((AltAST)$start); exitAlternative((AltAST)$start);
} }
: ^(ALT ruleElementOptions? element+) : ^(ALT elementOptions? element+)
| ^(ALT EPSILON) | ^(ALT EPSILON)
; ;
@ -806,8 +806,8 @@ element
| subrule | subrule
| ACTION {actionInAlt((ActionAST)$ACTION);} | ACTION {actionInAlt((ActionAST)$ACTION);}
| SEMPRED {sempredInAlt((PredAST)$SEMPRED);} | SEMPRED {sempredInAlt((PredAST)$SEMPRED);}
| ^(ACTION ruleElementOptions) {actionInAlt((ActionAST)$ACTION);} | ^(ACTION elementOptions) {actionInAlt((ActionAST)$ACTION);}
| ^(SEMPRED ruleElementOptions) {sempredInAlt((PredAST)$SEMPRED);} | ^(SEMPRED elementOptions) {sempredInAlt((PredAST)$SEMPRED);}
| ^(NOT blockSet) | ^(NOT blockSet)
| ^(NOT block) | ^(NOT block)
@ -888,7 +888,7 @@ atom
} }
: ^(DOT ID terminal) : ^(DOT ID terminal)
| ^(DOT ID ruleref) | ^(DOT ID ruleref)
| ^(WILDCARD ruleElementOptions) {wildcardRef($WILDCARD);} | ^(WILDCARD elementOptions) {wildcardRef($WILDCARD);}
| WILDCARD {wildcardRef($WILDCARD);} | WILDCARD {wildcardRef($WILDCARD);}
| terminal | terminal
| blockSet | blockSet
@ -963,33 +963,33 @@ terminal
@after { @after {
exitTerminal($start); exitTerminal($start);
} }
: ^(STRING_LITERAL ruleElementOptions) : ^(STRING_LITERAL elementOptions)
{stringRef((TerminalAST)$STRING_LITERAL);} {stringRef((TerminalAST)$STRING_LITERAL);}
| STRING_LITERAL {stringRef((TerminalAST)$STRING_LITERAL);} | STRING_LITERAL {stringRef((TerminalAST)$STRING_LITERAL);}
| ^(TOKEN_REF ruleElementOptions) {tokenRef((TerminalAST)$TOKEN_REF);} | ^(TOKEN_REF elementOptions) {tokenRef((TerminalAST)$TOKEN_REF);}
| TOKEN_REF {tokenRef((TerminalAST)$TOKEN_REF);} | TOKEN_REF {tokenRef((TerminalAST)$TOKEN_REF);}
; ;
ruleElementOptions elementOptions
@init { @init {
enterElementOptions($start); enterElementOptions($start);
} }
@after { @after {
exitElementOptions($start); exitElementOptions($start);
} }
: ^(ELEMENT_OPTIONS ruleElementOption[(GrammarASTWithOptions)$start.getParent()]*) : ^(ELEMENT_OPTIONS elementOption[(GrammarASTWithOptions)$start.getParent()]*)
; ;
ruleElementOption[GrammarASTWithOptions t] elementOption[GrammarASTWithOptions t]
@init { @init {
enterElementOption($start); enterElementOption($start);
} }
@after { @after {
exitElementOption($start); exitElementOption($start);
} }
: ID {ruleElementOption(t, $ID, null);} : ID {elementOption(t, $ID, null);}
| ^(ASSIGN id=ID v=ID) {ruleElementOption(t, $id, $v);} | ^(ASSIGN id=ID v=ID) {elementOption(t, $id, $v);}
| ^(ASSIGN ID v=STRING_LITERAL) {ruleElementOption(t, $ID, $v);} | ^(ASSIGN ID v=STRING_LITERAL) {elementOption(t, $ID, $v);}
| ^(ASSIGN ID v=ACTION) {ruleElementOption(t, $ID, $v);} | ^(ASSIGN ID v=ACTION) {elementOption(t, $ID, $v);}
| ^(ASSIGN ID v=INT) {ruleElementOption(t, $ID, $v);} | ^(ASSIGN ID v=INT) {elementOption(t, $ID, $v);}
; ;

View File

@ -121,12 +121,12 @@ outerAlternative returns [boolean isLeftRec]
; ;
binary binary
: ^( ALT ruleElementOptions? recurse element+ recurse ACTION? ) : ^( ALT elementOptions? recurse element+ recurse ACTION? )
{setAltAssoc((AltAST)$ALT,currentOuterAltNumber);} {setAltAssoc((AltAST)$ALT,currentOuterAltNumber);}
; ;
prefix prefix
: ^( ALT ruleElementOptions? : ^( ALT elementOptions?
({!((CommonTree)input.LT(1)).getText().equals(ruleName)}? element)+ ({!((CommonTree)input.LT(1)).getText().equals(ruleName)}? element)+
recurse ACTION? recurse ACTION?
) )
@ -134,14 +134,14 @@ prefix
; ;
suffix suffix
: ^( ALT ruleElementOptions? recurse element+ ) : ^( ALT elementOptions? recurse element+ )
{setAltAssoc((AltAST)$ALT,currentOuterAltNumber);} {setAltAssoc((AltAST)$ALT,currentOuterAltNumber);}
; ;
nonLeftRecur nonLeftRecur
: ^(ALT element+) // no assoc for these; ignore if <assoc=...> present : ^(ALT element+) // no assoc for these; ignore if <assoc=...> present
; ;
recurse recurse
: ^(ASSIGN ID recurseNoLabel) : ^(ASSIGN ID recurseNoLabel)
| recurseNoLabel | recurseNoLabel
@ -153,16 +153,16 @@ token returns [GrammarAST t=null]
: ^(ASSIGN ID s=token {$t = $s.t;}) : ^(ASSIGN ID s=token {$t = $s.t;})
| ^(PLUS_ASSIGN ID s=token {$t = $s.t;}) | ^(PLUS_ASSIGN ID s=token {$t = $s.t;})
| b=STRING_LITERAL {$t = $b;} | b=STRING_LITERAL {$t = $b;}
| ^(b=STRING_LITERAL ruleElementOptions) {$t = $b;} | ^(b=STRING_LITERAL elementOptions) {$t = $b;}
| ^(c=TOKEN_REF ruleElementOptions) {$t = $c;} | ^(c=TOKEN_REF elementOptions) {$t = $c;}
| c=TOKEN_REF {$t = $c;} | c=TOKEN_REF {$t = $c;}
; ;
ruleElementOptions elementOptions
: ^(ELEMENT_OPTIONS ruleElementOption*) : ^(ELEMENT_OPTIONS elementOption*)
; ;
ruleElementOption elementOption
: ID : ID
| ^(ASSIGN ID ID) | ^(ASSIGN ID ID)
| ^(ASSIGN ID STRING_LITERAL) | ^(ASSIGN ID STRING_LITERAL)
@ -200,16 +200,16 @@ block
; ;
alternative alternative
: ^(ALT ruleElementOptions? element+) : ^(ALT elementOptions? element+)
; ;
atom atom
: ^(RULE_REF ARG_ACTION?) : ^(RULE_REF ARG_ACTION?)
| ^(STRING_LITERAL ruleElementOptions) | ^(STRING_LITERAL elementOptions)
| STRING_LITERAL | STRING_LITERAL
| ^(TOKEN_REF ruleElementOptions) | ^(TOKEN_REF elementOptions)
| TOKEN_REF | TOKEN_REF
| ^(WILDCARD ruleElementOptions) | ^(WILDCARD elementOptions)
| WILDCARD | WILDCARD
| ^(DOT ID element) | ^(DOT ID element)
; ;

View File

@ -232,7 +232,7 @@ public class BasicSemanticChecks extends GrammarTreeVisitor {
} }
@Override @Override
public void ruleElementOption(GrammarASTWithOptions elem, GrammarAST ID, GrammarAST valueAST) { public void elementOption(GrammarASTWithOptions elem, GrammarAST ID, GrammarAST valueAST) {
String v = null; String v = null;
boolean ok = checkElementOptions(elem, ID, valueAST); boolean ok = checkElementOptions(elem, ID, valueAST);
// if ( ok ) { // if ( ok ) {

View File

@ -185,7 +185,7 @@ public class SymbolCollector extends GrammarTreeVisitor {
} }
@Override @Override
public void ruleElementOption(GrammarASTWithOptions t, GrammarAST ID, GrammarAST valueAST) { public void elementOption(GrammarASTWithOptions t, GrammarAST ID, GrammarAST valueAST) {
setActionResolver(valueAST); setActionResolver(valueAST);
} }