-
Notifications
You must be signed in to change notification settings - Fork 270
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
use String parameters in custom functions #70
Comments
Is 23A12B meant to be a variable? Variable names have to start with a letter or underscore. |
Hi Guy Thanks for your reply Is 23A12B meant to be a variable? No! this is a product number i have a custom function called QTY(productNumber), it returns qty of On ۱۶/۰۵/۲۴ 11:17, Udo Klimaschewski wrote:
|
I am sorry, but this is not possible. The parameters to functions are numbers, variable, constants or expressions. Strings are not supported. |
oh my god! On سهشنبه, مه 24, 2016 at 11:53 , Udo Klimaschewski
|
There might be a possible solution, for this the LazyNumber interface has to be extended: interface LazyNumber {
BigDecimal eval();
String getString();
} The
then you could define a function and extract the parameter string, but you have to make sure the parameter starts with a letter: Expression e = new Expression("QTY(product_id)").with("product_id", "P_23A12B");
e.addLazyFunction(e.new LazyFunction("QTY", 1) {
@Override
public LazyNumber lazyEval(List<LazyNumber> lazyParams) {
String s = lazyParams.get(0).getString();
// String s now holds "P_23A12B"
return lazyParams.get(0);
}
});
BigDecimal result = e.eval(); If you put a bit effort into the tokenizer, it should also be possible to support string literals as tokens. |
Now, my problem is solved! here my changed code: public class Expression {
} |
I am glad, this worked for you. |
Hi dear
I want to evaluate a function like this: myFunction(23A12B,H341B1), but the parser didn't recongize the whole 23A12B as a parameter!
how do i can do this?
The text was updated successfully, but these errors were encountered: