0

Let's say that in my expression input I like to make functions stand out with a special prefix like $:

var expr = "Your name is $proper([firstName]) $upper([lastName])";

where I would write custom functions for $proper and $upper.

However, I get console errors "no viable alternative at character '$'". It works if I get rid of the symbol, or use an underscore.

Is there a way to use symbol characters in function names in NCalc? This also doesn't work when the function begins with a number (as in, if I wanted to shorthand the function name double as 2x).

(Sort of similar to NCalc evaluation error no viable alternative at input ',')

Community
  • 1
  • 1
drzaus
  • 24,171
  • 16
  • 142
  • 201
  • Somewhat like the syntax required by a similar parsing library ExpressionEval https://expressioneval.codeplex.com/ – drzaus Dec 05 '14 at 20:19
  • Unfortunately, this would require a change to NCalc's parser as a $ symbol cannot appear as part of a function name. You could use something like `fnProper` and `fnUpper` instead if that would help. – Chris Walsh Jan 21 '15 at 11:44
  • @ChrisWalsh I was hoping there was just some undocumented or hidden feature that let you easily enable this, but I figured that was the case. – drzaus Jan 27 '15 at 13:31
  • Personally, as a developer, I would find function names prefixed with a `$` symbol as confusing. I would probably misread it as a variable name as is used in php. Underscores are probably your closest bet as you've already worked out. – Chris Walsh Jan 27 '15 at 13:47
  • 1
    @ChrisWalsh yeah it depends on what language you're coming from -- to my developer eye I just wanted something to make a function stand out better as opposed to blending into a mathematical expression. I was also looking for more cross-compatibility with the other parsing library ExpressionEval (which does use `$` prefixes) so I can transition existing expressions. – drzaus Jan 28 '15 at 15:13

0 Answers0