forked from jasder/antlr
new nodes, added visitor
[git-p4: depot-paths = "//depot/code/antlr4/main/": change = 9136]
This commit is contained in:
parent
9784ce3d22
commit
fd9027b4a0
|
@ -40,6 +40,7 @@ import org.antlr.v4.codegen.model.*;
|
|||
import org.antlr.v4.codegen.model.decl.*;
|
||||
import org.antlr.v4.codegen.model.ast.*;
|
||||
import org.antlr.v4.tool.*;
|
||||
import org.antlr.v4.tool.ast.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
|
|
|
@ -704,9 +704,9 @@ blockSuffix
|
|||
;
|
||||
|
||||
ebnfSuffix
|
||||
: QUESTION -> OPTIONAL[$start]
|
||||
| STAR -> CLOSURE[$start]
|
||||
| PLUS -> POSITIVE_CLOSURE[$start]
|
||||
: QUESTION -> OPTIONAL<OptionalBlockAST>[$start]
|
||||
| STAR -> CLOSURE<StarBlockAST>[$start]
|
||||
| PLUS -> POSITIVE_CLOSURE<PlusBlockAST>[$start]
|
||||
;
|
||||
|
||||
atom
|
||||
|
@ -722,13 +722,17 @@ atom
|
|||
// lexically contiguous (no spaces either side of the DOT)
|
||||
// otherwise it is two references with a wildcard in between
|
||||
// and not a qualified reference.
|
||||
/*
|
||||
{
|
||||
input.LT(1).getCharPositionInLine()+input.LT(1).getText().length()==
|
||||
input.LT(2).getCharPositionInLine() &&
|
||||
input.LT(2).getCharPositionInLine()+1==input.LT(3).getCharPositionInLine()
|
||||
}?
|
||||
id DOT ruleref -> ^(DOT id ruleref)
|
||||
| range (ROOT^ | BANG^)? // Range x..y - only valid in lexers
|
||||
|
||||
|
|
||||
*/
|
||||
range (ROOT^ | BANG^)? // Range x..y - only valid in lexers
|
||||
| terminal (ROOT^ | BANG^)?
|
||||
| ruleref
|
||||
| notSet (ROOT^|BANG^)?
|
||||
|
@ -749,8 +753,8 @@ atom
|
|||
// A set of characters (in a lexer) or terminal tokens, if a parser,
|
||||
// that are then used to create the inverse set of them.
|
||||
notSet
|
||||
: NOT setElement -> ^(NOT ^(SET[$setElement.start,"SET"] setElement))
|
||||
| NOT blockSet -> ^(NOT blockSet)
|
||||
: NOT setElement -> ^(NOT<NotAST>[$NOT] ^(SET<SetAST>[$setElement.start,"SET"] setElement))
|
||||
| NOT blockSet -> ^(NOT<NotAST>[$NOT] blockSet)
|
||||
;
|
||||
|
||||
blockSet
|
||||
|
@ -822,7 +826,7 @@ ruleref
|
|||
// error about any abuse of the .. operator.
|
||||
//
|
||||
range
|
||||
: STRING_LITERAL<TerminalAST> RANGE^ STRING_LITERAL<TerminalAST>
|
||||
: STRING_LITERAL<TerminalAST> RANGE<RangeAST>^ STRING_LITERAL<TerminalAST>
|
||||
;
|
||||
|
||||
terminal
|
||||
|
|
|
@ -65,6 +65,7 @@ options {
|
|||
*/
|
||||
package org.antlr.v4.parse;
|
||||
import org.antlr.v4.tool.*;
|
||||
import org.antlr.v4.tool.ast.*;
|
||||
}
|
||||
|
||||
@members {
|
||||
|
|
|
@ -61,6 +61,7 @@ options {
|
|||
*/
|
||||
package org.antlr.v4.parse;
|
||||
import org.antlr.v4.tool.*;
|
||||
import org.antlr.v4.tool.ast.*;
|
||||
import org.antlr.v4.automata.ATNFactory;
|
||||
}
|
||||
|
||||
|
|
|
@ -5,6 +5,7 @@ options { filter=true; }
|
|||
@header {
|
||||
package org.antlr.v4.parse;
|
||||
import org.antlr.v4.tool.*;
|
||||
import org.antlr.v4.tool.ast.*;
|
||||
}
|
||||
|
||||
@members {
|
||||
|
|
|
@ -12,6 +12,7 @@ package org.antlr.v4.parse;
|
|||
import org.antlr.v4.misc.Utils;
|
||||
import org.antlr.v4.misc.*;
|
||||
import org.antlr.v4.tool.*;
|
||||
import org.antlr.v4.tool.ast.*;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.antlr.runtime.Token;
|
|||
import org.antlr.runtime.tree.CommonTreeAdaptor;
|
||||
import org.antlr.v4.tool.ast.GrammarAST;
|
||||
import org.antlr.v4.tool.ast.GrammarASTErrorNode;
|
||||
import org.antlr.v4.tool.ast.GrammarASTWithOptions;
|
||||
import org.antlr.v4.tool.ast.RuleAST;
|
||||
import org.antlr.v4.tool.ast.TerminalAST;
|
||||
|
||||
public class GrammarASTAdaptor extends CommonTreeAdaptor {
|
||||
|
@ -52,7 +52,7 @@ public class GrammarASTAdaptor extends CommonTreeAdaptor {
|
|||
GrammarAST t = null;
|
||||
if ( tokenType==ANTLRParser.RULE ) {
|
||||
// needed by TreeWizard to make RULE tree
|
||||
t = new GrammarASTWithOptions(new CommonToken(tokenType, text));
|
||||
t = new RuleAST(new CommonToken(tokenType, text));
|
||||
}
|
||||
else if ( tokenType==ANTLRParser.STRING_LITERAL ) {
|
||||
// implicit lexer construction done with wizard; needs this node type
|
||||
|
|
|
@ -76,6 +76,7 @@ options {
|
|||
*/
|
||||
package org.antlr.v4.parse;
|
||||
import org.antlr.v4.tool.*;
|
||||
import org.antlr.v4.tool.ast.*;
|
||||
import java.lang.reflect.Method;
|
||||
}
|
||||
|
||||
|
|
|
@ -43,6 +43,7 @@ package org.antlr.v4.parse;
|
|||
|
||||
import org.antlr.v4.misc.*;
|
||||
import org.antlr.v4.tool.*;
|
||||
import org.antlr.v4.tool.ast.*;
|
||||
}
|
||||
|
||||
@members {
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.antlr.v4.tool.AttributeResolver;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
public class ActionAST extends GrammarAST {
|
||||
public class ActionAST extends GrammarAST implements RuleElementAST {
|
||||
// Alt, rule, grammar space
|
||||
public AttributeResolver resolver;
|
||||
public List<Token> chunks; // useful for ANTLR IDE developers
|
||||
|
@ -53,4 +53,6 @@ public class ActionAST extends GrammarAST {
|
|||
@Override
|
||||
public Tree dupNode() { return new ActionAST(this); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -62,4 +62,7 @@ public class AltAST extends GrammarAST {
|
|||
|
||||
@Override
|
||||
public Tree dupNode() { return new AltAST(this); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ import org.antlr.runtime.tree.Tree;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class BlockAST extends GrammarASTWithOptions {
|
||||
public class BlockAST extends GrammarASTWithOptions implements RuleElementAST {
|
||||
// TODO: maybe I need a Subrule object like Rule so these options mov to that?
|
||||
/** What are the default options for a subrule? */
|
||||
public static final Map defaultBlockOptions =
|
||||
|
@ -55,4 +55,7 @@ public class BlockAST extends GrammarASTWithOptions {
|
|||
|
||||
@Override
|
||||
public Tree dupNode() { return new BlockAST(this); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -46,4 +46,7 @@ public class DownAST extends TerminalAST {
|
|||
public String toString() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -215,4 +215,5 @@ public class GrammarAST extends CommonTree {
|
|||
return buf.toString();
|
||||
}
|
||||
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -8,4 +8,17 @@ t.visit(v);
|
|||
public interface GrammarASTVisitor {
|
||||
Object visit(RuleAST node);
|
||||
Object visit(AltAST node);
|
||||
Object visit(DownAST node);
|
||||
Object visit(GrammarAST node);
|
||||
Object visit(GrammarRootAST node);
|
||||
Object visit(NotAST node);
|
||||
Object visit(OptionalBlockAST node);
|
||||
Object visit(PlusBlockAST node);
|
||||
Object visit(PredAST node);
|
||||
Object visit(RangeAST node);
|
||||
Object visit(SetAST node);
|
||||
Object visit(StarBlockAST node);
|
||||
Object visit(TerminalAST node);
|
||||
Object visit(TreePatternAST node);
|
||||
Object visit(UpAST node);
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ import org.antlr.runtime.Token;
|
|||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class GrammarASTWithOptions extends GrammarAST {
|
||||
public abstract class GrammarASTWithOptions extends GrammarAST {
|
||||
protected Map<String, String> options;
|
||||
|
||||
public GrammarASTWithOptions(GrammarAST node) {
|
||||
|
|
|
@ -63,4 +63,7 @@ public class GrammarRootAST extends GrammarASTWithOptions {
|
|||
public GrammarRootAST(int type, Token t, String text) {
|
||||
super(type,t,text);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.antlr.v4.tool.ast;
|
||||
|
||||
import org.antlr.runtime.Token;
|
||||
|
||||
public class NotAST extends GrammarAST implements RuleElementAST {
|
||||
public NotAST(int type, Token t) { super(type, t); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
|
@ -0,0 +1,7 @@
|
|||
package org.antlr.v4.tool.ast;
|
||||
|
||||
import org.antlr.runtime.Token;
|
||||
|
||||
public class OptionalBlockAST extends GrammarAST implements RuleElementAST {
|
||||
public OptionalBlockAST(int type, Token t) { super(type, t); }
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.antlr.v4.tool.ast;
|
||||
|
||||
import org.antlr.runtime.Token;
|
||||
|
||||
public class PlusBlockAST extends GrammarAST implements RuleElementAST {
|
||||
public PlusBlockAST(int type, Token t) { super(type, t); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
|
@ -41,4 +41,7 @@ public class PredAST extends ActionAST {
|
|||
public PredAST(Token t) { super(t); }
|
||||
public PredAST(int type) { super(type); }
|
||||
public PredAST(int type, Token t) { super(type, t); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
package org.antlr.v4.tool.ast;
|
||||
|
||||
import org.antlr.runtime.Token;
|
||||
|
||||
public class RangeAST extends GrammarAST implements RuleElementAST {
|
||||
public RangeAST(Token t) { super(t); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
|
@ -58,5 +58,6 @@ public class RuleAST extends GrammarASTWithOptions {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
package org.antlr.v4.tool.ast;
|
||||
|
||||
/** Tag indicated AST node is a rule element like token or rule ref. */
|
||||
public interface RuleElementAST {
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.antlr.v4.tool.ast;
|
||||
|
||||
import org.antlr.runtime.Token;
|
||||
|
||||
public class SetAST extends GrammarAST implements RuleElementAST {
|
||||
public SetAST(int type, Token t, String text) { super(type,t,text); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
|
@ -0,0 +1,10 @@
|
|||
package org.antlr.v4.tool.ast;
|
||||
|
||||
import org.antlr.runtime.Token;
|
||||
|
||||
public class StarBlockAST extends GrammarAST implements RuleElementAST {
|
||||
public StarBlockAST(int type, Token t) { super(type, t); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
|
@ -32,7 +32,7 @@ package org.antlr.v4.tool.ast;
|
|||
import org.antlr.runtime.Token;
|
||||
import org.antlr.runtime.tree.Tree;
|
||||
|
||||
public class TerminalAST extends GrammarASTWithOptions {
|
||||
public class TerminalAST extends GrammarASTWithOptions implements RuleElementAST {
|
||||
public static final String defaultTokenOption = "node";
|
||||
|
||||
public TerminalAST(GrammarAST node) {
|
||||
|
@ -45,4 +45,7 @@ public class TerminalAST extends GrammarASTWithOptions {
|
|||
|
||||
@Override
|
||||
public Tree dupNode() { return new TerminalAST(this); }
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ package org.antlr.v4.tool.ast;
|
|||
import org.antlr.runtime.Token;
|
||||
import org.antlr.v4.runtime.atn.ATNState;
|
||||
|
||||
public class TreePatternAST extends GrammarAST {
|
||||
public class TreePatternAST extends GrammarAST implements RuleElementAST {
|
||||
/** Record ATN DN, UP nodes so we can find easily later */
|
||||
public ATNState downState;
|
||||
public ATNState upState;
|
||||
|
@ -40,4 +40,7 @@ public class TreePatternAST extends GrammarAST {
|
|||
public TreePatternAST(Token t) {
|
||||
super(t);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
|
@ -45,4 +45,7 @@ public class UpAST extends TerminalAST {
|
|||
public String toString() {
|
||||
return getText();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object visit(GrammarASTVisitor v) { return v.visit(this); }
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue