Skip to content

Commit

Permalink
[C] Add digit separator like is already implemented for C++
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.
  • Loading branch information
James Buren committed Nov 29, 2024
1 parent 9f08e35 commit 6cd133b
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 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
49 changes: 42 additions & 7 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 */
/* ^^^^^ constant.numeric.value.c */
/* ^^^^ invalid.illegal.numeric.suffix.c */
/* ^^^^^^ meta.number.integer.decimal.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
10 changes: 4 additions & 6 deletions Objective-C/syntax_test_objc.m
Original file line number Diff line number Diff line change
Expand Up @@ -920,8 +920,8 @@ - (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 */
/* ^^^^^ constant.numeric.value.c */
/* ^^^^ invalid.illegal.numeric.suffix.c */
/* ^^^^^^ meta.number.integer.decimal.c */
/* ^^^ constant.numeric.value.c */
/* ^^^ invalid.illegal.numeric.suffix.c */
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 6cd133b

Please sign in to comment.