diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-02-19 09:27:55 +0000 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-02-19 09:27:55 +0000 |
commit | 3bd45dc49a35b82dcc4ae93796c3e152d799bc0b (patch) | |
tree | 3a681ac5dbd777d2b6b116429cfbd934815661ce /main/parse.go | |
parent | a5a4db8283fda88c5bd42272de0258e5d134c5bd (diff) | |
download | stred-go-3bd45dc49a35b82dcc4ae93796c3e152d799bc0b.tar |
Move JSON serialising, deserialising and walking code into a separate package
Diffstat (limited to 'main/parse.go')
-rw-r--r-- | main/parse.go | 33 |
1 files changed, 17 insertions, 16 deletions
diff --git a/main/parse.go b/main/parse.go index 5466a02..73c7913 100644 --- a/main/parse.go +++ b/main/parse.go @@ -4,6 +4,7 @@ import ( "strings" "strconv" "fmt" + "main/walk" ) type parser struct { @@ -130,9 +131,9 @@ func (p *parser) parseFilter(minPower int) Filter { return lhs } -func (p *parser) parseLiterals() (items []WalkItem) { - var path Path - var value WalkValue +func (p *parser) parseLiterals() (items []walk.WalkItem) { + var path walk.Path + var value walk.WalkValue loop: for { token := p.next() switch token.typ { @@ -141,17 +142,17 @@ func (p *parser) parseLiterals() (items []WalkItem) { break loop case TokenComma: case TokenNullLiteral: - value = ValueNull{} + value = walk.ValueNull{} case TokenTrueLiteral: - value = ValueBool(true) + value = walk.ValueBool(true) case TokenFalseLiteral: - value = ValueBool(false) + value = walk.ValueBool(false) case TokenNumberLiteral: numberLiteral, err := strconv.ParseFloat(token.val, 64) if err != nil { panic("Error parsing number literal to float64") } - value = ValueNumber(numberLiteral) + value = walk.ValueNumber(numberLiteral) case TokenDoubleQuote: stringToken := p.next() if stringToken.typ != TokenStringLiteral { @@ -167,29 +168,29 @@ func (p *parser) parseLiterals() (items []WalkItem) { if path != nil { panic("Expected value after path:") } - path = Path{stringLiteral} + path = walk.Path{stringLiteral} } else { p.rewind(colon) - value = ValueString(stringLiteral) + value = walk.ValueString(stringLiteral) } case TokenTerminalLiteral: switch token.val { case "{": - value = MapBegin + value = walk.MapBegin case "}": - value = MapEnd + value = walk.MapEnd case "[": - value = ArrayBegin + value = walk.ArrayBegin case "]": - value = ArrayEnd + value = walk.ArrayEnd default: panic("Invalid terminal token") } } if value != nil { - items = append(items, WalkItem { - path: path, - value: value, + items = append(items, walk.WalkItem { + Path: path, + Value: value, }) path = nil value = nil |