You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
let expression = String::from("src_port == 8080 && dst_port == 6868");let engine = Engine::new();// Build the abstract syntax treelet ast = engine.compile_expression(expression).unwrap();// HERE: before I build the Scope, I would like to know which unbounded variables are even relevant.letmut scope = Scope::new();
scope.push("src_port",8080_i64).push("dst_port",6868_i64);let result = engine
.eval_ast_with_scope::<bool>(&mut scope,&ast).unwrap();
I would like to get something like ast.iter_unbounded_variables() which yields something like ["src_port", "dst_port"] in the end.
Thank you all in advance for any helpful input. :)
The text was updated successfully, but these errors were encountered:
There is a similar function to iterate all imported modules. Maybe you can base on that function and write something similar. Shouldn't be difficult....
But you need to take care of variables declared in local blocks.
Alternatively you can look at the parser implementation methods. They actually collect lists of unbounded variables as part of parsing closures that capture external variables. That's how the strict variables mode can work.
Thanks a bunch for your quick reply, @schungx! I did search for the function you mentioned and read a lot of the code, but I’m still not sure which one you’re talking about. Could you please give me the exact name or location of the function that iterates over all imported modules? I’ve also looked into the parser implementation, but I hope I can avoid getting too deep into the logic.
By the way, in the ast.statements() output, you can clearly see the variables. But maybe thinking about getting them out easily and confidently is a bit too naive of me, since the current expression is still quite simple.
If you're only parsing expressions then it gets easier because you don't declare local variables. Therefore any Variable node in the AST is a reference to an external variable.
It only gets hairy when you can declare local variables in blocks.
You can use the walk API to recursively scan through the AST to pick out the variables. This is simplest and quite easy to use. Just pass in a closure capturing a Vec or something and catch Variable nodes.
Imagine something like this:
I would like to get something like ast.iter_unbounded_variables() which yields something like ["src_port", "dst_port"] in the end.
Thank you all in advance for any helpful input. :)
The text was updated successfully, but these errors were encountered: