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

Added hex numbers support #28

Open michalf1 opened 4 years ago

VitaliyMF commented 4 years ago

This PR cannot be accepted:

varContext["ParseInt32"] = (Func<string,int>)((s) => {
  int numConst;
  if (!Int32.TryParse(lexem.GetValue(), NumberStyles.HexNumber, CultureInfo.InvariantCulture, out numConst)) {
    throw new Exception(String.Format("Invalid number: {0}", lexem.GetValue()));
  }
});
Console.WriteLine(lambdaParser.Eval("ParseInt(\"0xFF\")", varContext));
michalf1 commented 4 years ago

Hello Vitaliy, I don't agree that hex constants are not typical (I use them quite often). In my opinion the parser is incomplete without that functionality. Anyway I made some fixes and tests - now it's passing all tests. Br, Michał