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

Support integer literals of different radices and decimal numeric literals #199

Merged

Conversation

chengluyu
Copy link
Member

@chengluyu chengluyu commented Dec 30, 2023

This PR adds the support for various literals.

  • Hexadecimal integer literals: 0xCAFE, etc.
  • Octal integer literals: 0o4567, etc.
  • Binary integer literals: 0b0010, etc.
  • Decimal numeric literals in floating-point style: 1e100, 3.141592653589793, etc.
  • Support separators to be interleaved in all digits: 0x0010_1101, 12_34.56_78E+9_0, etc.
  • Lastly, the support for string escapes \\, \b, and \f. (I forgot this so it's not indicated by my commit messages. 🤦‍♂️)

Note

This PR does not support numeric literals starting with decimal points, for example, .5, because it conflicts with selecting tuple indices. We can check the accumulated tokens to determine the meaning of tokens such as .1, but I don't have time to summarize various situations and add tests right now, so I will leave it for future work.

@chengluyu chengluyu changed the title Support hex, octal, and binary integers Support integer literals of different radices and decimal numeric literals Dec 30, 2023
@chengluyu
Copy link
Member Author

6182f20 failed for some reasons. Strange.

@NeilKleistGao
Copy link
Member

6182f20 failed for some reasons. Strange.

Random-happened time-out problem lol.

Copy link
Contributor

@LPTK LPTK left a comment

Choose a reason for hiding this comment

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

LGTM besides @NeilKleistGao's comment.

shared/src/main/scala/mlscript/NewLexer.scala Outdated Show resolved Hide resolved
shared/src/main/scala/mlscript/NewLexer.scala Outdated Show resolved Hide resolved
shared/src/main/scala/mlscript/NewLexer.scala Outdated Show resolved Hide resolved
@LPTK LPTK merged commit f121cd0 into hkust-taco:new-definition-typing Jan 1, 2024
1 check passed
@LPTK LPTK deleted the lexer/numeric-literals branch January 1, 2024 14:57
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.

3 participants