summaryrefslogtreecommitdiff
path: root/internal
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 17:27:14 -0700
committerLuke Shumaker <lukeshu@lukeshu.com>2023-01-30 17:27:14 -0700
commit7de3be7d772ab32adb1a865450ba60567367064c (patch)
tree15e780cb853ef73746e6b71e66ef4bc980eb10fc /internal
parent75a59f2b56982bc753d594a5af375b23ef786fdf (diff)
parse: Simplify the stack states for arrays
We already have a wildcard, no need to invent a new state.
Diffstat (limited to 'internal')
-rw-r--r--internal/parse.go14
-rw-r--r--internal/parse_test.go2
2 files changed, 3 insertions, 13 deletions
diff --git a/internal/parse.go b/internal/parse.go
index 121857b..b11aae6 100644
--- a/internal/parse.go
+++ b/internal/parse.go
@@ -264,7 +264,6 @@ type Parser struct {
//
// [ array: waiting for item to start or ']'
// a array: reading item / waiting for ',' or ']'
- // ] array: waiting for item to start
//
// Within each element type, the stack item is replaced, not pushed.
//
@@ -308,7 +307,7 @@ type Parser struct {
// a" ["
// a" ["x
// a ["x"
- // ] ["x",
+ // a? ["x",
// a" ["x","
// a" ["x","y
// a ["x","y"
@@ -513,21 +512,12 @@ func (par *Parser) HandleRune(c rune) (RuneType, error) {
par.pushState(runeTypeAny)
return par.HandleRune(c)
}
- case RuneTypeArrayEnd: // waiting for item
- switch c {
- case 0x0020, 0x000A, 0x000D, 0x0009:
- return RuneTypeSpace, nil
- default:
- par.replaceState(RuneTypeArrayComma)
- par.pushState(runeTypeAny)
- return par.HandleRune(c)
- }
case RuneTypeArrayComma: // waiting for ',' or ']'
switch c {
case 0x0020, 0x000A, 0x000D, 0x0009:
return RuneTypeSpace, nil
case ',':
- par.replaceState(RuneTypeArrayEnd)
+ par.pushState(runeTypeAny)
return RuneTypeArrayComma, nil
case ']':
par.popState()
diff --git a/internal/parse_test.go b/internal/parse_test.go
index 91cd277..34977fb 100644
--- a/internal/parse_test.go
+++ b/internal/parse_test.go
@@ -51,7 +51,7 @@ func TestParserHandleRune(t *testing.T) {
`a"`, // ["
`a"`, // ["x
`a`, // ["x"
- `]`, // ["x",
+ `a?`, // ["x",
`a"`, // ["x","
`a"`, // ["x","y
`a`, // ["x","y"