-
Notifications
You must be signed in to change notification settings - Fork 150
Fix parsing to support uppercase 0X hex literals #219
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
Conversation
jserv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Run clang-format -i prior to submit.
Previously, literals with uppercase 0X prefix (e.g., "0XABC") were misparsed as invalid. This commit fixes that and improves compatibility with C99-style numeric constants. - Removed incorrect inclusion of 'x' as a hex digit in is_hex() - Updated is_numeric() to skip 0x/0X prefix when validating hex digits - Adjusted read_numeric_constant() to consistently handle both 0x and 0X prefixes
b6c708a to
49bcd8b
Compare
jserv
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consolidate the test suite to reflect the proposed changes.
|
|
||
| bool is_hex(char c) | ||
| { | ||
| return ((c >= '0' && c <= '9') || (c >= 'a' && c <= 'f') || c == 'x' || |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about adding c == 'X' to the expression instead of removing c == 'x' ?
If so, the proposed changes could be refined accordingly.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid treating 'x' or 'X' as valid hex digits, since they are part of the prefix (0x or 0X) but not valid hex characters themselves.
Add tests to verify valid and invalid forms of hex literals.
|
Thank @fourcolor for contributing! |
Previously, literals with uppercase 0X prefix (e.g., "0XABC") were misparsed as invalid. This commit fixes that and improves compatibility with C99-style numeric constants.
Summary by Bito
This pull request enhances numeric literal parsing by adding support for uppercase 0X hexadecimal prefixes, correcting previous misparsing issues. Modifications were made to the is_hex and is_numeric functions for better validation, and the read_numeric_constant function was updated for consistent handling of both prefix styles, improving C99 compatibility. New tests have been included to ensure the accuracy of these changes.