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

429 Add hex and binary literals and allow underscores #433

Merged
merged 1 commit into from
Apr 25, 2023

Conversation

michaelhkay
Copy link
Contributor

Addresses issue #429. The grammar is extended to allow hex and binary integer literals, and all numeric literals may contain underscores for readability.

@ndw
Copy link
Contributor

ndw commented Apr 7, 2023

👍

Copy link
Contributor

@ChristianGruen ChristianGruen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much appreciated (and no need for me to offer a pull request for this one anymore).

Thoughts:

  • Most languages seem to also support both 0X and 0B, but as X isn’t legal in character references either, I agree it’s probably better to only offer the lower-case options.
  • The new grammar does not allow integer literals to start with underscores (as _1 is a valid name test). To be consistent with other languages, maybe we should also disallow underscores at the end of Digits and the start/end of HexDigits and BinaryDigits?
    (: legal :)  0b0_1, 0x2_3, 4_5, 6_7.8_9,
  (: illegal :)  _1, 2._3, 4e_5, 6.7e_8
(: disallow? :)  0b_0, 0b1_, 0x_2, 0x3_, 4_, 5.6_, 7.8e9_

@ChristianGruen
Copy link
Contributor

Suggested grammar rules:

Digits       ::= Digit ((Digit | "_")* Digit)?
Digit        ::= [0-9]
HexDigits    ::= HexDigit ((HexDigit | "_")* HexDigit)?
HexDigit     ::= [0-9a-fA-F]
BinaryDigits ::= BinaryDigit ((BinaryDigit | "_")* BinaryDigit)?
BinaryDigit  ::= [01]

@ChristianGruen
Copy link
Contributor

Observation from Reece (QT4 CG Meeting 032):

Note that JavaScript disallows consecutive underscores, so 1_000 is valid, but 1__000 is invalid.

@ndw
Copy link
Contributor

ndw commented Apr 25, 2023

Accepted at meeting 032

@ndw ndw merged commit 7808793 into qt4cg:master Apr 25, 2023
@michaelhkay
Copy link
Contributor Author

Both Java and C# appear to allow adjacent underscores (and both prohibit terminal underscores).

@michaelhkay michaelhkay deleted the Issue429-hex-literals branch July 8, 2023 22:09
@michaelhkay michaelhkay changed the title Add hex and binary literals and allow underscores 429 Add hex and binary literals and allow underscores Mar 15, 2024
@michaelhkay michaelhkay added XPath An issue related to XPath XQuery An issue related to XQuery Enhancement A change or improvement to an existing feature Tests Added Tests have been added to the test suites Completed PR has been applied, tests written and tagged, no further action needed labels Mar 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Completed PR has been applied, tests written and tagged, no further action needed Enhancement A change or improvement to an existing feature Tests Added Tests have been added to the test suites XPath An issue related to XPath XQuery An issue related to XQuery
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants