Fix issue printing tokens from IntervalSet

This commit is contained in:
Peter Boyer 2016-01-03 22:44:36 -05:00
parent fa46c498af
commit ddd706baf2
6 changed files with 10 additions and 7 deletions

View File

@ -1 +1 @@
1 + 2 + 32 + (1 + 2) = 3 + 5
fail 1 + 2 + 32 + (1 + 2) = 3 + 5 ok-fkj

View File

@ -347,7 +347,6 @@ func (this *DefaultErrorStrategy) ReportUnwantedToken(recognizer Parser) {
var expecting = this.getExpectedTokens(recognizer)
var msg = "extraneous input " + tokenName + " expecting " +
expecting.StringVerbose(recognizer.GetLiteralNames(), recognizer.GetSymbolicNames(), false)
panic(msg)
recognizer.NotifyErrorListeners(msg, t, nil)
}

View File

@ -282,8 +282,7 @@ func (is *IntervalSet) toIndexString() string {
func (is *IntervalSet) toTokenString(literalNames []string, symbolicNames []string) string {
var names = make([]string, 0)
for i := 0; i < len(is.intervals); i++ {
var v = is.intervals[i]
for _,v := range is.intervals {
for j := v.start; j < v.stop; j++ {
names = append(names, is.elementName(literalNames, symbolicNames, j))
}
@ -301,7 +300,7 @@ func (i *IntervalSet) elementName(literalNames []string, symbolicNames []string,
} else if a == TokenEpsilon {
return "<EPSILON>"
} else {
if literalNames[a] != "" {
if a < len(literalNames) && literalNames[a] != "" {
return literalNames[a]
} else {
return symbolicNames[a]

View File

@ -69,7 +69,7 @@ func (this *BaseRecognizer) GetTokenNames() []string {
}
func (this *BaseRecognizer) GetSymbolicNames() []string {
return this.LiteralNames
return this.SymbolicNames
}
func (this *BaseRecognizer) GetLiteralNames() []string {

View File

@ -274,6 +274,11 @@ IntervalSet.prototype.toIndexString = function() {
IntervalSet.prototype.toTokenString = function(literalNames, symbolicNames) {
console.log(symbolicNames)
console.log(literalNames)
console.log(symbolicNames.length)
console.log(literalNames.length)
console.log(this.toString())
var names = [];
for (var i = 0; i < this.intervals.length; i++) {
var v = this.intervals[i];

View File

@ -1 +1 @@
1 + 2 + 32 + (1 + 2) = 3 + 5
fail 1 + 2 + 32 + (1 + 2) = 3 + 5 ok-fkj