diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-20 14:30:28 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-20 14:30:28 +0100 |
commit | 46720adb713a931447f4d899729b83b6171138db (patch) | |
tree | 1b78ea5a795030f090899ee312bd95ff6a75f3a1 /subex/parse.go | |
parent | c6d69701744c2b42b11680ae60f53c69bab1af63 (diff) | |
download | stred-go-46720adb713a931447f4d899729b83b6171138db.tar |
Add ~xyz~ shorthand for =`xyz`=
Diffstat (limited to 'subex/parse.go')
-rw-r--r-- | subex/parse.go | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/subex/parse.go b/subex/parse.go index 24ff3d1..4b1aa6e 100644 --- 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)} } |