Skip to content
This repository has been archived by the owner on Jun 10, 2024. It is now read-only.

Unable to parse expression strings that have multiple # #6

Closed
jobanputra opened this issue Dec 29, 2020 · 3 comments
Closed

Unable to parse expression strings that have multiple # #6

jobanputra opened this issue Dec 29, 2020 · 3 comments

Comments

@jobanputra
Copy link

jobanputra commented Dec 29, 2020

When the expression contains multiple # characters, the Expression constructor throws the following exception: "String '' was not recognized as a valid DateTime."

For example the expression that I am trying to parse is

Format("{0:(###) ###-####}", "9999999999")

Update: I understand that NCalc uses sharps (#) to delimit date. However # is a custom string specifier in the .NET framework.

@petli
Copy link
Contributor

petli commented Jan 7, 2021

Try this instead:

Format('{0:(###) ###-####}', '9999999999')

The NCalc expression syntax uses ' instead of " to represent strings (see https://github.com/ncalc/ncalc/wiki/Values).

You should've gotten a syntax error from the " rather than it continuing to the #, though. I think it looks like the lexer is configured to recover rather than immediately throwing an error, I'll look further into that.

@petli
Copy link
Contributor

petli commented Jan 7, 2021

Fix for the missing syntax error exception is included in this version: https://www.nuget.org/packages/NCalcAsync/2.1.5

@petli
Copy link
Contributor

petli commented Jan 7, 2021

Thanks for reporting this! It was a pretty deep bug in the expresison parser which have probably frustrated others over the years NCalc have existed.

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

No branches or pull requests

2 participants