Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support empty sequence value #503

Merged
merged 1 commit into from
Nov 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading