-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
fixed hex decimals on C #4094
fixed hex decimals on C #4094
Conversation
src/languages/c.js
Outdated
], | ||
relevance: 0 | ||
}; | ||
const 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.
Tabbing/spacing here should not have changed...
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 have fixed the indentation in the new commits
Also we really should have some tests here to validate both the old behavior and confirm the new behavior. Could we perhaps pull over the |
@joshgoebel i have also come up with a new test and expect files for number literals in C since all C++ number literals cannot be directly ported over due to c(gcc) not having digit seprators |
i have also noticed some keywords in the C keywords file that dont belong there for e.g -'auto' these work in c++ and not c. |
Please make sure your knowledge is 100% up-to-date before offering to start removing keywords. |
More tests would be welcome, but I don't think we need a separate issue for "add more tests to C"... but perhaps a meta-issue could be good - it would just be a placeholder for all grammars tagged with "good for beginners". Many grammars could use additional tests. |
src/languages/c.js
Outdated
{ begin: '\\b(0b[01\']+)' }, | ||
{ begin: '(-?)\\b([\\d\']+(\\.[\\d\']*)?|\\.[\\d\']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)' }, | ||
{ begin: '(-?)(0[xX][a-fA-F0-9]+(?:\'[a-fA-F0-9]+)*(?:\\.[a-fA-F0-9]*(?:\'[a-fA-F0-9]*)*)?(?:[pP][-+]?[0-9]+)?)' }, | ||
{ begin: '(-?)\\b\\d+(?:\'\\d+)*(?:\\.\\d*(?:\'\\d*)*)?(?:[eE][-+]?\\d+)?' } |
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.
Now if we could please just switch to match
vs begin
and literal regex: /.../
(vs strings)... then this is good to go I think. I'm also happy to do this cleanup myself, just might be a little while.
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.
@joshgoebel i've changed the match to begin , i also managed to correct for a issue in detecting hex longs that went previously undetected.
please review if any changes are needed
src/languages/c.js
Outdated
], | ||
{ match: /\b(0b[01']+)/ }, | ||
{ match: /(-?)\b([\d']+(\.[\d']*)?|\.[\d']+)((ll|LL|l|L)(u|U)?|(u|U)(ll|LL|l|L)?|f|F|b|B)/ }, | ||
{ match: /(-?)(0[xX][a-fA-F0-9]+(?:'[a-fA-F0-9]+)*(?:\.[a-fA-F0-9]*(?:'[a-fA-F0-9]*)*)?(?:[pP][-+]?[0-9]+)?(l|L)?(u|U)?)/ }, |
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.
Do we want need \b
here also?
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 did see a redundant \b and ive removed it
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 thought these were needed to prevent false positives... like say g2324
where the 234
would be identified as a number without the \b
, no?
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.
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.
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.
should i add \b
Yep. I think we need it.
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.
@joshgoebel ive fixed the false positive issue please review changes
add \b for last NUMBERS regex
Build Size ReportChanges to minified artifacts in 3 files changedTotal change +86 B View Changes
|
Resolves #4065
Changes
Changed the regex for hex numbers to accomdate decimal numbers
(first pr pls be nice 😁😁)
(https://github.com/highlightjs/highlight.js/issues/4065)
Checklist
Checklist