Go impl emits exact same debug messages as JS impl. Yessss....
This commit is contained in:
parent
7798333f72
commit
efa8676211
|
@ -7,11 +7,6 @@ import (
|
|||
|
||||
// A DFA walker that knows how to dump them to serialized strings.
|
||||
|
||||
type IDFASerializer interface {
|
||||
|
||||
}
|
||||
|
||||
|
||||
type DFASerializer struct {
|
||||
dfa *DFA
|
||||
literalNames, symbolicNames []string
|
||||
|
@ -44,8 +39,7 @@ func (this *DFASerializer) String() string {
|
|||
|
||||
var buf = ""
|
||||
var states = this.dfa.sortedStates()
|
||||
for i := 0; i < len(states); i++ {
|
||||
var s = states[i]
|
||||
for _,s := range states {
|
||||
if s.edges != nil {
|
||||
var n = len(s.edges)
|
||||
for j := 0; j < n; j++ {
|
||||
|
|
|
@ -121,6 +121,10 @@ func (this *DFAState) GetAltSet() *Set {
|
|||
}
|
||||
}
|
||||
|
||||
func (this *DFAState) setPrediction(v int) {
|
||||
this.prediction = v
|
||||
}
|
||||
|
||||
// Two {@link DFAState} instances are equal if their ATN configuration sets
|
||||
// are the same. This method is used to see if a state already exists.
|
||||
//
|
||||
|
@ -151,8 +155,8 @@ func (this *DFAState) String() string {
|
|||
func (this *DFAState) Hash() string {
|
||||
|
||||
var s string
|
||||
if (this.isAcceptState) {
|
||||
if (this.predicates != nil) {
|
||||
if this.isAcceptState {
|
||||
if this.predicates != nil {
|
||||
s = "=>" + fmt.Sprint(this.predicates)
|
||||
} else {
|
||||
s = "=>" + fmt.Sprint(this.prediction)
|
||||
|
|
|
@ -175,7 +175,7 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo
|
|||
for i := 0; i < ctx.length(); i++ {
|
||||
|
||||
returnState := la.atn.states[ctx.getReturnState(i)]
|
||||
la.__LOOK(returnState, stopState, ctx.GetParent(i), look, lookBusy, calledRuleStack, seeThruPreds, addEOF, i)
|
||||
la.__LOOK(returnState, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF, i)
|
||||
|
||||
}
|
||||
return
|
||||
|
|
|
@ -623,7 +623,7 @@ func (this *LexerATNSimulator) addDFAState(configs *ATNConfigSet) *DFAState {
|
|||
if firstConfigWithRuleStopState != nil {
|
||||
proposed.isAcceptState = true
|
||||
proposed.lexerActionExecutor = firstConfigWithRuleStopState.(*LexerATNConfig).lexerActionExecutor
|
||||
proposed.prediction = this.atn.ruleToTokenType[firstConfigWithRuleStopState.GetState().GetRuleIndex()]
|
||||
proposed.setPrediction(this.atn.ruleToTokenType[firstConfigWithRuleStopState.GetState().GetRuleIndex()])
|
||||
}
|
||||
var hash = proposed.Hash()
|
||||
var dfa = this.decisionToDFA[this.mode]
|
||||
|
|
|
@ -327,19 +327,19 @@ func (this *ParserATNSimulator) computeTargetState(dfa *DFA, previousD *DFAState
|
|||
// NO CONFLICT, UNIQUELY PREDICTED ALT
|
||||
D.isAcceptState = true
|
||||
D.configs.uniqueAlt = predictedAlt
|
||||
D.prediction = predictedAlt
|
||||
D.setPrediction( predictedAlt )
|
||||
} else if PredictionModehasSLLConflictTerminatingPrediction(this.predictionMode, reach) {
|
||||
// MORE THAN ONE VIABLE ALTERNATIVE
|
||||
D.configs.conflictingAlts = this.getConflictingAlts(reach)
|
||||
D.requiresFullContext = true
|
||||
// in SLL-only mode, we will stop at this state and return the minimum alt
|
||||
D.isAcceptState = true
|
||||
D.prediction = D.configs.conflictingAlts.minValue()
|
||||
D.setPrediction( D.configs.conflictingAlts.minValue() )
|
||||
}
|
||||
if D.isAcceptState && D.configs.hasSemanticContext {
|
||||
this.predicateDFAState(D, this.atn.getDecisionState(dfa.decision))
|
||||
if D.predicates != nil {
|
||||
D.prediction = ATNINVALID_ALT_NUMBER
|
||||
D.setPrediction( ATNINVALID_ALT_NUMBER )
|
||||
}
|
||||
}
|
||||
// all adds to dfa are done after we've created full D state
|
||||
|
@ -357,12 +357,12 @@ func (this *ParserATNSimulator) predicateDFAState(dfaState *DFAState, decisionSt
|
|||
var altToPred = this.getPredsForAmbigAlts(altsToCollectPredsFrom, dfaState.configs, nalts)
|
||||
if altToPred != nil {
|
||||
dfaState.predicates = this.getPredicatePredictions(altsToCollectPredsFrom, altToPred)
|
||||
dfaState.prediction = ATNINVALID_ALT_NUMBER // make sure we use preds
|
||||
dfaState.setPrediction( ATNINVALID_ALT_NUMBER ) // make sure we use preds
|
||||
} else {
|
||||
// There are preds in configs but they might go away
|
||||
// when OR'd together like {p}? || NONE == NONE. If neither
|
||||
// alt has preds, resolve to min alt
|
||||
dfaState.prediction = altsToCollectPredsFrom.minValue()
|
||||
dfaState.setPrediction( altsToCollectPredsFrom.minValue() )
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1072,7 +1072,6 @@ func (this *ParserATNSimulator) closure_(config IATNConfig, configs *ATNConfigSe
|
|||
fmt.Println(closureBusy)
|
||||
}
|
||||
|
||||
|
||||
if this._dfa != nil && this._dfa.precedenceDfa {
|
||||
fmt.Println("DEBUG 4")
|
||||
if t.(*EpsilonTransition).outermostPrecedenceReturn == this._dfa.atnStartState.GetRuleIndex() {
|
||||
|
|
|
@ -219,7 +219,7 @@ func (this *BitSet) values() []int {
|
|||
}
|
||||
|
||||
func (this *BitSet) minValue() int {
|
||||
min := 0
|
||||
min := 2147483647
|
||||
|
||||
for k, _ := range this.data {
|
||||
if k < min {
|
||||
|
|
|
@ -726,9 +726,11 @@ ArithmeticParser.prototype.relop = function() {
|
|||
this.state = 56;
|
||||
_la = this._input.LA(1);
|
||||
if(!((((_la) & ~0x1f) == 0 && ((1 << _la) & ((1 << ArithmeticParser.GT) | (1 << ArithmeticParser.LT) | (1 << ArithmeticParser.EQ))) !== 0))) {
|
||||
console.log("DEBUG1")
|
||||
this._errHandler.recoverInline(this);
|
||||
}
|
||||
else {
|
||||
console.log("DEBUG2")
|
||||
this.consume();
|
||||
}
|
||||
} catch (re) {
|
||||
|
|
|
@ -97,7 +97,6 @@ BufferedTokenStream.prototype.mark = function() {
|
|||
};
|
||||
|
||||
BufferedTokenStream.prototype.release = function(marker) {
|
||||
console.log("Nothing to release")
|
||||
// no resources to release
|
||||
};
|
||||
|
||||
|
|
|
@ -141,7 +141,6 @@ Parser.prototype.match = function(ttype) {
|
|||
if (t.type === ttype) {
|
||||
this._errHandler.reportMatch(this);
|
||||
this.consume();
|
||||
console.log("consume done")
|
||||
} else {
|
||||
t = this._errHandler.recoverInline(this);
|
||||
if (this.buildParseTrees && t.tokenIndex === -1) {
|
||||
|
|
|
@ -454,7 +454,7 @@ TestSetInline(s) ::= <<
|
|||
|
||||
// Javascript language spec - shift operators are 32 bits long max
|
||||
testShiftInRange(shiftAmount) ::= <<
|
||||
((<shiftAmount>) & 0x1f) == 0
|
||||
((<shiftAmount>) & -(0x1f+1)) == 0
|
||||
>>
|
||||
|
||||
// produces smaller bytecode only when bits.ttypes contains more than two items
|
||||
|
|
Loading…
Reference in New Issue