<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-21 10:06:58 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-21 10:06:58 +0100
commit40276dc66bffda2692096fb1facbc7cf44e18fde (patch)
tree03055914c6c1acdb890c5c85f6b35938ac0116a3
parentf1e5bc37723a4faa30bbfeed392c31489914eb50 (diff)
downloadstred-go-40276dc66bffda2692096fb1facbc7cf44e18fde.tar
Add ^xyz^ as a shorthand for ="xyz"= in subex
-rw-r--r--main/parse.go2
-rw-r--r--subex/parse.go25
2 files changed, 19 insertions, 8 deletions
diff --git a/main/parse.go b/main/parse.go
index dc86fd6..0c534e8 100644
--- a/main/parse.go
+++ b/main/parse.go
@@ -43,7 +43,7 @@ func (p *parser) parseSubex() subex.SubexAST {
panic("Missing subex from substitution")
}
var subexProgram string
- if delim.val == "=" || delim.val == "~" || delim.val == "\"" || delim.val == "`" {
+ if delim.val == "=" || delim.val == "~" || delim.val == "\"" || delim.val == "`" || delim.val == "^" {
subexProgram = delim.val + subexProgramToken.val + delim.val
} else {
subexProgram = subexProgramToken.val
diff --git a/subex/parse.go b/subex/parse.go
index 106663d..b403adc 100644
--- a/subex/parse.go
+++ b/subex/parse.go
@@ -166,7 +166,7 @@ func parseReplacement(l RuneReader) (output []OutputContent) {
switch r {
case eof:
panic("Missing closing \"")
- case '=':
+ case '=', '^':
break loop
case '$':
slot := l.Next()
@@ -287,6 +287,23 @@ func parseSubex(l RuneReader, minPower int) SubexAST {
case '=':
replacement := parseReplacement(l)
lhs = SubexASTOutput{replacement}
+ case '`':
+ literals := parseNonStringLiteral(l)
+ lhs = SubexASTEmpty{}
+ for _, literal := range literals {
+ lhs = SubexASTConcat {lhs, SubexASTCopyAtom {literal}}
+ }
+ case '^':
+ replacement := parseReplacement(l)
+ replacement = append(
+ []OutputContent{OutputAtomLiteral {walk.StringTerminal{}}},
+ replacement...
+ )
+ replacement = append(
+ replacement,
+ OutputAtomLiteral {walk.StringTerminal{}},
+ )
+ lhs = SubexASTOutput {replacement}
case '.':
lhs = SubexASTCopyAny{}
case '?':
@@ -301,12 +318,6 @@ func parseSubex(l RuneReader, minPower int) SubexAST {
lhs = SubexASTCopyValue{}
case '"':
lhs = SubexASTCopyAtom {walk.StringTerminal{}}
- case '`':
- literals := parseNonStringLiteral(l)
- lhs = SubexASTEmpty{}
- for _, literal := range literals {
- lhs = SubexASTConcat {lhs, SubexASTCopyAtom {literal}}
- }
case '~':
literals := parseNonStringLiteral(l)
var replacement []OutputContent