From 2402ada0e823a0ef2c3df0e97f5b0f64d9db4aff Mon Sep 17 00:00:00 2001 From: zxin <15670465+ichordev@users.noreply.github.com> Date: Thu, 25 Apr 2024 17:39:02 +1000 Subject: [PATCH 1/2] [D] Add highlighting for recognised __traits/pragmas --- D/D.sublime-syntax | 31 +++++++++++++++++++++---------- D/tests/syntax_test_d.d | 16 +++++++++++++--- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 49fb20387b..5ca4ddf505 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -65,6 +65,9 @@ variables: language_variable: 'this|super' reserved: '{{keyword}}|{{basic_type}}|{{language_constant}}|{{language_variable}}' + traits: 'isAbstractClass|isArithmetic|isAssociativeArray|isFinalClass|isPOD|isNested|isFuture|isDeprecated|isFloating|isIntegral|isScalar|isStaticArray|isUnsigned|isDisabled|isVirtualFunction|isVirtualMethod|isAbstractFunction|isFinalFunction|isStaticFunction|isOverrideFunction|isTemplate|isRef|isOut|isLazy|isReturnOnStack|isCopyable|isZeroInit|isModule|isPackage|hasMember|hasCopyConstructor|hasPostblit|identifier|getAliasThis|getAttributes|getFunctionAttributes|getFunctionVariadicStyle|getLinkage|getLocation|getMember|getOverloads|getParameterStorageClasses|getPointerBitmap|getCppNamespaces|getVisibility|getProtection|getTargetInfo|getVirtualFunctions|getVirtualMethods|getUnitTests|parent|child|classInstanceSize|classInstanceAlignment|getVirtualIndex|allMembers|derivedMembers|isSame|compiles|toType|initSymbol|parameters' + pragmas: 'crt_constructor|crt_destructor|inline|lib|linkerDirective|mangle|msg|printf|scanf|startaddress|LDC_alloca|LDC_allow_inline|LDC_extern_weak|LDC_global_crt_ctor|LDC_global_crt_dtor|LDC_inline_ir|LDC_intrinsic|LDC_never_inline|LDC_no_moduleinfo|LDC_no_typeinfo|LDC_va_start|LDC_va_arg|LDC_va_end|LDC_va_copy' + operator_overloads: 'opNeg|opCom|opPostInc|opPostDec|opCast|opAdd|opSub|opSub_r|opMul|opDiv|opDiv_r|opMod|opMod_r|opAnd|opOr|opXor|opShl|opShl_r|opShr|opShr_r|opUShr|opUShr_r|opCat|opCat_r|opEquals|opEquals|opCmp|opCmp|opCmp|opCmp|opAddAssign|opSubAssign|opMulAssign|opDivAssign|opModAssign|opAndAssign|opOrAssign|opXorAssign|opShlAssign|opShrAssign|opUShrAssign|opCatAssign|opIndex|opIndexAssign|opCall|opSlice|opSliceAssign|opPos|opAdd_r|opMul_r|opAnd_r|opOr_r|opXor_r' block_statement_loohahead: '(?={)' @@ -697,16 +700,20 @@ contexts: scope: punctuation.section.parens.end.d pop: true pragma-attribute: + - match: '\b({{pragmas}})\b' + scope: variable.function.d constant.other.d + set: pragma-in - match: '\b({{name}})\b' scope: variable.function.d - set: - - match: '\)' - scope: punctuation.section.parens.end.d - pop: true - - match: ',' - scope: punctuation.separator.sequence.d - set: [pragma-attribute-after, value-list] - - include: not-whitespace-illegal-pop + set: pragma-in + - include: not-whitespace-illegal-pop + pragma-in: + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true + - match: ',' + scope: punctuation.separator.sequence.d + set: [pragma-attribute-after, value-list] - include: not-whitespace-illegal-pop pragma-attribute-after: - match: '\)' @@ -1191,12 +1198,16 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: - - match: '\b{{name}}\b' - scope: variable.function.d + - match: '\b({{traits}})\b' + scope: variable.function.d constant.other.d set: - match: ',' scope: punctuation.separator.sequence.d set: [value-parens-after, value-list] + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true + - include: not-whitespace-illegal-pop - match: '\b(function|delegate)\b' scope: meta.function.d keyword.other.d set: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 184de94615..9dc25c0bdb 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -505,6 +505,16 @@ extern(1) // ^^^^ variable.function.d // ^^^^ storage.type.d // ^ punctuation.section.parens.end.d + pragma(inline) pragma(mangle, "main"): +//^^^^^^ keyword.other.pragma.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^ variable.function.d +// ^ punctuation.section.parens.end.d +// ^^^^^^ keyword.other.pragma.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^ variable.function.d constant.other.d +// ^^^^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d private: //^^^^^^^ storage.modifier.access-control.d // ^ punctuation.separator.d @@ -2897,10 +2907,10 @@ extern(1) __traits(foo, a); //^^^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d -// ^^^ variable.function.d +// ^^^ invalid.illegal.d // ^ punctuation.separator.sequence.d // ^ meta.path.d variable.other.d -// ^ punctuation.section.parens.end.d +// ^ invalid.illegal.d // ^ punctuation.terminator.d values ~= toValue(__traits(getMember, this, primaryKey)); //^^^^^^ meta.path.d variable.other.d @@ -2910,7 +2920,7 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^^^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d -// ^^^^^^^^^ variable.function.d +// ^^^^^^^^^ variable.function.d constant.other.d // ^ punctuation.separator.sequence.d // ^^^^ variable.language.d // ^ punctuation.separator.sequence.d From 61fe2301d09e709e3972b05bbe83340efee4282d Mon Sep 17 00:00:00 2001 From: zxin <15670465+ichordev@users.noreply.github.com> Date: Sat, 27 Apr 2024 01:25:23 +1000 Subject: [PATCH 2/2] [D] Remove variable.function.d from traits keywords/pragma identifiers --- D/D.sublime-syntax | 4 ++-- D/tests/syntax_test_d.d | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 5ca4ddf505..98adf67ac4 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -701,7 +701,7 @@ contexts: pop: true pragma-attribute: - match: '\b({{pragmas}})\b' - scope: variable.function.d constant.other.d + scope: constant.other.d set: pragma-in - match: '\b({{name}})\b' scope: variable.function.d @@ -1199,7 +1199,7 @@ contexts: scope: punctuation.section.parens.begin.d set: - match: '\b({{traits}})\b' - scope: variable.function.d constant.other.d + scope: constant.other.d set: - match: ',' scope: punctuation.separator.sequence.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 9dc25c0bdb..575057499c 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -508,11 +508,11 @@ extern(1) pragma(inline) pragma(mangle, "main"): //^^^^^^ keyword.other.pragma.d // ^ punctuation.section.parens.begin.d -// ^^^^^^ variable.function.d +// ^^^^^^ constant.other.d // ^ punctuation.section.parens.end.d // ^^^^^^ keyword.other.pragma.d // ^ punctuation.section.parens.begin.d -// ^^^^^^ variable.function.d constant.other.d +// ^^^^^^ constant.other.d // ^^^^^^ string.quoted.double.d // ^ punctuation.section.parens.end.d private: @@ -2920,7 +2920,7 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^^^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d -// ^^^^^^^^^ variable.function.d constant.other.d +// ^^^^^^^^^ constant.other.d // ^ punctuation.separator.sequence.d // ^^^^ variable.language.d // ^ punctuation.separator.sequence.d