forked from jasder/antlr
Fixes to Go runtime, tool
This commit is contained in:
parent
92b8f9f891
commit
89f1192cb6
|
@ -72,7 +72,7 @@ func (this *ATN) NextTokensInContext(s ATNState, ctx RuleContext) *IntervalSet {
|
||||||
func (this *ATN) NextTokensNoContext(s ATNState) *IntervalSet {
|
func (this *ATN) NextTokensNoContext(s ATNState) *IntervalSet {
|
||||||
if s.GetNextTokenWithinRule() != nil {
|
if s.GetNextTokenWithinRule() != nil {
|
||||||
if PortDebug {
|
if PortDebug {
|
||||||
fmt.Println("DEBUG 1")
|
fmt.Println("DEBUG A")
|
||||||
}
|
}
|
||||||
return s.GetNextTokenWithinRule()
|
return s.GetNextTokenWithinRule()
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@ package antlr4
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"reflect"
|
// "reflect"
|
||||||
"strconv"
|
"strconv"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -14,8 +14,13 @@ import (
|
||||||
// an ATN state.
|
// an ATN state.
|
||||||
//
|
//
|
||||||
|
|
||||||
|
type Comparable interface {
|
||||||
|
equals(other interface{}) bool
|
||||||
|
}
|
||||||
|
|
||||||
type ATNConfig interface {
|
type ATNConfig interface {
|
||||||
Hasher
|
Hasher
|
||||||
|
Comparable
|
||||||
|
|
||||||
getPrecedenceFilterSuppressed() bool
|
getPrecedenceFilterSuppressed() bool
|
||||||
setPrecedenceFilterSuppressed(bool)
|
setPrecedenceFilterSuppressed(bool)
|
||||||
|
@ -144,14 +149,30 @@ func (this *BaseATNConfig) SetReachesIntoOuterContext(v int) {
|
||||||
// the same state, they predict the same alternative, and
|
// the same state, they predict the same alternative, and
|
||||||
// syntactic/semantic contexts are the same.
|
// syntactic/semantic contexts are the same.
|
||||||
///
|
///
|
||||||
func (this *BaseATNConfig) equals(other interface{}) bool {
|
func (this *BaseATNConfig) equals(o interface{}) bool {
|
||||||
if this == other {
|
|
||||||
|
if this == o {
|
||||||
return true
|
return true
|
||||||
} else if _, ok := other.(*BaseATNConfig); !ok {
|
|
||||||
return false
|
|
||||||
} else {
|
|
||||||
return reflect.DeepEqual(this, other)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
other, ok := o.(*BaseATNConfig)
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
var b bool
|
||||||
|
if this.context==nil {
|
||||||
|
b = other.context==nil
|
||||||
|
} else {
|
||||||
|
b = this.context.equals(other.context)
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.state.GetStateNumber() == other.state.GetStateNumber() &&
|
||||||
|
this.alt==other.alt &&
|
||||||
|
this.semanticContext.equals(other.semanticContext) &&
|
||||||
|
this.precedenceFilterSuppressed==other.precedenceFilterSuppressed &&
|
||||||
|
b;
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *BaseATNConfig) shortHash() string {
|
func (this *BaseATNConfig) shortHash() string {
|
||||||
|
@ -295,8 +316,7 @@ func (this *LexerATNConfig) equals(other interface{}) bool {
|
||||||
if b {
|
if b {
|
||||||
return false
|
return false
|
||||||
} else {
|
} else {
|
||||||
panic("Not implemented")
|
return this.BaseATNConfig.equals(othert.BaseATNConfig)
|
||||||
// return ATNConfig.prototype.equals.call(this, other)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -660,6 +660,10 @@ func (this *ParserATNSimulator) removeAllConfigsNotInRuleStopState(configs ATNCo
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ParserATNSimulator) computeStartState(p ATNState, ctx RuleContext, fullCtx bool) ATNConfigSet {
|
func (this *ParserATNSimulator) computeStartState(p ATNState, ctx RuleContext, fullCtx bool) ATNConfigSet {
|
||||||
|
|
||||||
|
if PortDebug {
|
||||||
|
fmt.Println("computeStartState")
|
||||||
|
}
|
||||||
// always at least the implicit call to start rule
|
// always at least the implicit call to start rule
|
||||||
var initialContext = predictionContextFromRuleContext(this.atn, ctx)
|
var initialContext = predictionContextFromRuleContext(this.atn, ctx)
|
||||||
var configs = NewBaseATNConfigSet(fullCtx)
|
var configs = NewBaseATNConfigSet(fullCtx)
|
||||||
|
@ -954,7 +958,7 @@ func (this *ParserATNSimulator) evalSemanticContext(predPredictions []*PredPredi
|
||||||
}
|
}
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
fmt.Println(predPredictions)
|
|
||||||
var predicateEvaluationResult = pair.pred.evaluate(this.parser, outerContext)
|
var predicateEvaluationResult = pair.pred.evaluate(this.parser, outerContext)
|
||||||
if ParserATNSimulatorDebug || ParserATNSimulatorDFADebug {
|
if ParserATNSimulatorDebug || ParserATNSimulatorDFADebug {
|
||||||
fmt.Println("eval pred " + pair.String() + "=" + fmt.Sprint(predicateEvaluationResult))
|
fmt.Println("eval pred " + pair.String() + "=" + fmt.Sprint(predicateEvaluationResult))
|
||||||
|
@ -1002,7 +1006,7 @@ func (this *ParserATNSimulator) closureCheckingStopState(config ATNConfig, confi
|
||||||
// we have no context info, just chase follow links (if greedy)
|
// we have no context info, just chase follow links (if greedy)
|
||||||
if ParserATNSimulatorDebug {
|
if ParserATNSimulatorDebug {
|
||||||
if PortDebug {
|
if PortDebug {
|
||||||
fmt.Println("DEBUG 1")
|
fmt.Println("DEBUG B")
|
||||||
}
|
}
|
||||||
fmt.Println("FALLING off rule " + this.getRuleName(config.GetState().GetRuleIndex()))
|
fmt.Println("FALLING off rule " + this.getRuleName(config.GetState().GetRuleIndex()))
|
||||||
}
|
}
|
||||||
|
@ -1057,7 +1061,7 @@ func (this *ParserATNSimulator) closure_(config ATNConfig, configs ATNConfigSet,
|
||||||
var c = this.getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx, treatEofAsEpsilon)
|
var c = this.getEpsilonTarget(config, t, continueCollecting, depth == 0, fullCtx, treatEofAsEpsilon)
|
||||||
if c != nil {
|
if c != nil {
|
||||||
if PortDebug {
|
if PortDebug {
|
||||||
fmt.Println("DEBUG 1")
|
fmt.Println("DEBUG 1 ok")
|
||||||
}
|
}
|
||||||
if !t.getIsEpsilon() && closureBusy.add(c) != c {
|
if !t.getIsEpsilon() && closureBusy.add(c) != c {
|
||||||
// avoid infinite recursion for EOF* and EOF+
|
// avoid infinite recursion for EOF* and EOF+
|
||||||
|
@ -1069,6 +1073,7 @@ func (this *ParserATNSimulator) closure_(config ATNConfig, configs ATNConfigSet,
|
||||||
|
|
||||||
if PortDebug {
|
if PortDebug {
|
||||||
fmt.Println("DEBUG 2")
|
fmt.Println("DEBUG 2")
|
||||||
|
fmt.Println(closureBusy)
|
||||||
}
|
}
|
||||||
// target fell off end of rule mark resulting c as having dipped into outer context
|
// target fell off end of rule mark resulting c as having dipped into outer context
|
||||||
// We can't get here if incoming config was rule stop and we had context
|
// We can't get here if incoming config was rule stop and we had context
|
||||||
|
@ -1094,7 +1099,7 @@ func (this *ParserATNSimulator) closure_(config ATNConfig, configs ATNConfigSet,
|
||||||
fmt.Println("DEBUG 4")
|
fmt.Println("DEBUG 4")
|
||||||
}
|
}
|
||||||
if t.(*EpsilonTransition).outermostPrecedenceReturn == this._dfa.atnStartState.GetRuleIndex() {
|
if t.(*EpsilonTransition).outermostPrecedenceReturn == this._dfa.atnStartState.GetRuleIndex() {
|
||||||
c.precedenceFilterSuppressed = true
|
c.setPrecedenceFilterSuppressed(true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1123,7 +1128,7 @@ func (this *ParserATNSimulator) getRuleName(index int) string {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *ParserATNSimulator) getEpsilonTarget(config ATNConfig, t Transition, collectPredicates, inContext, fullCtx, treatEofAsEpsilon bool) *BaseATNConfig {
|
func (this *ParserATNSimulator) getEpsilonTarget(config ATNConfig, t Transition, collectPredicates, inContext, fullCtx, treatEofAsEpsilon bool) ATNConfig {
|
||||||
|
|
||||||
switch t.getSerializationType() {
|
switch t.getSerializationType() {
|
||||||
case TransitionRULE:
|
case TransitionRULE:
|
||||||
|
|
|
@ -14,9 +14,10 @@ import (
|
||||||
//
|
//
|
||||||
|
|
||||||
type SemanticContext interface {
|
type SemanticContext interface {
|
||||||
|
Comparable
|
||||||
|
|
||||||
evaluate(parser Recognizer, outerContext RuleContext) bool
|
evaluate(parser Recognizer, outerContext RuleContext) bool
|
||||||
evalPrecedence(parser Recognizer, outerContext RuleContext) SemanticContext
|
evalPrecedence(parser Recognizer, outerContext RuleContext) SemanticContext
|
||||||
equals(interface{}) bool
|
|
||||||
String() string
|
String() string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +383,6 @@ func (this *OR) Hash() string {
|
||||||
// unordered.</p>
|
// unordered.</p>
|
||||||
//
|
//
|
||||||
func (this *OR) evaluate(parser Recognizer, outerContext RuleContext) bool {
|
func (this *OR) evaluate(parser Recognizer, outerContext RuleContext) bool {
|
||||||
fmt.Println("HI")
|
|
||||||
for i := 0; i < len(this.opnds); i++ {
|
for i := 0; i < len(this.opnds); i++ {
|
||||||
if this.opnds[i].evaluate(parser, outerContext) {
|
if this.opnds[i].evaluate(parser, outerContext) {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -72,6 +72,18 @@ func NewSet(hashFunction func(interface{}) string, equalsFunction func(interface
|
||||||
return s
|
return s
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func standardEqualsFunction(a interface{}, b interface{}) bool {
|
||||||
|
|
||||||
|
ac, oka := a.(Comparable)
|
||||||
|
bc, okb := b.(Comparable)
|
||||||
|
|
||||||
|
if !oka || !okb {
|
||||||
|
panic("Not Comparable")
|
||||||
|
}
|
||||||
|
|
||||||
|
return ac.equals(bc)
|
||||||
|
}
|
||||||
|
|
||||||
func standardHashFunction(a interface{}) string {
|
func standardHashFunction(a interface{}) string {
|
||||||
h, ok := a.(Hasher)
|
h, ok := a.(Hasher)
|
||||||
|
|
||||||
|
@ -79,7 +91,7 @@ func standardHashFunction(a interface{}) string {
|
||||||
return h.Hash()
|
return h.Hash()
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprint(a)
|
panic("Not Hasher")
|
||||||
}
|
}
|
||||||
|
|
||||||
//func getBytes(key interface{}) ([]byte, error) {
|
//func getBytes(key interface{}) ([]byte, error) {
|
||||||
|
@ -102,9 +114,6 @@ func hashCode(s string) string {
|
||||||
return fmt.Sprint(h.Sum32())
|
return fmt.Sprint(h.Sum32())
|
||||||
}
|
}
|
||||||
|
|
||||||
func standardEqualsFunction(a interface{}, b interface{}) bool {
|
|
||||||
return standardHashFunction(a) == standardHashFunction(b)
|
|
||||||
}
|
|
||||||
|
|
||||||
func (this *Set) length() int {
|
func (this *Set) length() int {
|
||||||
return len(this.data)
|
return len(this.data)
|
||||||
|
@ -141,7 +150,6 @@ func (this *Set) contains(value interface{}) bool {
|
||||||
values := this.data[key]
|
values := this.data[key]
|
||||||
|
|
||||||
if this.data[key] != nil {
|
if this.data[key] != nil {
|
||||||
|
|
||||||
for i := 0; i < len(values); i++ {
|
for i := 0; i < len(values); i++ {
|
||||||
if this.equalsFunction(value, values[i]) {
|
if this.equalsFunction(value, values[i]) {
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
PORT_DEBUG = false
|
||||||
|
|
||||||
|
var antlr4 = require("./antlr4/index"),
|
||||||
|
tree = antlr4.tree
|
||||||
|
JSONLexer = require("./JSONLexer").JSONLexer,
|
||||||
|
JSONParser = require("./JSONParser").JSONParser,
|
||||||
|
JSONListener = require("./JSONListener").JSONListener;
|
||||||
|
|
||||||
|
var a = new antlr4.FileStream("foo.txt");
|
||||||
|
var l = new JSONLexer(a);
|
||||||
|
var s = new antlr4.CommonTokenStream(l, 0);
|
||||||
|
var p = new JSONParser(s);
|
||||||
|
p.buildParseTrees = true;
|
||||||
|
|
||||||
|
KeyPrinter = function() {
|
||||||
|
JSONListener.call(this); // inherit default listener
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
|
||||||
|
// inherit default listener
|
||||||
|
KeyPrinter.prototype = Object.create(JSONListener.prototype);
|
||||||
|
KeyPrinter.prototype.constructor = KeyPrinter;
|
||||||
|
|
||||||
|
// override default listener behavior
|
||||||
|
KeyPrinter.prototype.enterValue = function(ctx) {
|
||||||
|
console.log(ctx.start.text);
|
||||||
|
};
|
||||||
|
|
||||||
|
var tree = p.json();
|
||||||
|
|
||||||
|
var printer = new KeyPrinter();
|
||||||
|
antlr4.tree.ParseTreeWalker.DEFAULT.walk(printer, tree);
|
|
@ -76,7 +76,7 @@ ATN.prototype.nextTokensInContext = function(s, ctx) {
|
||||||
ATN.prototype.nextTokensNoContext = function(s) {
|
ATN.prototype.nextTokensNoContext = function(s) {
|
||||||
if (s.nextTokenWithinRule !== null ) {
|
if (s.nextTokenWithinRule !== null ) {
|
||||||
if (PORT_DEBUG) {
|
if (PORT_DEBUG) {
|
||||||
console.log("DEBUG 1")
|
console.log("DEBUG A")
|
||||||
}
|
}
|
||||||
return s.nextTokenWithinRule;
|
return s.nextTokenWithinRule;
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,10 +169,6 @@ LexerATNSimulator.prototype.matchATN = function(input) {
|
||||||
var suppressEdge = s0_closure.hasSemanticContext;
|
var suppressEdge = s0_closure.hasSemanticContext;
|
||||||
s0_closure.hasSemanticContext = false;
|
s0_closure.hasSemanticContext = false;
|
||||||
|
|
||||||
if (PORT_DEBUG) {
|
|
||||||
console.log(s0_closure.toString())
|
|
||||||
}
|
|
||||||
|
|
||||||
var next = this.addDFAState(s0_closure);
|
var next = this.addDFAState(s0_closure);
|
||||||
if (!suppressEdge) {
|
if (!suppressEdge) {
|
||||||
this.decisionToDFA[this.mode].s0 = next;
|
this.decisionToDFA[this.mode].s0 = next;
|
||||||
|
@ -224,6 +220,7 @@ LexerATNSimulator.prototype.execATN = function(input, ds0) {
|
||||||
// if (PORT_DEBUG) {
|
// if (PORT_DEBUG) {
|
||||||
// console.log(target)
|
// console.log(target)
|
||||||
// }
|
// }
|
||||||
|
|
||||||
if (target === null) {
|
if (target === null) {
|
||||||
target = this.computeTargetState(input, s, t);
|
target = this.computeTargetState(input, s, t);
|
||||||
// print("Computed:" + str(target))
|
// print("Computed:" + str(target))
|
||||||
|
@ -316,7 +313,7 @@ LexerATNSimulator.prototype.failOrAccept = function(prevAccept, input, reach, t)
|
||||||
prevAccept.index, prevAccept.line, prevAccept.column);
|
prevAccept.index, prevAccept.line, prevAccept.column);
|
||||||
|
|
||||||
if (PORT_DEBUG) {
|
if (PORT_DEBUG) {
|
||||||
console.log("Prevaccept", prevAccept.dfaState.prediction)
|
console.log(prevAccept.dfaState.prediction)
|
||||||
}
|
}
|
||||||
|
|
||||||
return prevAccept.dfaState.prediction;
|
return prevAccept.dfaState.prediction;
|
||||||
|
|
|
@ -318,7 +318,6 @@ ParserATNSimulator.prototype.debug_list_atn_decisions = false;
|
||||||
ParserATNSimulator.prototype.dfa_debug = false;
|
ParserATNSimulator.prototype.dfa_debug = false;
|
||||||
ParserATNSimulator.prototype.retry_debug = false;
|
ParserATNSimulator.prototype.retry_debug = false;
|
||||||
|
|
||||||
|
|
||||||
ParserATNSimulator.prototype.reset = function() {
|
ParserATNSimulator.prototype.reset = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -903,6 +902,11 @@ ParserATNSimulator.prototype.removeAllConfigsNotInRuleStopState = function(confi
|
||||||
};
|
};
|
||||||
|
|
||||||
ParserATNSimulator.prototype.computeStartState = function(p, ctx, fullCtx) {
|
ParserATNSimulator.prototype.computeStartState = function(p, ctx, fullCtx) {
|
||||||
|
|
||||||
|
if (PORT_DEBUG){
|
||||||
|
console.log("computeStartState")
|
||||||
|
}
|
||||||
|
|
||||||
// always at least the implicit call to start rule
|
// always at least the implicit call to start rule
|
||||||
var initialContext = predictionContextFromRuleContext(this.atn, ctx);
|
var initialContext = predictionContextFromRuleContext(this.atn, ctx);
|
||||||
var configs = new ATNConfigSet(fullCtx);
|
var configs = new ATNConfigSet(fullCtx);
|
||||||
|
@ -1257,7 +1261,7 @@ ParserATNSimulator.prototype.closureCheckingStopState = function(config, configs
|
||||||
// we have no context info, just chase follow links (if greedy)
|
// we have no context info, just chase follow links (if greedy)
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
if (PORT_DEBUG) {
|
if (PORT_DEBUG) {
|
||||||
console.log("DEBUG 1")
|
console.log("DEBUG B")
|
||||||
}
|
}
|
||||||
console.log("FALLING off rule " + this.getRuleName(config.state.ruleIndex));
|
console.log("FALLING off rule " + this.getRuleName(config.state.ruleIndex));
|
||||||
}
|
}
|
||||||
|
@ -1312,7 +1316,7 @@ ParserATNSimulator.prototype.closure_ = function(config, configs, closureBusy, c
|
||||||
var c = this.getEpsilonTarget(config, t, continueCollecting, depth === 0, fullCtx, treatEofAsEpsilon);
|
var c = this.getEpsilonTarget(config, t, continueCollecting, depth === 0, fullCtx, treatEofAsEpsilon);
|
||||||
if (c!==null) {
|
if (c!==null) {
|
||||||
if (PORT_DEBUG) {
|
if (PORT_DEBUG) {
|
||||||
console.log("DEBUG 1")
|
console.log("DEBUG 1 ok")
|
||||||
}
|
}
|
||||||
if (!t.isEpsilon && closureBusy.add(c)!==c){
|
if (!t.isEpsilon && closureBusy.add(c)!==c){
|
||||||
// avoid infinite recursion for EOF* and EOF+
|
// avoid infinite recursion for EOF* and EOF+
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
a=b+1;
|
|
@ -1,32 +1,43 @@
|
||||||
PORT_DEBUG = false
|
PORT_DEBUG = false
|
||||||
|
|
||||||
var antlr4 = require("./antlr4/index"),
|
var antlr4 = require('./antlr4/index');
|
||||||
tree = antlr4.tree
|
var TLexer = require('./TLexer');
|
||||||
JSONLexer = require("./JSONLexer").JSONLexer,
|
var TParser = require('./TParser');
|
||||||
JSONParser = require("./JSONParser").JSONParser,
|
var TListener = require('./TListener').TListener;
|
||||||
JSONListener = require("./JSONListener").JSONListener;
|
// var TVisitor = require('./parser/TVisitor').TVisitor;
|
||||||
|
|
||||||
var a = new antlr4.FileStream("foo.txt");
|
function TreeShapeListener() {
|
||||||
var l = new JSONLexer(a);
|
antlr4.tree.ParseTreeListener.call(this);
|
||||||
var s = new antlr4.CommonTokenStream(l, 0);
|
return this;
|
||||||
var p = new JSONParser(s);
|
}
|
||||||
p.buildParseTrees = true;
|
|
||||||
|
|
||||||
KeyPrinter = function() {
|
TreeShapeListener.prototype = Object.create(antlr4.tree.ParseTreeListener.prototype);
|
||||||
JSONListener.call(this); // inherit default listener
|
TreeShapeListener.prototype.constructor = TreeShapeListener;
|
||||||
return this;
|
|
||||||
|
TreeShapeListener.prototype.enterEveryRule = function(ctx) {
|
||||||
|
for(var i=0;i<ctx.getChildCount; i++) {
|
||||||
|
var child = ctx.getChild(i);
|
||||||
|
var parent = child.parentCtx;
|
||||||
|
if(parent.getRuleContext() !== ctx || !(parent instanceof antlr4.tree.RuleNode)) {
|
||||||
|
throw "Invalid parse tree shape detected.";
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// inherit default listener
|
function main(argv) {
|
||||||
KeyPrinter.prototype = Object.create(JSONListener.prototype);
|
var input = new antlr4.FileStream(argv[2]);
|
||||||
KeyPrinter.prototype.constructor = KeyPrinter;
|
var lexer = new TLexer.TLexer(input);
|
||||||
|
var stream = new antlr4.CommonTokenStream(lexer);
|
||||||
|
var parser = new TParser.TParser(stream);
|
||||||
|
parser.buildParseTrees = true;
|
||||||
|
printer = function() {
|
||||||
|
this.println = function(s) { console.log(s); }
|
||||||
|
this.print = function(s) { process.stdout.write(s); }
|
||||||
|
return this;
|
||||||
|
};
|
||||||
|
parser.printer = new printer();
|
||||||
|
var tree = parser.program();
|
||||||
|
antlr4.tree.ParseTreeWalker.DEFAULT.walk(new TreeShapeListener(), tree);
|
||||||
|
}
|
||||||
|
|
||||||
// override default listener behavior
|
main(process.argv);
|
||||||
KeyPrinter.prototype.enterValue = function(ctx) {
|
|
||||||
console.log(ctx.start.text);
|
|
||||||
};
|
|
||||||
|
|
||||||
var tree = p.json();
|
|
||||||
|
|
||||||
var printer = new KeyPrinter();
|
|
||||||
antlr4.tree.ParseTreeWalker.DEFAULT.walk(printer, tree);
|
|
||||||
|
|
|
@ -194,7 +194,8 @@ func (l *<lexer.name>) Action(localctx antlr4.RuleContext, ruleIndex, actionInde
|
||||||
l.<f.name>_Action(t, actionIndex)
|
l.<f.name>_Action(t, actionIndex)
|
||||||
<else>
|
<else>
|
||||||
l.<f.name>_Action(localctx, actionIndex)
|
l.<f.name>_Action(localctx, actionIndex)
|
||||||
<endif>}; separator="\n">
|
<endif>
|
||||||
|
break}; separator="\n">
|
||||||
default:
|
default:
|
||||||
panic("No registered action for:" + fmt.Sprint(ruleIndex))
|
panic("No registered action for:" + fmt.Sprint(ruleIndex))
|
||||||
}
|
}
|
||||||
|
@ -233,7 +234,7 @@ func (l *<lexer.name>) <r.name; format="cap">_Action(localctx <if(r.isRuleContex
|
||||||
<actions:{index|
|
<actions:{index|
|
||||||
case <index>:
|
case <index>:
|
||||||
<actions.(index)>
|
<actions.(index)>
|
||||||
}; separator="\n">
|
break}; separator="\n">
|
||||||
default:
|
default:
|
||||||
panic("No registered action for:" + fmt.Sprint(actionIndex))
|
panic("No registered action for:" + fmt.Sprint(actionIndex))
|
||||||
}
|
}
|
||||||
|
@ -361,7 +362,7 @@ p.SetState(<choice.stateNumber>)
|
||||||
switch p.GetTokenStream().LA(1) {
|
switch p.GetTokenStream().LA(1) {
|
||||||
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
||||||
<alt>
|
<alt>
|
||||||
}; separator="\n">
|
break }; separator="\n">
|
||||||
default:
|
default:
|
||||||
<error>
|
<error>
|
||||||
}
|
}
|
||||||
|
@ -372,7 +373,7 @@ p.SetState(<choice.stateNumber>)
|
||||||
switch p.GetTokenStream().LA(1) {
|
switch p.GetTokenStream().LA(1) {
|
||||||
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
<choice.altLook,alts:{look,alt| <cases(ttypes=look)>
|
||||||
<alt>
|
<alt>
|
||||||
}; separator="\n">
|
break }; separator="\n">
|
||||||
default:
|
default:
|
||||||
<error>
|
<error>
|
||||||
}
|
}
|
||||||
|
@ -423,6 +424,7 @@ switch la_ {
|
||||||
<alts:{alt |
|
<alts:{alt |
|
||||||
case <i>:
|
case <i>:
|
||||||
<alt>
|
<alt>
|
||||||
|
break
|
||||||
}; separator="\n">
|
}; separator="\n">
|
||||||
}
|
}
|
||||||
>>
|
>>
|
||||||
|
@ -463,7 +465,7 @@ for ok := true; ok; ok = _alt!=<choice.exitAlt> && _alt!= antlr4.ATNInvalidAltNu
|
||||||
<alts:{alt|
|
<alts:{alt|
|
||||||
case <i><if(!choice.ast.greedy)>+1<endif>:
|
case <i><if(!choice.ast.greedy)>+1<endif>:
|
||||||
<alt>
|
<alt>
|
||||||
//}; separator="\n">
|
break }; separator="\n">
|
||||||
default:
|
default:
|
||||||
<error>
|
<error>
|
||||||
}
|
}
|
||||||
|
@ -510,7 +512,7 @@ bitsetInlineComparison(s, bits) ::= <%
|
||||||
%>
|
%>
|
||||||
|
|
||||||
cases(ttypes) ::= <<
|
cases(ttypes) ::= <<
|
||||||
<ttypes:{t | case <parser.name><t>:}; separator="\n">
|
<ttypes:{t | case <parser.name><t>:}; separator="fallthrough \n">
|
||||||
>>
|
>>
|
||||||
|
|
||||||
InvokeRule(r, argExprsChunks) ::= <<
|
InvokeRule(r, argExprsChunks) ::= <<
|
||||||
|
@ -709,6 +711,7 @@ type I<struct.name> interface {
|
||||||
antlr4.ParserRuleContext
|
antlr4.ParserRuleContext
|
||||||
|
|
||||||
GetParser() antlr4.Parser
|
GetParser() antlr4.Parser
|
||||||
|
get<struct.name>() // to differentiate from other interfaces
|
||||||
|
|
||||||
<struct.tokenDecls:{a | Get<a.name; format="cap">() <TokenLabelType()> }; separator="\n">
|
<struct.tokenDecls:{a | Get<a.name; format="cap">() <TokenLabelType()> }; separator="\n">
|
||||||
<struct.tokenDecls:{a | Set<a.name; format="cap">(<TokenLabelType()>) }; separator="\n">
|
<struct.tokenDecls:{a | Set<a.name; format="cap">(<TokenLabelType()>) }; separator="\n">
|
||||||
|
@ -738,6 +741,8 @@ func NewEmpty<struct.name>() *<struct.name> {
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (*<struct.name>) get<struct.name>() {}
|
||||||
|
|
||||||
func New<struct.name>(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int<struct.ctorAttrs:{a | , <a.name> <a.type;format="lower">}>) *<struct.name> {
|
func New<struct.name>(parser antlr4.Parser, parent antlr4.ParserRuleContext, invokingState int<struct.ctorAttrs:{a | , <a.name> <a.type;format="lower">}>) *<struct.name> {
|
||||||
|
|
||||||
var p = new(<struct.name>)
|
var p = new(<struct.name>)
|
||||||
|
|
Loading…
Reference in New Issue