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

Add support for changes to number literals introduced in Go 1.13 #32

Merged
merged 1 commit into from
Sep 16, 2019

Conversation

tohjustin
Copy link
Contributor

Requirements

The updated grammar should support syntax highlighting for the following:

  • Binary integer literals: The prefix 0b or 0B indicates a binary integer literal such as 0b1011.
  • Octal integer literals: The prefix 0o or 0O indicates an octal integer literal such as 0o660. The existing octal notation indicated by a leading 0 followed by octal digits remains valid.
  • Hexadecimal floating point literals The prefix 0x or 0X may now be used to express the mantissa of a floating-point number in hexadecimal format such as 0x1.0p-1021. A hexadecimal floating-point number must always have an exponent, written as the letter p or P followed by an exponent in decimal. The exponent scales the mantissa by 2 to the power of the exponent.
  • Imaginary literals: The imaginary suffix i may now be used with any (binary, decimal, hexadecimal) integer or floating-point literal.
  • Digit separators: The digits of any number literal may now be separated (grouped) using underscores, such as in 1_000_000, 0b_1010_0110, or 3.1415_9265. An underscore may appear between any two digits or the literal prefix and the first digit.

(taken from Go 1.13 Release Notes)

Description of the Change

All the tree-sitter grammar are manually converted from the EBNF (Extended Backus-Naur Form) expressions for each number literal type found in The Go Programming Language Specification:

All new test cases added to corpus/expressions.txt are obtained from examples in The Go Programming Language Specification

Playground containing code snippet to test with: https://play.golang.org/p/IuWyvmHjHs0

Alternate Designs

N/A

Benefits

N/A

Possible Drawbacks

N/A

Applicable Issues

Fixes #31
Related atom/language-go#174 (PR: atom/language-go#175)

@maxbrunsfeld
Copy link
Contributor

@tohjustin This is very nice. Thank you very much!

@maxbrunsfeld maxbrunsfeld merged commit 4d27a8a into tree-sitter:master Sep 16, 2019
@tohjustin
Copy link
Contributor Author

Thanks! Glad I could help :)

@tohjustin tohjustin deleted the issue-31 branch September 16, 2019 16:30
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.

Add support for binary integer literal
2 participants