From db8800dcdac60a48ef4a4f084940581222e643ad Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Thu, 20 Apr 2023 12:33:04 +0100 Subject: Replaces the start and end terminals of strings with a single terminal, with " as a literal for it --- subex/parse.go | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'subex/parse.go') 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 '`': -- cgit v1.2.3