pqarrays

Paddy 2016-02-25 Parent:bfe2a4af6bdf Child:9a415db0346a

1:ce9c92fc81ab Go to Latest

pqarrays/lexer.go

Fix bug parsing empty arrays, make golint and go vet happy. Add comments to make golint happy. Also, because comments are a good thing to have. Turn += 1 and -= 1 into ++ and --, respectively, so golint will be happy. Fix an improperly formated errorf, where a rune was being treated as a string. Thanks, go vet! Fix whitespace parsing, returning the parse functions again instead of just skipping the one character. Now if we have more than one whitespace character in a row, they'll all be skipped. Add a parseStringOrNullOrEnd parse function that will be called after the tokenArrayStart character, to fix a bug where empty arrays were expecting a string or null and getting the array end character. This is only valid after tokenArrayStart, however; in other places where parseSeparatorOrDelim is used, it wouldn't be appropriate. Add a parser test for an empty array.

History
     1.1 --- a/lexer.go	Sun Apr 19 23:47:36 2015 -0400
     1.2 +++ b/lexer.go	Thu Feb 25 23:52:05 2016 -0800
     1.3 @@ -178,14 +178,14 @@
     1.4  func lexLeftDelim(l *lexer) stateFunc {
     1.5  	l.pos += len(leftDelim)
     1.6  	l.emit(tokenArrayStart)
     1.7 -	l.arrayDepth += 1
     1.8 +	l.arrayDepth++
     1.9  	return lexItem
    1.10  }
    1.11  
    1.12  func lexRightDelim(l *lexer) stateFunc {
    1.13  	l.pos += len(rightDelim)
    1.14  	l.emit(tokenArrayEnd)
    1.15 -	l.arrayDepth -= 1
    1.16 +	l.arrayDepth--
    1.17  	return lexSeparator
    1.18  }
    1.19  
    1.20 @@ -293,6 +293,6 @@
    1.21  		return nil
    1.22  	} else {
    1.23  		l.backup()
    1.24 -		return l.errorf("expected %s, none found before %s\n", separator, l.input[l.pos:])
    1.25 +		return l.errorf("expected %s, none found before %s\n", string(separator), l.input[l.pos:])
    1.26  	}
    1.27  }