<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-20 14:30:28 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-20 14:30:28 +0100
commit46720adb713a931447f4d899729b83b6171138db (patch)
tree1b78ea5a795030f090899ee312bd95ff6a75f3a1
parentc6d69701744c2b42b11680ae60f53c69bab1af63 (diff)
downloadstred-go-46720adb713a931447f4d899729b83b6171138db.tar
Add ~xyz~ shorthand for =`xyz`=
-rw-r--r--subex/parse.go11
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)}
}