clarkmcc/cel-rust

Ability to check which functions/variables a script references

Closed this issue · 3 comments

It would be nice if the parser took note of which functions and variables a given script actually made use of and made that information available to the embedding program.

My primary motivation for wanting this is so that I can cache some variables to the scripts that reference them, and only run scripts when certain variables change. Currently, there is no way to tell which scripts actually reference specific functions/variables, so there's no way to make any kind of mapping between references and which scripts reference them. Besides this, it could be used for general sandboxing notifications, like if certain functions/variables were only valid in certain contexts, the user of this library could print a coherent diagnostic about the offending reference, instead of reporting that a reference simply doesn't exist. And, even besides that, it would just be nice for debugging and diagnostics.

I've opened a PR for this. If you'd like to play with it, I'm happy to consider any feedback for the API. The functionality is exposed through the parser package but most users only use that package through the interpreter's Program type.

[dependencies]
cel-interpreter = { git = "https://github.com/clarkmcc/cel-rust", branch = "60-get-variable-function-references-in-expr" }

Wow, you're like a genie, this is exactly what I wanted! API looks perfect to me, it's pretty much exactly how I would have done it. I'll leave this open for anyone else to comment, but feel free to close it as completed if you're satisfied with the API.

Excellent! Happy to hear we're on the same page. I'll get the PR merged and ticket closed once we're squared away on the cloning feedback.