diff --git a/parser/parser.go b/parser/parser.go index 7a765c8..5d7bfb3 100644 --- a/parser/parser.go +++ b/parser/parser.go @@ -447,6 +447,11 @@ func (p *parser) parseMappingValue(ctx *context) (ast.Node, error) { ntk = p.nextNotCommentToken() antk = p.afterNextNotCommentToken() } + if tk := p.nextNotCommentToken(); tk != nil && tk.Position.Line > node.Start.Position.Line && tk.Position.Column > node.Start.Position.Column { + // a: b + // c <= this token is invalid. + return nil, errors.ErrSyntax("value is not allowed in this context", tk) + } if len(node.Values) == 1 { mapKeyCol := mvnode.Key.GetToken().Position.Column commentTk := p.nextToken() diff --git a/parser/parser_test.go b/parser/parser_test.go index 6b8b3ae..7adfe77 100644 --- a/parser/parser_test.go +++ b/parser/parser_test.go @@ -998,6 +998,44 @@ b }, { ` +a: 'b' + c: d +`, + ` +[3:3] value is not allowed in this context + 2 | a: 'b' +> 3 | c: d + ^ +`, + }, + { + ` +a: 'b' + - c +`, + ` +[3:3] value is not allowed in this context + 2 | a: 'b' +> 3 | - c + ^ +`, + }, + { + ` +a: 'b' + # comment + - c +`, + ` +[4:3] value is not allowed in this context + 2 | a: 'b' + 3 | # comment +> 4 | - c + ^ +`, + }, + { + ` a: 1 b - c