Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to get rendered expressions #80

Open
StrangeYear opened this issue Apr 25, 2022 · 4 comments
Open

How to get rendered expressions #80

StrangeYear opened this issue Apr 25, 2022 · 4 comments

Comments

@StrangeYear
Copy link

Example:
expression: a + b > 6
args: {"a":3,"b":4}
result: 3 + 4 > 6

Because i need to show the user the calculation process of the expression rather than the direct result.
Thanks.

@StrangeYear
Copy link
Author

Or if can get the names and locations of all parameters.it's fine too.

@skyf0cker
Copy link

I don't think it can be supported appropriately by current implement. If #78 can be implemented, you can use this feature to achieve what you want.
If no one work on this issue, i will try to work on it later in my spare time.
CC @generikvault

@generikvault
Copy link
Collaborator

@skyf0cker yeah sry. gval is a spare time project for me as well. Feel free to make a pull request.

@StrangeYear you can override the calculation itself:

var lang = gval.Full(
  gval.InfixNumberOperator("+", func(a, b float64) (interface{}, error) {
    fmt.Printf("%d + %d\n", a, b)  // or collect it in a more appropiate way
    return a + b, nil
  }),
  gval.InfixNumberOperator(">", func(a, b float64) (interface{}, error) {
    fmt.Printf("%d > %d\n", a, b) 
    return a > b, nil
  }),

but you would have to override every operator for this approach. I don't now wether this helps you or not.

@Gigaclank
Copy link

I Have a similar idea going on in my head at the moment.

Ideally I would like to identify where the expression was "triggered"

say I have (foo > bar) || ( foo > baz) I would like to be able to know that it was the left side of the operator or the right side that triggered a result to be true this would help me narrow down the causes of some business logic alerts.
but to also then be able to know the evaluated expression for the relative expression would also benefit debugging greatly.

A workaround is to split out the logic and analyze each expression separately.

@generikvault I assume your suggestion here about the language override would be the simplest approach to achieve something like what I am looking for?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants