diff options
author | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-20 12:33:04 +0100 |
---|---|---|
committer | Charlie Stanton <charlie@shtanton.xyz> | 2023-04-20 12:33:04 +0100 |
commit | db8800dcdac60a48ef4a4f084940581222e643ad (patch) | |
tree | e2fa532501fbe03fec801262b4e286d4a8323a24 /subex/parse.go | |
parent | 3d5730276b8866c3458f163f3050fe2daea259e3 (diff) | |
download | stred-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/parse.go')
-rw-r--r-- | subex/parse.go | 12 |
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 '`': |