Skip to content

Commit

Permalink
fix parsing of document
Browse files Browse the repository at this point in the history
  • Loading branch information
goccy committed Nov 2, 2024
1 parent c83be7f commit 03adbc4
Show file tree
Hide file tree
Showing 4 changed files with 519 additions and 83 deletions.
304 changes: 304 additions & 0 deletions lexer/lexer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1850,10 +1850,310 @@ a: >
},
},
},
{
YAML: `
s: >
1s
`,
Tokens: token.Tokens{
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "s",
Origin: "\ns",
},
{
Type: token.MappingValueType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockStructureIndicator,
Value: ":",
Origin: ":",
},
{
Type: token.FoldedType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockScalarIndicator,
Value: ">",
Origin: " >\n",
},
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "1s\n",
Origin: " 1s\n",
},
},
},
{
YAML: `
s: >1
1s
`,
Tokens: token.Tokens{
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "s",
Origin: "\ns",
},
{
Type: token.MappingValueType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockStructureIndicator,
Value: ":",
Origin: ":",
},
{
Type: token.FoldedType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockScalarIndicator,
Value: ">1",
Origin: " >1\n",
},
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: " 1s\n",
Origin: " 1s\n",
},
},
},
{
YAML: `
s: >+2
1s
`,
Tokens: token.Tokens{
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "s",
Origin: "\ns",
},
{
Type: token.MappingValueType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockStructureIndicator,
Value: ":",
Origin: ":",
},
{
Type: token.FoldedType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockScalarIndicator,
Value: ">+2",
Origin: " >+2\n",
},
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: " 1s\n",
Origin: " 1s\n",
},
},
},
{
YAML: `
s: >-3
1s
`,
Tokens: token.Tokens{
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "s",
Origin: "\ns",
},
{
Type: token.MappingValueType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockStructureIndicator,
Value: ":",
Origin: ":",
},
{
Type: token.FoldedType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockScalarIndicator,
Value: ">-3",
Origin: " >-3\n",
},
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: " 1s",
Origin: " 1s\n",
},
},
},
{
YAML: `
s: >
1s
2s
`,
Tokens: token.Tokens{
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "s",
Origin: "\ns",
},
{
Type: token.MappingValueType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockStructureIndicator,
Value: ":",
Origin: ":",
},
{
Type: token.FoldedType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockScalarIndicator,
Value: ">",
Origin: " >\n",
},
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "1s 2s\n",
Origin: " 1s\n 2s\n",
},
},
},
{
YAML: `
s: >
1s
2s
3s
`,
Tokens: token.Tokens{
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "s",
Origin: "\ns",
},
{
Type: token.MappingValueType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockStructureIndicator,
Value: ":",
Origin: ":",
},
{
Type: token.FoldedType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockScalarIndicator,
Value: ">",
Origin: " >\n",
},
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "1s\n 2s\n3s\n",
Origin: " 1s\n 2s\n 3s\n",
},
},
},
{
YAML: `
s: >
1s
2s
3s
4s
5s
`,
Tokens: token.Tokens{
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "s",
Origin: "\ns",
},
{
Type: token.MappingValueType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockStructureIndicator,
Value: ":",
Origin: ":",
},
{
Type: token.FoldedType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockScalarIndicator,
Value: ">",
Origin: " >\n",
},
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "1s\n 2s\n 3s\n4s 5s\n",
Origin: " 1s\n 2s\n 3s\n 4s\n 5s\n",
},
},
},
{
YAML: `
s: >-3
1s
2s
3s
4s
5s
`,
Tokens: token.Tokens{
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: "s",
Origin: "\ns",
},
{
Type: token.MappingValueType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockStructureIndicator,
Value: ":",
Origin: ":",
},
{
Type: token.FoldedType,
CharacterType: token.CharacterTypeIndicator,
Indicator: token.BlockScalarIndicator,
Value: ">-3",
Origin: " >-3\n",
},
{
Type: token.StringType,
CharacterType: token.CharacterTypeMiscellaneous,
Indicator: token.NotIndicator,
Value: " 1s\n 2s\n 3s\n 4s\n 5s",
Origin: " 1s\n 2s\n 3s\n 4s\n 5s\n",
},
},
},
}
for _, test := range tests {
t.Run(test.YAML, func(t *testing.T) {
tokens := lexer.Tokenize(test.YAML)
tokens.Dump()
if len(tokens) != len(test.Tokens) {
t.Fatalf("Tokenize(%q) token count mismatch, expected: %d got: %d", test.YAML, len(test.Tokens), len(tokens))
}
Expand Down Expand Up @@ -2464,6 +2764,10 @@ a: |invalid`,
name: "invalid document number",
src: ">\n1",
},
{
name: "invalid document header option number",
src: "a: >3\n 1",
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions parser/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1126,6 +1126,15 @@ b: - 2
1 | |
> 2 | 1
^
`,
},
{
"a: >3\n 1",
`
[2:3] found invalid token
1 | a: >3
> 2 | 1
^
`,
},
}
Expand Down
Loading

0 comments on commit 03adbc4

Please sign in to comment.