Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
P
perxis-go
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
perxis
perxis-go
Commits
b03b3456
Commit
b03b3456
authored
1 year ago
by
Danis Kirasirov
Browse files
Options
Downloads
Patches
Plain Diff
rename import
parent
451d936e
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
pkg/expr/expr.go
+2
-2
2 additions, 2 deletions
pkg/expr/expr.go
pkg/expr/mongo.go
+28
-28
28 additions, 28 deletions
pkg/expr/mongo.go
with
30 additions
and
30 deletions
pkg/expr/expr.go
+
2
−
2
View file @
b03b3456
...
@@ -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
:=
compiler
2
.
Compile
(
tree
,
GetDefaultConfig
(
env
))
program
,
err
:=
compiler
.
Compile
(
tree
,
GetDefaultConfig
(
env
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
This diff is collapsed.
Click to expand it.
pkg/expr/mongo.go
+
28
−
28
View file @
b03b3456
...
@@ -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
:=
&
c
ompiler
{
tree
:
tree
,
env
:
env
,
config
:
config
,
identifierRenameFn
:
identifierRenameFn
}
c
:=
&
mongoC
ompiler
{
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
c
ompiler
struct
{
type
mongoC
ompiler
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
*
c
ompiler
)
eval
(
node
ast
.
Node
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
:=
compiler
2
.
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
*
c
ompiler
)
compile
(
node
ast
.
Node
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
NilNode
(
node
*
ast
.
NilNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
NilNode
(
node
*
ast
.
NilNode
)
interface
{}
{
return
nil
return
nil
}
}
func
(
c
*
c
ompiler
)
IdentifierNode
(
node
*
ast
.
IdentifierNode
)
string
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
IntegerNode
(
node
*
ast
.
IntegerNode
)
int
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
FloatNode
(
node
*
ast
.
FloatNode
)
float64
{
func
(
c
*
mongoC
ompiler
)
FloatNode
(
node
*
ast
.
FloatNode
)
float64
{
return
node
.
Value
return
node
.
Value
}
}
func
(
c
*
c
ompiler
)
BoolNode
(
node
*
ast
.
BoolNode
)
bool
{
func
(
c
*
mongoC
ompiler
)
BoolNode
(
node
*
ast
.
BoolNode
)
bool
{
return
node
.
Value
return
node
.
Value
}
}
func
(
c
*
c
ompiler
)
StringNode
(
node
*
ast
.
StringNode
)
string
{
func
(
c
*
mongoC
ompiler
)
StringNode
(
node
*
ast
.
StringNode
)
string
{
return
node
.
Value
return
node
.
Value
}
}
func
(
c
*
c
ompiler
)
ConstantNode
(
node
*
ast
.
ConstantNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
ConstantNode
(
node
*
ast
.
ConstantNode
)
interface
{}
{
return
node
.
Value
return
node
.
Value
}
}
func
(
c
*
c
ompiler
)
UnaryNode
(
node
*
ast
.
UnaryNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
identifier
(
node
ast
.
Node
)
string
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
BinaryNode
(
node
*
ast
.
BinaryNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
ChainNode
(
node
*
ast
.
ChainNode
)
string
{
func
(
c
*
mongoC
ompiler
)
ChainNode
(
node
*
ast
.
ChainNode
)
string
{
panic
(
"unsupported chain node"
)
panic
(
"unsupported chain node"
)
}
}
func
(
c
*
c
ompiler
)
MemberNode
(
node
*
ast
.
MemberNode
)
string
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
SliceNode
(
node
*
ast
.
SliceNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
SliceNode
(
node
*
ast
.
SliceNode
)
interface
{}
{
panic
(
"unsupported slice node"
)
panic
(
"unsupported slice node"
)
}
}
func
(
c
*
c
ompiler
)
CallNode
(
node
*
ast
.
CallNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
BuiltinNode
(
node
*
ast
.
BuiltinNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
ClosureNode
(
node
*
ast
.
ClosureNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
ClosureNode
(
node
*
ast
.
ClosureNode
)
interface
{}
{
return
c
.
compile
(
node
.
Node
)
return
c
.
compile
(
node
.
Node
)
}
}
func
(
c
*
c
ompiler
)
PointerNode
(
node
*
ast
.
PointerNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
ConditionalNode
(
node
*
ast
.
ConditionalNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
VariableDeclaratorNode
(
node
*
ast
.
VariableDeclaratorNode
)
int
{
func
(
c
*
mongoC
ompiler
)
VariableDeclaratorNode
(
node
*
ast
.
VariableDeclaratorNode
)
int
{
panic
(
"unsupported variable declarator node "
)
panic
(
"unsupported variable declarator node "
)
}
}
func
(
c
*
c
ompiler
)
ArrayNode
(
node
*
ast
.
ArrayNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
MapNode
(
node
*
ast
.
MapNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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
*
c
ompiler
)
PairNode
(
node
*
ast
.
PairNode
)
interface
{}
{
func
(
c
*
mongoC
ompiler
)
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)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment