<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex/parse.go
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2024-03-30 15:20:07 +0000
committerCharlie Stanton <charlie@shtanton.xyz>2024-03-30 15:20:07 +0000
commit7a9f00b9bd39173494ea734b899a9f099dafb306 (patch)
treea169451bcba8c424ade1ff5cdac29eef6818d8d8 /subex/parse.go
parent9d82785f46949151b783d83648b39ce9ba40c615 (diff)
downloadstred-go-7a9f00b9bd39173494ea734b899a9f099dafb306.tar
Add array value destructure
Diffstat (limited to 'subex/parse.go')
-rw-r--r--subex/parse.go21
1 files changed, 18 insertions, 3 deletions
diff --git a/subex/parse.go b/subex/parse.go
index f1565f5..98821fd 100644
--- a/subex/parse.go
+++ b/subex/parse.go
@@ -34,13 +34,18 @@ const (
NoneStructure Structure = iota
StringStructure
ArrayStructure
+ ArrayValuesStructure
)
-func (s Structure) innerType() Type {
+func (s Structure) String() string {
switch s {
+ case NoneStructure:
+ return "-"
case StringStructure:
- return RuneType
+ return "~"
case ArrayStructure:
- return ValueType
+ return "@"
+ case ArrayValuesStructure:
+ return ":"
default:
panic("Invalid structure")
}
@@ -321,6 +326,9 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub
case ArrayStructure:
innerInType = ValueType
expectedInType = ValueType
+ case ArrayValuesStructure:
+ innerInType = ValueType
+ expectedInType = ValueType
default:
panic("Invalid structure")
}
@@ -345,6 +353,9 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub
case '@':
structure = ArrayStructure
expectedInnerOutType = ValueType
+ case ':':
+ structure = ArrayValuesStructure
+ expectedInnerOutType = ValueType
default:
panic("Missing matching destructure")
}
@@ -358,6 +369,8 @@ func parseDestructure(l RuneReader, destructure Structure, inType Type) (lhs Sub
outType = ValueType
case ArrayStructure:
outType = ValueType
+ case ArrayValuesStructure:
+ outType = ValueType
}
lhs = SubexASTDestructure {
@@ -385,6 +398,8 @@ func parseSubex(l RuneReader, minPower int, inType Type) (lhs SubexAST, outType
lhs, outType = parseDestructure(l, StringStructure, inType)
case '@':
lhs, outType = parseDestructure(l, ArrayStructure, inType)
+ case ':':
+ lhs, outType = parseDestructure(l, ArrayValuesStructure, inType)
// TODO
// case '[':
// rangeParts := parseRangeSubex(l)