Skip to content
Snippets Groups Projects
Commit b03b3456 authored by Danis Kirasirov's avatar Danis Kirasirov
Browse files

rename import

parent 451d936e
Branches
Tags
No related merge requests found
...@@ -5,7 +5,7 @@ import ( ...@@ -5,7 +5,7 @@ import (
"strings" "strings"
"git.perx.ru/perxis/perxis-go/pkg/data" "git.perx.ru/perxis/perxis-go/pkg/data"
compiler2 "github.com/expr-lang/expr/compiler" "github.com/expr-lang/expr/compiler"
"github.com/expr-lang/expr/parser" "github.com/expr-lang/expr/parser"
"github.com/expr-lang/expr/vm" "github.com/expr-lang/expr/vm"
"golang.org/x/net/context" "golang.org/x/net/context"
...@@ -39,7 +39,7 @@ func Eval(ctx context.Context, input string, env map[string]interface{}) (interf ...@@ -39,7 +39,7 @@ func Eval(ctx context.Context, input string, env map[string]interface{}) (interf
env, _ = cfg.Env.(map[string]interface{}) env, _ = cfg.Env.(map[string]interface{})
program, err := compiler2.Compile(tree, GetDefaultConfig(env)) program, err := compiler.Compile(tree, GetDefaultConfig(env))
if err != nil { if err != nil {
return nil, err return nil, err
} }
......
...@@ -8,7 +8,7 @@ import ( ...@@ -8,7 +8,7 @@ import (
"github.com/expr-lang/expr" "github.com/expr-lang/expr"
"github.com/expr-lang/expr/ast" "github.com/expr-lang/expr/ast"
compiler2 "github.com/expr-lang/expr/compiler" "github.com/expr-lang/expr/compiler"
"github.com/expr-lang/expr/conf" "github.com/expr-lang/expr/conf"
"github.com/expr-lang/expr/parser" "github.com/expr-lang/expr/parser"
"go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/bson"
...@@ -56,7 +56,7 @@ func convertToMongo(ctx context.Context, tree *parser.Tree, env map[string]inter ...@@ -56,7 +56,7 @@ func convertToMongo(ctx context.Context, tree *parser.Tree, env map[string]inter
} }
} }
c := &compiler{tree: tree, env: env, config: config, identifierRenameFn: identifierRenameFn} c := &mongoCompiler{tree: tree, env: env, config: config, identifierRenameFn: identifierRenameFn}
v, ok := c.compile(tree.Node).(bson.M) v, ok := c.compile(tree.Node).(bson.M)
if !ok || v == nil { if !ok || v == nil {
return nil, fmt.Errorf("invalid expression") return nil, fmt.Errorf("invalid expression")
...@@ -64,19 +64,19 @@ func convertToMongo(ctx context.Context, tree *parser.Tree, env map[string]inter ...@@ -64,19 +64,19 @@ func convertToMongo(ctx context.Context, tree *parser.Tree, env map[string]inter
return v, nil return v, nil
} }
type compiler struct { type mongoCompiler struct {
env map[string]interface{} env map[string]interface{}
tree *parser.Tree tree *parser.Tree
config *conf.Config config *conf.Config
identifierRenameFn func(string) string identifierRenameFn func(string) string
} }
func (c *compiler) eval(node ast.Node) interface{} { func (c *mongoCompiler) eval(node ast.Node) interface{} {
t := &parser.Tree{ t := &parser.Tree{
Node: node, Node: node,
Source: c.tree.Source, Source: c.tree.Source,
} }
prg, err := compiler2.Compile(t, c.config) prg, err := compiler.Compile(t, c.config)
if err != nil { if err != nil {
panic(fmt.Sprintf("compile error %s", err.Error())) panic(fmt.Sprintf("compile error %s", err.Error()))
} }
...@@ -87,7 +87,7 @@ func (c *compiler) eval(node ast.Node) interface{} { ...@@ -87,7 +87,7 @@ func (c *compiler) eval(node ast.Node) interface{} {
return ret return ret
} }
func (c *compiler) compile(node ast.Node) interface{} { func (c *mongoCompiler) compile(node ast.Node) interface{} {
switch n := node.(type) { switch n := node.(type) {
case *ast.NilNode: case *ast.NilNode:
return c.NilNode(n) return c.NilNode(n)
...@@ -136,11 +136,11 @@ func (c *compiler) compile(node ast.Node) interface{} { ...@@ -136,11 +136,11 @@ func (c *compiler) compile(node ast.Node) interface{} {
} }
} }
func (c *compiler) NilNode(node *ast.NilNode) interface{} { func (c *mongoCompiler) NilNode(node *ast.NilNode) interface{} {
return nil return nil
} }
func (c *compiler) IdentifierNode(node *ast.IdentifierNode) string { func (c *mongoCompiler) IdentifierNode(node *ast.IdentifierNode) string {
identifier := node.Value identifier := node.Value
if c.identifierRenameFn != nil { if c.identifierRenameFn != nil {
identifier = c.identifierRenameFn(identifier) identifier = c.identifierRenameFn(identifier)
...@@ -148,7 +148,7 @@ func (c *compiler) IdentifierNode(node *ast.IdentifierNode) string { ...@@ -148,7 +148,7 @@ func (c *compiler) IdentifierNode(node *ast.IdentifierNode) string {
return identifier return identifier
} }
func (c *compiler) IntegerNode(node *ast.IntegerNode) int { func (c *mongoCompiler) IntegerNode(node *ast.IntegerNode) int {
return node.Value return node.Value
//t := node.Type() //t := node.Type()
//if t == nil { //if t == nil {
...@@ -189,23 +189,23 @@ func (c *compiler) IntegerNode(node *ast.IntegerNode) int { ...@@ -189,23 +189,23 @@ func (c *compiler) IntegerNode(node *ast.IntegerNode) int {
//} //}
} }
func (c *compiler) FloatNode(node *ast.FloatNode) float64 { func (c *mongoCompiler) FloatNode(node *ast.FloatNode) float64 {
return node.Value return node.Value
} }
func (c *compiler) BoolNode(node *ast.BoolNode) bool { func (c *mongoCompiler) BoolNode(node *ast.BoolNode) bool {
return node.Value return node.Value
} }
func (c *compiler) StringNode(node *ast.StringNode) string { func (c *mongoCompiler) StringNode(node *ast.StringNode) string {
return node.Value return node.Value
} }
func (c *compiler) ConstantNode(node *ast.ConstantNode) interface{} { func (c *mongoCompiler) ConstantNode(node *ast.ConstantNode) interface{} {
return node.Value return node.Value
} }
func (c *compiler) UnaryNode(node *ast.UnaryNode) interface{} { func (c *mongoCompiler) UnaryNode(node *ast.UnaryNode) interface{} {
op := c.compile(node.Node) op := c.compile(node.Node)
switch node.Operator { switch node.Operator {
...@@ -217,7 +217,7 @@ func (c *compiler) UnaryNode(node *ast.UnaryNode) interface{} { ...@@ -217,7 +217,7 @@ func (c *compiler) UnaryNode(node *ast.UnaryNode) interface{} {
} }
} }
func (c *compiler) identifier(node ast.Node) string { func (c *mongoCompiler) identifier(node ast.Node) string {
switch l := node.(type) { switch l := node.(type) {
case *ast.MemberNode: case *ast.MemberNode:
return c.MemberNode(l) return c.MemberNode(l)
...@@ -227,7 +227,7 @@ func (c *compiler) identifier(node ast.Node) string { ...@@ -227,7 +227,7 @@ func (c *compiler) identifier(node ast.Node) string {
panic(fmt.Sprintf("incorrect identifier node (%v) ", ast.Dump(node))) panic(fmt.Sprintf("incorrect identifier node (%v) ", ast.Dump(node)))
} }
func (c *compiler) BinaryNode(node *ast.BinaryNode) interface{} { func (c *mongoCompiler) BinaryNode(node *ast.BinaryNode) interface{} {
switch node.Operator { switch node.Operator {
case "==": case "==":
return bson.M{c.identifier(node.Left): c.eval(node.Right)} return bson.M{c.identifier(node.Left): c.eval(node.Right)}
...@@ -322,11 +322,11 @@ func (c *compiler) BinaryNode(node *ast.BinaryNode) interface{} { ...@@ -322,11 +322,11 @@ func (c *compiler) BinaryNode(node *ast.BinaryNode) interface{} {
} }
} }
func (c *compiler) ChainNode(node *ast.ChainNode) string { func (c *mongoCompiler) ChainNode(node *ast.ChainNode) string {
panic("unsupported chain node") panic("unsupported chain node")
} }
func (c *compiler) MemberNode(node *ast.MemberNode) string { func (c *mongoCompiler) MemberNode(node *ast.MemberNode) string {
v := c.compile(node.Node) v := c.compile(node.Node)
if val, ok := v.(string); ok { if val, ok := v.(string); ok {
return fmt.Sprintf("%s.%s", val, node.Property) return fmt.Sprintf("%s.%s", val, node.Property)
...@@ -334,11 +334,11 @@ func (c *compiler) MemberNode(node *ast.MemberNode) string { ...@@ -334,11 +334,11 @@ func (c *compiler) MemberNode(node *ast.MemberNode) string {
panic(fmt.Sprintf("unsupported property for %v", ast.Dump(node.Node))) panic(fmt.Sprintf("unsupported property for %v", ast.Dump(node.Node)))
} }
func (c *compiler) SliceNode(node *ast.SliceNode) interface{} { func (c *mongoCompiler) SliceNode(node *ast.SliceNode) interface{} {
panic("unsupported slice node") panic("unsupported slice node")
} }
func (c *compiler) CallNode(node *ast.CallNode) interface{} { func (c *mongoCompiler) CallNode(node *ast.CallNode) interface{} {
switch node.Callee.String() { switch node.Callee.String() {
case "search", "q": case "search", "q":
val := c.compile(node.Arguments[0]) val := c.compile(node.Arguments[0])
...@@ -438,7 +438,7 @@ func (c *compiler) CallNode(node *ast.CallNode) interface{} { ...@@ -438,7 +438,7 @@ func (c *compiler) CallNode(node *ast.CallNode) interface{} {
//c.emit(op, c.makeConstant(Call{Name: node.Name, Size: len(node.Arguments)})...) //c.emit(op, c.makeConstant(Call{Name: node.Name, Size: len(node.Arguments)})...)
} }
func (c *compiler) BuiltinNode(node *ast.BuiltinNode) interface{} { func (c *mongoCompiler) BuiltinNode(node *ast.BuiltinNode) interface{} {
panic("unsupported builin node") panic("unsupported builin node")
//switch node.Name { //switch node.Name {
//case "len": //case "len":
...@@ -583,18 +583,18 @@ func (c *compiler) BuiltinNode(node *ast.BuiltinNode) interface{} { ...@@ -583,18 +583,18 @@ func (c *compiler) BuiltinNode(node *ast.BuiltinNode) interface{} {
// return size // return size
//} //}
func (c *compiler) ClosureNode(node *ast.ClosureNode) interface{} { func (c *mongoCompiler) ClosureNode(node *ast.ClosureNode) interface{} {
return c.compile(node.Node) return c.compile(node.Node)
} }
func (c *compiler) PointerNode(node *ast.PointerNode) interface{} { func (c *mongoCompiler) PointerNode(node *ast.PointerNode) interface{} {
panic("unsupported pointer node") panic("unsupported pointer node")
//c.emit(OpLoad, c.makeConstant("array")...) //c.emit(OpLoad, c.makeConstant("array")...)
//c.emit(OpLoad, c.makeConstant("i")...) //c.emit(OpLoad, c.makeConstant("i")...)
//c.emit(OpIndex) //c.emit(OpIndex)
} }
func (c *compiler) ConditionalNode(node *ast.ConditionalNode) interface{} { func (c *mongoCompiler) ConditionalNode(node *ast.ConditionalNode) interface{} {
panic("unsupported conditional node") panic("unsupported conditional node")
//c.compile(node.Cond) //c.compile(node.Cond)
//otherwise := c.emit(OpJumpIfFalse, c.placeholder()...) //otherwise := c.emit(OpJumpIfFalse, c.placeholder()...)
...@@ -610,11 +610,11 @@ func (c *compiler) ConditionalNode(node *ast.ConditionalNode) interface{} { ...@@ -610,11 +610,11 @@ func (c *compiler) ConditionalNode(node *ast.ConditionalNode) interface{} {
//c.patchJump(end) //c.patchJump(end)
} }
func (c *compiler) VariableDeclaratorNode(node *ast.VariableDeclaratorNode) int { func (c *mongoCompiler) VariableDeclaratorNode(node *ast.VariableDeclaratorNode) int {
panic("unsupported variable declarator node ") panic("unsupported variable declarator node ")
} }
func (c *compiler) ArrayNode(node *ast.ArrayNode) interface{} { func (c *mongoCompiler) ArrayNode(node *ast.ArrayNode) interface{} {
panic("unsupported array node") panic("unsupported array node")
//for _, node := range node.Nodes { //for _, node := range node.Nodes {
// c.compile(node) // c.compile(node)
...@@ -624,7 +624,7 @@ func (c *compiler) ArrayNode(node *ast.ArrayNode) interface{} { ...@@ -624,7 +624,7 @@ func (c *compiler) ArrayNode(node *ast.ArrayNode) interface{} {
//c.emit(OpArray) //c.emit(OpArray)
} }
func (c *compiler) MapNode(node *ast.MapNode) interface{} { func (c *mongoCompiler) MapNode(node *ast.MapNode) interface{} {
panic("unsupported map node") panic("unsupported map node")
//for _, pair := range node.Pairs { //for _, pair := range node.Pairs {
// c.compile(pair) // c.compile(pair)
...@@ -634,7 +634,7 @@ func (c *compiler) MapNode(node *ast.MapNode) interface{} { ...@@ -634,7 +634,7 @@ func (c *compiler) MapNode(node *ast.MapNode) interface{} {
//c.emit(OpMap) //c.emit(OpMap)
} }
func (c *compiler) PairNode(node *ast.PairNode) interface{} { func (c *mongoCompiler) PairNode(node *ast.PairNode) interface{} {
panic("unsupported pair node") panic("unsupported pair node")
//c.compile(node.Key) //c.compile(node.Key)
//c.compile(node.Value) //c.compile(node.Value)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment