Fix multiline array
This commit is contained in:
+8
-2
@@ -76,6 +76,7 @@ type lexer struct {
|
||||
pos int
|
||||
width int
|
||||
tokens chan token
|
||||
depth int
|
||||
}
|
||||
|
||||
func (l *lexer) run() {
|
||||
@@ -177,8 +178,10 @@ func lexRvalue(l *lexer) stateFn {
|
||||
next := l.peek()
|
||||
switch next {
|
||||
case '[':
|
||||
l.depth += 1
|
||||
return lexLeftBracket
|
||||
case ']':
|
||||
l.depth -= 1
|
||||
return lexRightBracket
|
||||
case '#':
|
||||
return lexComment
|
||||
@@ -189,8 +192,11 @@ func lexRvalue(l *lexer) stateFn {
|
||||
case '\n':
|
||||
l.ignore()
|
||||
l.pos += 1
|
||||
/*l.emit(tokenEOF)*/
|
||||
return lexVoid
|
||||
if l.depth == 0 {
|
||||
return lexVoid
|
||||
} else {
|
||||
return lexRvalue
|
||||
}
|
||||
}
|
||||
|
||||
if l.follow("true") {
|
||||
|
||||
@@ -88,6 +88,13 @@ func TestArraySimple(t *testing.T) {
|
||||
})
|
||||
}
|
||||
|
||||
func TestArrayMultiline(t *testing.T) {
|
||||
tree := Load("a = [42,\n21, 10,]")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
"a": []int64{int64(42), int64(21), int64(10)},
|
||||
})
|
||||
}
|
||||
|
||||
func TestArrayNested(t *testing.T) {
|
||||
tree := Load("a = [[42, 21], [10]]")
|
||||
assertTree(t, tree, map[string]interface{}{
|
||||
|
||||
Reference in New Issue
Block a user