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

rename import

parent 451d936e
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,7 @@ import (
"strings"
"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/vm"
"golang.org/x/net/context"
......@@ -39,7 +39,7 @@ func Eval(ctx context.Context, input string, env map[string]interface{}) (interf
env, _ = cfg.Env.(map[string]interface{})
program, err := compiler2.Compile(tree, GetDefaultConfig(env))
program, err := compiler.Compile(tree, GetDefaultConfig(env))
if err != nil {
return nil, err
}
......
......@@ -8,7 +8,7 @@ import (
"github.com/expr-lang/expr"
"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/parser"
"go.mongodb.org/mongo-driver/bson"
......@@ -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)
if !ok || v == nil {
return nil, fmt.Errorf("invalid expression")
......@@ -64,19 +64,19 @@ func convertToMongo(ctx context.Context, tree *parser.Tree, env map[string]inter
return v, nil
}
type compiler struct {
type mongoCompiler struct {
env map[string]interface{}
tree *parser.Tree
config *conf.Config
identifierRenameFn func(string) string
}
func (c *compiler) eval(node ast.Node) interface{} {
func (c *mongoCompiler) eval(node ast.Node) interface{} {
t := &parser.Tree{
Node: node,
Source: c.tree.Source,
}
prg, err := compiler2.Compile(t, c.config)
prg, err := compiler.Compile(t, c.config)
if err != nil {
panic(fmt.Sprintf("compile error %s", err.Error()))
}
......@@ -87,7 +87,7 @@ func (c *compiler) eval(node ast.Node) interface{} {
return ret
}
func (c *compiler) compile(node ast.Node) interface{} {
func (c *mongoCompiler) compile(node ast.Node) interface{} {
switch n := node.(type) {
case *ast.NilNode:
return c.NilNode(n)
......@@ -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
}
func (c *compiler) IdentifierNode(node *ast.IdentifierNode) string {
func (c *mongoCompiler) IdentifierNode(node *ast.IdentifierNode) string {
identifier := node.Value
if c.identifierRenameFn != nil {
identifier = c.identifierRenameFn(identifier)
......@@ -148,7 +148,7 @@ func (c *compiler) IdentifierNode(node *ast.IdentifierNode) string {
return identifier
}
func (c *compiler) IntegerNode(node *ast.IntegerNode) int {
func (c *mongoCompiler) IntegerNode(node *ast.IntegerNode) int {
return node.Value
//t := node.Type()
//if t == nil {
......@@ -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
}
func (c *compiler) BoolNode(node *ast.BoolNode) bool {
func (c *mongoCompiler) BoolNode(node *ast.BoolNode) bool {
return node.Value
}
func (c *compiler) StringNode(node *ast.StringNode) string {
func (c *mongoCompiler) StringNode(node *ast.StringNode) string {
return node.Value
}
func (c *compiler) ConstantNode(node *ast.ConstantNode) interface{} {
func (c *mongoCompiler) ConstantNode(node *ast.ConstantNode) interface{} {
return node.Value
}
func (c *compiler) UnaryNode(node *ast.UnaryNode) interface{} {
func (c *mongoCompiler) UnaryNode(node *ast.UnaryNode) interface{} {
op := c.compile(node.Node)
switch node.Operator {
......@@ -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) {
case *ast.MemberNode:
return c.MemberNode(l)
......@@ -227,7 +227,7 @@ func (c *compiler) identifier(node ast.Node) string {
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 {
case "==":
return bson.M{c.identifier(node.Left): c.eval(node.Right)}
......@@ -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")
}
func (c *compiler) MemberNode(node *ast.MemberNode) string {
func (c *mongoCompiler) MemberNode(node *ast.MemberNode) string {
v := c.compile(node.Node)
if val, ok := v.(string); ok {
return fmt.Sprintf("%s.%s", val, node.Property)
......@@ -334,11 +334,11 @@ func (c *compiler) MemberNode(node *ast.MemberNode) string {
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")
}
func (c *compiler) CallNode(node *ast.CallNode) interface{} {
func (c *mongoCompiler) CallNode(node *ast.CallNode) interface{} {
switch node.Callee.String() {
case "search", "q":
val := c.compile(node.Arguments[0])
......@@ -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)})...)
}
func (c *compiler) BuiltinNode(node *ast.BuiltinNode) interface{} {
func (c *mongoCompiler) BuiltinNode(node *ast.BuiltinNode) interface{} {
panic("unsupported builin node")
//switch node.Name {
//case "len":
......@@ -583,18 +583,18 @@ func (c *compiler) BuiltinNode(node *ast.BuiltinNode) interface{} {
// return size
//}
func (c *compiler) ClosureNode(node *ast.ClosureNode) interface{} {
func (c *mongoCompiler) ClosureNode(node *ast.ClosureNode) interface{} {
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")
//c.emit(OpLoad, c.makeConstant("array")...)
//c.emit(OpLoad, c.makeConstant("i")...)
//c.emit(OpIndex)
}
func (c *compiler) ConditionalNode(node *ast.ConditionalNode) interface{} {
func (c *mongoCompiler) ConditionalNode(node *ast.ConditionalNode) interface{} {
panic("unsupported conditional node")
//c.compile(node.Cond)
//otherwise := c.emit(OpJumpIfFalse, c.placeholder()...)
......@@ -610,11 +610,11 @@ func (c *compiler) ConditionalNode(node *ast.ConditionalNode) interface{} {
//c.patchJump(end)
}
func (c *compiler) VariableDeclaratorNode(node *ast.VariableDeclaratorNode) int {
func (c *mongoCompiler) VariableDeclaratorNode(node *ast.VariableDeclaratorNode) int {
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")
//for _, node := range node.Nodes {
// c.compile(node)
......@@ -624,7 +624,7 @@ func (c *compiler) ArrayNode(node *ast.ArrayNode) interface{} {
//c.emit(OpArray)
}
func (c *compiler) MapNode(node *ast.MapNode) interface{} {
func (c *mongoCompiler) MapNode(node *ast.MapNode) interface{} {
panic("unsupported map node")
//for _, pair := range node.Pairs {
// c.compile(pair)
......@@ -634,7 +634,7 @@ func (c *compiler) MapNode(node *ast.MapNode) interface{} {
//c.emit(OpMap)
}
func (c *compiler) PairNode(node *ast.PairNode) interface{} {
func (c *mongoCompiler) PairNode(node *ast.PairNode) interface{} {
panic("unsupported pair node")
//c.compile(node.Key)
//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