<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-04-20 12:33:04 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2023-04-20 12:33:04 +0100
commitdb8800dcdac60a48ef4a4f084940581222e643ad (patch)
treee2fa532501fbe03fec801262b4e286d4a8323a24 /subex
parent3d5730276b8866c3458f163f3050fe2daea259e3 (diff)
downloadstred-go-db8800dcdac60a48ef4a4f084940581222e643ad.tar
Replaces the start and end terminals of strings with a single terminal, with " as a literal for it
Diffstat (limited to 'subex')
-rw-r--r--subex/parse.go12
1 files changed, 11 insertions, 1 deletions
diff --git a/subex/parse.go b/subex/parse.go
index 9e47e0b..b1d54ac 100644
--- a/subex/parse.go
+++ b/subex/parse.go
@@ -39,7 +39,7 @@ func parseTerminatorAtomLiteral(termType rune, l RuneReader) walk.Atom {
case '@':
return expectBracket(l, walk.ArrayBegin, walk.ArrayEnd)
case '~':
- return expectBracket(l, walk.StartString{}, walk.EndString{})
+ return expectBracket(l, walk.StringTerminal{}, walk.StringTerminal{})
case '#':
return expectBracket(l, walk.MapBegin, walk.MapEnd)
default:
@@ -193,6 +193,8 @@ func parseReplacement(l RuneReader) (output []OutputContent) {
for _, literal := range literals {
output = append(output, OutputAtomLiteral {literal})
}
+ case '"':
+ output = append(output, OutputAtomLiteral {walk.StringTerminal{}})
default:
output = append(output, OutputAtomLiteral{atom: walk.StringAtom(r)})
}
@@ -218,6 +220,9 @@ func parseRangeSubex(l RuneReader) map[walk.Atom]walk.Atom {
literals := parseNonStringLiteral(l)
froms = append(froms, literals...)
continue
+ } else if fromsStart == '"' {
+ froms = append(froms, walk.StringTerminal{})
+ continue
} else {
atom := parseTerminatorAtomLiteral(fromsStart, l)
if atom != nil {
@@ -252,6 +257,9 @@ func parseRangeSubex(l RuneReader) map[walk.Atom]walk.Atom {
literals := parseNonStringLiteral(l)
tos = append(tos, literals...)
continue
+ } else if tosStart == '"' {
+ tos = append(tos, walk.StringTerminal{})
+ continue
} else {
atom := parseTerminatorAtomLiteral(tosStart, l)
if atom != nil {
@@ -307,6 +315,8 @@ func parseSubex(l RuneReader, minPower int) SubexAST {
lhs = SubexASTOutput{replacement}
case '.':
lhs = SubexASTCopyAny{}
+ case '"':
+ lhs = SubexASTCopyAtom {walk.StringTerminal{}}
case '@', '#', '~':
lhs = SubexASTCopyAtom{atom: parseTerminatorAtomLiteral(r, l)}
case '`':