diff --git a/parser/parser.go b/parser/parser.go index de102eeb..7a765c85 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -476,9 +476,11 @@ func (p *parser) parseSequenceEntry(ctx *context) (*ast.SequenceNode, error) { curColumn := tk.Position.Column for tk.Type == token.SequenceEntryType { p.progress(1) // skip sequence token + entryTk := tk tk = p.currentToken() if tk == nil { - return nil, errors.ErrSyntax("empty sequence value", p.previousToken()) + sequenceNode.Values = append(sequenceNode.Values, ast.Null(p.createNullToken(entryTk))) + break } var comment *ast.CommentGroupNode if tk.Type == token.CommentType { diff --git a/parser/parser_test.go b/parser/parser_test.go index 6c824a00..46897e6b 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -16,83 +16,86 @@ import ( func TestParser(t *testing.T) { sources := []string{ - "null\n", - "0_", - "{}\n", - "v: hi\n", - "v: \"true\"\n", - "v: \"false\"\n", - "v: true\n", - "v: false\n", - "v: 10\n", - "v: -10\n", - "v: 42\n", - "v: 4294967296\n", - "v: \"10\"\n", - "v: 0.1\n", - "v: 0.99\n", - "v: -0.1\n", - "v: .inf\n", - "v: -.inf\n", - "v: .nan\n", - "v: null\n", - "v: \"\"\n", - "v:\n- A\n- B\n", - "a: '-'\n", - "123\n", - "hello: world\n", - "a: null\n", - "v:\n- A\n- 1\n- B:\n - 2\n - 3\n", - "a:\n b: c\n", - "a: {x: 1}\n", - "t2: 2018-01-09T10:40:47Z\nt4: 2098-01-09T10:40:47Z\n", - "a: [1, 2]\n", - "a: {b: c, d: e}\n", - "a: 3s\n", - "a: \n", - "a: \"1:1\"\n", - "a: 1.2.3.4\n", - "a: \"2015-02-24T18:19:39Z\"\n", - "a: 'b: c'\n", - "a: 'Hello #comment'\n", - "a: abc <> ghi", - "a: <-\n B\n C\n", - "v: |-\n 0\n", - "v: |-\n 0\nx: 0", - `"a\n1\nb"`, - `{"a":"b"}`, - `!!map { - ? !!str "explicit":!!str "entry", - ? !!str "implicit" : !!str "entry", - ? !!null "" : !!null "", -}`, - "\"a\": a\n\"b\": b", - "'a': a\n'b': b", - "a: \r\n b: 1\r\n", - "a_ok: \r bc: 2\r", - "a_mk: \n bd: 3\n", - "a: :a", - "{a: , b: c}", - "value: >\n", - "value: >\n\n", - "value: >\nother:", - "value: >\n\nother:", + /* + "null\n", + "0_", + "{}\n", + "v: hi\n", + "v: \"true\"\n", + "v: \"false\"\n", + "v: true\n", + "v: false\n", + "v: 10\n", + "v: -10\n", + "v: 42\n", + "v: 4294967296\n", + "v: \"10\"\n", + "v: 0.1\n", + "v: 0.99\n", + "v: -0.1\n", + "v: .inf\n", + "v: -.inf\n", + "v: .nan\n", + "v: null\n", + "v: \"\"\n", + "v:\n- A\n- B\n", + "a: '-'\n", + "123\n", + "hello: world\n", + "a: null\n", + "v:\n- A\n- 1\n- B:\n - 2\n - 3\n", + "a:\n b: c\n", + "a: {x: 1}\n", + "t2: 2018-01-09T10:40:47Z\nt4: 2098-01-09T10:40:47Z\n", + "a: [1, 2]\n", + "a: {b: c, d: e}\n", + "a: 3s\n", + "a: \n", + "a: \"1:1\"\n", + "a: 1.2.3.4\n", + "a: \"2015-02-24T18:19:39Z\"\n", + "a: 'b: c'\n", + "a: 'Hello #comment'\n", + "a: abc <> ghi", + "a: <-\n B\n C\n", + "v: |-\n 0\n", + "v: |-\n 0\nx: 0", + `"a\n1\nb"`, + `{"a":"b"}`, + `!!map { + ? !!str "explicit":!!str "entry", + ? !!str "implicit" : !!str "entry", + ? !!null "" : !!null "", + }`, + "\"a\": a\n\"b\": b", + "'a': a\n'b': b", + "a: \r\n b: 1\r\n", + "a_ok: \r bc: 2\r", + "a_mk: \n bd: 3\n", + "a: :a", + "{a: , b: c}", + "value: >\n", + "value: >\n\n", + "value: >\nother:", + "value: >\n\nother:", + */ + "a:\n-", } for _, src := range sources { if _, err := parser.Parse(lexer.Tokenize(src), 0); err != nil { @@ -974,19 +977,6 @@ a }, { ` -a: -- b: c -- `, - ` -[4:1] empty sequence value - 2 | a: - 3 | - b: c -> 4 | - - ^ -`, - }, - { - ` a: |invalidopt foo `, @@ -1052,7 +1042,7 @@ a: - b: - `, ` -[3:4] empty sequence value +[3:4] block sequence entries are not allowed in this context 2 | a: - > 3 | b: - ^ diff --git a/scanner/scanner.go b/scanner/scanner.go index c6b5d4cc..371bd8a3 100644 --- a/scanner/scanner.go +++ b/scanner/scanner.go @@ -802,7 +802,7 @@ func (s *Scanner) scanSequence(ctx *Context) bool { } nc := ctx.nextChar() - if nc != ' ' && !s.isNewLineChar(nc) { + if nc != 0 && nc != ' ' && !s.isNewLineChar(nc) { return false }