-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
enh(haskell) BinaryLiterals, NumericUnderscores, HexFloatLiterals #3150
Merged
joshgoebel
merged 5 commits into
highlightjs:main
from
martijnbastiaan:haskell-numerical-underscores
Apr 20, 2021
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e2151e3
enh(haskell) Add support for BinaryLiterals
martijnbastiaan c55ad76
enh(haskell) Add support for NumericUnderscores
martijnbastiaan 29479c1
enh(haskell) Restucture Haskell number parsing
martijnbastiaan 6277cf4
Update CHANGES.md
joshgoebel 5fbd326
Merge branch 'main' into haskell-numerical-underscores
joshgoebel File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<span class="hljs-number">0b001_001</span> | ||
<span class="hljs-number">0x000_0FF</span> | ||
<span class="hljs-number">132_15</span> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
0b001_001 | ||
0x000_0FF | ||
132_15 |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally we do not match
-
since it could often by unary or binary and we do not try and figure out such distinctions. (very hard to do also without look-behind)Also please add additional tests for some of the
e
variants, etc.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there two variants here? (hex and regular?) It seems so. Please split them out into
variants
for readability and maintenance rather than using a more complex single regex. See many other grammars for examples.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah right, I just copied it from
C_NUMBER_MODE
. I'll make a few tests though :-)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, if it's exactly the same it of course shouldn't need to be copied at all... but if it's now specific to this language then we should clean it up into variants for future use - which is just the general policy on such things.
I'd suggest we could perhaps clean up
C_NUMBER_MODE
as well but too many grammars are likely dependent on it being exactly how it is now - but that doesn't mean we can't have nicer and easy to read matches in the individual grammars. :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll add such thoughts to the v12 list. v11 is already big enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah let me clarify a bit: I copied it and then added
|_
to optionally match the underscores.I'm a bit fuzzy on what you want me to do; should I just make a clean version for Haskell numbers?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See https://github.com/highlightjs/highlight.js/blob/main/src/languages/swift.js#L121 for an example.
When we start adding custom numeric rules to grammars then we always do it as nicely as possible (for future readability and maintenance). That means separate
variants
for hex, binary, etc... (as you see in Swift) not just one large regex with multiple rules "hidden" inside.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Excellent. I'll get to it tonight. Thanks for the quick responses :)