Allow disabling debug statements
This commit is contained in:
parent
efa8676211
commit
89427b7f45
|
@ -1 +1 @@
|
||||||
1 + 2 = 3 + 5
|
1 + 2 + 32 + (1 + 2) = 3 + 5
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package antlr4
|
package antlr4
|
||||||
import "fmt"
|
import "fmt"
|
||||||
|
|
||||||
|
const (
|
||||||
|
PortDebug = false
|
||||||
|
)
|
||||||
|
|
||||||
var ATNINVALID_ALT_NUMBER = 0
|
var ATNINVALID_ALT_NUMBER = 0
|
||||||
|
|
||||||
type ATN struct {
|
type ATN struct {
|
||||||
|
@ -65,11 +69,15 @@ func (this *ATN) nextTokensInContext(s IATNState, ctx IRuleContext) *IntervalSet
|
||||||
// rule.
|
// rule.
|
||||||
func (this *ATN) nextTokensNoContext(s IATNState) *IntervalSet {
|
func (this *ATN) nextTokensNoContext(s IATNState) *IntervalSet {
|
||||||
if s.GetNextTokenWithinRule() != nil {
|
if s.GetNextTokenWithinRule() != nil {
|
||||||
fmt.Println("DEBUG 1")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 1")
|
||||||
|
}
|
||||||
return s.GetNextTokenWithinRule()
|
return s.GetNextTokenWithinRule()
|
||||||
}
|
}
|
||||||
fmt.Println("DEBUG 2")
|
if PortDebug {
|
||||||
fmt.Println(this.nextTokensInContext(s, nil))
|
fmt.Println("DEBUG 2")
|
||||||
|
fmt.Println(this.nextTokensInContext(s, nil))
|
||||||
|
}
|
||||||
s.SetNextTokenWithinRule(this.nextTokensInContext(s, nil))
|
s.SetNextTokenWithinRule(this.nextTokensInContext(s, nil))
|
||||||
s.GetNextTokenWithinRule().readOnly = true
|
s.GetNextTokenWithinRule().readOnly = true
|
||||||
return s.GetNextTokenWithinRule()
|
return s.GetNextTokenWithinRule()
|
||||||
|
|
|
@ -48,7 +48,9 @@ var CommonTokenFactoryDEFAULT = NewCommonTokenFactory(false)
|
||||||
|
|
||||||
func (this *CommonTokenFactory) Create(source *TokenSourceCharStreamPair, ttype int, text string, channel, start, stop, line, column int) IToken {
|
func (this *CommonTokenFactory) Create(source *TokenSourceCharStreamPair, ttype int, text string, channel, start, stop, line, column int) IToken {
|
||||||
|
|
||||||
fmt.Println("Token factory creating: " + text)
|
if PortDebug {
|
||||||
|
fmt.Println("Token factory creating: " + text)
|
||||||
|
}
|
||||||
|
|
||||||
var t = NewCommonToken(source, ttype, channel, start, stop)
|
var t = NewCommonToken(source, ttype, channel, start, stop)
|
||||||
t.line = line
|
t.line = line
|
||||||
|
@ -65,7 +67,9 @@ func (this *CommonTokenFactory) Create(source *TokenSourceCharStreamPair, ttype
|
||||||
|
|
||||||
func (this *CommonTokenFactory) createThin(ttype int, text string) IToken {
|
func (this *CommonTokenFactory) createThin(ttype int, text string) IToken {
|
||||||
|
|
||||||
fmt.Println("Token factory creating: " + text)
|
if PortDebug {
|
||||||
|
fmt.Println("Token factory creating: " + text)
|
||||||
|
}
|
||||||
|
|
||||||
var t = NewCommonToken(nil, ttype, TokenDefaultChannel, -1, -1)
|
var t = NewCommonToken(nil, ttype, TokenDefaultChannel, -1, -1)
|
||||||
t.SetText(text)
|
t.SetText(text)
|
||||||
|
|
|
@ -55,12 +55,16 @@ func (bt *CommonTokenStream) Consume() {
|
||||||
skipEofCheck = false
|
skipEofCheck = false
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("Consume 1")
|
if PortDebug {
|
||||||
|
fmt.Println("Consume 1")
|
||||||
|
}
|
||||||
if !skipEofCheck && bt.LA(1) == TokenEOF {
|
if !skipEofCheck && bt.LA(1) == TokenEOF {
|
||||||
panic("cannot consume EOF")
|
panic("cannot consume EOF")
|
||||||
}
|
}
|
||||||
if bt.Sync(bt.index + 1) {
|
if bt.Sync(bt.index + 1) {
|
||||||
fmt.Println("Consume 2")
|
if PortDebug {
|
||||||
|
fmt.Println("Consume 2")
|
||||||
|
}
|
||||||
bt.index = bt.adjustSeekIndex(bt.index + 1)
|
bt.index = bt.adjustSeekIndex(bt.index + 1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -75,7 +79,9 @@ func (bt *CommonTokenStream) Sync(i int) bool {
|
||||||
var n = i - len(bt.tokens) + 1 // how many more elements we need?
|
var n = i - len(bt.tokens) + 1 // how many more elements we need?
|
||||||
if n > 0 {
|
if n > 0 {
|
||||||
var fetched = bt.fetch(n)
|
var fetched = bt.fetch(n)
|
||||||
fmt.Println("Sync done")
|
if PortDebug {
|
||||||
|
fmt.Println("Sync done")
|
||||||
|
}
|
||||||
return fetched >= n
|
return fetched >= n
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
|
@ -92,7 +98,9 @@ func (bt *CommonTokenStream) fetch(n int) int {
|
||||||
|
|
||||||
for i := 0; i < n; i++ {
|
for i := 0; i < n; i++ {
|
||||||
var t IToken = bt.tokenSource.nextToken()
|
var t IToken = bt.tokenSource.nextToken()
|
||||||
fmt.Println("fetch loop")
|
if PortDebug {
|
||||||
|
fmt.Println("fetch loop")
|
||||||
|
}
|
||||||
t.SetTokenIndex( len(bt.tokens) )
|
t.SetTokenIndex( len(bt.tokens) )
|
||||||
bt.tokens = append(bt.tokens, t)
|
bt.tokens = append(bt.tokens, t)
|
||||||
if t.GetTokenType() == TokenEOF {
|
if t.GetTokenType() == TokenEOF {
|
||||||
|
@ -101,7 +109,9 @@ func (bt *CommonTokenStream) fetch(n int) int {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("fetch done")
|
if PortDebug {
|
||||||
|
fmt.Println("fetch done")
|
||||||
|
}
|
||||||
return n
|
return n
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -24,19 +24,27 @@ func NewDefaultErrorListener() *DefaultErrorListener {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DefaultErrorListener) SyntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
|
func (this *DefaultErrorListener) SyntaxError(recognizer IRecognizer, offendingSymbol interface{}, line, column int, msg string, e IRecognitionException) {
|
||||||
fmt.Println("SyntaxError!")
|
if PortDebug {
|
||||||
|
fmt.Println("SyntaxError!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DefaultErrorListener) ReportAmbiguity(recognizer IParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
func (this *DefaultErrorListener) ReportAmbiguity(recognizer IParser, dfa *DFA, startIndex, stopIndex int, exact bool, ambigAlts *BitSet, configs *ATNConfigSet) {
|
||||||
fmt.Println("ReportAmbiguity!")
|
if PortDebug {
|
||||||
|
fmt.Println("ReportAmbiguity!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DefaultErrorListener) ReportAttemptingFullContext(recognizer IParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
|
func (this *DefaultErrorListener) ReportAttemptingFullContext(recognizer IParser, dfa *DFA, startIndex, stopIndex int, conflictingAlts *BitSet, configs *ATNConfigSet) {
|
||||||
fmt.Println("ReportAttemptingFullContext!")
|
if PortDebug {
|
||||||
|
fmt.Println("ReportAttemptingFullContext!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DefaultErrorListener) ReportContextSensitivity(recognizer IParser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
|
func (this *DefaultErrorListener) ReportContextSensitivity(recognizer IParser, dfa *DFA, startIndex, stopIndex, prediction int, configs *ATNConfigSet) {
|
||||||
fmt.Println("ReportContextSensitivity!")
|
if PortDebug {
|
||||||
|
fmt.Println("ReportContextSensitivity!")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
type ConsoleErrorListener struct {
|
type ConsoleErrorListener struct {
|
||||||
|
|
|
@ -209,26 +209,36 @@ func (this *DefaultErrorStrategy) Sync(recognizer IParser) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("STATE" + strconv.Itoa(recognizer.GetState()))
|
if PortDebug {
|
||||||
|
fmt.Println("STATE" + strconv.Itoa(recognizer.GetState()))
|
||||||
|
}
|
||||||
|
|
||||||
var s = recognizer.GetInterpreter().atn.states[recognizer.GetState()]
|
var s = recognizer.GetInterpreter().atn.states[recognizer.GetState()]
|
||||||
var la = recognizer.GetTokenStream().LA(1)
|
var la = recognizer.GetTokenStream().LA(1)
|
||||||
|
|
||||||
fmt.Println("LA" + strconv.Itoa(la))
|
if PortDebug {
|
||||||
|
fmt.Println("LA" + strconv.Itoa(la))
|
||||||
|
}
|
||||||
|
|
||||||
// try cheaper subset first might get lucky. seems to shave a wee bit off
|
// try cheaper subset first might get lucky. seems to shave a wee bit off
|
||||||
if la == TokenEOF || recognizer.GetATN().nextTokens(s, nil).contains(la) {
|
if la == TokenEOF || recognizer.GetATN().nextTokens(s, nil).contains(la) {
|
||||||
fmt.Println("OK1")
|
if PortDebug {
|
||||||
|
fmt.Println("OK1")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
// Return but don't end recovery. only do that upon valid token Match
|
// Return but don't end recovery. only do that upon valid token Match
|
||||||
if recognizer.isExpectedToken(la) {
|
if recognizer.isExpectedToken(la) {
|
||||||
fmt.Println("OK2")
|
if PortDebug {
|
||||||
|
fmt.Println("OK2")
|
||||||
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("LA" + strconv.Itoa(la))
|
if PortDebug {
|
||||||
fmt.Println(recognizer.GetATN().nextTokens(s, nil))
|
fmt.Println("LA" + strconv.Itoa(la))
|
||||||
|
fmt.Println(recognizer.GetATN().nextTokens(s, nil))
|
||||||
|
}
|
||||||
|
|
||||||
switch s.GetStateType() {
|
switch s.GetStateType() {
|
||||||
case ATNStateBLOCK_START:
|
case ATNStateBLOCK_START:
|
||||||
|
@ -545,7 +555,9 @@ func (this *DefaultErrorStrategy) getMissingSymbol(recognizer IParser) IToken {
|
||||||
|
|
||||||
tf := recognizer.GetTokenFactory()
|
tf := recognizer.GetTokenFactory()
|
||||||
|
|
||||||
fmt.Println("Missing symbol error")
|
if PortDebug {
|
||||||
|
fmt.Println("Missing symbol error")
|
||||||
|
}
|
||||||
return tf.Create( current.GetSource(), expectedTokenType, tokenText, TokenDefaultChannel, -1, -1, current.GetLine(), current.GetColumn())
|
return tf.Create( current.GetSource(), expectedTokenType, tokenText, TokenDefaultChannel, -1, -1, current.GetLine(), current.GetColumn())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,9 @@ func NewFileStream(fileName string) *FileStream {
|
||||||
fs.filename = fileName
|
fs.filename = fileName
|
||||||
s := string(buf.Bytes())
|
s := string(buf.Bytes())
|
||||||
|
|
||||||
fmt.Println(s)
|
if PortDebug {
|
||||||
|
fmt.Println(s)
|
||||||
|
}
|
||||||
fs.InputStream = NewInputStream(s)
|
fs.InputStream = NewInputStream(s)
|
||||||
|
|
||||||
return fs
|
return fs
|
||||||
|
|
|
@ -67,7 +67,9 @@ func (is *InputStream) Mark() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (is *InputStream) Release(marker int) {
|
func (is *InputStream) Release(marker int) {
|
||||||
fmt.Println("RELEASING")
|
if PortDebug {
|
||||||
|
fmt.Println("RELEASING")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (is *InputStream) Seek(index int) {
|
func (is *InputStream) Seek(index int) {
|
||||||
|
|
|
@ -68,7 +68,9 @@ func (i *IntervalSet) addRange(l, h int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (is *IntervalSet) addInterval(v *Interval) {
|
func (is *IntervalSet) addInterval(v *Interval) {
|
||||||
fmt.Println("addInterval" + v.String())
|
if PortDebug {
|
||||||
|
fmt.Println("addInterval" + v.String())
|
||||||
|
}
|
||||||
if is.intervals == nil {
|
if is.intervals == nil {
|
||||||
is.intervals = make([]*Interval, 0)
|
is.intervals = make([]*Interval, 0)
|
||||||
is.intervals = append(is.intervals, v)
|
is.intervals = append(is.intervals, v)
|
||||||
|
@ -96,9 +98,13 @@ func (is *IntervalSet) addInterval(v *Interval) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (i *IntervalSet) addSet(other *IntervalSet) *IntervalSet {
|
func (i *IntervalSet) addSet(other *IntervalSet) *IntervalSet {
|
||||||
fmt.Println("addSet")
|
if PortDebug {
|
||||||
|
fmt.Println("addSet")
|
||||||
|
}
|
||||||
if other.intervals != nil {
|
if other.intervals != nil {
|
||||||
fmt.Println(len(other.intervals))
|
if PortDebug {
|
||||||
|
fmt.Println(len(other.intervals))
|
||||||
|
}
|
||||||
for k := 0; k < len(other.intervals); k++ {
|
for k := 0; k < len(other.intervals); k++ {
|
||||||
var i2 = other.intervals[k]
|
var i2 = other.intervals[k]
|
||||||
i.addInterval(NewInterval(i2.start, i2.stop))
|
i.addInterval(NewInterval(i2.start, i2.stop))
|
||||||
|
|
|
@ -75,16 +75,20 @@ func (la *LL1Analyzer) LOOK(s, stopState IATNState, ctx IRuleContext) *IntervalS
|
||||||
if ctx != nil {
|
if ctx != nil {
|
||||||
lookContext = predictionContextFromRuleContext(s.GetATN(), ctx)
|
lookContext = predictionContextFromRuleContext(s.GetATN(), ctx)
|
||||||
}
|
}
|
||||||
fmt.Println("DEBUG 5")
|
if PortDebug {
|
||||||
// fmt.Println("DEBUG" + lookContext.String())
|
fmt.Println("DEBUG 5")
|
||||||
fmt.Println(s)
|
// fmt.Println("DEBUG" + lookContext.String())
|
||||||
fmt.Println(stopState)
|
fmt.Println(s)
|
||||||
fmt.Println(lookContext)
|
fmt.Println(stopState)
|
||||||
fmt.Println(r)
|
fmt.Println(lookContext)
|
||||||
fmt.Println(seeThruPreds)
|
fmt.Println(r)
|
||||||
fmt.Println("=====")
|
fmt.Println(seeThruPreds)
|
||||||
|
fmt.Println("=====")
|
||||||
|
}
|
||||||
la._LOOK(s, stopState, lookContext, r, NewSet(nil, nil), NewBitSet(), seeThruPreds, true)
|
la._LOOK(s, stopState, lookContext, r, NewSet(nil, nil), NewBitSet(), seeThruPreds, true)
|
||||||
fmt.Println(r)
|
if PortDebug {
|
||||||
|
fmt.Println(r)
|
||||||
|
}
|
||||||
return r
|
return r
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,7 +151,9 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo
|
||||||
lookBusy.add(c)
|
lookBusy.add(c)
|
||||||
|
|
||||||
if s == stopState {
|
if s == stopState {
|
||||||
fmt.Println("DEBUG 6")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 6")
|
||||||
|
}
|
||||||
if ctx == nil {
|
if ctx == nil {
|
||||||
look.addOne(TokenEpsilon)
|
look.addOne(TokenEpsilon)
|
||||||
return
|
return
|
||||||
|
@ -169,7 +175,9 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo
|
||||||
}
|
}
|
||||||
|
|
||||||
if ctx != PredictionContextEMPTY {
|
if ctx != PredictionContextEMPTY {
|
||||||
fmt.Println("DEBUG 7")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 7")
|
||||||
|
}
|
||||||
|
|
||||||
// run thru all possible stack tops in ctx
|
// run thru all possible stack tops in ctx
|
||||||
for i := 0; i < ctx.length(); i++ {
|
for i := 0; i < ctx.length(); i++ {
|
||||||
|
@ -188,7 +196,9 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo
|
||||||
t := s.GetTransitions()[i]
|
t := s.GetTransitions()[i]
|
||||||
|
|
||||||
if t1, ok := t.(*RuleTransition); ok {
|
if t1, ok := t.(*RuleTransition); ok {
|
||||||
fmt.Println("DEBUG 8")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 8")
|
||||||
|
}
|
||||||
|
|
||||||
if calledRuleStack.contains(t1.getTarget().GetRuleIndex()) {
|
if calledRuleStack.contains(t1.getTarget().GetRuleIndex()) {
|
||||||
continue
|
continue
|
||||||
|
@ -198,32 +208,37 @@ func (la *LL1Analyzer) _LOOK(s, stopState IATNState, ctx IPredictionContext, loo
|
||||||
|
|
||||||
la.___LOOK(stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF, t1)
|
la.___LOOK(stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF, t1)
|
||||||
|
|
||||||
fmt.Println(look)
|
if PortDebug {
|
||||||
//
|
fmt.Println(look)
|
||||||
// defer func() {
|
}
|
||||||
// calledRuleStack.remove(t1.getTarget().GetRuleIndex())
|
|
||||||
// }()
|
|
||||||
//
|
|
||||||
// calledRuleStack.add(t1.getTarget().GetRuleIndex())
|
|
||||||
// la._LOOK(t1.getTarget(), stopState, newContext, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
|
||||||
|
|
||||||
} else if t2, ok := t.(IAbstractPredicateTransition); ok {
|
} else if t2, ok := t.(IAbstractPredicateTransition); ok {
|
||||||
fmt.Println("DEBUG 9")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 9")
|
||||||
|
}
|
||||||
if seeThruPreds {
|
if seeThruPreds {
|
||||||
la._LOOK(t2.getTarget(), stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
la._LOOK(t2.getTarget(), stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
||||||
} else {
|
} else {
|
||||||
look.addOne(LL1AnalyzerHIT_PRED)
|
look.addOne(LL1AnalyzerHIT_PRED)
|
||||||
}
|
}
|
||||||
} else if t.getIsEpsilon() {
|
} else if t.getIsEpsilon() {
|
||||||
fmt.Println("DEBUG 10")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 10")
|
||||||
|
}
|
||||||
la._LOOK(t.getTarget(), stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
la._LOOK(t.getTarget(), stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF)
|
||||||
} else if _, ok := t.(*WildcardTransition); ok {
|
} else if _, ok := t.(*WildcardTransition); ok {
|
||||||
fmt.Println("DEBUG 11")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 11")
|
||||||
|
}
|
||||||
look.addRange(TokenMinUserTokenType, la.atn.maxTokenType)
|
look.addRange(TokenMinUserTokenType, la.atn.maxTokenType)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("DEBUG 12")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 12")
|
||||||
|
}
|
||||||
set := t.getLabel()
|
set := t.getLabel()
|
||||||
fmt.Println(set)
|
if PortDebug {
|
||||||
|
fmt.Println(set)
|
||||||
|
}
|
||||||
if set != nil {
|
if set != nil {
|
||||||
if _, ok := t.(*NotSetTransition); ok {
|
if _, ok := t.(*NotSetTransition); ok {
|
||||||
set = set.complement(TokenMinUserTokenType, la.atn.maxTokenType)
|
set = set.complement(TokenMinUserTokenType, la.atn.maxTokenType)
|
||||||
|
|
|
@ -211,10 +211,14 @@ func (l *Lexer) nextToken() IToken {
|
||||||
if l._type != LexerMore {
|
if l._type != LexerMore {
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
fmt.Println("lex inner loop")
|
if PortDebug {
|
||||||
|
fmt.Println("lex inner loop")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("lex loop")
|
if PortDebug {
|
||||||
|
fmt.Println("lex loop")
|
||||||
|
}
|
||||||
if continueOuter {
|
if continueOuter {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
@ -293,7 +297,9 @@ func (l *Lexer) emitToken(token IToken) {
|
||||||
// custom Token objects or provide a Newfactory.
|
// custom Token objects or provide a Newfactory.
|
||||||
// /
|
// /
|
||||||
func (l *Lexer) emit() IToken {
|
func (l *Lexer) emit() IToken {
|
||||||
fmt.Println("emit")
|
if PortDebug {
|
||||||
|
fmt.Println("emit")
|
||||||
|
}
|
||||||
var t = l._factory.Create(l._tokenFactorySourcePair, l._type, l._text, l._channel, l._tokenStartCharIndex, l.getCharIndex()-1, l._tokenStartLine, l._tokenStartColumn)
|
var t = l._factory.Create(l._tokenFactorySourcePair, l._type, l._text, l._channel, l._tokenStartCharIndex, l.getCharIndex()-1, l._tokenStartLine, l._tokenStartColumn)
|
||||||
l.emitToken(t)
|
l.emitToken(t)
|
||||||
return t
|
return t
|
||||||
|
@ -302,7 +308,9 @@ func (l *Lexer) emit() IToken {
|
||||||
func (l *Lexer) emitEOF() IToken {
|
func (l *Lexer) emitEOF() IToken {
|
||||||
cpos := l.getCharPositionInLine()
|
cpos := l.getCharPositionInLine()
|
||||||
lpos := l.getLine()
|
lpos := l.getLine()
|
||||||
fmt.Println("emitEOF")
|
if PortDebug {
|
||||||
|
fmt.Println("emitEOF")
|
||||||
|
}
|
||||||
var eof = l._factory.Create(l._tokenFactorySourcePair, TokenEOF, "", TokenDefaultChannel, l._input.Index(), l._input.Index()-1, lpos, cpos)
|
var eof = l._factory.Create(l._tokenFactorySourcePair, TokenEOF, "", TokenDefaultChannel, l._input.Index(), l._input.Index()-1, lpos, cpos)
|
||||||
l.emitToken(eof)
|
l.emitToken(eof)
|
||||||
return eof
|
return eof
|
||||||
|
@ -351,12 +359,16 @@ func (this *Lexer) GetATN() *ATN {
|
||||||
// Forces load of all tokens. Does not include EOF token.
|
// Forces load of all tokens. Does not include EOF token.
|
||||||
// /
|
// /
|
||||||
func (l *Lexer) getAllTokens() []IToken {
|
func (l *Lexer) getAllTokens() []IToken {
|
||||||
fmt.Println("getAllTokens")
|
if PortDebug {
|
||||||
|
fmt.Println("getAllTokens")
|
||||||
|
}
|
||||||
var tokens = make([]IToken, 0)
|
var tokens = make([]IToken, 0)
|
||||||
var t = l.nextToken()
|
var t = l.nextToken()
|
||||||
for t.GetTokenType() != TokenEOF {
|
for t.GetTokenType() != TokenEOF {
|
||||||
tokens = append(tokens, t)
|
tokens = append(tokens, t)
|
||||||
fmt.Println("getAllTokens")
|
if PortDebug {
|
||||||
|
fmt.Println("getAllTokens")
|
||||||
|
}
|
||||||
t = l.nextToken()
|
t = l.nextToken()
|
||||||
}
|
}
|
||||||
return tokens
|
return tokens
|
||||||
|
|
|
@ -88,7 +88,7 @@ func NewLexerATNSimulator(recog ILexer, atn *ATN, decisionToDFA []*DFA, sharedCo
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
var LexerATNSimulatorDebug = true
|
var LexerATNSimulatorDebug = false
|
||||||
var LexerATNSimulatorDFADebug = false
|
var LexerATNSimulatorDFADebug = false
|
||||||
|
|
||||||
var LexerATNSimulatorMIN_DFA_EDGE = 0
|
var LexerATNSimulatorMIN_DFA_EDGE = 0
|
||||||
|
@ -105,14 +105,18 @@ func (this *LexerATNSimulator) copyState(simulator *LexerATNSimulator) {
|
||||||
|
|
||||||
func (this *LexerATNSimulator) Match(input CharStream, mode int) int {
|
func (this *LexerATNSimulator) Match(input CharStream, mode int) int {
|
||||||
|
|
||||||
fmt.Println("Match")
|
if PortDebug {
|
||||||
|
fmt.Println("Match")
|
||||||
|
}
|
||||||
|
|
||||||
this.Match_calls += 1
|
this.Match_calls += 1
|
||||||
this.mode = mode
|
this.mode = mode
|
||||||
var mark = input.Mark()
|
var mark = input.Mark()
|
||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
fmt.Println("FINALLY")
|
if PortDebug {
|
||||||
|
fmt.Println("FINALLY")
|
||||||
|
}
|
||||||
input.Release(mark)
|
input.Release(mark)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
@ -122,10 +126,14 @@ func (this *LexerATNSimulator) Match(input CharStream, mode int) int {
|
||||||
var dfa = this.decisionToDFA[mode]
|
var dfa = this.decisionToDFA[mode]
|
||||||
|
|
||||||
if dfa.s0 == nil {
|
if dfa.s0 == nil {
|
||||||
fmt.Println("MatchATN")
|
if PortDebug {
|
||||||
|
fmt.Println("MatchATN")
|
||||||
|
}
|
||||||
return this.MatchATN(input)
|
return this.MatchATN(input)
|
||||||
} else {
|
} else {
|
||||||
fmt.Println("execATN")
|
if PortDebug {
|
||||||
|
fmt.Println("execATN")
|
||||||
|
}
|
||||||
return this.execATN(input, dfa.s0)
|
return this.execATN(input, dfa.s0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -224,7 +232,9 @@ func (this *LexerATNSimulator) execATN(input CharStream, ds0 *DFAState) int {
|
||||||
s = target // flip current DFA target becomes Newsrc/from state
|
s = target // flip current DFA target becomes Newsrc/from state
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("DONE WITH execATN loop")
|
if PortDebug {
|
||||||
|
fmt.Println("DONE WITH execATN loop")
|
||||||
|
}
|
||||||
return this.failOrAccept(this.prevAccept, input, s.configs, t)
|
return this.failOrAccept(this.prevAccept, input, s.configs, t)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -286,7 +296,9 @@ func (this *LexerATNSimulator) failOrAccept(prevAccept *SimState, input CharStre
|
||||||
var lexerActionExecutor = prevAccept.dfaState.lexerActionExecutor
|
var lexerActionExecutor = prevAccept.dfaState.lexerActionExecutor
|
||||||
this.accept(input, lexerActionExecutor, this.startIndex, prevAccept.index, prevAccept.line, prevAccept.column)
|
this.accept(input, lexerActionExecutor, this.startIndex, prevAccept.index, prevAccept.line, prevAccept.column)
|
||||||
|
|
||||||
fmt.Println(prevAccept.dfaState.prediction)
|
if PortDebug {
|
||||||
|
fmt.Println(prevAccept.dfaState.prediction)
|
||||||
|
}
|
||||||
return prevAccept.dfaState.prediction
|
return prevAccept.dfaState.prediction
|
||||||
} else {
|
} else {
|
||||||
// if no accept and EOF is first char, return EOF
|
// if no accept and EOF is first char, return EOF
|
||||||
|
@ -357,7 +369,9 @@ func (this *LexerATNSimulator) getReachableTarget(trans ITransition, t int) IATN
|
||||||
|
|
||||||
func (this *LexerATNSimulator) computeStartState(input CharStream, p IATNState) *OrderedATNConfigSet {
|
func (this *LexerATNSimulator) computeStartState(input CharStream, p IATNState) *OrderedATNConfigSet {
|
||||||
|
|
||||||
fmt.Println("DEBUG" + strconv.Itoa(len(p.GetTransitions())))
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG" + strconv.Itoa(len(p.GetTransitions())))
|
||||||
|
}
|
||||||
|
|
||||||
var configs = NewOrderedATNConfigSet()
|
var configs = NewOrderedATNConfigSet()
|
||||||
for i := 0; i < len(p.GetTransitions()); i++ {
|
for i := 0; i < len(p.GetTransitions()); i++ {
|
||||||
|
@ -366,7 +380,9 @@ func (this *LexerATNSimulator) computeStartState(input CharStream, p IATNState)
|
||||||
this.closure(input, cfg, configs.ATNConfigSet, false, false, false)
|
this.closure(input, cfg, configs.ATNConfigSet, false, false, false)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("DEBUG" + configs.String())
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG" + configs.String())
|
||||||
|
}
|
||||||
|
|
||||||
return configs
|
return configs
|
||||||
}
|
}
|
||||||
|
@ -661,7 +677,9 @@ func (this *LexerATNSimulator) consume(input CharStream) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *LexerATNSimulator) GetTokenName(tt int) string {
|
func (this *LexerATNSimulator) GetTokenName(tt int) string {
|
||||||
fmt.Println(tt)
|
if PortDebug {
|
||||||
|
fmt.Println(tt)
|
||||||
|
}
|
||||||
if tt == -1 {
|
if tt == -1 {
|
||||||
return "EOF"
|
return "EOF"
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -126,10 +126,14 @@ func (p *Parser) GetParseListeners() []ParseTreeListener {
|
||||||
|
|
||||||
func (p *Parser) Match(ttype int) IToken {
|
func (p *Parser) Match(ttype int) IToken {
|
||||||
|
|
||||||
fmt.Println("get current token")
|
if PortDebug {
|
||||||
|
fmt.Println("get current token")
|
||||||
|
}
|
||||||
var t = p.getCurrentToken()
|
var t = p.getCurrentToken()
|
||||||
|
|
||||||
fmt.Println("TOKEN IS " + t.GetText())
|
if PortDebug {
|
||||||
|
fmt.Println("TOKEN IS " + t.GetText())
|
||||||
|
}
|
||||||
|
|
||||||
if t.GetTokenType() == ttype {
|
if t.GetTokenType() == ttype {
|
||||||
p._errHandler.ReportMatch(p)
|
p._errHandler.ReportMatch(p)
|
||||||
|
@ -144,7 +148,9 @@ func (p *Parser) Match(ttype int) IToken {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Println("match done")
|
if PortDebug {
|
||||||
|
fmt.Println("match done")
|
||||||
|
}
|
||||||
|
|
||||||
return t
|
return t
|
||||||
}
|
}
|
||||||
|
@ -411,9 +417,13 @@ func (p *Parser) NotifyErrorListeners(msg string, offendingToken IToken, err IRe
|
||||||
func (p *Parser) Consume() IToken {
|
func (p *Parser) Consume() IToken {
|
||||||
var o = p.getCurrentToken()
|
var o = p.getCurrentToken()
|
||||||
if o.GetTokenType() != TokenEOF {
|
if o.GetTokenType() != TokenEOF {
|
||||||
fmt.Println("Consuming")
|
if PortDebug {
|
||||||
|
fmt.Println("Consuming")
|
||||||
|
}
|
||||||
p.GetInputStream().Consume()
|
p.GetInputStream().Consume()
|
||||||
fmt.Println("Done consuming")
|
if PortDebug {
|
||||||
|
fmt.Println("Done consuming")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
var hasListener = p._parseListeners != nil && len(p._parseListeners) > 0
|
var hasListener = p._parseListeners != nil && len(p._parseListeners) > 0
|
||||||
if p.BuildParseTrees || hasListener {
|
if p.BuildParseTrees || hasListener {
|
||||||
|
|
|
@ -47,7 +47,7 @@ func NewParserATNSimulator(parser IParser, atn *ATN, decisionToDFA []*DFA, share
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
|
|
||||||
var ParserATNSimulatorDebug = true
|
var ParserATNSimulatorDebug = false
|
||||||
var ParserATNSimulatorListATNDecisions = false
|
var ParserATNSimulatorListATNDecisions = false
|
||||||
var ParserATNSimulatorDFADebug = false
|
var ParserATNSimulatorDFADebug = false
|
||||||
var ParserATNSimulatorRetryDebug = false
|
var ParserATNSimulatorRetryDebug = false
|
||||||
|
@ -57,7 +57,9 @@ func (this *ParserATNSimulator) reset() {
|
||||||
|
|
||||||
func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int, outerContext IParserRuleContext) int {
|
func (this *ParserATNSimulator) AdaptivePredict(input TokenStream, decision int, outerContext IParserRuleContext) int {
|
||||||
|
|
||||||
fmt.Println("Adaptive preduct")
|
if PortDebug {
|
||||||
|
fmt.Println("Adaptive predict")
|
||||||
|
}
|
||||||
|
|
||||||
if ParserATNSimulatorDebug || ParserATNSimulatorListATNDecisions {
|
if ParserATNSimulatorDebug || ParserATNSimulatorListATNDecisions {
|
||||||
|
|
||||||
|
@ -998,7 +1000,9 @@ func (this *ParserATNSimulator) closureCheckingStopState(config IATNConfig, conf
|
||||||
} else {
|
} else {
|
||||||
// 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 {
|
||||||
fmt.Println("DEBUG 1")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 1")
|
||||||
|
}
|
||||||
fmt.Println("FALLING off rule " + this.getRuleName(config.GetState().GetRuleIndex()))
|
fmt.Println("FALLING off rule " + this.getRuleName(config.GetState().GetRuleIndex()))
|
||||||
}
|
}
|
||||||
this.closure_(config, configs, closureBusy, collectPredicates, fullCtx, depth, treatEofAsEpsilon)
|
this.closure_(config, configs, closureBusy, collectPredicates, fullCtx, depth, treatEofAsEpsilon)
|
||||||
|
@ -1023,7 +1027,9 @@ func (this *ParserATNSimulator) closureCheckingStopState(config IATNConfig, conf
|
||||||
} else {
|
} else {
|
||||||
// else if we have no context info, just chase follow links (if greedy)
|
// else if we have no context info, just chase follow links (if greedy)
|
||||||
if ParserATNSimulatorDebug {
|
if ParserATNSimulatorDebug {
|
||||||
fmt.Println("DEBUG 2")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 2")
|
||||||
|
}
|
||||||
fmt.Println("FALLING off rule " + this.getRuleName(config.GetState().GetRuleIndex()))
|
fmt.Println("FALLING off rule " + this.getRuleName(config.GetState().GetRuleIndex()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1033,7 +1039,9 @@ func (this *ParserATNSimulator) closureCheckingStopState(config IATNConfig, conf
|
||||||
|
|
||||||
// Do the actual work of walking epsilon edges//
|
// Do the actual work of walking epsilon edges//
|
||||||
func (this *ParserATNSimulator) closure_(config IATNConfig, configs *ATNConfigSet, closureBusy *Set, collectPredicates, fullCtx bool, depth int, treatEofAsEpsilon bool) {
|
func (this *ParserATNSimulator) closure_(config IATNConfig, configs *ATNConfigSet, closureBusy *Set, collectPredicates, fullCtx bool, depth int, treatEofAsEpsilon bool) {
|
||||||
fmt.Println("closure_")
|
if PortDebug {
|
||||||
|
fmt.Println("closure_")
|
||||||
|
}
|
||||||
var p = config.GetState()
|
var p = config.GetState()
|
||||||
// optimization
|
// optimization
|
||||||
if !p.GetEpsilonOnlyTransitions() {
|
if !p.GetEpsilonOnlyTransitions() {
|
||||||
|
@ -1047,7 +1055,9 @@ func (this *ParserATNSimulator) closure_(config IATNConfig, configs *ATNConfigSe
|
||||||
var continueCollecting = collectPredicates && !ok
|
var continueCollecting = collectPredicates && !ok
|
||||||
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 {
|
||||||
fmt.Println("DEBUG 1")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 1")
|
||||||
|
}
|
||||||
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+
|
||||||
continue
|
continue
|
||||||
|
@ -1056,7 +1066,9 @@ func (this *ParserATNSimulator) closure_(config IATNConfig, configs *ATNConfigSe
|
||||||
|
|
||||||
if _, ok := config.GetState().(*RuleStopState); ok {
|
if _, ok := config.GetState().(*RuleStopState); ok {
|
||||||
|
|
||||||
fmt.Println("DEBUG 2")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 2")
|
||||||
|
}
|
||||||
// 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
|
||||||
// track how far we dip into outer context. Might
|
// track how far we dip into outer context. Might
|
||||||
|
@ -1064,16 +1076,22 @@ func (this *ParserATNSimulator) closure_(config IATNConfig, configs *ATNConfigSe
|
||||||
// preds if this is > 0.
|
// preds if this is > 0.
|
||||||
|
|
||||||
if closureBusy.add(c) != c {
|
if closureBusy.add(c) != c {
|
||||||
fmt.Println("DEBUG 3")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 3")
|
||||||
|
}
|
||||||
// avoid infinite recursion for right-recursive rules
|
// avoid infinite recursion for right-recursive rules
|
||||||
continue
|
continue
|
||||||
} else {
|
} else {
|
||||||
fmt.Println(c)
|
if PortDebug {
|
||||||
fmt.Println(closureBusy)
|
fmt.Println(c)
|
||||||
|
fmt.Println(closureBusy)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if this._dfa != nil && this._dfa.precedenceDfa {
|
if this._dfa != nil && this._dfa.precedenceDfa {
|
||||||
fmt.Println("DEBUG 4")
|
if PortDebug {
|
||||||
|
fmt.Println("DEBUG 4")
|
||||||
|
}
|
||||||
if t.(*EpsilonTransition).outermostPrecedenceReturn == this._dfa.atnStartState.GetRuleIndex() {
|
if t.(*EpsilonTransition).outermostPrecedenceReturn == this._dfa.atnStartState.GetRuleIndex() {
|
||||||
c.precedenceFilterSuppressed = true
|
c.precedenceFilterSuppressed = true
|
||||||
}
|
}
|
||||||
|
@ -1292,7 +1310,9 @@ func (this *ParserATNSimulator) getConflictingAltsOrUniqueAlt(configs *ATNConfig
|
||||||
|
|
||||||
func (this *ParserATNSimulator) GetTokenName(t int) string {
|
func (this *ParserATNSimulator) GetTokenName(t int) string {
|
||||||
|
|
||||||
fmt.Println("Get token name")
|
if PortDebug {
|
||||||
|
fmt.Println("Get token name")
|
||||||
|
}
|
||||||
|
|
||||||
if t == TokenEOF {
|
if t == TokenEOF {
|
||||||
return "EOF"
|
return "EOF"
|
||||||
|
|
|
@ -83,7 +83,9 @@ func (this *Recognizer) GetState() int {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *Recognizer) SetState(v int) {
|
func (this *Recognizer) SetState(v int) {
|
||||||
fmt.Println("SETTING STATE " + strconv.Itoa(v) + " from " + strconv.Itoa(this.state))
|
if PortDebug {
|
||||||
|
fmt.Println("SETTING STATE " + strconv.Itoa(v) + " from " + strconv.Itoa(this.state))
|
||||||
|
}
|
||||||
|
|
||||||
this.state = v
|
this.state = v
|
||||||
}
|
}
|
||||||
|
|
|
@ -1462,7 +1462,6 @@ public class ParserATNSimulator extends ATNSimulator {
|
||||||
boolean fullCtx,
|
boolean fullCtx,
|
||||||
boolean treatEofAsEpsilon)
|
boolean treatEofAsEpsilon)
|
||||||
{
|
{
|
||||||
console.log("closure");
|
|
||||||
final int initialDepth = 0;
|
final int initialDepth = 0;
|
||||||
closureCheckingStopState(config, configs, closureBusy, collectPredicates,
|
closureCheckingStopState(config, configs, closureBusy, collectPredicates,
|
||||||
fullCtx,
|
fullCtx,
|
||||||
|
|
|
@ -726,11 +726,9 @@ ArithmeticParser.prototype.relop = function() {
|
||||||
this.state = 56;
|
this.state = 56;
|
||||||
_la = this._input.LA(1);
|
_la = this._input.LA(1);
|
||||||
if(!((((_la) & ~0x1f) == 0 && ((1 << _la) & ((1 << ArithmeticParser.GT) | (1 << ArithmeticParser.LT) | (1 << ArithmeticParser.EQ))) !== 0))) {
|
if(!((((_la) & ~0x1f) == 0 && ((1 << _la) & ((1 << ArithmeticParser.GT) | (1 << ArithmeticParser.LT) | (1 << ArithmeticParser.EQ))) !== 0))) {
|
||||||
console.log("DEBUG1")
|
|
||||||
this._errHandler.recoverInline(this);
|
this._errHandler.recoverInline(this);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
console.log("DEBUG2")
|
|
||||||
this.consume();
|
this.consume();
|
||||||
}
|
}
|
||||||
} catch (re) {
|
} catch (re) {
|
||||||
|
@ -820,7 +818,6 @@ ArithmeticParser.prototype.number = function() {
|
||||||
do {
|
do {
|
||||||
this.state = 61;
|
this.state = 61;
|
||||||
this.match(ArithmeticParser.DIGIT);
|
this.match(ArithmeticParser.DIGIT);
|
||||||
console.log("Done with match")
|
|
||||||
this.state = 64;
|
this.state = 64;
|
||||||
this._errHandler.sync(this);
|
this._errHandler.sync(this);
|
||||||
_la = this._input.LA(1);
|
_la = this._input.LA(1);
|
||||||
|
|
|
@ -129,12 +129,16 @@ BufferedTokenStream.prototype.consume = function() {
|
||||||
// not yet initialized
|
// not yet initialized
|
||||||
skipEofCheck = false;
|
skipEofCheck = false;
|
||||||
}
|
}
|
||||||
console.log("consume 1")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("consume 1")
|
||||||
|
}
|
||||||
if (!skipEofCheck && this.LA(1) === Token.EOF) {
|
if (!skipEofCheck && this.LA(1) === Token.EOF) {
|
||||||
throw "cannot consume EOF";
|
throw "cannot consume EOF";
|
||||||
}
|
}
|
||||||
if (this.sync(this.index + 1)) {
|
if (this.sync(this.index + 1)) {
|
||||||
console.log("consume 2")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("consume 2")
|
||||||
|
}
|
||||||
this.index = this.adjustSeekIndex(this.index + 1);
|
this.index = this.adjustSeekIndex(this.index + 1);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -149,7 +153,9 @@ BufferedTokenStream.prototype.sync = function(i) {
|
||||||
var n = i - this.tokens.length + 1; // how many more elements we need?
|
var n = i - this.tokens.length + 1; // how many more elements we need?
|
||||||
if (n > 0) {
|
if (n > 0) {
|
||||||
var fetched = this.fetch(n);
|
var fetched = this.fetch(n);
|
||||||
console.log("sync done")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("sync done")
|
||||||
|
}
|
||||||
|
|
||||||
return fetched >= n;
|
return fetched >= n;
|
||||||
}
|
}
|
||||||
|
@ -166,7 +172,9 @@ BufferedTokenStream.prototype.fetch = function(n) {
|
||||||
}
|
}
|
||||||
for (var i = 0; i < n; i++) {
|
for (var i = 0; i < n; i++) {
|
||||||
var t = this.tokenSource.nextToken();
|
var t = this.tokenSource.nextToken();
|
||||||
console.log("fetch loop")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("fetch loop")
|
||||||
|
}
|
||||||
t.tokenIndex = this.tokens.length;
|
t.tokenIndex = this.tokens.length;
|
||||||
this.tokens.push(t);
|
this.tokens.push(t);
|
||||||
if (t.type === Token.EOF) {
|
if (t.type === Token.EOF) {
|
||||||
|
@ -175,7 +183,9 @@ BufferedTokenStream.prototype.fetch = function(n) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("fetch done")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("fetch done")
|
||||||
|
}
|
||||||
return n;
|
return n;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -74,7 +74,9 @@ CommonTokenFactory.DEFAULT = new CommonTokenFactory();
|
||||||
|
|
||||||
CommonTokenFactory.prototype.create = function(source, type, text, channel, start, stop, line, column) {
|
CommonTokenFactory.prototype.create = function(source, type, text, channel, start, stop, line, column) {
|
||||||
|
|
||||||
console.log("Token factory creating: " + text)
|
if (PORT_DEBUG) {
|
||||||
|
console.log("Token factory creating: " + text)
|
||||||
|
}
|
||||||
|
|
||||||
var t = new CommonToken(source, type, channel, start, stop);
|
var t = new CommonToken(source, type, channel, start, stop);
|
||||||
t.line = line;
|
t.line = line;
|
||||||
|
@ -89,7 +91,9 @@ CommonTokenFactory.prototype.create = function(source, type, text, channel, star
|
||||||
|
|
||||||
CommonTokenFactory.prototype.createThin = function(type, text) {
|
CommonTokenFactory.prototype.createThin = function(type, text) {
|
||||||
|
|
||||||
console.log("Token factory creating: " + text)
|
if (PORT_DEBUG) {
|
||||||
|
console.log("Token factory creating: " + text)
|
||||||
|
}
|
||||||
|
|
||||||
var t = new CommonToken(null, type);
|
var t = new CommonToken(null, type);
|
||||||
t.text = text;
|
t.text = text;
|
||||||
|
|
|
@ -42,7 +42,9 @@ function FileStream(fileName) {
|
||||||
InputStream.call(this, data);
|
InputStream.call(this, data);
|
||||||
this.fileName = fileName;
|
this.fileName = fileName;
|
||||||
|
|
||||||
console.log(data);
|
if (PORT_DEBUG) {
|
||||||
|
console.log(data);
|
||||||
|
}
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -101,7 +101,9 @@ InputStream.prototype.mark = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
InputStream.prototype.release = function(marker) {
|
InputStream.prototype.release = function(marker) {
|
||||||
console.log("RELEASING")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("RELEASING")
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// consume() ahead until p==_index; can't just set p=_index as we must
|
// consume() ahead until p==_index; can't just set p=_index as we must
|
||||||
|
|
|
@ -50,7 +50,9 @@ IntervalSet.prototype.addRange = function(l, h) {
|
||||||
};
|
};
|
||||||
|
|
||||||
IntervalSet.prototype.addInterval = function(v) {
|
IntervalSet.prototype.addInterval = function(v) {
|
||||||
console.log("addInterval" + v.toString())
|
if (PORT_DEBUG) {
|
||||||
|
console.log("addInterval" + v.toString())
|
||||||
|
}
|
||||||
if (this.intervals === null) {
|
if (this.intervals === null) {
|
||||||
this.intervals = [];
|
this.intervals = [];
|
||||||
this.intervals.push(v);
|
this.intervals.push(v);
|
||||||
|
@ -81,9 +83,13 @@ IntervalSet.prototype.addInterval = function(v) {
|
||||||
};
|
};
|
||||||
|
|
||||||
IntervalSet.prototype.addSet = function(other) {
|
IntervalSet.prototype.addSet = function(other) {
|
||||||
console.log("addSet")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("addSet")
|
||||||
|
}
|
||||||
if (other.intervals !== null) {
|
if (other.intervals !== null) {
|
||||||
console.log(other.intervals.length)
|
if (PORT_DEBUG) {
|
||||||
|
console.log(other.intervals.length)
|
||||||
|
}
|
||||||
for (var k = 0; k < other.intervals.length; k++) {
|
for (var k = 0; k < other.intervals.length; k++) {
|
||||||
var i = other.intervals[k];
|
var i = other.intervals[k];
|
||||||
this.addInterval(new Interval(i.start, i.stop));
|
this.addInterval(new Interval(i.start, i.stop));
|
||||||
|
|
|
@ -110,15 +110,19 @@ LL1Analyzer.prototype.LOOK = function(s, stopState, ctx) {
|
||||||
var seeThruPreds = true; // ignore preds; get all lookahead
|
var seeThruPreds = true; // ignore preds; get all lookahead
|
||||||
ctx = ctx || null;
|
ctx = ctx || null;
|
||||||
var lookContext = ctx!==null ? predictionContextFromRuleContext(s.atn, ctx) : null;
|
var lookContext = ctx!==null ? predictionContextFromRuleContext(s.atn, ctx) : null;
|
||||||
console.log("DEBUG 5")
|
if (PORT_DEBUG) {
|
||||||
console.log(s.toString())
|
console.log("DEBUG 5")
|
||||||
console.log(stopState)
|
console.log(s.toString())
|
||||||
console.log(lookContext)
|
console.log(stopState)
|
||||||
console.log(r.toString())
|
console.log(lookContext)
|
||||||
console.log(seeThruPreds)
|
console.log(r.toString())
|
||||||
console.log("=====")
|
console.log(seeThruPreds)
|
||||||
|
console.log("=====")
|
||||||
|
}
|
||||||
this._LOOK(s, stopState, lookContext, r, new Set(), new BitSet(), seeThruPreds, true);
|
this._LOOK(s, stopState, lookContext, r, new Set(), new BitSet(), seeThruPreds, true);
|
||||||
console.log(r.toString())
|
if (PORT_DEBUG) {
|
||||||
|
console.log(r.toString())
|
||||||
|
}
|
||||||
return r;
|
return r;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -159,7 +163,9 @@ LL1Analyzer.prototype._LOOK = function(s, stopState , ctx, look, lookBusy, calle
|
||||||
}
|
}
|
||||||
lookBusy.add(c);
|
lookBusy.add(c);
|
||||||
if (s === stopState) {
|
if (s === stopState) {
|
||||||
console.log("DEBUG 6")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 6")
|
||||||
|
}
|
||||||
if (ctx ===null) {
|
if (ctx ===null) {
|
||||||
look.addOne(Token.EPSILON);
|
look.addOne(Token.EPSILON);
|
||||||
return;
|
return;
|
||||||
|
@ -177,7 +183,9 @@ LL1Analyzer.prototype._LOOK = function(s, stopState , ctx, look, lookBusy, calle
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (ctx !== PredictionContext.EMPTY) {
|
if (ctx !== PredictionContext.EMPTY) {
|
||||||
console.log("DEBUG 7")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 7")
|
||||||
|
}
|
||||||
// run thru all possible stack tops in ctx
|
// run thru all possible stack tops in ctx
|
||||||
for(var i=0; i<ctx.length; i++) {
|
for(var i=0; i<ctx.length; i++) {
|
||||||
var returnState = this.atn.states[ctx.getReturnState(i)];
|
var returnState = this.atn.states[ctx.getReturnState(i)];
|
||||||
|
@ -198,7 +206,9 @@ LL1Analyzer.prototype._LOOK = function(s, stopState , ctx, look, lookBusy, calle
|
||||||
var t = s.transitions[j];
|
var t = s.transitions[j];
|
||||||
if (t.constructor === RuleTransition) {
|
if (t.constructor === RuleTransition) {
|
||||||
|
|
||||||
console.log("DEBUG 8")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 8")
|
||||||
|
}
|
||||||
|
|
||||||
if (calledRuleStack.contains(t.target.ruleIndex)) {
|
if (calledRuleStack.contains(t.target.ruleIndex)) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -211,25 +221,37 @@ LL1Analyzer.prototype._LOOK = function(s, stopState , ctx, look, lookBusy, calle
|
||||||
calledRuleStack.remove(t.target.ruleIndex);
|
calledRuleStack.remove(t.target.ruleIndex);
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log(look.toString())
|
if (PORT_DEBUG) {
|
||||||
|
console.log(look.toString())
|
||||||
|
}
|
||||||
|
|
||||||
} else if (t instanceof AbstractPredicateTransition ) {
|
} else if (t instanceof AbstractPredicateTransition ) {
|
||||||
console.log("DEBUG 9")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 9")
|
||||||
|
}
|
||||||
if (seeThruPreds) {
|
if (seeThruPreds) {
|
||||||
this._LOOK(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
this._LOOK(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||||
} else {
|
} else {
|
||||||
look.addOne(LL1Analyzer.HIT_PRED);
|
look.addOne(LL1Analyzer.HIT_PRED);
|
||||||
}
|
}
|
||||||
} else if( t.isEpsilon) {
|
} else if( t.isEpsilon) {
|
||||||
console.log("DEBUG 10")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 10")
|
||||||
|
}
|
||||||
this._LOOK(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
this._LOOK(t.target, stopState, ctx, look, lookBusy, calledRuleStack, seeThruPreds, addEOF);
|
||||||
} else if (t.constructor === WildcardTransition) {
|
} else if (t.constructor === WildcardTransition) {
|
||||||
console.log("DEBUG 11")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 11")
|
||||||
|
}
|
||||||
look.addRange( Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType );
|
look.addRange( Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType );
|
||||||
} else {
|
} else {
|
||||||
console.log("DEBUG 12")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 12")
|
||||||
|
}
|
||||||
var set = t.label;
|
var set = t.label;
|
||||||
console.log(set.toString())
|
if (PORT_DEBUG) {
|
||||||
|
console.log(set.toString())
|
||||||
|
}
|
||||||
if (set !== null) {
|
if (set !== null) {
|
||||||
if (t instanceof NotSetTransition) {
|
if (t instanceof NotSetTransition) {
|
||||||
set = set.complement(Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType);
|
set = set.complement(Token.MIN_USER_TOKEN_TYPE, this.atn.maxTokenType);
|
||||||
|
|
|
@ -169,10 +169,14 @@ Lexer.prototype.nextToken = function() {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("lex inner loop")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("lex inner loop")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("lex loop")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("lex loop")
|
||||||
|
}
|
||||||
|
|
||||||
if (continueOuter) {
|
if (continueOuter) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -262,7 +266,9 @@ Lexer.prototype.emitToken = function(token) {
|
||||||
// custom Token objects or provide a new factory.
|
// custom Token objects or provide a new factory.
|
||||||
// /
|
// /
|
||||||
Lexer.prototype.emit = function() {
|
Lexer.prototype.emit = function() {
|
||||||
console.log("emit")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("emit")
|
||||||
|
}
|
||||||
var t = this._factory.create(this._tokenFactorySourcePair, this._type,
|
var t = this._factory.create(this._tokenFactorySourcePair, this._type,
|
||||||
this._text, this._channel, this._tokenStartCharIndex, this
|
this._text, this._channel, this._tokenStartCharIndex, this
|
||||||
.getCharIndex() - 1, this._tokenStartLine,
|
.getCharIndex() - 1, this._tokenStartLine,
|
||||||
|
@ -272,7 +278,9 @@ Lexer.prototype.emit = function() {
|
||||||
};
|
};
|
||||||
|
|
||||||
Lexer.prototype.emitEOF = function() {
|
Lexer.prototype.emitEOF = function() {
|
||||||
console.log("emitEOF")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("emitEOF")
|
||||||
|
}
|
||||||
var cpos = this.column;
|
var cpos = this.column;
|
||||||
var lpos = this.line;
|
var lpos = this.line;
|
||||||
var eof = this._factory.create(this._tokenFactorySourcePair, Token.EOF,
|
var eof = this._factory.create(this._tokenFactorySourcePair, Token.EOF,
|
||||||
|
|
|
@ -134,10 +134,14 @@ Parser.prototype.reset = function() {
|
||||||
|
|
||||||
Parser.prototype.match = function(ttype) {
|
Parser.prototype.match = function(ttype) {
|
||||||
|
|
||||||
console.log("get current token")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("get current token")
|
||||||
|
}
|
||||||
var t = this.getCurrentToken();
|
var t = this.getCurrentToken();
|
||||||
|
|
||||||
console.log("TOKEN IS " + t.text)
|
if (PORT_DEBUG) {
|
||||||
|
console.log("TOKEN IS " + t.text)
|
||||||
|
}
|
||||||
if (t.type === ttype) {
|
if (t.type === ttype) {
|
||||||
this._errHandler.reportMatch(this);
|
this._errHandler.reportMatch(this);
|
||||||
this.consume();
|
this.consume();
|
||||||
|
@ -151,7 +155,9 @@ Parser.prototype.match = function(ttype) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Match done")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("Match done")
|
||||||
|
}
|
||||||
|
|
||||||
return t;
|
return t;
|
||||||
};
|
};
|
||||||
|
@ -405,9 +411,13 @@ Parser.prototype.notifyErrorListeners = function(msg, offendingToken, err) {
|
||||||
Parser.prototype.consume = function() {
|
Parser.prototype.consume = function() {
|
||||||
var o = this.getCurrentToken();
|
var o = this.getCurrentToken();
|
||||||
if (o.type !== Token.EOF) {
|
if (o.type !== Token.EOF) {
|
||||||
console.log("Consuming")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("Consuming")
|
||||||
|
}
|
||||||
this.getInputStream().consume();
|
this.getInputStream().consume();
|
||||||
console.log("done consuming")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("done consuming")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var hasListener = this._parseListeners !== null && this._parseListeners.length > 0;
|
var hasListener = this._parseListeners !== null && this._parseListeners.length > 0;
|
||||||
|
|
|
@ -164,7 +164,9 @@ Object.defineProperty(Recognizer.prototype, "state", {
|
||||||
return this._stateNumber;
|
return this._stateNumber;
|
||||||
},
|
},
|
||||||
set : function(state) {
|
set : function(state) {
|
||||||
console.log("SETTING STATE" + state + " from " + this._stateNumber )
|
if (PORT_DEBUG) {
|
||||||
|
console.log("SETTING STATE" + state + " from " + this._stateNumber )
|
||||||
|
}
|
||||||
this._stateNumber = state;
|
this._stateNumber = state;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -75,11 +75,15 @@ ATN.prototype.nextTokensInContext = function(s, ctx) {
|
||||||
// rule.
|
// rule.
|
||||||
ATN.prototype.nextTokensNoContext = function(s) {
|
ATN.prototype.nextTokensNoContext = function(s) {
|
||||||
if (s.nextTokenWithinRule !== null ) {
|
if (s.nextTokenWithinRule !== null ) {
|
||||||
console.log("DEBUG 1")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 1")
|
||||||
|
}
|
||||||
return s.nextTokenWithinRule;
|
return s.nextTokenWithinRule;
|
||||||
}
|
}
|
||||||
console.log("DEBUG 2")
|
if (PORT_DEBUG) {
|
||||||
console.log(this.nextTokensInContext(s, null).toString())
|
console.log("DEBUG 2")
|
||||||
|
console.log(this.nextTokensInContext(s, null).toString())
|
||||||
|
}
|
||||||
s.nextTokenWithinRule = this.nextTokensInContext(s, null);
|
s.nextTokenWithinRule = this.nextTokensInContext(s, null);
|
||||||
s.nextTokenWithinRule.readOnly = true;
|
s.nextTokenWithinRule.readOnly = true;
|
||||||
return s.nextTokenWithinRule;
|
return s.nextTokenWithinRule;
|
||||||
|
|
|
@ -101,7 +101,7 @@ function LexerATNSimulator(recog, atn, decisionToDFA, sharedContextCache) {
|
||||||
LexerATNSimulator.prototype = Object.create(ATNSimulator.prototype);
|
LexerATNSimulator.prototype = Object.create(ATNSimulator.prototype);
|
||||||
LexerATNSimulator.prototype.constructor = LexerATNSimulator;
|
LexerATNSimulator.prototype.constructor = LexerATNSimulator;
|
||||||
|
|
||||||
LexerATNSimulator.prototype.debug = true;
|
LexerATNSimulator.prototype.debug = false;
|
||||||
LexerATNSimulator.prototype.dfa_debug = false;
|
LexerATNSimulator.prototype.dfa_debug = false;
|
||||||
|
|
||||||
LexerATNSimulator.MIN_DFA_EDGE = 0;
|
LexerATNSimulator.MIN_DFA_EDGE = 0;
|
||||||
|
@ -118,7 +118,9 @@ LexerATNSimulator.prototype.copyState = function(simulator) {
|
||||||
|
|
||||||
LexerATNSimulator.prototype.match = function(input, mode) {
|
LexerATNSimulator.prototype.match = function(input, mode) {
|
||||||
|
|
||||||
console.log("MATCH")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("MATCH")
|
||||||
|
}
|
||||||
|
|
||||||
this.match_calls += 1;
|
this.match_calls += 1;
|
||||||
this.mode = mode;
|
this.mode = mode;
|
||||||
|
@ -128,15 +130,21 @@ LexerATNSimulator.prototype.match = function(input, mode) {
|
||||||
this.prevAccept.reset();
|
this.prevAccept.reset();
|
||||||
var dfa = this.decisionToDFA[mode];
|
var dfa = this.decisionToDFA[mode];
|
||||||
if (dfa.s0 === null) {
|
if (dfa.s0 === null) {
|
||||||
console.log("matchATN")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("matchATN")
|
||||||
|
}
|
||||||
return this.matchATN(input);
|
return this.matchATN(input);
|
||||||
} else {
|
} else {
|
||||||
console.log("execATN")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("execATN")
|
||||||
|
}
|
||||||
var res = this.execATN(input, dfa.s0);
|
var res = this.execATN(input, dfa.s0);
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
console.log("FINALLY")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("FINALLY")
|
||||||
|
}
|
||||||
input.release(mark);
|
input.release(mark);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -233,7 +241,9 @@ LexerATNSimulator.prototype.execATN = function(input, ds0) {
|
||||||
s = target; // flip; current DFA target becomes new src/from state
|
s = target; // flip; current DFA target becomes new src/from state
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("Done with execATN loop")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("Done with execATN loop")
|
||||||
|
}
|
||||||
return this.failOrAccept(this.prevAccept, input, s.configs, t);
|
return this.failOrAccept(this.prevAccept, input, s.configs, t);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -298,7 +308,9 @@ LexerATNSimulator.prototype.failOrAccept = function(prevAccept, input, reach, t)
|
||||||
this.accept(input, lexerActionExecutor, this.startIndex,
|
this.accept(input, lexerActionExecutor, this.startIndex,
|
||||||
prevAccept.index, prevAccept.line, prevAccept.column);
|
prevAccept.index, prevAccept.line, prevAccept.column);
|
||||||
|
|
||||||
console.log("Prevaccept", prevAccept.dfaState.prediction)
|
if (PORT_DEBUG) {
|
||||||
|
console.log("Prevaccept", prevAccept.dfaState.prediction)
|
||||||
|
}
|
||||||
|
|
||||||
return prevAccept.dfaState.prediction;
|
return prevAccept.dfaState.prediction;
|
||||||
} else {
|
} else {
|
||||||
|
@ -669,7 +681,9 @@ LexerATNSimulator.prototype.consume = function(input) {
|
||||||
};
|
};
|
||||||
|
|
||||||
LexerATNSimulator.prototype.getTokenName = function(tt) {
|
LexerATNSimulator.prototype.getTokenName = function(tt) {
|
||||||
console.log(tt);
|
if (PORT_DEBUG) {
|
||||||
|
console.log(tt);
|
||||||
|
}
|
||||||
if (tt === -1) {
|
if (tt === -1) {
|
||||||
return "EOF";
|
return "EOF";
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -313,7 +313,7 @@ function ParserATNSimulator(parser, atn, decisionToDFA, sharedContextCache) {
|
||||||
ParserATNSimulator.prototype = Object.create(ATNSimulator.prototype);
|
ParserATNSimulator.prototype = Object.create(ATNSimulator.prototype);
|
||||||
ParserATNSimulator.prototype.constructor = ParserATNSimulator;
|
ParserATNSimulator.prototype.constructor = ParserATNSimulator;
|
||||||
|
|
||||||
ParserATNSimulator.prototype.debug = true;
|
ParserATNSimulator.prototype.debug = false;
|
||||||
ParserATNSimulator.prototype.debug_list_atn_decisions = false;
|
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;
|
||||||
|
@ -324,7 +324,9 @@ ParserATNSimulator.prototype.reset = function() {
|
||||||
|
|
||||||
ParserATNSimulator.prototype.adaptivePredict = function(input, decision, outerContext) {
|
ParserATNSimulator.prototype.adaptivePredict = function(input, decision, outerContext) {
|
||||||
|
|
||||||
console.log("adaptive predict")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("adaptive predict")
|
||||||
|
}
|
||||||
|
|
||||||
if (this.debug || this.debug_list_atn_decisions) {
|
if (this.debug || this.debug_list_atn_decisions) {
|
||||||
console.log("adaptivePredict decision " + decision +
|
console.log("adaptivePredict decision " + decision +
|
||||||
|
@ -1254,7 +1256,9 @@ ParserATNSimulator.prototype.closureCheckingStopState = function(config, configs
|
||||||
} else {
|
} else {
|
||||||
// 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) {
|
||||||
console.log("DEBUG 1")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 1")
|
||||||
|
}
|
||||||
console.log("FALLING off rule " + this.getRuleName(config.state.ruleIndex));
|
console.log("FALLING off rule " + this.getRuleName(config.state.ruleIndex));
|
||||||
}
|
}
|
||||||
this.closure_(config, configs, closureBusy, collectPredicates,
|
this.closure_(config, configs, closureBusy, collectPredicates,
|
||||||
|
@ -1280,7 +1284,9 @@ ParserATNSimulator.prototype.closureCheckingStopState = function(config, configs
|
||||||
} else {
|
} else {
|
||||||
// else if we have no context info, just chase follow links (if greedy)
|
// else if we have no context info, just chase follow links (if greedy)
|
||||||
if (this.debug) {
|
if (this.debug) {
|
||||||
console.log("DEBUG 2")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 2")
|
||||||
|
}
|
||||||
console.log("FALLING off rule " + this.getRuleName(config.state.ruleIndex));
|
console.log("FALLING off rule " + this.getRuleName(config.state.ruleIndex));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1290,7 +1296,9 @@ ParserATNSimulator.prototype.closureCheckingStopState = function(config, configs
|
||||||
|
|
||||||
// Do the actual work of walking epsilon edges//
|
// Do the actual work of walking epsilon edges//
|
||||||
ParserATNSimulator.prototype.closure_ = function(config, configs, closureBusy, collectPredicates, fullCtx, depth, treatEofAsEpsilon) {
|
ParserATNSimulator.prototype.closure_ = function(config, configs, closureBusy, collectPredicates, fullCtx, depth, treatEofAsEpsilon) {
|
||||||
console.log("closure_")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("closure_")
|
||||||
|
}
|
||||||
var p = config.state;
|
var p = config.state;
|
||||||
// optimization
|
// optimization
|
||||||
if (! p.epsilonOnlyTransitions) {
|
if (! p.epsilonOnlyTransitions) {
|
||||||
|
@ -1303,7 +1311,9 @@ ParserATNSimulator.prototype.closure_ = function(config, configs, closureBusy, c
|
||||||
var continueCollecting = collectPredicates && !(t instanceof ActionTransition);
|
var continueCollecting = collectPredicates && !(t instanceof ActionTransition);
|
||||||
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) {
|
||||||
console.log("DEBUG 1")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 1")
|
||||||
|
}
|
||||||
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+
|
||||||
continue;
|
continue;
|
||||||
|
@ -1311,7 +1321,9 @@ ParserATNSimulator.prototype.closure_ = function(config, configs, closureBusy, c
|
||||||
var newDepth = depth;
|
var newDepth = depth;
|
||||||
if ( config.state instanceof RuleStopState) {
|
if ( config.state instanceof RuleStopState) {
|
||||||
|
|
||||||
console.log("DEBUG 2")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 2")
|
||||||
|
}
|
||||||
// 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
|
||||||
// track how far we dip into outer context. Might
|
// track how far we dip into outer context. Might
|
||||||
|
@ -1319,16 +1331,22 @@ ParserATNSimulator.prototype.closure_ = function(config, configs, closureBusy, c
|
||||||
// preds if this is > 0.
|
// preds if this is > 0.
|
||||||
|
|
||||||
if (closureBusy.add(c)!==c) {
|
if (closureBusy.add(c)!==c) {
|
||||||
console.log("DEBUG 3")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 3")
|
||||||
|
}
|
||||||
// avoid infinite recursion for right-recursive rules
|
// avoid infinite recursion for right-recursive rules
|
||||||
continue;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
console.log(c.toString())
|
if (PORT_DEBUG) {
|
||||||
console.log(closureBusy.toString())
|
console.log(c.toString())
|
||||||
|
console.log(closureBusy.toString())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this._dfa !== null && this._dfa.precedenceDfa) {
|
if (this._dfa !== null && this._dfa.precedenceDfa) {
|
||||||
console.log("DEBUG 4")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("DEBUG 4")
|
||||||
|
}
|
||||||
if (t.outermostPrecedenceReturn === this._dfa.atnStartState.ruleIndex) {
|
if (t.outermostPrecedenceReturn === this._dfa.atnStartState.ruleIndex) {
|
||||||
c.precedenceFilterSuppressed = true;
|
c.precedenceFilterSuppressed = true;
|
||||||
}
|
}
|
||||||
|
@ -1528,7 +1546,9 @@ ParserATNSimulator.prototype.getConflictingAltsOrUniqueAlt = function(configs) {
|
||||||
|
|
||||||
ParserATNSimulator.prototype.getTokenName = function( t) {
|
ParserATNSimulator.prototype.getTokenName = function( t) {
|
||||||
|
|
||||||
console.log("Get token name")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("Get token name")
|
||||||
|
}
|
||||||
|
|
||||||
if (t===Token.EOF) {
|
if (t===Token.EOF) {
|
||||||
return "EOF";
|
return "EOF";
|
||||||
|
|
|
@ -245,26 +245,35 @@ DefaultErrorStrategy.prototype.sync = function(recognizer) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("STATE" + recognizer.state)
|
if (PORT_DEBUG) {
|
||||||
|
console.log("STATE" + recognizer.state)
|
||||||
|
}
|
||||||
|
|
||||||
var s = recognizer._interp.atn.states[recognizer.state];
|
var s = recognizer._interp.atn.states[recognizer.state];
|
||||||
var la = recognizer.getTokenStream().LA(1);
|
var la = recognizer.getTokenStream().LA(1);
|
||||||
|
|
||||||
console.log("LA" + la);
|
if (PORT_DEBUG) {
|
||||||
|
console.log("LA" + la);
|
||||||
|
}
|
||||||
|
|
||||||
// try cheaper subset first; might get lucky. seems to shave a wee bit off
|
// try cheaper subset first; might get lucky. seems to shave a wee bit off
|
||||||
if (la===Token.EOF || recognizer.atn.nextTokens(s).contains(la)) {
|
if (la===Token.EOF || recognizer.atn.nextTokens(s).contains(la)) {
|
||||||
console.log("OK1")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("OK1")
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Return but don't end recovery. only do that upon valid token match
|
// Return but don't end recovery. only do that upon valid token match
|
||||||
if(recognizer.isExpectedToken(la)) {
|
if(recognizer.isExpectedToken(la)) {
|
||||||
console.log("OK2")
|
if (PORT_DEBUG) {
|
||||||
|
console.log("OK2")
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
console.log("LA" + la)
|
if (PORT_DEBUG) {
|
||||||
// console.log(recognizer.GetATN().nextTokens(s, nil))
|
console.log("LA" + la)
|
||||||
|
}
|
||||||
|
|
||||||
switch (s.stateType) {
|
switch (s.stateType) {
|
||||||
case ATNState.BLOCK_START:
|
case ATNState.BLOCK_START:
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
1 + 2 = 3 + 5
|
1 + 2 + 32 + (1 + 2) = 3 + 5
|
||||||
|
|
|
@ -1,3 +1,5 @@
|
||||||
|
PORT_DEBUG = false
|
||||||
|
|
||||||
var antlr4 = require("./antlr4/index"),
|
var antlr4 = require("./antlr4/index"),
|
||||||
tree = antlr4.tree
|
tree = antlr4.tree
|
||||||
ArithmeticLexer = require("./ArithmeticLexer").ArithmeticLexer,
|
ArithmeticLexer = require("./ArithmeticLexer").ArithmeticLexer,
|
||||||
|
|
Loading…
Reference in New Issue