From a17a70436e715bb86f1870d8e279a5a7b47415de Mon Sep 17 00:00:00 2001 From: IchorDev <15670465+ichordev@users.noreply.github.com> Date: Sat, 27 Apr 2024 17:29:34 +1000 Subject: [PATCH] [D] Separate built-in type-aliases from built-in types (#3965) This commit separates built-in type-aliases (e.g. `size_t`, `string`) from built-in types (e.g. `int`, `float`) so that their identifiers aren't treated as reserved (they aren't, e.g. you can make your own `string`), and so that they can be highlighted separately. --- D/D.sublime-syntax | 22 +++++++++++++++------- D/tests/syntax_test_d.d | 36 ++++++++++++++++++------------------ D/tests/syntax_test_old.d | 2 +- 3 files changed, 34 insertions(+), 26 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 7cb8c7ec6d..3ddf8d312b 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -60,7 +60,8 @@ variables: construction_lookahead: '(?=~?\s*this\s*\()' keyword: 'else|enum|export|extern|debug|default|delegate|delete|deprecated|do|body|break|case|cast|catch|class|const|continue|abstract|alias|align|asm|assert|auto|final|finally|for|foreach|foreach_reverse|function|goto|if|immutable|import|in|inout|interface|invariant|is|lazy|macro|mixin|module|new|nothrow|out|override|package|pragma|private|protected|public|pure|ref|return|scope|shared|static|struct|switch|synchronized|template|throw|try|typeid|typeof|union|unittest|version|while|with|__gshared|__traits|__vector|__parameters' - basic_type: 'bool|byte|cdouble|cent|cfloat|char|creal|dchar|double|float|idouble|ifloat|int|ireal|long|real|short|ubyte|ucent|uint|ulong|ushort|void|wchar|string|dstring|wstring|size_t|ptrdiff_t' + basic_type: 'bool|byte|cdouble|cent|cfloat|char|creal|dchar|double|float|idouble|ifloat|int|ireal|long|real|short|ubyte|ucent|uint|ulong|ushort|void|wchar' + builtin_type_alias: 'string|dstring|wstring|size_t|ptrdiff_t|noreturn' language_constant: 'null|true|false|__FILE__|__FILE_FULL_PATH__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__|__ctfe' language_variable: 'this|super' reserved: '{{keyword}}|{{basic_type}}|{{language_constant}}|{{language_variable}}' @@ -1243,6 +1244,9 @@ contexts: - match: '\b({{basic_type}})\b' scope: storage.type.d set: value-after + - match: '\b({{builtin_type_alias}})\b' + scope: support.type.builtin-alias.d + set: value-after - match: '\b({{name}})\s*(=>)' captures: 1: variable.parameter.d @@ -2235,15 +2239,19 @@ contexts: - match: '\b{{name}}\b(?=\s*!)' scope: meta.function-call.template.d meta.path.d variable.function.d pop: true + - match: '\b{{builtin_type_alias}}\b' + scope: meta.path.d support.type.builtin-alias.d + set: type-identifier-after - match: '\b{{name}}\b' scope: meta.path.d storage.type.d - set: - - match: \. - scope: meta.path.d punctuation.accessor.dot.d - set: type-identifier - - match: '(?=\S)' - pop: true + set: type-identifier-after - include: not-whitespace-illegal-pop + type-identifier-after: + - match: \. + scope: meta.path.d punctuation.accessor.dot.d + set: type-identifier + - match: '(?=\S)' + pop: true type-identifier-ref: - match: \. scope: meta.path.d punctuation.accessor.dot.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 036f146c6e..7c679aea3d 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -547,7 +547,7 @@ extern(1) // ^ meta.path.d variable.other.d // ^ punctuation.terminator.d string foo = import("foo.txt"); -//^^^^^^ storage.type.d +//^^^^^^ support.type.builtin-alias.d // ^^^ variable.other.d // ^ keyword.operator.assignment.d // ^^^^^^ keyword.control.import.d @@ -580,7 +580,7 @@ extern(1) // ^^^^^ storage.modifier.d // ^^^ storage.type.d // ^ punctuation.section.brackets.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.end.d // ^ punctuation.separator.sequence.d // ^^^ entity.name.type.d @@ -599,7 +599,7 @@ extern(1) // ^^^^^ storage.modifier.d // ^^^ storage.type.d // ^ punctuation.section.brackets.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.end.d // ^^^^^^^^^ entity.name.type.d // ^ punctuation.separator.sequence.d @@ -649,7 +649,7 @@ extern(1) foo[string] b = 123; //^^^ storage.type.d // ^ punctuation.section.brackets.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.end.d // ^ variable.other.d // ^ keyword.operator.assignment.d @@ -915,7 +915,7 @@ extern(1) //^^^^^ keyword.declaration.union.d // ^^^^ entity.name.union.d // ^ punctuation.section.group.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ variable.parameter.d @@ -996,7 +996,7 @@ extern(1) // ^ punctuation.separator.mapping.d // ^^^ storage.type.d // ^ punctuation.section.brackets.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d // ^^^^ entity.name.constant.d @@ -1278,7 +1278,7 @@ extern(1) int[string] foo() {} //^^^ storage.type.d // ^ punctuation.section.brackets.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.end.d // ^^^ meta.function.d entity.name.function.d // ^^ meta.function.parameters.d @@ -1381,7 +1381,7 @@ extern(1) // ^ variable.parameter.d // ^^^ keyword.operator.variadic.d // ^ punctuation.separator.sequence.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ variable.parameter.d @@ -1499,7 +1499,7 @@ extern(1) const(string) foo(T)(ref const(int) a, auto ref T b) {} //^^^^^ storage.modifier.d // ^ punctuation.section.group.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.group.end.d // ^^^ meta.function.d entity.name.function.d // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d @@ -1531,7 +1531,7 @@ extern(1) // ^ keyword.operator.comparison.d // ^^^ storage.type.d // ^ punctuation.separator.sequence.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ variable.parameter.d // ^ keyword.operator.comparison.d // ^^^ string.quoted.double.d @@ -1806,7 +1806,7 @@ extern(1) //^^^^^^^^ keyword.declaration.template.d // ^ entity.name.template.d // ^ punctuation.section.group.begin.d - // ^^^^^^ storage.type.d + // ^^^^^^ support.type.builtin-alias.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d @@ -2071,7 +2071,7 @@ extern(1) for (size_t i; !val.empty; val.popFront(), ++i) {} //^^^ keyword.control.loop.d // ^ punctuation.section.parens.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ variable.other.d // ^ punctuation.terminator.d // ^ keyword.operator.logical.d @@ -2288,7 +2288,7 @@ extern(1) // ^ punctuation.separator.sequence.d // ^^^^^ string.quoted.double.d // ^ punctuation.section.parens.end.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.begin.d // ^^ meta.number.integer.decimal.d // ^ punctuation.section.brackets.end.d @@ -2319,7 +2319,7 @@ extern(1) // ^ punctuation.separator.sequence.d // ^ meta.number.integer.decimal.d // ^ punctuation.section.parens.end.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.begin.d // ^^ meta.number.integer.decimal.d // ^ punctuation.section.brackets.end.d @@ -2536,7 +2536,7 @@ extern(1) // ^ punctuation.terminator.d string[] f = [ -//^^^^^^ storage.type.d +//^^^^^^ support.type.builtin-alias.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ variable.other.d @@ -2901,7 +2901,7 @@ extern(1) // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^^^^^^^^^^^ meta.function.d @@ -2912,7 +2912,7 @@ extern(1) function size_t(foo a) {}; //^^^^^^^^^^^^^^^ meta.function.d //^^^^^^^^ keyword.other.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d @@ -3078,7 +3078,7 @@ extern(1) // ^^^^^^^^^^^ meta.function.d entity.name.function.d // ^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^ support.type.builtin-alias.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ variable.parameter.d diff --git a/D/tests/syntax_test_old.d b/D/tests/syntax_test_old.d index 55eb1ece77..7e8e4e2b18 100644 --- a/D/tests/syntax_test_old.d +++ b/D/tests/syntax_test_old.d @@ -46,7 +46,7 @@ template testTemplate(X) { enum test = true; string g = "test"; - // ^ storage.type + // ^ support.type.builtin-alias.d } else enum test = false;