forked from jasder/antlr
see A.g4 for getter syntax; use e() not gete(). adding ContextGetterDecl.java
This commit is contained in:
parent
203ad46820
commit
6c2beb530d
|
@ -1,5 +1,16 @@
|
|||
grammar A;
|
||||
|
||||
/*
|
||||
Auto gen:
|
||||
public Token ID() { }
|
||||
public List<Token> x() { }
|
||||
public Token x(int i) { }
|
||||
public eContext e() { }
|
||||
or: public List<eContext> e() { }
|
||||
*/
|
||||
z : ID x+=INT+ e {List x = $INT; Token t = $ID;} ;
|
||||
|
||||
/*
|
||||
s : Q q=e {Object o=$q.v;} -> one
|
||||
| z=e {Object o=$z.v;}
|
||||
;
|
||||
|
@ -9,9 +20,9 @@ e returns [int v]
|
|||
| b=e '+' e
|
||||
| '(' x=e ')'
|
||||
;
|
||||
|
||||
INT : '9';
|
||||
*/
|
||||
/*
|
||||
INT : '9';
|
||||
a : u=A A -> x
|
||||
| B b {Token t=$B;} -> y
|
||||
| C+ -> z
|
||||
|
|
|
@ -493,6 +493,8 @@ TokenListDecl(t) ::= "List\<Token> <t.name> = new ArrayList\<Token>()"
|
|||
RuleContextDecl(r) ::= "<r.ctxName> <r.name>"
|
||||
RuleContextListDecl(rdecl) ::= "List\<<rdecl.ctxName>> <rdecl.name> = new ArrayList\<<rdecl.ctxName>>()"
|
||||
|
||||
ContextGetterDecl(g) ::= "public <g.decl> get<t.name>() { }"
|
||||
|
||||
LexerRuleContext() ::= "RuleContext"
|
||||
|
||||
/** The rule context name is the rule followed by a suffix; e.g.,
|
||||
|
@ -500,10 +502,10 @@ LexerRuleContext() ::= "RuleContext"
|
|||
*/
|
||||
RuleContextNameSuffix() ::= "Context"
|
||||
|
||||
ImplicitTokenLabel(tokenName) ::= "<tokenName>"
|
||||
ImplicitRuleLabel(ruleName) ::= "<ruleName>"
|
||||
ImplicitTokenLabel(tokenName) ::= "_<tokenName>"
|
||||
ImplicitRuleLabel(ruleName) ::= "_<ruleName>"
|
||||
ImplicitSetLabel(id) ::= "_tset<id>"
|
||||
ListLabelName(label) ::= "<label>_list"
|
||||
ListLabelName(label) ::= "<label>"
|
||||
|
||||
CaptureNextToken(d) ::= "<d.varName> = _input.LT(1);"
|
||||
CaptureNextTokenType(d) ::= "<d.varName> = _input.LA(1);"
|
||||
|
@ -531,7 +533,7 @@ public static class <s.name> extends <superClass><if(interfaces)> implements <in
|
|||
|
||||
AltLabelStructDecl(s,attrs,visitorDispatchMethods) ::= <<
|
||||
public static class <s.name> extends <currentRule.name>Context {
|
||||
<attrs:{a | public <a>;}; separator="\n">
|
||||
<attrs:{a | public <a.decl> get<a.name>() {\}}; separator="\n">
|
||||
public <s.name>(<currentRule.name>Context ctx) { copyFrom(ctx); }
|
||||
<visitorDispatchMethods; separator="\n">
|
||||
}
|
||||
|
|
|
@ -91,6 +91,12 @@ public class ParserFactory extends DefaultOutputModelFactory {
|
|||
LabeledOp matchOp = new MatchToken(this, (TerminalAST) ID);
|
||||
if ( labelAST!=null ) {
|
||||
String label = labelAST.getText();
|
||||
if ( labelAST.parent.getType() == ANTLRParser.PLUS_ASSIGN ) {
|
||||
TokenListDecl l = getTokenListLabelDecl(label);
|
||||
getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), l);
|
||||
}
|
||||
|
||||
// String label = labelAST.getText();
|
||||
Decl d = getTokenLabelDecl(label);
|
||||
((MatchToken)matchOp).labels.add(d);
|
||||
getCurrentRuleFunction().addContextDecl(ID.getAltLabel(), d);
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.antlr.v4.codegen.model.decl;
|
||||
|
||||
import org.antlr.v4.codegen.OutputModelFactory;
|
||||
|
||||
/** public Token getID() { } */
|
||||
public class ContextGetterDecl extends Decl {
|
||||
public ContextGetterDecl(OutputModelFactory factory, String name, String decl) {
|
||||
super(factory, name, decl);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue