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