From 40276dc66bffda2692096fb1facbc7cf44e18fde Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Fri, 21 Apr 2023 10:06:58 +0100 Subject: Add ^xyz^ as a shorthand for ="xyz"= in subex --- subex/parse.go | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) (limited to 'subex/parse.go') 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 -- cgit v1.2.3