<- Back to shtanton's homepage
aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--subex/main_test.go113
-rw-r--r--subex/parse.go12
-rw-r--r--subex/subexast.go8
3 files changed, 129 insertions, 4 deletions
diff --git a/subex/main_test.go b/subex/main_test.go
index 0b4ee1b..78a62c4 100644
--- a/subex/main_test.go
+++ b/subex/main_test.go
@@ -69,6 +69,119 @@ func TestSubexMain(t *testing.T) {
walk.StringValue("ello"),
},
},
+ {
+ subex: "@(..$a`$a$a`{-0})@",
+ input: []walk.Value {
+ walk.ArrayValue {
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NullValue{},
+ },
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.BoolValue(true),
+ },
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NumberValue(5.4),
+ },
+ walk.ArrayElement {
+ Index: 5,
+ Value: walk.StringValue("hello"),
+ },
+ walk.ArrayElement {
+ Index: 3,
+ Value: walk.ArrayValue {
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NullValue{},
+ },
+ },
+ },
+ walk.ArrayElement {
+ Index: 1,
+ Value: walk.MapValue {
+ walk.MapElement {
+ Key: "key",
+ Value: walk.StringValue("value"),
+ },
+ },
+ },
+ },
+ },
+ expected: []walk.Value {
+ walk.ArrayValue {
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NullValue{},
+ },
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NullValue{},
+ },
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.BoolValue(true),
+ },
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.BoolValue(true),
+ },
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NumberValue(5.4),
+ },
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NumberValue(5.4),
+ },
+ walk.ArrayElement {
+ Index: 5,
+ Value: walk.StringValue("hello"),
+ },
+ walk.ArrayElement {
+ Index: 5,
+ Value: walk.StringValue("hello"),
+ },
+ walk.ArrayElement {
+ Index: 3,
+ Value: walk.ArrayValue {
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NullValue{},
+ },
+ },
+ },
+ walk.ArrayElement {
+ Index: 3,
+ Value: walk.ArrayValue {
+ walk.ArrayElement {
+ Index: 0,
+ Value: walk.NullValue{},
+ },
+ },
+ },
+ walk.ArrayElement {
+ Index: 1,
+ Value: walk.MapValue {
+ walk.MapElement {
+ Key: "key",
+ Value: walk.StringValue("value"),
+ },
+ },
+ },
+ walk.ArrayElement {
+ Index: 1,
+ Value: walk.MapValue {
+ walk.MapElement {
+ Key: "key",
+ Value: walk.StringValue("value"),
+ },
+ },
+ },
+ },
+ },
+ },
}
for _, test := range tests {
diff --git a/subex/parse.go b/subex/parse.go
index fa98ecc..9602a4b 100644
--- a/subex/parse.go
+++ b/subex/parse.go
@@ -293,6 +293,18 @@ func parseSubex(l RuneReader, minPower int, inType Type, outType Type) SubexAST
panic("Missing matching ~")
}
lhs = SubexASTEnterString {lhs}
+ case '@':
+ if !accept(l, "(") {
+ panic("Missing ( after @")
+ }
+ lhs = parseSubex(l, 0, ValueType, ValueType)
+ if !accept(l, ")") {
+ panic("Missing matching )")
+ }
+ if !accept(l, "@") {
+ panic("Missing matching ~")
+ }
+ lhs = SubexASTEnterArray {lhs}
// TODO
// case '[':
// rangeParts := parseRangeSubex(l)
diff --git a/subex/subexast.go b/subex/subexast.go
index cc7313b..cef853b 100644
--- a/subex/subexast.go
+++ b/subex/subexast.go
@@ -472,10 +472,10 @@ func (ast SubexASTEnterArray) compileWith(next SubexState, slotMap *SlotMap, inT
panic("Invalid types for SubexASTEnterArray")
}
return &SubexCaptureBeginState {
- next: &SubexIncrementNestState {
- next: &SubexCopyState {
- filter: anyArrayFilter{},
- next: &SubexDiscardState {
+ next: &SubexCopyState {
+ filter: anyArrayFilter{},
+ next: &SubexDiscardState {
+ next: &SubexIncrementNestState {
next: &SubexCaptureBeginState {
next: ast.Content.compileWith(
&SubexDiscardTerminalState {