From ab16112f69bbc7d4f4bb70163f01dd7bb4ac2010 Mon Sep 17 00:00:00 2001 From: Masaaki Goshima Date: Sun, 3 Nov 2024 14:06:57 +0900 Subject: [PATCH] support empty sequence value (#503) --- parser/parser.go | 4 +++- parser/parser_test.go | 16 ++-------------- scanner/scanner.go | 2 +- 3 files changed, 6 insertions(+), 16 deletions(-) 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..6b8b3ae9 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -93,6 +93,7 @@ func TestParser(t *testing.T) { "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 +975,6 @@ a }, { ` -a: -- b: c -- `, - ` -[4:1] empty sequence value - 2 | a: - 3 | - b: c -> 4 | - - ^ -`, - }, - { - ` a: |invalidopt foo `, @@ -1052,7 +1040,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 }