Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added hex numbers support #28

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

michalf1
Copy link

No description provided.

@VitaliyMF
Copy link
Contributor

VitaliyMF commented Jun 26, 2020

This PR cannot be accepted:

  • existing tests are not passed, no tests for expressions with hex-numbers
  • this code can lead to 'index-out-of-range': if (s[lexem.End] == '0' && s[lexem.End + 1] == 'x') {
  • motivation to have hex-numbers in expressions is not explained. Hex constants are not typical, and when they are needed it is easier to provide custom function in the evaluation context to parse them, something like this:
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));

Michal added 2 commits June 26, 2020 22:09
Added tests for hex numbers
@michalf1
Copy link
Author

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ł

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

Successfully merging this pull request may close these issues.

None yet

2 participants