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

Fix highlighting for non-decimal numbers with underscores #78

Merged
merged 2 commits into from
May 20, 2024

Conversation

smercer10
Copy link
Contributor

@smercer10 smercer10 commented May 14, 2024

Resolves #71

Made some minor changes to the match regexes for binary, octal, and hexadecimal numbers. The syntax highlighting should now be indicative of valid Gleam number formats:

  • A single underscore in the middle of a number (including between the base prefix and first digit) ✅
  • More than one contiguous underscore ❌
  • An underscore at the start or end of a number ❌

Before

image

After

image

@smercer10
Copy link
Contributor Author

smercer10 commented May 15, 2024

Is it also worth supporting numbers with uppercase base prefixes? E.g., 0B, 0O, 0X. Although the formatter automatically converts them to the lowercase variants, perhaps in the intermediate stage it's worth indicating (through highlighting) that they're valid number formats and will compile if left as is?

@PastMoments
Copy link

Is it also worth supporting numbers with uppercase base prefixes? E.g., 0B, 0O, 0X. Although the formatter automatically converts them to the lowercase variants, perhaps in the intermediate stage it's worth indicating (through highlighting) that they're valid number formats and will compile if left as is?

I think it's worth it, also because there may be workflows that run the formatter very infrequently

@smercer10
Copy link
Contributor Author

Is it also worth supporting numbers with uppercase base prefixes? E.g., 0B, 0O, 0X. Although the formatter automatically converts them to the lowercase variants, perhaps in the intermediate stage it's worth indicating (through highlighting) that they're valid number formats and will compile if left as is?

For now I've made it so that numbers with uppercase base prefixes are highlighted as valid numbers, but will happily revert if there are strong reasons against it. I think if the compiler supports it, then syntax highlighting should reflect that, even if it's not particularly idiomatic.

Before

image

After

image

Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

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

Thank you!!

@lpil lpil merged commit 5898983 into gleam-lang:main May 20, 2024
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.

LSP: Hexadecimal and Binary literals don't get highlighted if used with underscore
3 participants