Repository navigation
fix(cpp): highlight integer literals with digit separators in #define - #4547
Open
fguzman-stack wants to merge 1 commit into
Open
fguzman-stack wants to merge 1 commit into
fguzman-stack wants to merge 1 commit into
Conversation
C++ digit separators (e.g. 1'000'000'000) inside a preprocessor directive were swallowed by the character-literal string mode, leaving an unterminated apostrophe that treated the rest of the line as a string. Add a separator-only number rule to the PREPROCESSOR mode so these literals are highlighted and no longer break the following lines, while keeping the existing behaviour of not highlighting plain numbers in #define directives. Closes highlightjs#3928 Assisted-by: Claude Sonnet Signed-off-by: fguzman-stack <222879315+fguzman-stack@users.noreply.github.com>
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
C++ integer literals that use digit separators (e.g.
1'000'000'000) break highlighting when written inside a preprocessor directive such as#define.The
PREPROCESSORmode only listsSTRINGSin itscontains, so the'in1'000'000'000is matched by the character-literal string rule. It pairs up greedily ('0') and leaves an unterminated quote, so everything after the directive gets swallowed as ahljs-string. See #3928.Fix
Add a separator-only number rule (
PREPROCESSOR_NUMBERS) to thePREPROCESSORmode so that a numeric literal containing at least one'is consumed as anumberbeforeSTRINGScan claim it.This is deliberately narrow: plain numbers inside
#defineare still not highlighted, which preserves the existing behavior asserted by the preprocessor tests (e.g.while (0),#define foo 1<<16). It only fixes the case that was actually broken.Tests
Added
test/markup/cpp/preprocessor-numberscovering binary / hex / octal / decimal separator literals inside#define, plus following code that must stay un-swallowed.ONLY_LANGUAGES=cpp npm run test-markup-> 20 passing.preprocessor-numbersfails and the other 19 still pass (confirms it is a real regression guard).eslint --no-eslintrc -c .eslintrc.lang.js src/languages/cpp.js-> clean.Closes #3928