From c7c977a80f86baf2977ece3ee61ef66312edc676 Mon Sep 17 00:00:00 2001 From: James Buren Date: Sat, 23 Nov 2024 20:30:17 -0600 Subject: [PATCH] [C] Add digit separator like is already implemented for C++ 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. --- C++/C.sublime-syntax | 8 ++++---- C++/syntax_test_c.c | 45 +++++++++++++++++++++++++++++++++++++++----- 2 files changed, 44 insertions(+), 9 deletions(-) diff --git a/C++/C.sublime-syntax b/C++/C.sublime-syntax index 4d60c3468b..779b35d7b7 100644 --- a/C++/C.sublime-syntax +++ b/C++/C.sublime-syntax @@ -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}}*)' diff --git a/C++/syntax_test_c.c b/C++/syntax_test_c.c index a419c38071..a34072aa56 100644 --- a/C++/syntax_test_c.c +++ b/C++/syntax_test_c.c @@ -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 */ @@ -1174,12 +1175,18 @@ dec7 = 1234567890uLL; dec8 = 1'234_567'890s0f; /* ^ meta.number.integer.decimal.c constant.numeric.value.c */ -/* ^^^^^^^^^ string.quoted.single */ +/* ^^^^ 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 */ @@ -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 */ @@ -1236,9 +1249,7 @@ hex1 = 0x0+0xFL+0xaull+0xallu+0xfu+0x'f'12_4uz; /* ^ constant.numeric.suffix.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 */ @@ -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 */