Support Hexadecimal, Octal and Binary syntax#7695
Support Hexadecimal, Octal and Binary syntax#7695shikanime wants to merge 9 commits intoNixOS:masterfrom
Conversation
| 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.
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.
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.
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 <roberth@users.noreply.github.com>
Co-authored-by: Robert Hensing <roberth@users.noreply.github.com>
|
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/**.shsrc/*/tests