stred

Stred: Streaming Tree Editor. Like sed but for JSON
git clone http://shtanton.xyz/git/repo/stred
Log | Files | Refs

commit 46720adb713a931447f4d899729b83b6171138db
parent c6d69701744c2b42b11680ae60f53c69bab1af63
Author: Charlie Stanton <charlie@shtanton.xyz>
Date:   Thu, 20 Apr 2023 14:30:28 +0100

Add ~xyz~ shorthand for =`xyz`=

Diffstat:
Msubex/parse.go | 11++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/subex/parse.go b/subex/parse.go @@ -61,7 +61,7 @@ func parseNonStringLiteral(l RuneReader) (literals []walk.Atom) { continue } switch r { - case '`': + case '`', '~': return literals case ' ', '\t': continue @@ -91,6 +91,8 @@ func parseNonStringLiteral(l RuneReader) (literals []walk.Atom) { literals = append(literals, walk.ArrayBegin) case ']': literals = append(literals, walk.ArrayEnd) + default: + panic("Invalid literal") } } } @@ -295,6 +297,13 @@ func parseSubex(l RuneReader, minPower int) SubexAST { for _, literal := range literals { lhs = SubexASTConcat {lhs, SubexASTCopyAtom {literal}} } + case '~': + literals := parseNonStringLiteral(l) + var replacement []OutputContent + for _, literal := range literals { + replacement = append(replacement, OutputAtomLiteral {literal}) + } + lhs = SubexASTOutput {replacement} default: lhs = SubexASTCopyAtom{atom: walk.StringAtom(r)} }