ExpressionEvaluator icon indicating copy to clipboard operation
ExpressionEvaluator copied to clipboard

Escaping variable names

Open cantacuzene opened this issue 5 years ago • 3 comments

Hi Seb! First of all I'd like to say this library is quite a marvel compared to the alternatives we have in the dotnet world!. Keep up the good work!!

This is not an issue per say, but i'm wondering if there is a way to escape the variables names in expressions.

The goal here would be to allow hyphen-case variables to be properly identified by the parser for example i'd like to be able to evaluate expressions like this :

var exp = "net-pv / Total::net-pv"

where net-pv and Total::net-pv are both variables.

If the functionality does not exist , a quick win might be to use string literals to help distinguish variable names in the expression

var exp = $"{net-pv}/{Total::net-pv}"

cantacuzene avatar Jul 22 '20 12:07 cantacuzene

Hello @cantacuzene. I am sorry it's hard for me to give fast answer for now because I am in vacations and I only have my smartphone. I don't know if I fully understand your question but the answer is that there is no integrated solution to escape variables. But by inheritance you could define your own syntax for this by modifying the parsing process. For a first example for your case look here

You can find some documentation on the wiki Here

An other way to do it could be with "on the fly" function. Something like getVar(net-pv) For the doc look here.

codingseb avatar Jul 23 '20 22:07 codingseb

Hi @codingseb this was exactly what I was looking for. I guess I should have digged further into the manual, I totally missed this parsing customization section ... I am not a big fan of inheritence but it'll work just fine :) Thanks a lot for your reply!

cantacuzene avatar Aug 06 '20 14:08 cantacuzene

I reopen this because it could be useful for others.

codingseb avatar Jan 04 '21 19:01 codingseb