nreco / lambdaparser

Runtime parser for string expressions (formulas, method calls). Builds dynamic LINQ expression tree and compiles it to lambda delegate.
http://www.nrecosite.com/
MIT License
309 stars 55 forks source link

"Expected value" error in simple expression #39

Closed NutmegAdam closed 3 years ago

NutmegAdam commented 3 years ago

Hello,

I have been trying to figure out why a more complex expression using vars was failing, but after working it down to a simple example, I still get an unexpected failure:

var result = parser.Eval("200 / 150 >= .75", vars);
Expected value at 12: 200 / 150 >= .75

I have tried using parentheses also, to no avail. It looks from the unit tests that all of the basic operators and such that I'm using are supported (even in the more complex example), so I'm scratching my head hoping it's not something so blindingly obvious that I'm going to feel like an idiot :)

I have used this parser for more complex expressions with no issue, and the only difference in this case that I can discern is that this is a nested operation (whereby 200 / 150 needs to be evaluated, and then the result used for the comparison). But, some of the unit tests seem to indicate this is possible, for example:

Assert.Equal(true, lambdaParser.Eval(" (1+testObj.IntProp)==2 ? testObj.FldTrue : false ", varContext));

So, I'm at a loss! What have I missed?

VitaliyMF commented 3 years ago

.75 is simply not a valid value for LambdaParser. Numbers always should start with a digit, so valid number should be 0.75.

NutmegAdam commented 3 years ago

...wow, just what I was afraid of, I did miss something simple. Guess I need more coffee! Thanks very much for the quick feedback.