From 637b2323f6e9b8a0d08f26bcbb284c6f46c52615 Mon Sep 17 00:00:00 2001 From: James Buren Date: Sat, 23 Nov 2024 20:30:17 -0600 Subject: [PATCH 1/2] [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 | 49 +++++++++++++++++++++++++++++----- Objective-C/syntax_test_objc.m | 10 +++---- 3 files changed, 50 insertions(+), 17 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..f2102fa62c 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 */ @@ -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 */ @@ -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 */ @@ -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 */ @@ -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 */ diff --git a/Objective-C/syntax_test_objc.m b/Objective-C/syntax_test_objc.m index 9ba2514aed..4a75072468 100644 --- a/Objective-C/syntax_test_objc.m +++ b/Objective-C/syntax_test_objc.m @@ -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 */ @@ -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 */ From 39257998abb09755045cf0ebfdeaa61263b17fcb Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sun, 8 Dec 2024 15:15:07 +0100 Subject: [PATCH 2/2] [C] Adjust syntax tests --- C++/syntax_test_c.c | 2 +- Objective-C/syntax_test_objc.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/C++/syntax_test_c.c b/C++/syntax_test_c.c index f2102fa62c..de451da8fb 100644 --- a/C++/syntax_test_c.c +++ b/C++/syntax_test_c.c @@ -1174,9 +1174,9 @@ dec7 = 1234567890uLL; /* ^ punctuation.terminator - constant */ dec8 = 1'234_567'890s0f; +/* ^^^^^^^^^^^^^^^^ meta.number.integer.decimal.c */ /* ^^^^^ 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 */ diff --git a/Objective-C/syntax_test_objc.m b/Objective-C/syntax_test_objc.m index 4a75072468..a94f7ff039 100644 --- a/Objective-C/syntax_test_objc.m +++ b/Objective-C/syntax_test_objc.m @@ -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 */ /* ^^^^ invalid.illegal.numeric.suffix.c */ -/* ^^^^^^ meta.number.integer.decimal.c */ /* ^^^ constant.numeric.value.c */ /* ^^^ invalid.illegal.numeric.suffix.c */ /* ^ punctuation.terminator - constant */