Fix multiline array

This commit is contained in:
Thomas Pelletier
2013-02-24 23:09:33 +01:00
parent 6782b75410
commit 55291dbfa9
2 changed files with 15 additions and 2 deletions
+8 -2
View File
@@ -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") {
+7
View File
@@ -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{}{