-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Support Hexadecimal, Octal and Binary syntax #7695
base: master
Are you sure you want to change the base?
Conversation
@@ -113,6 +113,9 @@ static StringToken unescapeStr(SymbolTable & symbols, char * s, size_t length) | |||
ANY .|\n | |||
ID [a-zA-Z\_][a-zA-Z0-9\_\'\-]* | |||
INT [0-9]+ | |||
BIN 0b[01]+ | |||
OCT 0o[0-7]+ |
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 suggest to change INT
to [1-9][0-9]*
and OCT
to 0[0-7]*
, so octal numbers start with 0 which is IMHO more common. On the other hand, this would break padding with leading zeros, but this looks better with spaces anyway IMHO. This would make 0 an octal 0, but it is still zero. The letter o is quite similar to 0, so 0o77
and 0077
look very similar and one might expect them to be both octal values, so at least add 0[0-7]+
as an alternative to 0o[0-7]+
.
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 don't think we should break 010 == 10
, as Nix is meant to be a very stable language. It does seem like a good idea to warn about zero-padded integers, as the existence of octal support makes them quite ambiguous.
Aesthetics are of secondary importance, and explicit is good.
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.
We should definitely deprecate 010 == 10
, as numbers starting with 0
are usually read as octals for historic reasons. Perhaps a warning like »Deprecated syntax: If you intended to zero-pad a decimal value, consider to use spaces instead. If you meant to write an octal value, write 0o<value>
. Values starting with 0
are ambiguous.«.
Another issue: Binary values tend to be quite long, so like in python, allowing _
to group e.g. bytes might be beneficial for readability, for decimals (e.g. multiple of 1000) or hexadecimals (e.g. words/dwords) and perhaps for floating point literals as well.
Co-authored-by: Robert Hensing <[email protected]>
Co-authored-by: Robert Hensing <[email protected]>
I think we can potentially unblock this PR by running an experiment:
I think this should be discussed with the Nix team. Click for possible future steps (not necessary to discuss yet; overly detailed)Follow-up steps:
|
Triaged in the Nix team meeting:
|
This pull request has been mentioned on NixOS Discourse. There might be relevant details there: https://discourse.nixos.org/t/2023-02-24-nix-team-meeting-minutes-35/25757/1 |
Any update about this? |
Motivation
Add support for integer literal syntax such as
Context
fixes #7578
I don't know where to write the tests for the parser/lexer, feel free to comment on this!
Checklist for maintainers
Maintainers: tick if completed or explain if not relevant
tests/**.sh
src/*/tests