json: fix overly-greedy keyword scanning
Logic error in the scanner caused it to always consume the remainder of the string.
This commit is contained in:
parent
bd0cbc1c81
commit
8dfc3c4bbe
@ -165,7 +165,7 @@ Byte:
|
|||||||
for i = 0; i < len(buf); i++ {
|
for i = 0; i < len(buf); i++ {
|
||||||
b := buf[i]
|
b := buf[i]
|
||||||
switch {
|
switch {
|
||||||
case b >= 'a' || b <= 'z' || b >= 'A' || b <= 'Z' || b == '_':
|
case (b >= 'a' && b <= 'z') || (b >= 'A' && b <= 'Z') || b == '_':
|
||||||
p.Pos.Byte++
|
p.Pos.Byte++
|
||||||
p.Pos.Column++
|
p.Pos.Column++
|
||||||
default:
|
default:
|
||||||
|
@ -510,6 +510,74 @@ func TestScan(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
`[true]`,
|
||||||
|
[]token{
|
||||||
|
{
|
||||||
|
Type: tokenBrackO,
|
||||||
|
Bytes: []byte(`[`),
|
||||||
|
Range: zcl.Range{
|
||||||
|
Start: zcl.Pos{
|
||||||
|
Byte: 0,
|
||||||
|
Line: 1,
|
||||||
|
Column: 1,
|
||||||
|
},
|
||||||
|
End: zcl.Pos{
|
||||||
|
Byte: 1,
|
||||||
|
Line: 1,
|
||||||
|
Column: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: tokenKeyword,
|
||||||
|
Bytes: []byte(`true`),
|
||||||
|
Range: zcl.Range{
|
||||||
|
Start: zcl.Pos{
|
||||||
|
Byte: 1,
|
||||||
|
Line: 1,
|
||||||
|
Column: 2,
|
||||||
|
},
|
||||||
|
End: zcl.Pos{
|
||||||
|
Byte: 5,
|
||||||
|
Line: 1,
|
||||||
|
Column: 6,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: tokenBrackC,
|
||||||
|
Bytes: []byte(`]`),
|
||||||
|
Range: zcl.Range{
|
||||||
|
Start: zcl.Pos{
|
||||||
|
Byte: 5,
|
||||||
|
Line: 1,
|
||||||
|
Column: 6,
|
||||||
|
},
|
||||||
|
End: zcl.Pos{
|
||||||
|
Byte: 6,
|
||||||
|
Line: 1,
|
||||||
|
Column: 7,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Type: tokenEOF,
|
||||||
|
Range: zcl.Range{
|
||||||
|
Start: zcl.Pos{
|
||||||
|
Byte: 6,
|
||||||
|
Line: 1,
|
||||||
|
Column: 7,
|
||||||
|
},
|
||||||
|
End: zcl.Pos{
|
||||||
|
Byte: 6,
|
||||||
|
Line: 1,
|
||||||
|
Column: 7,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
{
|
{
|
||||||
`""`,
|
`""`,
|
||||||
[]token{
|
[]token{
|
||||||
|
Loading…
Reference in New Issue
Block a user