mirror of
https://github.com/MontFerret/ferret.git
synced 2024-12-14 11:23:02 +02:00
Added param to member expression
This commit is contained in:
parent
24370d8178
commit
9c0e81a2f4
@ -63,4 +63,21 @@ func TestParam(t *testing.T) {
|
||||
So(string(out), ShouldEqual, `[1,2,3,4]`)
|
||||
|
||||
})
|
||||
|
||||
Convey("Should be possible to use in member expression", t, func() {
|
||||
prog := compiler.New().
|
||||
MustCompile(`
|
||||
RETURN @param.value
|
||||
`)
|
||||
|
||||
out := prog.MustRun(
|
||||
context.Background(),
|
||||
runtime.WithParam("param", map[string]interface{}{
|
||||
"value": "foobar",
|
||||
}),
|
||||
)
|
||||
|
||||
So(string(out), ShouldEqual, `"foobar"`)
|
||||
|
||||
})
|
||||
}
|
||||
|
@ -736,39 +736,13 @@ func (v *visitor) doVisitForExpressionStatement(ctx *fql.ForExpressionStatementC
|
||||
}
|
||||
|
||||
func (v *visitor) doVisitMemberExpression(ctx *fql.MemberExpressionContext, scope *scope) (core.Expression, error) {
|
||||
var source core.Expression
|
||||
var children []antlr.Tree
|
||||
member, err := v.doVisitMember(ctx.Member().(*fql.MemberContext), scope)
|
||||
|
||||
identifier := ctx.Identifier()
|
||||
|
||||
if identifier != nil {
|
||||
varName := ctx.Identifier().GetText()
|
||||
|
||||
_, err := scope.GetVariable(varName)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
varExp, err := expressions.NewVariableExpression(v.getSourceMap(ctx), varName)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
source = varExp
|
||||
children = ctx.GetChildren()
|
||||
} else {
|
||||
fcall, err := v.doVisitFunctionCallExpression(ctx.FunctionCallExpression().(*fql.FunctionCallExpressionContext), scope)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
source = fcall
|
||||
children = ctx.GetChildren()[1:]
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
children := ctx.MemberPath().GetChildren()
|
||||
path := make([]core.Expression, 0, len(children))
|
||||
|
||||
for _, child := range children {
|
||||
@ -808,9 +782,9 @@ func (v *visitor) doVisitMemberExpression(ctx *fql.MemberExpressionContext, scop
|
||||
path = append(path, exp)
|
||||
}
|
||||
|
||||
member, err := expressions.NewMemberExpression(
|
||||
exp, err := expressions.NewMemberExpression(
|
||||
v.getSourceMap(ctx),
|
||||
source,
|
||||
member,
|
||||
path,
|
||||
)
|
||||
|
||||
@ -818,7 +792,51 @@ func (v *visitor) doVisitMemberExpression(ctx *fql.MemberExpressionContext, scop
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return member, nil
|
||||
return exp, nil
|
||||
}
|
||||
|
||||
func (v *visitor) doVisitMember(ctx *fql.MemberContext, scope *scope) (core.Expression, error) {
|
||||
identifier := ctx.Identifier()
|
||||
|
||||
if identifier != nil {
|
||||
varName := ctx.Identifier().GetText()
|
||||
|
||||
_, err := scope.GetVariable(varName)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
exp, err := expressions.NewVariableExpression(v.getSourceMap(ctx), varName)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return exp, nil
|
||||
}
|
||||
|
||||
fnCall := ctx.FunctionCallExpression()
|
||||
|
||||
if fnCall != nil {
|
||||
exp, err := v.doVisitFunctionCallExpression(fnCall.(*fql.FunctionCallExpressionContext), scope)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return exp, nil
|
||||
}
|
||||
|
||||
param := ctx.Param()
|
||||
|
||||
exp, err := v.doVisitParamContext(param.(*fql.ParamContext), scope)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return exp, nil
|
||||
}
|
||||
|
||||
func (v *visitor) doVisitObjectLiteral(ctx *fql.ObjectLiteralContext, scope *scope) (core.Expression, error) {
|
||||
|
@ -209,11 +209,19 @@ functionCallExpression
|
||||
: namespace Identifier arguments
|
||||
;
|
||||
|
||||
member
|
||||
: Identifier
|
||||
| functionCallExpression
|
||||
| param
|
||||
;
|
||||
|
||||
memberPath
|
||||
: (Dot propertyName (computedPropertyName)*)+
|
||||
| computedPropertyName (Dot propertyName (computedPropertyName)*)* (computedPropertyName (Dot propertyName)*)*
|
||||
;
|
||||
|
||||
memberExpression
|
||||
: Identifier (Dot propertyName (computedPropertyName)*)+
|
||||
| Identifier computedPropertyName (Dot propertyName (computedPropertyName)*)* (computedPropertyName (Dot propertyName)*)*
|
||||
| functionCallExpression (Dot propertyName (computedPropertyName)*)+
|
||||
| functionCallExpression computedPropertyName (Dot propertyName (computedPropertyName)*)* (computedPropertyName (Dot propertyName)*)*
|
||||
: member memberPath
|
||||
;
|
||||
|
||||
arguments
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because it is too large
Load Diff
@ -286,6 +286,18 @@ func (s *BaseFqlParserListener) EnterFunctionCallExpression(ctx *FunctionCallExp
|
||||
// ExitFunctionCallExpression is called when production functionCallExpression is exited.
|
||||
func (s *BaseFqlParserListener) ExitFunctionCallExpression(ctx *FunctionCallExpressionContext) {}
|
||||
|
||||
// EnterMember is called when production member is entered.
|
||||
func (s *BaseFqlParserListener) EnterMember(ctx *MemberContext) {}
|
||||
|
||||
// ExitMember is called when production member is exited.
|
||||
func (s *BaseFqlParserListener) ExitMember(ctx *MemberContext) {}
|
||||
|
||||
// EnterMemberPath is called when production memberPath is entered.
|
||||
func (s *BaseFqlParserListener) EnterMemberPath(ctx *MemberPathContext) {}
|
||||
|
||||
// ExitMemberPath is called when production memberPath is exited.
|
||||
func (s *BaseFqlParserListener) ExitMemberPath(ctx *MemberPathContext) {}
|
||||
|
||||
// EnterMemberExpression is called when production memberExpression is entered.
|
||||
func (s *BaseFqlParserListener) EnterMemberExpression(ctx *MemberExpressionContext) {}
|
||||
|
||||
|
@ -183,6 +183,14 @@ func (v *BaseFqlParserVisitor) VisitFunctionCallExpression(ctx *FunctionCallExpr
|
||||
return v.VisitChildren(ctx)
|
||||
}
|
||||
|
||||
func (v *BaseFqlParserVisitor) VisitMember(ctx *MemberContext) interface{} {
|
||||
return v.VisitChildren(ctx)
|
||||
}
|
||||
|
||||
func (v *BaseFqlParserVisitor) VisitMemberPath(ctx *MemberPathContext) interface{} {
|
||||
return v.VisitChildren(ctx)
|
||||
}
|
||||
|
||||
func (v *BaseFqlParserVisitor) VisitMemberExpression(ctx *MemberExpressionContext) interface{} {
|
||||
return v.VisitChildren(ctx)
|
||||
}
|
||||
|
@ -139,6 +139,12 @@ type FqlParserListener interface {
|
||||
// EnterFunctionCallExpression is called when entering the functionCallExpression production.
|
||||
EnterFunctionCallExpression(c *FunctionCallExpressionContext)
|
||||
|
||||
// EnterMember is called when entering the member production.
|
||||
EnterMember(c *MemberContext)
|
||||
|
||||
// EnterMemberPath is called when entering the memberPath production.
|
||||
EnterMemberPath(c *MemberPathContext)
|
||||
|
||||
// EnterMemberExpression is called when entering the memberExpression production.
|
||||
EnterMemberExpression(c *MemberExpressionContext)
|
||||
|
||||
@ -310,6 +316,12 @@ type FqlParserListener interface {
|
||||
// ExitFunctionCallExpression is called when exiting the functionCallExpression production.
|
||||
ExitFunctionCallExpression(c *FunctionCallExpressionContext)
|
||||
|
||||
// ExitMember is called when exiting the member production.
|
||||
ExitMember(c *MemberContext)
|
||||
|
||||
// ExitMemberPath is called when exiting the memberPath production.
|
||||
ExitMemberPath(c *MemberPathContext)
|
||||
|
||||
// ExitMemberExpression is called when exiting the memberExpression production.
|
||||
ExitMemberExpression(c *MemberExpressionContext)
|
||||
|
||||
|
@ -139,6 +139,12 @@ type FqlParserVisitor interface {
|
||||
// Visit a parse tree produced by FqlParser#functionCallExpression.
|
||||
VisitFunctionCallExpression(ctx *FunctionCallExpressionContext) interface{}
|
||||
|
||||
// Visit a parse tree produced by FqlParser#member.
|
||||
VisitMember(ctx *MemberContext) interface{}
|
||||
|
||||
// Visit a parse tree produced by FqlParser#memberPath.
|
||||
VisitMemberPath(ctx *MemberPathContext) interface{}
|
||||
|
||||
// Visit a parse tree produced by FqlParser#memberExpression.
|
||||
VisitMemberExpression(ctx *MemberExpressionContext) interface{}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user