From a2636b27fdadb2b7951fa35fe301e8e6b41fc28a Mon Sep 17 00:00:00 2001 From: Charlie Stanton Date: Wed, 22 Feb 2023 20:52:20 +0000 Subject: Modify subex to take JSON split into "data" Currently no way to reassemble the data on the other side Much of the potential data cannot be interacted with meaningfully, only the string functionality is implemented Should rename data to something else --- subex/parse.go | 41 ++++++++++++++++++++++------------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'subex/parse.go') diff --git a/subex/parse.go b/subex/parse.go index af575eb..0c79dc3 100644 --- a/subex/parse.go +++ b/subex/parse.go @@ -1,5 +1,9 @@ package subex +import ( + "main/walk" +) + func parseReplacement(l *RuneReader) (output []TransducerOutput) { loop: for { r := l.next() @@ -13,17 +17,18 @@ func parseReplacement(l *RuneReader) (output []TransducerOutput) { if slot == eof { panic("Missing slot character") } - output = append(output, TransducerReplacementLoad(slot)) + output = append(output, TransducerReplacementLoad{datum: slot}) default: - output = append(output, TransducerReplacementRune(r)) + output = append(output, TransducerReplacementRune{datum: r}) } } return output } -func parseRangeSubex(l *RuneReader) map[rune]rune { - parts := make(map[rune]rune) - var froms []rune +// Parse the contents of a range subex [] into a map +func parseRangeSubex(l *RuneReader) map[walk.Datum]walk.Datum { + parts := make(map[walk.Datum]walk.Datum) + var froms []walk.Datum var hasTo bool for { fromsStart := l.next() @@ -34,43 +39,41 @@ func parseRangeSubex(l *RuneReader) map[rune]rune { hasTo = true break } - var fromsEnd rune if l.accept("-") { - fromsEnd = l.next() + fromsEnd := l.next() if fromsEnd == ']' || fromsEnd == '=' { l.rewind() fromsEnd = fromsStart } + for i := fromsStart; i <= fromsEnd; i += 1 { + froms = append(froms, i) + } } else { - fromsEnd = fromsStart - } - for i := fromsStart; i <= fromsEnd; i += 1 { - froms = append(froms, i) + froms = append(froms, fromsStart) } } if len(froms) == 0 { panic("Missing from part of range expression") } - var tos []rune + var tos []walk.Datum if hasTo { for { tosStart := l.next() if tosStart == ']' { break } - var tosEnd rune if l.accept("-") { - tosEnd = l.next() + tosEnd := l.next() if tosEnd == ']' { l.rewind() tosEnd = tosStart } + for i := tosStart; i <= tosEnd; i += 1 { + tos = append(tos, i) + } } else { - tosEnd = tosStart - } - for i := tosStart; i <= tosEnd; i += 1 { - tos = append(tos, i) + tos = append(tos, tosStart) } } } else { @@ -122,7 +125,7 @@ func parseSubex(l *RuneReader, minPower int) SubexAST { case '.': lhs = SubexASTCopyAny{} default: - lhs = SubexASTCopyRune(r) + lhs = SubexASTCopyRune{datum: r} } loop: for { if minPower <= 0 { -- cgit v1.2.3