Skip to content

Commit

Permalink
[C] Apply same digit separators for C/C++ (#4101)
Browse files Browse the repository at this point in the history
C23 added this feature previously available in C++. This should
close #3972 as well as both C and C++ now have syntax support for
the ' digit separator.

This was implemented by just copying the digit variables from the
C++ syntax file as it is the same construct in the end. The existing
tests were updated to fix the part of the existing tests were broken
by this new feature.

Furthermore, some tests from C++ were adapted for C to add better
testing for the new digit seperator. I also included tests for the
newer base 2 integer contants. The C file did not have any tests for
that yet.

Co-authored-by: deathaxe <[email protected]>
  • Loading branch information
braewoods and deathaxe authored Dec 9, 2024
1 parent 3b59164 commit 52c3ca9
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 19 deletions.
8 changes: 4 additions & 4 deletions C++/C.sublime-syntax
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ first_line_match: |-
variables:
# number digits
bin_digit: '[01]'
oct_digit: '[0-7]'
dec_digit: '\d'
hex_digit: '\h'
bin_digit: '[01'']'
oct_digit: '[0-7'']'
dec_digit: '[\d'']'
hex_digit: '[\h'']'

# number exponents
dec_exponent: '(?:[eE][-+]?{{dec_digit}}*)'
Expand Down
51 changes: 43 additions & 8 deletions C++/syntax_test_c.c
Original file line number Diff line number Diff line change
Expand Up @@ -1133,6 +1133,7 @@ static const unsigned char image_png[] = {
dec0 = 0;
/* ^ meta.number.integer.decimal.c constant.numeric.value.c */
/* ^ punctuation.terminator - constant */

dec1 = 1234567890;
/* ^^^^^^^^^^ meta.number.integer.decimal.c constant.numeric.value.c */
/* ^ punctuation.terminator - constant */
Expand Down Expand Up @@ -1173,13 +1174,19 @@ dec7 = 1234567890uLL;
/* ^ punctuation.terminator - constant */

dec8 = 1'234_567'890s0f;
/* ^ meta.number.integer.decimal.c constant.numeric.value.c */
/* ^^^^^^^^^ string.quoted.single */
/* ^^^^^^ meta.number.integer.decimal.c */
/* ^^^^^^^^^^^^^^^^ meta.number.integer.decimal.c */
/* ^^^^^ constant.numeric.value.c */
/* ^^^^ invalid.illegal.numeric.suffix.c */
/* ^^^ constant.numeric.value.c */
/* ^^^ invalid.illegal.numeric.suffix.c */
/* ^ punctuation.terminator - constant */

dec9 = 2'354'202'076LL;
/* ^^^^^^^^^^^^^^^ meta.number.integer.decimal.c */
/* ^^^^^^^^^^^^^ constant.numeric.value.c */
/* ^^ constant.numeric.suffix.c */
/* ^ punctuation.terminator - constant */

oct1 = 01234567;
/* ^^^^^^^^ meta.number.integer.octal.c */
/* ^ constant.numeric.base.c */
Expand Down Expand Up @@ -1207,13 +1214,19 @@ oct4 = 01234567ulL;
/* ^^^ constant.numeric.suffix.c */
/* ^ punctuation.terminator - constant */

oct2 = 01284967Z0L;
oct5 = 01284967Z0L;
/* ^^^^^^^^^^^ meta.number.integer.octal.c */
/* ^ constant.numeric.base.c */
/* ^^ constant.numeric.value.c */
/* ^^^^^^^^ invalid.illegal.numeric.suffix.c */
/* ^ punctuation.terminator - constant */

oct6 = 014'70;
/* ^^^^^^ meta.number.integer.octal.c */
/* ^ constant.numeric.base.c */
/* ^^^^^ constant.numeric.value.c */
/* ^ punctuation.terminator - constant */

hex1 = 0x0+0xFL+0xaull+0xallu+0xfu+0x'f'12_4uz;
/* ^^^ meta.number.integer.hexadecimal.c */
/* ^^ constant.numeric.base.c */
Expand All @@ -1234,11 +1247,9 @@ hex1 = 0x0+0xFL+0xaull+0xallu+0xfu+0x'f'12_4uz;
/* ^^ constant.numeric.base.c */
/* ^ constant.numeric.value.c */
/* ^ constant.numeric.suffix.c */
/* ^^ meta.number.integer.hexadecimal.c */
/* ^^^^^^^ meta.number.integer.hexadecimal.c */
/* ^^ constant.numeric.base.c */
/* ^^^ string.quoted.single.c */
/* ^^^^^^ meta.number.integer.decimal.c */
/* ^^ constant.numeric.value.c */
/* ^^^^^ constant.numeric.value.c */
/* ^^^^ invalid.illegal.numeric.suffix.c */
/* ^ punctuation.terminator - constant */

Expand All @@ -1255,6 +1266,30 @@ hex2 = 0xc1.01AbFp-1+0x1.45c778p+7f;
/* ^ constant.numeric.suffix.c */
/* ^ punctuation.terminator - constant */

hex3 = 0xA7'45'8C'38;
/* ^^^^^^^^^^^^^ meta.number.integer.hexadecimal.c */
/* ^^ constant.numeric.base.c */
/* ^^^^^^^^^^^ constant.numeric.value.c */
/* ^ punctuation.terminator - constant */

bin1 = 0b010110;
/* ^^^^^^^^ meta.number.integer.binary */
/* ^^ constant.numeric.base */
/* ^^^^^^ constant.numeric.value */
/* ^ punctuation.terminator - constant */

bin2 = 0B010010;
/* ^^^^^^^^ meta.number.integer.binary */
/* ^^ constant.numeric.base */
/* ^^^^^^ constant.numeric.value */
/* ^ punctuation.terminator - constant */

bin3 = 0b1001'1101'0010'1100;
/* ^^^^^^^^^^^^^^^^^^^^^ meta.number.integer.binary */
/* ^^ constant.numeric.base */
/* ^^^^^^^^^^^^^^^^^^^ constant.numeric.value */
/* ^ punctuation.terminator - constant */

f = 1.1+1.1e1+1.1e-1+1.1f+1.1e1f+1.1e-1f+1.1L+1.1e1L+1.1e-1L;
/* ^^^ meta.number.float.decimal.c */
/* ^^^ constant.numeric.value.c */
Expand Down
12 changes: 5 additions & 7 deletions Objective-C/syntax_test_objc.m
Original file line number Diff line number Diff line change
Expand Up @@ -920,9 +920,9 @@ - (void)debugOutput:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2)
/* ^ punctuation.terminator - constant */
dec8 = 1'234_567'890s0f;
/* ^ meta.number.integer.decimal.c constant.numeric.value.c */
/* ^^^^^^^^^ string.quoted.single */
/* ^^^^^^ meta.number.integer.decimal.c */
/* ^^^^^^^^^^^^^^^^ meta.number.integer.decimal.c */
/* ^^^^^ constant.numeric.value.c */
/* ^^^^ invalid.illegal.numeric.suffix.c */
/* ^^^ constant.numeric.value.c */
/* ^^^ invalid.illegal.numeric.suffix.c */
/* ^ punctuation.terminator - constant */
Expand Down Expand Up @@ -981,11 +981,9 @@ - (void)debugOutput:(NSString *)format, ... NS_FORMAT_FUNCTION(1,2)
/* ^^ constant.numeric.base.c */
/* ^ constant.numeric.value.c */
/* ^ constant.numeric.suffix.c */
/* ^^ meta.number.integer.hexadecimal.c */
/* ^^^^^^^ meta.number.integer.hexadecimal.c */
/* ^^ constant.numeric.base.c */
/* ^^^ string.quoted.single.c */
/* ^^^^^^ meta.number.integer.decimal.c */
/* ^^ constant.numeric.value.c */
/* ^^^^^ constant.numeric.value.c */
/* ^^^^ invalid.illegal.numeric.suffix.c */
/* ^ punctuation.terminator - constant */
Expand Down

0 comments on commit 52c3ca9

Please sign in to comment.