Multiply wip

This commit is contained in:
Mike Farah 2020-10-19 08:36:33 +11:00
parent 391ab8d70c
commit 49b810cedd
6 changed files with 57 additions and 0 deletions

View File

@ -40,6 +40,8 @@ var Union = &OperationType{Type: "UNION", NumArgs: 2, Precedence: 10, Handler: U
var Intersection = &OperationType{Type: "INTERSECTION", NumArgs: 2, Precedence: 20, Handler: IntersectionOperator}
var Assign = &OperationType{Type: "ASSIGN", NumArgs: 2, Precedence: 40, Handler: AssignOperator}
var Multiply = &OperationType{Type: "MULTIPLY", NumArgs: 2, Precedence: 40, Handler: MultiplyOperator}
var Equals = &OperationType{Type: "EQUALS", NumArgs: 2, Precedence: 40, Handler: EqualsOperator}
var Pipe = &OperationType{Type: "PIPE", NumArgs: 2, Precedence: 45, Handler: PipeOperator}

View File

@ -0,0 +1,20 @@
package treeops
import "github.com/elliotchance/orderedmap"
func MultiplyOperator(d *dataTreeNavigator, matchingNodes *orderedmap.OrderedMap, pathNode *PathTreeNode) (*orderedmap.OrderedMap, error) {
lhs, err := d.getMatchingNodes(matchingNodes, pathNode.Lhs)
if err != nil {
return nil, err
}
for el := lhs.Front(); el != nil; el = el.Next() {
candidate := el.Value.(*CandidateNode)
// TODO handle scalar mulitplication
switch candidate.Node.Kind {
case
}
}
return matchingNodes, nil
}

View File

@ -0,0 +1,27 @@
package treeops
import (
"testing"
)
var mergeOperatorScenarios = []expressionScenario{
{
document: `{a: frog, b: cat}`,
expression: `.a * .b`,
expected: []string{
"D0, P[], (!!map)::{a: cat, b: cat}\n",
},
}, {
document: `{a: {things: great}, b: {also: me}}`,
expression: `.a * .b`,
expected: []string{
"D0, P[], (!!map)::{a: {also: me, things: great}, b: {also: me}}\n",
},
},
}
func TestMergeOperatorScenarios(t *testing.T) {
for _, tt := range mergeOperatorScenarios {
testScenario(t, &tt)
}
}

View File

@ -153,6 +153,7 @@ func initLexer() (*lex.Lexer, error) {
lexer.Add([]byte(`\[`), literalToken(OpenCollect, "[", false))
lexer.Add([]byte(`\]`), literalToken(CloseCollect, "]", true))
lexer.Add([]byte(`\*`), opToken(Multiply))
// lexer.Add([]byte(`[^ \,\|\.\[\(\)=]+`), stringValue(false))
err := lexer.Compile()

View File

@ -0,0 +1 @@
{a: {b: apple, c: cactus}}

View File

@ -0,0 +1,6 @@
{
"a": {
"b": "apple",
"c": "cactus"
}
}