<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
path: root/subex
diff options
context:
space:
mode:
authorCharlie Stanton <charlie@shtanton.xyz>2024-05-02 21:45:45 +0100
committerCharlie Stanton <charlie@shtanton.xyz>2024-05-02 21:45:45 +0100
commitb434fe4e14f6dcc8d1d7433a29351b8e8ea77d37 (patch)
tree50b7e54713d23c965f6ffc23d9feeecd1dd60301 /subex
parent22ccb0c370cf2690f1b1a80fe003e05c6ba5e5ed (diff)
downloadstred-go-main.tar
Add , subex syntax to make FullMerge commands easierHEADmain
Diffstat (limited to 'subex')
-rw-r--r--subex/filter.go20
-rw-r--r--subex/parse.go11
-rw-r--r--subex/subexast.go12
3 files changed, 43 insertions, 0 deletions
diff --git a/subex/filter.go b/subex/filter.go
index ae4b8ab..309d6c7 100644
--- a/subex/filter.go
+++ b/subex/filter.go
@@ -27,6 +27,26 @@ func (_ anyBoolFilter) valueFilter(value walk.Value) bool {
return isBool
}
+type simpleValueFilter struct {}
+func (_ simpleValueFilter) valueFilter(value walk.Value) bool {
+ switch value := value.(type) {
+ case walk.NullValue:
+ return true
+ case walk.BoolValue:
+ return true
+ case walk.NumberValue:
+ return true
+ case walk.StringValue:
+ return true
+ case walk.ArrayValue:
+ return len(value) == 0
+ case walk.MapValue:
+ return len(value) == 0
+ default:
+ panic("Invalid value type")
+ }
+}
+
type anyValueFilter struct {}
func (_ anyValueFilter) valueFilter(value walk.Value) bool {
return true
diff --git a/subex/parse.go b/subex/parse.go
index 9a7a75c..e91008a 100644
--- a/subex/parse.go
+++ b/subex/parse.go
@@ -520,6 +520,17 @@ func parseSubex(l RuneReader, minPower int, inType Type) (lhs SubexAST, outType
} else {
lhs = SubexASTCopyAnyValue{}
}
+ case ',':
+ switch inType {
+ case ValueType:
+ outType = inType
+ lhs = SubexASTCopyAnySimpleValue{}
+ case RuneType:
+ outType = inType
+ lhs = SubexASTCopyRune{','}
+ default:
+ panic("Invalid inType")
+ }
case '?':
outType = inType
lhs = SubexASTCopyBool{}
diff --git a/subex/subexast.go b/subex/subexast.go
index d08ddac..655a783 100644
--- a/subex/subexast.go
+++ b/subex/subexast.go
@@ -238,6 +238,18 @@ func (ast SubexASTCopyNumber) String() string {
return "%"
}
+// Read in a null, bool, number, string or empty array or map and output it unchanged
+type SubexASTCopyAnySimpleValue struct {}
+func (ast SubexASTCopyAnySimpleValue) compileWith(next SubexState, slotMap *SlotMap, inType Type, outType Type) SubexState {
+ if inType != ValueType || outType != ValueType {
+ panic("Invalid types for SubexASTCopyAnySimpleValue")
+ }
+ return &SubexCopyState {
+ next: next,
+ filter: simpleValueFilter{},
+ }
+}
+
// Read in any single Atom and output it unchanged
type SubexASTCopyAnyValue struct {}
func (ast SubexASTCopyAnyValue) compileWith(next SubexState, slotMap *SlotMap, inType Type, outType Type) SubexState {