Skip to content

Commit

Permalink
support empty sequence value (#503)
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy authored Nov 3, 2024
1 parent 8f8d730 commit ab16112
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 16 deletions.
4 changes: 3 additions & 1 deletion parser/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
16 changes: 2 additions & 14 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -974,19 +975,6 @@ a
},
{
`
a:
- b: c
- `,
`
[4:1] empty sequence value
2 | a:
3 | - b: c
> 4 | -
^
`,
},
{
`
a: |invalidopt
foo
`,
Expand Down Expand Up @@ -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: -
^
Expand Down
2 changes: 1 addition & 1 deletion scanner/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down

0 comments on commit ab16112

Please sign in to comment.