diff options
Diffstat (limited to 'subex/parse.go')
-rw-r--r-- | subex/parse.go | 41 |
1 files changed, 22 insertions, 19 deletions
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 { |