-
-
Notifications
You must be signed in to change notification settings - Fork 463
-
Hello!
I am playing with expr and my use case is multi-line re-use expr scripts, am trying to do that like so:
func main() { env := map[string]interface{}{ "println": fmt.Println, } code := ` let foo = "asdf"; let bar = "fsda"; println(foo); println(bar) ` program, err := expr.Compile(code, expr.Env(env)) if err != nil { panic(err) } output, err := expr.Run(program, env) if err != nil { panic(err) } fmt.Println(output) }
I've tried variations of println(foo), no ;, etc. But it seems like I can only execute one func at a time?
I get either the following errors:
panic: unexpected token Operator(";") (4:13)
| println(foo);
| ............^
panic: unexpected token Identifier("println") (5:1)
| println(bar)
| ^
Beta Was this translation helpful? Give feedback.
All reactions
I've added support for SequenceNode! Now Expr, starting with 1.17, will support multiline expressions!
foo(); bar(); let x = baz(); x + 1
Replies: 2 comments
-
Currenly there is no way to do those. As Expr is designed to work with expressions.
One "hack" to overcome this, is to return an expression:
let foo = "asdf";
let bar = "fsda";
[
println(foo),
println(bar),
]
Also I think we should add support for statments in Expr as well via a feature flag.
Beta Was this translation helpful? Give feedback.
All reactions
-
I've added support for SequenceNode! Now Expr, starting with 1.17, will support multiline expressions!
foo(); bar(); let x = baz(); x + 1
Beta Was this translation helpful? Give feedback.