Skip to content

fix(cpp): highlight digit separators in defines - #4444

Draft
iamdhrv wants to merge 2 commits into
highlightjs:mainfrom
iamdhrv:agent/fix-cpp-digit-separators
Draft

fix(cpp): highlight digit separators in defines#4444
iamdhrv wants to merge 2 commits into
highlightjs:mainfrom
iamdhrv:agent/fix-cpp-digit-separators

Conversation

@iamdhrv

@iamdhrv iamdhrv commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Changes

  • run the existing C/C++ number modes before string modes inside preprocessor directives
  • add markup regressions for apostrophe digit separators in #define values
  • add the required changelog entry

This prevents literals such as 100'000 in a macro definition from treating the apostrophe as the start of a string while preserving normal preprocessor string handling.

Resolves #4443

Validation

  • npm run build
  • ONLY_LANGUAGES="c cpp" npm run test-markup (18 passed)
  • npm test (1578 passed, 3 pending)
  • ESLint on the changed C and C++ grammar files
  • git diff --check

Checklist

  • Added markup tests for both affected languages
  • Updated the changelog at CHANGES.md

Development note: implemented with Codex assistance and validated locally with the full Node.js test suite.

iamdhrv added 2 commits July 15, 2026 22:27
Signed-off-by: Dhruv Maniya <dhruvmaniya1998@gmail.com>
Signed-off-by: Dhruv Maniya <dhruvmaniya1998@gmail.com>
@github-actions

Copy link
Copy Markdown

Build Size Report

Changes to minified artifacts in /build, after gzip compression.

8 files changed

Total change +8 B

View Changes
file base pr diff
es/core.min.js 8.24 KB 8.24 KB -1 B
es/highlight.min.js 8.24 KB 8.24 KB -1 B
es/languages/arduino.min.js 4.62 KB 4.62 KB +1 B
es/languages/c.min.js 1.97 KB 1.97 KB +2 B
es/languages/cpp.min.js 2.6 KB 2.6 KB +2 B
languages/arduino.min.js 4.63 KB 4.63 KB +2 B
languages/c.min.js 1.97 KB 1.98 KB +2 B
languages/cpp.min.js 2.6 KB 2.6 KB +1 B

@joshgoebel

Copy link
Copy Markdown
Member

We either need more parsing examples or we'll need to lock this down to just #define if that's the intended scope - not all the other pre-processor directives.

@Baltsat Baltsat left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I checked the exact head (854c6ed) with the full test and lint suite. The new NUMBERS entry applies to every PREPROCESSOR, so #if, #elif, and #line now highlight separator literals too, while the fixtures still cover only #define.

There is also a continued-definition case that currently breaks in both grammars:

#define LIMIT 10'\
000

This renders 10 as a number and the remainder as a string. After phase-2 line splicing, the logical token is 10'000, so it should remain one number token.

Could you add a regression for this form and make the numeric mode survive the continuation? Please also either add examples for the intended non-#define directives or confine the behavior to #define, as requested in the earlier scope review.

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.

(C and C++) Defines treat digit separator in defines as string beginning

3 participants