<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/parse.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2023-02-22 20:52:20 +0000
committerCharlie Stanton <charlie@shtanton.xyz>2023-02-22 20:52:20 +0000
commita2636b27fdadb2b7951fa35fe301e8e6b41fc28a (patch)
tree35561560d067c9987a626c4a77ea3f688547a015 /subex/parse.go
parent3bd45dc49a35b82dcc4ae93796c3e152d799bc0b (diff)
downloadstred-go-a2636b27fdadb2b7951fa35fe301e8e6b41fc28a.tar
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
Diffstat (limited to 'subex/parse.go')
-rw-r--r--subex/parse.go41
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 {