From 162671c9789d7d04225da777b05c7cf9e0249aec Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 16 Jan 2019 11:12:45 +1100 Subject: [PATCH 001/108] Fix D doc comments --- D/Comments.tmPreferences | 78 +++++++++++++++++++++++++++++++++++----- 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/D/Comments.tmPreferences b/D/Comments.tmPreferences index c59ed6a974..8d4c87de81 100644 --- a/D/Comments.tmPreferences +++ b/D/Comments.tmPreferences @@ -13,31 +13,31 @@ name TM_COMMENT_START value - /* + // name - TM_COMMENT_END + TM_COMMENT_START_2 value - */ + /* name - TM_COMMENT_MODE + TM_COMMENT_END_2 value - block + */ name - TM_COMMENT_DISABLE_INDENT + TM_COMMENT_MODE_2 value - yes + block name - TM_COMMENT_START_2 + TM_COMMENT_DISABLE_INDENT_2 value - // + yes name @@ -57,6 +57,66 @@ value block + + name + TM_COMMENT_DISABLE_INDENT_3 + value + yes + + + name + TM_COMMENT_START_4 + value + /// + + + name + TM_COMMENT_START_5 + value + /** + + + name + TM_COMMENT_END_5 + value + */ + + + name + TM_COMMENT_MODE_5 + value + block + + + name + TM_COMMENT_DISABLE_INDENT_5 + value + yes + + + name + TM_COMMENT_START_6 + value + /++ + + + name + TM_COMMENT_END_6 + value + +/ + + + name + TM_COMMENT_MODE_6 + value + block + + + name + TM_COMMENT_DISABLE_INDENT_6 + value + yes + From 23299b9364bfefb31584c5400ff8d00414fc0120 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 16 Jan 2019 12:19:01 +1100 Subject: [PATCH 002/108] Fix spacing in D snippets --- D/Snippets/foreach-reverse.sublime-snippet | 4 ++-- D/Snippets/foreach.sublime-snippet | 2 +- D/Snippets/if-else.sublime-snippet | 2 +- D/Snippets/if.sublime-snippet | 2 +- D/Snippets/version.sublime-snippet | 2 +- D/Snippets/while.sublime-snippet | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/D/Snippets/foreach-reverse.sublime-snippet b/D/Snippets/foreach-reverse.sublime-snippet index 2d48423718..39688ed07d 100644 --- a/D/Snippets/foreach-reverse.sublime-snippet +++ b/D/Snippets/foreach-reverse.sublime-snippet @@ -1,9 +1,9 @@ - fer source.d - foreach_reverse(…; …) { … } + foreach_reverse (…; …) { … } diff --git a/D/Snippets/foreach.sublime-snippet b/D/Snippets/foreach.sublime-snippet index 50ba615a41..dbadab50c0 100644 --- a/D/Snippets/foreach.sublime-snippet +++ b/D/Snippets/foreach.sublime-snippet @@ -1,5 +1,5 @@ - diff --git a/D/Snippets/if-else.sublime-snippet b/D/Snippets/if-else.sublime-snippet index 023ec80530..5f2749243a 100644 --- a/D/Snippets/if-else.sublime-snippet +++ b/D/Snippets/if-else.sublime-snippet @@ -1,5 +1,5 @@ - - diff --git a/D/Snippets/version.sublime-snippet b/D/Snippets/version.sublime-snippet index a53516310a..b7d9ff73b5 100644 --- a/D/Snippets/version.sublime-snippet +++ b/D/Snippets/version.sublime-snippet @@ -1,5 +1,5 @@ - diff --git a/D/Snippets/while.sublime-snippet b/D/Snippets/while.sublime-snippet index 93b0184708..6f6c825f48 100644 --- a/D/Snippets/while.sublime-snippet +++ b/D/Snippets/while.sublime-snippet @@ -1,5 +1,5 @@ - From 972c2da5e84ba73b184cb8a9f0611053d498dae5 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 16 Jan 2019 17:03:55 +1100 Subject: [PATCH 003/108] Add rdmd to build system for running a single file immediately --- D/D.sublime-build | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/D/D.sublime-build b/D/D.sublime-build index 19f3835568..6fff6da06d 100644 --- a/D/D.sublime-build +++ b/D/D.sublime-build @@ -1,5 +1,13 @@ { "cmd": ["dmd", "$file"], "file_regex": "^(.*?)\\(([0-9]+)\\)", - "selector": "source.d" + "selector": "source.d", + + "variants": + [ + { + "name": "Run", + "cmd": ["rdmd", "$file"], + } + ] } From 9f746a487363ab206c35332692935a039f3b54d6 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 16 Jan 2019 19:04:44 +1100 Subject: [PATCH 004/108] Implement proper literal parsing for strings and numbers; fix nested comments --- D/D.sublime-syntax | 176 +++++++++++++++++++++++++++++++++++---------- D/syntax_test_d.d | 128 +++++++++++++++++++++++++++++++++ 2 files changed, 266 insertions(+), 38 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 5008d52290..dc693e4158 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -8,6 +8,11 @@ file_extensions: - di first_line_match: ^#!.*\bg?dmd\b. scope: source.d +variables: + identifier: '[[:alpha:]_][[:alnum:]_]*' + string_postfix: '[cwd]?' + escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' + hex_char: '[0-9a-fA-F]' contexts: main: - match: /\*\*/ @@ -176,21 +181,8 @@ contexts: scope: constant.language.d - match: \b(this|super)\b scope: variable.language.d - - match: |- - (?x) - ( - (\b0(x|X)[0-9a-fA-F](_[0-9a-fA-F]+)*) # 0x0, 0X0, 0x000_000 - | - ( - (\b[0-9]+(_[0-9]+)*\.?([0-9]+_[0-9]+)?[0-9]*) # 0.0, 0_0.0, 0.0_0 - | - (\.[0-9]+(_[0-9]+)*) # .0, .0_0 - )((e|E)(\+|-)?[0-9]+)? # 0e+5 - ) - ([LlFfUuDd]|UL|ul)? # 0l, 0U, 0Lu, 0UL - \b - scope: constant.numeric.d - - include: string_escaped_char + - include: number + - include: character - include: strings - match: (==|!=|<=|>=|<>|<|>) scope: keyword.operator.comparison.d @@ -228,6 +220,12 @@ contexts: - match: \*/ scope: punctuation.definition.comment.d pop: true + - match: (//).*$\n? + scope: comment.line.double-slash.d + captures: + 1: punctuation.definition.comment.d + - include: nested_comment + nested_comment: - match: /\+ scope: punctuation.definition.comment.d push: @@ -235,10 +233,7 @@ contexts: - match: \+/ scope: punctuation.definition.comment.d pop: true - - match: (//).*$\n? - scope: comment.line.double-slash.d - captures: - 1: punctuation.definition.comment.d + - include: nested_comment constant_placeholder: - match: '(?i:%(\([a-z_]+\))?#?0?\-?[ ]?\+?([0-9]*|\*)(\.([0-9]*|\*))?[hL]?[a-z%])' scope: constant.other.placeholder.d @@ -259,8 +254,6 @@ contexts: pop: true - match: '(?<=\})' pop: true - regular_expressions: - - include: scope:source.regexp.python statement-remainder: - match: \( push: @@ -282,48 +275,155 @@ contexts: - match: '\b(void|byte|short|char|int|long|float|double|boolean|([a-z]\w+\.)*[A-Z]\w+(?![\(\.]))\b' scope: storage.type.d string_escaped_char: - - match: '\\(\\|[abefnprtv''"?]|[0-3]\d{,2}|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8}|&\w+;)' + - match: '{{escape_sequence}}' scope: constant.character.escape.d - match: \\. scope: invalid.illegal.unknown-escape.d + number: + # TODO: Hex floats + - match: |- + (?x) + ( + (\b0[xX]{{hex_char}}+(_{{hex_char}}+)*) # 0x0, 0X0, 0x000_000 + | + (\b0[bB][01]+(_[01]+)*) + | + ( + (\b[0-9]+(_[0-9]+)*\.?([0-9]+_[0-9]+)?[0-9]*) # 0.0, 0_0.0, 0.0_0 + | + (\.[0-9]+(_[0-9]+)*) # .0, .0_0 + )((e|E)(\+|-)?[0-9]+)? # 0e+5 + ) + (L[uU]|[uU]L|[LuU])? # 0l, 0U, 0Lu, 0UL + \b + captures: + 1: constant.numeric.d + 15: storage.type.integer.d + character: + - match: \'(?:({{escape_sequence}})|[^\\'])\' + scope: string.quoted.single.d + captures: + 1: constant.character.escape.d + - match: \'.*\' + scope: invalid.illegal.d strings: + # Regular string - match: '"' scope: punctuation.definition.string.begin.d push: - meta_scope: string.quoted.double.d - - match: '"' - scope: punctuation.definition.string.end.d + - match: '(")({{string_postfix}})' + captures: + 1: punctuation.definition.string.end.d + 2: storage.type.string.d pop: true - include: string_escaped_char - - match: (r)(") - captures: - 1: storage.type.string.d - 2: punctuation.definition.string.begin.d + # Wysiwyg string + - match: r" + scope: punctuation.definition.string.begin.d push: - meta_scope: string.quoted.double.raw.d - - match: ((?<=")(")|") + - match: '(")({{string_postfix}})' captures: 1: punctuation.definition.string.end.d - 2: meta.empty-string.double.d + 2: storage.type.string.d pop: true - - include: regular_expressions + # Alternate Wysiwyg string - match: "`" scope: punctuation.definition.string.begin.d push: - meta_scope: string.quoted.double.raw.backtick.d - - match: ((?<=`)(`)|`) + - match: '(`)({{string_postfix}})' captures: 1: punctuation.definition.string.end.d - 2: meta.empty-string.double.d + 2: storage.type.string.d pop: true - - match: "'" + # Deprecated Hex string + - match: x" scope: punctuation.definition.string.begin.d push: - - meta_scope: string.quoted.single.d - - match: "'" - scope: punctuation.definition.string.end.d + - meta_scope: string.quoted.double.raw.d + - match: '(")({{string_postfix}})' + captures: + 1: punctuation.definition.string.end.d + 2: storage.type.string.d pop: true - - include: string_escaped_char + - match: '\s*' + - match: '{{hex_char}}\s*{{hex_char}}' + scope: constant.character.escape.d + - match: '.' + scope: invalid.illegal.unknown-escape.d + # Deliminated string with custom identifier + - match: 'q"({{identifier}})(.*)$' + scope: punctuation.definition.string.begin.d + captures: + 2: invalid.illegal.d + push: + - meta_scope: string.quoted.double.raw.d + - match: '(^\1")({{string_postfix}})' + captures: + 1: punctuation.definition.string.end.d + 2: storage.type.string.d + pop: true + # Nested Deliminated strings + - match: 'q"\[' + scope: punctuation.definition.string.begin.d + push: + - meta_scope: string.quoted.double.raw.d + - match: '(\]")({{string_postfix}})' + captures: + 1: punctuation.definition.string.end.d + 2: storage.type.string.d + pop: true + - match: 'q"\(' + scope: punctuation.definition.string.begin.d + push: + - meta_scope: string.quoted.double.raw.d + - match: '(\)")({{string_postfix}})' + captures: + 1: punctuation.definition.string.end.d + 2: storage.type.string.d + pop: true + - match: 'q"<' + scope: punctuation.definition.string.begin.d + push: + - meta_scope: string.quoted.double.raw.d + - match: '(>")({{string_postfix}})' + captures: + 1: punctuation.definition.string.end.d + 2: storage.type.string.d + pop: true + - match: 'q"{' + scope: punctuation.definition.string.begin.d + push: + - meta_scope: string.quoted.double.raw.d + - match: '(}")({{string_postfix}})' + captures: + 1: punctuation.definition.string.end.d + 2: storage.type.string.d + pop: true + # Other deliminated string + - match: 'q"(.)' + scope: punctuation.definition.string.begin.d + push: + - meta_scope: string.quoted.double.raw.d + - match: '(\1"|\1(.))({{string_postfix}})' + captures: + 1: punctuation.definition.string.end.d + 2: invalid.illegal.d + 3: storage.type.string.d + pop: true + # Token string + - match: 'q{' + scope: punctuation.definition.string.begin.d + push: token-string + token-string: + - meta_scope: string.unquoted.embedded.d.d + - meta_content_scope: source.d + - match: '}' + scope: punctuation.definition.string.end.d + pop: true + - include: main support-type-built-ins-classes-d: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b scope: support.type.built-ins.classes.d diff --git a/D/syntax_test_d.d b/D/syntax_test_d.d index 6243a5af27..4b7cf7106a 100644 --- a/D/syntax_test_d.d +++ b/D/syntax_test_d.d @@ -4,6 +4,134 @@ module test; import std.stdio; + /+ +//^^ comment.block.nested.d punctuation.definition.comment.d + /+ +//^^ comment.block.nested.d comment.block.nested.d punctuation.definition.comment.d + +/ +//^^ comment.block.nested.d comment.block.nested.d punctuation.definition.comment.d + +/ +//^^ comment.block.nested.d punctuation.definition.comment.d + +auto wysiwyg = r"foo \n\"; +// ^^ punctuation.definition.string.begin.d +// ^^^^^^^^^^ string.quoted.double.raw.d +// ^ punctuation.definition.string.end.d +auto wysiwygAlt = `foo\n\`; +// ^ punctuation.definition.string.begin.d +// ^^^^^^^^ string.quoted.double.raw.backtick.d +// ^ punctuation.definition.string.end.d +auto doubleQuoted = "c:\'\"\?\\\0\a\b\f\n\r\t\v\x0B\2\12\762\u0feb\Uabcdef98\""; +// ^ punctuation.definition.string.begin.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.character.escape.d +// ^ punctuation.definition.string.end.d +auto invalidEscape = "\p"; +// ^^ string.quoted.double.d invalid.illegal.unknown-escape.d +auto hexString = x"00 ba +// ^^ punctuation.definition.string.begin.d +// ^^^^^^^^ string.quoted.double.raw.d + 5 5 b"; +// ^^^^^^^ string.quoted.double.raw.d +// ^^^ string.quoted.double.raw.d constant.character.escape.d +// ^ string.quoted.double.raw.d invalid.illegal.unknown-escape.d +// ^ string.quoted.double.raw.d punctuation.definition.string.end.d +auto deliminated = q"SQL_1 +// ^^^^^^^ string.quoted.double.raw.d punctuation.definition.string.begin.d + select foo \n +// ^^^^^^^^^^^^^^ string.quoted.double.raw.d +SQL_1"; +// <- string.quoted.double.raw.d punctuation.definition.string.end.d +// ^^^ string.quoted.double.raw.d punctuation.definition.string.end.d +auto deliminatedBad = q"SQL\ +// ^ string.quoted.double.raw.d punctuation.definition.string.begin.d invalid.illegal.d +SQL" +auto deliminatedNested = q"(f("))" + q"{f{"}}" + q"[f["]]" + q">"; +// ^^^ punctuation.definition.string.begin.d +// ^^^^^^^^^ string.quoted.double.raw.d +// ^^ punctuation.definition.string.end.d +// ^^^ punctuation.definition.string.begin.d +// ^^^^^^^^^ string.quoted.double.raw.d +// ^^ punctuation.definition.string.end.d +// ^^^ punctuation.definition.string.begin.d +// ^^^^^^^^^ string.quoted.double.raw.d +// ^^ punctuation.definition.string.end.d +// ^^^ punctuation.definition.string.begin.d +// ^^^^^^^^^ string.quoted.double.raw.d +// ^^ punctuation.definition.string.end.d +auto deliminatedAny = q"/foo(xxx)/"; +// ^^^ punctuation.definition.string.begin.d +// ^^^^^^^^^^^^^ string.quoted.double.raw.d +// ^^ punctuation.definition.string.end.d +auto stringPostfix = ``c + ""w + q"//"d; +// ^ string.quoted.double.raw.backtick.d storage.type.string.d +// ^ string.quoted.double.d storage.type.string.d +// ^ string.quoted.double.raw.d storage.type.string.d +auto tokenString = q{ +// ^^ string.unquoted.embedded.d.d punctuation.definition.string.begin.d + this is +// ^^^^ string.unquoted.embedded.d.d source.d variable.language.d +// ^^ string.unquoted.embedded.d.d source.d keyword.other.d + /*}*/ + __TIME__ +// ^^^^^^^^ string.unquoted.embedded.d.d source.d constant.language.d +}; +// <- string.unquoted.embedded.d.d punctuation.definition.string.end.d + + +auto c = 'a'; +// ^^^ string.quoted.single.d +c = 'Ó'; +// ^^^ string.quoted.single.d +c = '\n'; +// ^^^^ string.quoted.single.d +// ^^ constant.character.escape.d +c = '\x'; +// ^^^^ invalid.illegal.d +c = 'aa'; +// ^^^^ invalid.illegal.d +c = '\'; +// ^^^ invalid.illegal.d +c = ''; +// ^^ invalid.illegal.d +c = '''; +// ^^ invalid.illegal.d + +auto dec = 2_0_000; +// ^^^^^^^ constant.numeric.d +dec = 1L; +// ^ constant.numeric.d +// ^ storage.type.integer.d +dec = 1u; +// ^ constant.numeric.d +// ^ storage.type.integer.d +dec = 1U; +// ^ constant.numeric.d +// ^ storage.type.integer.d +dec = 1Lu; +// ^ constant.numeric.d +// ^^ storage.type.integer.d +dec = 1LU; +// ^ constant.numeric.d +// ^^ storage.type.integer.d +dec = 1uL; +// ^ constant.numeric.d +// ^^ storage.type.integer.d +dec = 1UL; +// ^ constant.numeric.d +// ^^ storage.type.integer.d +auto bin = 0b1; +// ^^^ constant.numeric.d +bin = 0b10_1; +// ^^^^^^ constant.numeric.d +bin = 0B1; +// ^^^ constant.numeric.d +auto hex = 0xF; +// ^^^ constant.numeric.d +hex = 0x012_3; +// ^^^^^^^ constant.numeric.d +hex = 0X1; +// ^^^ constant.numeric.d shared static this() // ^ storage.modifier // ^ storage.modifier From 61f9c41b1bbce021edfe51e6d72f222cccea4ac2 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 16 Jan 2019 18:13:04 +1100 Subject: [PATCH 005/108] Fix module declaration parsing --- D/D.sublime-syntax | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index dc693e4158..0d5580b1e0 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -9,11 +9,13 @@ file_extensions: first_line_match: ^#!.*\bg?dmd\b. scope: source.d variables: - identifier: '[[:alpha:]_][[:alnum:]_]*' + name: '[[:alpha:]_][[:alnum:]_]*' + identifier: '{{name}}(?:\.{{name}})*' string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' contexts: + main: - match: /\*\*/ scope: comment.block.empty.d punctuation.definition.comment.d @@ -170,11 +172,11 @@ contexts: scope: keyword.control.alias.d - match: \b(import)\b scope: keyword.control.import.d - - match: '^\s*(module)\s+([^ ;]+?);' + - match: '^\s*(module)\s+({{identifier}});' scope: meta.module.d captures: 1: keyword.control.module.d - 2: entity.name.function.package.d + 2: entity.name.namespace.d - match: \b(true|false)\b scope: constant.language.boolean.d - match: \b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|null)\b @@ -354,7 +356,7 @@ contexts: - match: '.' scope: invalid.illegal.unknown-escape.d # Deliminated string with custom identifier - - match: 'q"({{identifier}})(.*)$' + - match: 'q"({{name}})(.*)$' scope: punctuation.definition.string.begin.d captures: 2: invalid.illegal.d From f5326d5b94bc9baf79cf9b3da88e2a1519912616 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Thu, 17 Jan 2019 12:48:21 +1100 Subject: [PATCH 006/108] Fix attribute parsing with support for UDAs --- D/D.sublime-syntax | 142 ++++++++++++++++++++++++++++++++++++++------- D/syntax_test_d.d | 102 +++++++++++++++++++++++++++++++- 2 files changed, 219 insertions(+), 25 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 0d5580b1e0..54e6ec69c3 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -14,12 +14,22 @@ variables: string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' -contexts: + attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' + at_attributes: 'disable|nogc|property|safe|system|trusted' +contexts: main: + - match: '^\s*(module)\s+({{identifier}});' + scope: meta.module.d + captures: + 1: keyword.control.module.d + 2: entity.name.namespace.d - match: /\*\*/ scope: comment.block.empty.d punctuation.definition.comment.d - include: scope:text.html.javadoc + - include: attribute-specifier + - include: comments + - include: all-types - match: |- (?x)^\s* ((?:\b(private|package|protected|public|export|static|final|native|synchronized|abstract)\b\s*)*) # modifier @@ -142,14 +152,8 @@ contexts: - include: $top_level_main - match: '\b([A-Z][A-Z0-9_]+)\b' scope: constant.other.d - - include: comments - - include: all-types - - match: \b(private|protected|public|export)\b - scope: storage.modifier.access-control.d - match: \b(auto|static|override|final|const|abstract|volatile|synchronized|lazy|immutable|shared|__gshared|pure|nothrow|ref)\b scope: storage.modifier.d - - match: '@[a-zA-Z]\w+\b' - scope: storage.attribute.d - match: \b(template|interface|class|enum|struct|union)\b scope: storage.type.d - match: \b(ushort|int|uint|long|ulong|float|void|byte|ubyte|double|bit|char|wchar|ucent|cent|short|bool|dchar|real|ireal|ifloat|idouble|creal|cfloat|cdouble|string)\b @@ -166,17 +170,10 @@ contexts: scope: keyword.control.repeat.d - match: \b(version|return|with|invariant|body|scope|in|out|inout|asm|mixin|function|delegate)\b scope: keyword.control.statement.d - - match: \b(pragma)\b - scope: keyword.control.pragma.d - match: \b(alias|typedef)\b scope: keyword.control.alias.d - match: \b(import)\b scope: keyword.control.import.d - - match: '^\s*(module)\s+({{identifier}});' - scope: meta.module.d - captures: - 1: keyword.control.module.d - 2: entity.name.namespace.d - match: \b(true|false)\b scope: constant.language.boolean.d - match: \b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|null)\b @@ -200,8 +197,6 @@ contexts: scope: keyword.other.d - match: \b(new|throws)\b scope: keyword.other.class-fns.d - - match: \b(package|extern)\b - scope: keyword.other.external.d - match: \b(deprecated|unittest|debug)\b scope: keyword.other.debug.d - match: \b(u_char|u_short|u_int|u_long|ushort|uint|u_quad_t|quad_t|qaddr_t|caddr_t|daddr_t|dev_t|fixpt_t|blkcnt_t|blksize_t|gid_t|in_addr_t|in_port_t|ino_t|key_t|mode_t|nlink_t|id_t|pid_t|off_t|segsz_t|swblk_t|uid_t|id_t|clock_t|size_t|ssize_t|time_t|useconds_t|suseconds_t)\b @@ -418,14 +413,117 @@ contexts: # Token string - match: 'q{' scope: punctuation.definition.string.begin.d - push: token-string - token-string: - - meta_scope: string.unquoted.embedded.d.d - - meta_content_scope: source.d - - match: '}' - scope: punctuation.definition.string.end.d + push: + - meta_scope: string.unquoted.embedded.d.d + - meta_content_scope: source.d + - match: '}' + scope: punctuation.definition.string.end.d + pop: true + - include: main + attribute-specifier: + - include: attribute + - match: ':' + scope: punctuation.section.d + attribute: + - match: '\b({{attributes}})\b' + scope: storage.modifier.d + - match: '(@)' + scope: punctuation.definition.annotation.begin.d + push: at-attribute + - match: '\b(extern)\s*(\()' + captures: + 1: keyword.other.external.d + 2: punctuation.definition.annotation.begin.d + push: extern-attribute + - match: '\b(align)\s*(\()' + captures: + 1: keyword.other.alignment.d + 2: punctuation.definition.annotation.begin.d + push: align-attribute + - match: '\b(deprecated)\s*(\()' + captures: + 1: keyword.other.deprecated.d + 2: punctuation.definition.annotation.begin.d + push: deprecated-attribute + - match: '\b(deprecated)\b' + scope: keyword.other.deprecated.d + - include: visibility-attributes + - match: '\b(pragma)\s*(\()' + captures: + 1: keyword.other.pragma.d + 2: punctuation.definition.annotation.begin.d + push: pragma-attribute + at-attribute: + - match: '({{at_attributes}})\b' + scope: storage.attribute.d + pop: true + - match: '\(' + scope: punctuation.definition.annotation.begin.d + set: uda + - match: '({{name}})\s*(\()' + captures: + 1: variable.function.d + 2: punctuation.definition.annotation.begin.d + set: uda + - match: '({{name}})\b' + scope: variable.other.constant.d pop: true + uda: - include: main + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + extern-attribute: + - match: '(C\+\+|C|D|Windows|System|Objective-C)' + scope: string.other.d + - match: '{{identifier}}' + scope: string.other.d + - match: ',' + scope: punctuation.separator.sequence.d + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + - match: '\s' + - match: '.' + scope: invalid.illegal.d + align-attribute: + - include: main + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + deprecated-attribute: + - include: main + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + visibility-attributes: + - match: '\b(private|protected|public|export)\b' + scope: storage.modifier.access-control.d + - match: '\b(package)\s*(\()' + captures: + 1: storage.modifier.access-control.d + 2: punctuation.definition.annotation.begin.d + push: + - match: '{{identifier}}' + scope: variable.other.constant.d + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + - match: '.' + scope: invalid.illegal.d + - match: '\b(package)\b' + scope: storage.modifier.access-control.d + pragma-attribute: + - match: '\b({{name}})\b' + scope: variable.function.d + set: + - include: main + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + - match: \s + - match: '.' + scope: invalid.illegal.d support-type-built-ins-classes-d: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b scope: support.type.built-ins.classes.d diff --git a/D/syntax_test_d.d b/D/syntax_test_d.d index 4b7cf7106a..b057045f24 100644 --- a/D/syntax_test_d.d +++ b/D/syntax_test_d.d @@ -1,6 +1,14 @@ // SYNTAX TEST "Packages/D/D.sublime-syntax" module test; +// <- meta.module.d keyword.control.module.d + // <- meta.module.d keyword.control.module.d +//^^^^ meta.module.d keyword.control.module.d + // ^^^^ meta.module.d entity.name.namespace.d + module foo.a.b1_3; +//^^^^^^^^^^^^^^^^^^ meta.module.d +//^^^^^^ keyword.control.module.d +// ^^^^^^^^^^ entity.name.namespace.d import std.stdio; @@ -132,10 +140,98 @@ hex = 0x012_3; // ^^^^^^^ constant.numeric.d hex = 0X1; // ^^^ constant.numeric.d + + @foo: +//^ punctuation.definition.annotation.begin.d +// ^^^ variable.other.constant.d +// ^ punctuation.section.d + @(void)@safer@Foo(2, 4)@property +//^^ punctuation.definition.annotation.begin.d +// ^^^^ storage.type.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^ variable.other.constant.d +// ^ punctuation.definition.annotation.begin.d +// ^^^ variable.function.d +// ^ punctuation.definition.annotation.begin.d +// ^ constant.numeric.d +// ^ constant.numeric.d +// ^ punctuation.definition.annotation.end.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^^^^ storage.attribute.d + static shared const immutable auto final synchronized __gshared nothrow pure ref +//^^^^^^ storage.modifier.d +// ^^^^^^ storage.modifier.d +// ^^^^^ storage.modifier.d +// ^^^^^^^^^ storage.modifier.d +// ^^^^ storage.modifier.d +// ^^^^^ storage.modifier.d +// ^^^^^^^^^^^^ storage.modifier.d +// ^^^^^^^^^ storage.modifier.d +// ^^^^^^^ storage.modifier.d +// ^^^^ storage.modifier.d +// ^^^ storage.modifier.d + extern(C) extern (C++, foo.a) +//^^^^^^ keyword.other.external.d +// ^ punctuation.definition.annotation.begin.d +// ^ string.other.d +// ^ punctuation.definition.annotation.end.d +// ^^^^^^ keyword.other.external.d +// ^ punctuation.definition.annotation.begin.d +// ^^^ string.other.d +// ^ punctuation.separator.sequence.d +// ^^^^^ string.other.d +// ^ punctuation.definition.annotation.end.d +extern(1) +// ^ invalid.illegal.d + align(1) align(foo * 2) +//^^^^^ keyword.other.alignment.d +// ^ punctuation.definition.annotation.begin.d +// ^ constant.numeric.d +// ^ punctuation.definition.annotation.end.d +// ^^^^^ keyword.other.alignment.d +// ^ punctuation.definition.annotation.begin.d +// ^ keyword.operator.arithmetic.d +// ^ constant.numeric.d +// ^ punctuation.definition.annotation.end.d + deprecated +//^^^^^^^^^^ keyword.other.deprecated.d + deprecated("message") deprecated(q{void}) +//^^^^^^^^^^ keyword.other.deprecated.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^^^^^ string.quoted.double.d +// ^ punctuation.definition.annotation.end.d +// ^^^^^^^^^^ keyword.other.deprecated.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^ string.unquoted.embedded.d.d source.d storage.type.d +// ^ punctuation.definition.annotation.end.d + private protected public export package +//^^^^^^^ storage.modifier.access-control.d +// ^^^^^^^^^ storage.modifier.access-control.d +// ^^^^^^ storage.modifier.access-control.d +// ^^^^^^ storage.modifier.access-control.d +// ^^^^^^^ storage.modifier.access-control.d + package(foo.bar.) +//^^^^^^^ storage.modifier.access-control.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^^^ variable.other.constant.d +// ^ invalid.illegal.d +// ^ punctuation.definition.annotation.end.d + pragma(f) pragma(test, void) +//^^^^^^ keyword.other.pragma.d +// ^ punctuation.definition.annotation.begin.d +// ^ variable.function.d +// ^ punctuation.definition.annotation.end.d +// ^^^^^^ keyword.other.pragma.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^ variable.function.d +// ^^^^ storage.type.d +// ^ punctuation.definition.annotation.end.d + + shared static this() // ^ storage.modifier // ^ storage.modifier -// ^ entity.name + ^ entity.name { } @@ -186,9 +282,9 @@ template testTemplate(X) // ^ storage.attribute auto takeByRef(ref int h) -// ^ storage.type + ^ storage.type // ^ storage.modifier -// ^ storage.type + ^ storage.type { synchronized // ^ storage.modifier From f04ef6269fd00d87216cb33612db168f3184ce4e Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Thu, 17 Jan 2019 15:35:01 +1100 Subject: [PATCH 007/108] Implement shebang parsing and module validation --- D/D.sublime-syntax | 97 +++++++++++++++++++---------------- D/tests/syntax_test_shebang.d | 10 ++++ 2 files changed, 64 insertions(+), 43 deletions(-) create mode 100644 D/tests/syntax_test_shebang.d diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 54e6ec69c3..b82f528c8e 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -19,16 +19,31 @@ variables: at_attributes: 'disable|nogc|property|safe|system|trusted' contexts: main: - - match: '^\s*(module)\s+({{identifier}});' + - match: '^#!.*$' + scope: comment.line.shebang.d + set: main-after-shebang + - match: '(?=.)' + set: main-after-shebang + main-after-shebang: + - include: comments + - include: attribute-specifier + - match: '\b(module)\s+({{identifier}})(;)' scope: meta.module.d captures: 1: keyword.control.module.d 2: entity.name.namespace.d - - match: /\*\*/ - scope: comment.block.empty.d punctuation.definition.comment.d - - include: scope:text.html.javadoc + 3: punctuation.terminator.d + set: module-context + - match: '\s' + - match: (?=.) + set: module-context + module-context: + # - match: /\*\*/ + # scope: comment.block.empty.d punctuation.definition.comment.d + # - include: scope:text.html.javadoc - include: attribute-specifier - include: comments + - include: imports - include: all-types - match: |- (?x)^\s* @@ -209,28 +224,6 @@ contexts: - include: support-type-built-ins-d - include: support-type-d - include: storage-type-d - comments: - - match: /\* - scope: punctuation.definition.comment.d - push: - - meta_scope: comment.block.d - - match: \*/ - scope: punctuation.definition.comment.d - pop: true - - match: (//).*$\n? - scope: comment.line.double-slash.d - captures: - 1: punctuation.definition.comment.d - - include: nested_comment - nested_comment: - - match: /\+ - scope: punctuation.definition.comment.d - push: - - meta_scope: comment.block.nested.d - - match: \+/ - scope: punctuation.definition.comment.d - pop: true - - include: nested_comment constant_placeholder: - match: '(?i:%(\([a-z_]+\))?#?0?\-?[ ]?\+?([0-9]*|\*)(\.([0-9]*|\*))?[hL]?[a-z%])' scope: constant.other.placeholder.d @@ -271,11 +264,28 @@ contexts: storage-type-d: - match: '\b(void|byte|short|char|int|long|float|double|boolean|([a-z]\w+\.)*[A-Z]\w+(?![\(\.]))\b' scope: storage.type.d - string_escaped_char: - - match: '{{escape_sequence}}' - scope: constant.character.escape.d - - match: \\. - scope: invalid.illegal.unknown-escape.d + comments: + - match: /\* + scope: punctuation.definition.comment.d + push: + - meta_scope: comment.block.d + - match: \*/ + scope: punctuation.definition.comment.d + pop: true + - match: (//).*$\n? + scope: comment.line.double-slash.d + captures: + 1: punctuation.definition.comment.d + - include: nested_comment + nested_comment: + - match: /\+ + scope: punctuation.definition.comment.d + push: + - meta_scope: comment.block.nested.d + - match: \+/ + scope: punctuation.definition.comment.d + pop: true + - include: nested_comment number: # TODO: Hex floats - match: |- @@ -314,7 +324,10 @@ contexts: 1: punctuation.definition.string.end.d 2: storage.type.string.d pop: true - - include: string_escaped_char + - match: '{{escape_sequence}}' + scope: constant.character.escape.d + - match: \\. + scope: invalid.illegal.unknown-escape.d # Wysiwyg string - match: r" scope: punctuation.definition.string.begin.d @@ -345,10 +358,9 @@ contexts: 1: punctuation.definition.string.end.d 2: storage.type.string.d pop: true - - match: '\s*' - match: '{{hex_char}}\s*{{hex_char}}' scope: constant.character.escape.d - - match: '.' + - match: '[^\s]' scope: invalid.illegal.unknown-escape.d # Deliminated string with custom identifier - match: 'q"({{name}})(.*)$' @@ -419,7 +431,7 @@ contexts: - match: '}' scope: punctuation.definition.string.end.d pop: true - - include: main + - include: module-context attribute-specifier: - include: attribute - match: ':' @@ -469,7 +481,7 @@ contexts: scope: variable.other.constant.d pop: true uda: - - include: main + - include: module-context - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -483,16 +495,15 @@ contexts: - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - - match: '\s' - - match: '.' + - match: '[^\s]' scope: invalid.illegal.d align-attribute: - - include: main + - include: module-context - match: '\)' scope: punctuation.definition.annotation.end.d pop: true deprecated-attribute: - - include: main + - include: module-context - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -517,12 +528,12 @@ contexts: - match: '\b({{name}})\b' scope: variable.function.d set: - - include: main + - include: module-context - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - - match: \s - - match: '.' + - match: '[^\s]' + scope: invalid.illegal.d scope: invalid.illegal.d support-type-built-ins-classes-d: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b diff --git a/D/tests/syntax_test_shebang.d b/D/tests/syntax_test_shebang.d new file mode 100644 index 0000000000..84ac960208 --- /dev/null +++ b/D/tests/syntax_test_shebang.d @@ -0,0 +1,10 @@ +#! SYNTAX TEST "Packages/D/D.sublime-syntax" +#! <- comment.line.shebang.d + #! <- comment.line.shebang.d +#!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.shebang.d + +// foo +#! ^^^ comment.line.double-slash.d + +#! foo +#! ^^^ - comment.line.shebang.d From 3eccd678bdccff159149cd59e96f32a590f8ed9b Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Thu, 17 Jan 2019 15:35:51 +1100 Subject: [PATCH 008/108] Implement proper import parsing --- D/D.sublime-syntax | 75 +++++++++- D/{ => tests}/syntax_test_d.d | 252 +++++----------------------------- 2 files changed, 111 insertions(+), 216 deletions(-) rename D/{ => tests}/syntax_test_d.d (68%) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index b82f528c8e..4610e09396 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -11,6 +11,7 @@ scope: source.d variables: name: '[[:alpha:]_][[:alnum:]_]*' identifier: '{{name}}(?:\.{{name}})*' + std_identifier: '(?:std|core)\.{{identifier}}' string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' @@ -187,8 +188,6 @@ contexts: scope: keyword.control.statement.d - match: \b(alias|typedef)\b scope: keyword.control.alias.d - - match: \b(import)\b - scope: keyword.control.import.d - match: \b(true|false)\b scope: constant.language.boolean.d - match: \b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|null)\b @@ -534,6 +533,78 @@ contexts: pop: true - match: '[^\s]' scope: invalid.illegal.d + imports: + - match: '\b(import)\b' + scope: keyword.control.import.d + push: import-list + import-list: + - match: '\b(?:({{std_identifier}})|({{identifier}}))\b' + captures: + 1: support.module.d + 2: variable.other.constant.d + set: + - match: ':' + scope: punctuation.separator.import-binding.d + set: import-binding-list + - match: ';' + scope: punctuation.terminator.d + pop: true + - match: ',' + scope: punctuation.separator.sequence.d + set: import-list + - match: '=' + scope: keyword.operator.assignment.d + set: + - match: '\b(?:({{std_identifier}})|({{identifier}}))\b' + captures: + 1: support.module.d + 2: variable.other.constant.d + set: + - match: ';' + scope: punctuation.terminator.d + pop: true + - match: ',' + scope: punctuation.separator.sequence.d + set: import-list + + - match: '[^\s]' + scope: invalid.illegal.d + - match: '[^\s]' + scope: invalid.illegal.d + - match: '[^\s]' + scope: invalid.illegal.d + - match: '[^\s]' + scope: invalid.illegal.d + import-binding-list: + - match: '\b({{identifier}})\b' + scope: variable.other.constant.d + set: + - match: ';' + scope: punctuation.terminator.d + pop: true + - match: ',' + scope: punctuation.separator.sequence.d + set: import-binding-list + - match: '=' + scope: keyword.operator.assignment.d + set: + - match: '\b({{identifier}})\b' + scope: variable.other.constant.d + set: + - match: ';' + scope: punctuation.terminator.d + pop: true + - match: ',' + scope: punctuation.separator.sequence.d + set: import-binding-list + + - match: '[^\s]' + scope: invalid.illegal.d + - match: '[^\s]' + scope: invalid.illegal.d + - match: '[^\s]' + scope: invalid.illegal.d + - match: '[^\s]' scope: invalid.illegal.d support-type-built-ins-classes-d: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b diff --git a/D/syntax_test_d.d b/D/tests/syntax_test_d.d similarity index 68% rename from D/syntax_test_d.d rename to D/tests/syntax_test_d.d index b057045f24..b2a798eae4 100644 --- a/D/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1,16 +1,13 @@ // SYNTAX TEST "Packages/D/D.sublime-syntax" -module test; +module foo.a.b1_3; // <- meta.module.d keyword.control.module.d // <- meta.module.d keyword.control.module.d //^^^^ meta.module.d keyword.control.module.d - // ^^^^ meta.module.d entity.name.namespace.d +// ^^^^^^^^^^ meta.module.d entity.name.namespace.d +// ^ meta.module.d punctuation.terminator.d module foo.a.b1_3; -//^^^^^^^^^^^^^^^^^^ meta.module.d -//^^^^^^ keyword.control.module.d -// ^^^^^^^^^^ entity.name.namespace.d - -import std.stdio; +//^^^^^^^^^^^^^^^^^^ - meta.module.d /+ //^^ comment.block.nested.d punctuation.definition.comment.d @@ -78,11 +75,11 @@ auto stringPostfix = ``c + ""w + q"//"d; auto tokenString = q{ // ^^ string.unquoted.embedded.d.d punctuation.definition.string.begin.d this is -// ^^^^ string.unquoted.embedded.d.d source.d variable.language.d -// ^^ string.unquoted.embedded.d.d source.d keyword.other.d +// ^^^^ source.d variable.language.d +// ^^ source.d keyword.other.d /*}*/ __TIME__ -// ^^^^^^^^ string.unquoted.embedded.d.d source.d constant.language.d +// ^^^^^^^^ source.d constant.language.d }; // <- string.unquoted.embedded.d.d punctuation.definition.string.end.d @@ -227,207 +224,34 @@ extern(1) // ^^^^ storage.type.d // ^ punctuation.definition.annotation.end.d - -shared static this() -// ^ storage.modifier -// ^ storage.modifier - ^ entity.name -{ -} - -__gshared int a = 5_000; -// ^ storage.modifier -// ^ storage.type -// ^ constant.numeric -shared int b = 5000; -// ^ storage.modifier -// ^ storage.type -// ^ constant.numeric - -int c = 0x0; -// ^ constant.numeric -int d = 0x0_00; -// ^ constant.numeric -float e = .0_0; -// ^ constant.numeric - -template testTemplate(X) -{ - static if (is(X)) - // ^ storage.modifier - // ^ keyword.control - { - enum test = true; - immutable int f = 0; - // ^ storage.modifier - // ^ storage.type - } - else static if (!is(X)) - // ^ keyword.control - // ^ storage.modifier - // ^ keyword.control - { - enum test = true; - string g = "test"; - // ^ storage.type - } - else - enum test = false; -} - -@safe pure nothrow @nogc unittest {} -// ^ storage.attribute -// ^ storage.modifier -// ^ storage.modifier -// ^ storage.attribute - -auto takeByRef(ref int h) - ^ storage.type -// ^ storage.modifier - ^ storage.type -{ - synchronized - // ^ storage.modifier - { - h += 1; - } -} - -void main(char[][] args) -// ^ meta.function entity.name.function -{ -// <- meta.function meta.block - foreach(argc, argv; args) - { - // <- meta.function meta.block meta.block - auto cl = new CmdLin(argc, argv); - // ^ keyword.other - // ^ meta.block - keyword.type - writefln("%s%s arg: %s", cl.argnum, cl.suffix, cl.argv); - delete cl; - // ^ keyword.other - } - - struct specs - { - int count, allocated; - } - - specs argspecs(char[][] args) - in { - // ^ meta.function meta.block meta.function meta.block - assert (args.length > 0); - } - out (result) { - assert(result.count == CmdLin.total); - // ^ meta.block - keyword.type - assert(result.allocated > 0); - } - body { - // ^ meta.function meta.block meta.function keyword.control.statement - // ^ meta.function meta.block meta.function meta.block - specs* s = new specs; - s.count = args.length; - s.allocated = typeof(args).sizeof; - foreach(argv; args) - s.allocated += argv.length * typeof(argv[0]).sizeof; - return *s; - } - - char[] argcmsg = "argc = %d".dup; - char[] allocmsg = "allocated = %d".dup; - writefln(argcmsg ~ ", " ~ allocmsg, - argspecs(args).count,argspecs(args).allocated); -} -// ^ source.d - -class CmdLin -{ -// <- meta.class meta.block - private { - // ^ meta.class meta.block meta.block - int _argc; - char[] _argv; - static uint _totalc; - } - - public: - this(int argc, char[] argv) - { - _argc = argc + 1; - _argv = argv; - _totalc++; - } - - ~this() - // ^ entity.name - { - } - - int argnum() - { - struct Foo { - } - return _argc; - } - - char[] argv() - { - return _argv; - } - - wchar[] suffix() - // ^ storage.type - // ^ entity.name - { - wchar[] suffix; - switch(_argc) - { - case 1: - suffix = "st"w.dup; - break; - case 2: - suffix = "nd"w.dup; - break; - case 3: - suffix = "rd"w.dup; - break; - default: - suffix = "th"w.dup; - } - return suffix; - } - - static typeof(_totalc) total() - // ^ storage.modifier - // ^ storage.type - // ^ entity.name - { - return _totalc; - } - - invariant - { - assert(_argc > 0); - assert(_totalc >= _argc); - } -} - // <- - meta.class - -extern(C): -struct the_c_struct; - -class MyClass { -// <- storage.type -} - -string sA = r"$"; -// ^ punctuation.definition.string.end - -void func() -in { - assert(true); -} -do { -// <- meta.function keyword.control -} + import foo; +//^^^^^^ keyword.control.import.d +// ^^^ variable.other.constant.d +// ^ punctuation.terminator.d + import std.foo; import core.thread; +//^^^^^^ keyword.control.import.d +// ^^^^^^^ support.module.d +// ^ punctuation.terminator.d +// ^^^^^^ keyword.control.import.d +// ^^^^^^^^^^^ support.module.d +// ^ punctuation.terminator.d + import foo'; +// ^ invalid.illegal.d + import foo, a = bar, std : foo, bar, c = d; +//^^^^^^ keyword.control.import.d +// ^^^ variable.other.constant.d +// ^ punctuation.separator.sequence.d +// ^ variable.other.constant.d +// ^ keyword.operator.assignment.d +// ^^^ variable.other.constant.d +// ^ punctuation.separator.sequence.d +// ^^^ variable.other.constant.d +// ^ punctuation.separator.import-binding.d +// ^^^ variable.other.constant.d +// ^ punctuation.separator.sequence.d +// ^^^ variable.other.constant.d +// ^ punctuation.separator.sequence.d +// ^ variable.other.constant.d +// ^ keyword.operator.assignment.d +// ^ variable.other.constant.d +// ^ punctuation.terminator.d From 2caa34b1b558f95ee8a4baca1fa0f8853acc971e Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 10:52:42 +1100 Subject: [PATCH 009/108] Rudimentary reimplementation of function and variable parsing --- D/D.sublime-syntax | 175 +++++++++++++++++++++++++++++----- D/old_syntax_test.d | 205 ++++++++++++++++++++++++++++++++++++++++ D/tests/syntax_test_d.d | 21 ++++ 3 files changed, 376 insertions(+), 25 deletions(-) create mode 100644 D/old_syntax_test.d diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 4610e09396..49107d64a2 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -12,12 +12,18 @@ variables: name: '[[:alpha:]_][[:alnum:]_]*' identifier: '{{name}}(?:\.{{name}})*' std_identifier: '(?:std|core)\.{{identifier}}' + identifier_ref: '\.?{{identifier}}' + type_look_ahead: '(?=\b({{identifier_ref}}))' string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' + type_ctor: 'const|immutable|inout|shared' + type2_look_ahead: '(?=\*|\[|\bdelegate\b|\bfunction\b)' attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' at_attributes: 'disable|nogc|property|safe|system|trusted' + + basic_types: 'bool|byte|ubyte|short|ushort|int|uint|long|ulong|cent|ucent|char|wchar|dchar|float|double|real|ifloat|idouble|ireal|cfloat|cdouble|creal|void' contexts: main: - match: '^#!.*$' @@ -26,7 +32,7 @@ contexts: - match: '(?=.)' set: main-after-shebang main-after-shebang: - - include: comments + - include: comment - include: attribute-specifier - match: '\b(module)\s+({{identifier}})(;)' scope: meta.module.d @@ -39,12 +45,13 @@ contexts: - match: (?=.) set: module-context module-context: + - match: '\b(module)\b' # - match: /\*\*/ # scope: comment.block.empty.d punctuation.definition.comment.d # - include: scope:text.html.javadoc - include: attribute-specifier - - include: comments - - include: imports + - include: comment + - include: declaration - include: all-types - match: |- (?x)^\s* @@ -144,22 +151,22 @@ contexts: - meta_scope: meta.function.d meta.function.destructor.d - include: function_assertions - include: $top_level_main - - match: |- - (?x)^\s* - (?!else(?:\s+static)?\s+if\b) - ((?:\b(?:private|package|protected|public|export|static|final|native|lazy|synchronized|abstract|threadsafe|transient|override|pure|nothrow)\b\s*)*+) # modifier - (\b(?:void|boolean|byte|char|short|int|float|long|double|[\w_]+[\w0-9_]*|(?:\w+\.)*[A-Z]\w+)\b(?:<(?:(?:(?:\w+\.)*[A-Z]\w+)(?:\s*,\s*)?)+>|(?:\[\s*\])*)?|typeof\(.*?\)|const\(.*?\)\*?)\s* # type - (\w+)\s* # identifier - (?!.*;) # abort if line has a ; - (?=\() - captures: - 1: storage.modifier.d - 2: storage.type.d - 3: entity.name.function.d - push: - - meta_scope: meta.function.d - - include: function_assertions - - include: $top_level_main + # - match: |- + # (?x)^\s* + # (?!else(?:\s+static)?\s+if\b) + # ((?:\b(?:private|package|protected|public|export|static|final|native|lazy|synchronized|abstract|threadsafe|transient|override|pure|nothrow)\b\s*)*+) # modifier + # (\b(?:void|boolean|byte|char|short|int|float|long|double|[\w_]+[\w0-9_]*|(?:\w+\.)*[A-Z]\w+)\b(?:<(?:(?:(?:\w+\.)*[A-Z]\w+)(?:\s*,\s*)?)+>|(?:\[\s*\])*)?|typeof\(.*?\)|const\(.*?\)\*?)\s* # type + # (\w+)\s* # identifier + # (?!.*;) # abort if line has a ; + # (?=\() + # captures: + # 1: storage.modifier.d + # 2: storage.type.d + # 3: entity.name.function.d + # push: + # - meta_scope: meta.function.d + # - include: function_assertions + # - include: $top_level_main - match: '\{' push: - meta_scope: meta.block.d @@ -196,7 +203,7 @@ contexts: scope: variable.language.d - include: number - include: character - - include: strings + - include: string - match: (==|!=|<=|>=|<>|<|>) scope: keyword.operator.comparison.d - match: (\-\-|\+\+) @@ -263,7 +270,10 @@ contexts: storage-type-d: - match: '\b(void|byte|short|char|int|long|float|double|boolean|([a-z]\w+\.)*[A-Z]\w+(?![\(\.]))\b' scope: storage.type.d - comments: + function-context: + - include: comment + - include: declaration + comment: - match: /\* scope: punctuation.definition.comment.d push: @@ -271,7 +281,7 @@ contexts: - match: \*/ scope: punctuation.definition.comment.d pop: true - - match: (//).*$\n? + - match: (//).*$ scope: comment.line.double-slash.d captures: 1: punctuation.definition.comment.d @@ -312,7 +322,7 @@ contexts: 1: constant.character.escape.d - match: \'.*\' scope: invalid.illegal.d - strings: + string: # Regular string - match: '"' scope: punctuation.definition.string.begin.d @@ -373,7 +383,7 @@ contexts: 1: punctuation.definition.string.end.d 2: storage.type.string.d pop: true - # Nested Deliminated strings + # Nested Deliminated string - match: 'q"\[' scope: punctuation.definition.string.begin.d push: @@ -533,7 +543,7 @@ contexts: pop: true - match: '[^\s]' scope: invalid.illegal.d - imports: + import: - match: '\b(import)\b' scope: keyword.control.import.d push: import-list @@ -606,6 +616,121 @@ contexts: scope: invalid.illegal.d - match: '[^\s]' scope: invalid.illegal.d + type: + - match: '\b({{type_ctor}})\b' + scope: storage.modifier.d + set: + - match: '\(' + scope: punctuation.section.group.begin.d + set: [basic-type2, type-storage-modifier-end, type] + - match: '(?=[^\s])' + set: type + - match: '(?=[^\s])' + set: basic-type + type-storage-modifier-end: + - match: '\)' + scope: punctuation.section.group.end.d + pop: true + - match: '(?=[^\s])' + scope: invalid.illegal.d + basic-type: + - match: '\b({{identifier_ref}})\b' + scope: storage.type.d + set: + - match: '{{type2_look_ahead}}' + set: basic-type2 + - match: '(?=[^\s])' + pop: true + # TODO: More basic types + - match: '(?=[^\s])' + pop: true + basic-type2: + - match: '\*' + scope: keyword.operator.pointer.d + - match: '\[' + scope: keyword.operator.other.d + push: + # TODO: Ranges + - match: '{{type_look_ahead}}' + push: type + - include: value + - match: '\]' + scope: keyword.operator.other.d + pop: true + - match: '\b(delegate|function)\b' + scope: keyword.other.d + push: function-pointer-type + - match: '(?=[^\s])' + pop: true + function-pointer-type: + # TODO + - match: '.' + pop: true + declaration: + - include: import + - include: function-or-variable + function-or-variable: + - match: '{{type_look_ahead}}' + push: [function-or-variable-after-type, type] + function-or-variable-after-type: + - match: '\b({{name}})\s*(=)' + captures: + 1: variable.other.d + 2: keyword.operator.assignment.d + set: + - include: value + - match: '\;' + scope: punctuation.terminator.d + pop: true + - match: '\b({{name}})\s*(;)' + captures: + 1: variable.other.d + 2: punctuation.terminator.d + pop: true + - match: '\b({{name}})\s*(?=\(|$)' + captures: + 1: entity.name.function.d + set: [function-definition, function-argument-definition-list] + - match: '(?=[^\s])' + pop: true + function-definition: + - match: '\{' + scope: punctuation.section.block.begin.d + push: function-context + - match: ';' + pop: true + value: + - include: number + - include: string + function-argument-definition-list: + - match: '\(' + scope: punctuation.section.group.start.d + set: + - match: '{{type_look_ahead}}' + set: [function-argument, type] + - match: '(?=[^\s])' + pop: true + function-argument: + - match: '\b{{name}}\b' + scope: variable.parameter.d + set: + - match: ',' + set: [function-argument, type] + - match: '=' + # TODO + - match: '\)' + scope: punctuation.section.group.end.d + pop: true + - match: '[^\s]' + scope: invalid.illegal.d + # - match: '\.\.\.' # TODO + - match: ',' + push: type + - match: '\)' + scope: punctuation.section.group.end.d + pop: true + - match: '[^\s]' + scope: invalid.illegal.d support-type-built-ins-classes-d: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b scope: support.type.built-ins.classes.d diff --git a/D/old_syntax_test.d b/D/old_syntax_test.d new file mode 100644 index 0000000000..2b18a0139a --- /dev/null +++ b/D/old_syntax_test.d @@ -0,0 +1,205 @@ + + +shared static this() +// ^ storage.modifier +// ^ storage.modifier + ^ entity.name +{ +} + +__gshared int a = 5_000; +// ^ storage.modifier +// ^ storage.type +// ^ constant.numeric +shared int b = 5000; +// ^ storage.modifier +// ^ storage.type +// ^ constant.numeric + +int c = 0x0; +// ^ constant.numeric +int d = 0x0_00; +// ^ constant.numeric +float e = .0_0; +// ^ constant.numeric + +template testTemplate(X) +{ + static if (is(X)) + // ^ storage.modifier + // ^ keyword.control + { + enum test = true; + immutable int f = 0; + // ^ storage.modifier + // ^ storage.type + } + else static if (!is(X)) + // ^ keyword.control + // ^ storage.modifier + // ^ keyword.control + { + enum test = true; + string g = "test"; + // ^ storage.type + } + else + enum test = false; +} + +@safe pure nothrow @nogc unittest {} +// ^ storage.attribute +// ^ storage.modifier +// ^ storage.modifier +// ^ storage.attribute + +auto takeByRef(ref int h) + //^ storage.type +// ^ storage.modifier + //^ storage.type +{ + synchronized + // ^ storage.modifier + { + h += 1; + } +} + +void main(char[][] args) +// ^ meta.function entity.name.function +{ +// <- meta.function meta.block + foreach(argc, argv; args) + { + // <- meta.function meta.block meta.block + auto cl = new CmdLin(argc, argv); + // ^ keyword.other + // ^ meta.block - keyword.type + writefln("%s%s arg: %s", cl.argnum, cl.suffix, cl.argv); + delete cl; + // ^ keyword.other + } + + struct specs + { + int count, allocated; + } + + specs argspecs(char[][] args) + in { + // ^ meta.function meta.block meta.function meta.block + assert (args.length > 0); + } + out (result) { + assert(result.count == CmdLin.total); + // ^ meta.block - keyword.type + assert(result.allocated > 0); + } + body { + // ^ meta.function meta.block meta.function keyword.control.statement + // ^ meta.function meta.block meta.function meta.block + specs* s = new specs; + s.count = args.length; + s.allocated = typeof(args).sizeof; + foreach(argv; args) + s.allocated += argv.length * typeof(argv[0]).sizeof; + return *s; + } + + char[] argcmsg = "argc = %d".dup; + char[] allocmsg = "allocated = %d".dup; + writefln(argcmsg ~ ", " ~ allocmsg, + argspecs(args).count,argspecs(args).allocated); +} +// ^ source.d + +class CmdLin +{ +// <- meta.class meta.block + private { + // ^ meta.class meta.block meta.block + int _argc; + char[] _argv; + static uint _totalc; + } + + public: + this(int argc, char[] argv) + { + _argc = argc + 1; + _argv = argv; + _totalc++; + } + + ~this() + // ^ entity.name + { + } + + int argnum() + { + struct Foo { + } + return _argc; + } + + char[] argv() + { + return _argv; + } + + wchar[] suffix() + // ^ storage.type + // ^ entity.name + { + wchar[] suffix; + switch(_argc) + { + case 1: + suffix = "st"w.dup; + break; + case 2: + suffix = "nd"w.dup; + break; + case 3: + suffix = "rd"w.dup; + break; + default: + suffix = "th"w.dup; + } + return suffix; + } + + static typeof(_totalc) total() + // ^ storage.modifier + // ^ storage.type + // ^ entity.name + { + return _totalc; + } + + invariant + { + assert(_argc > 0); + assert(_totalc >= _argc); + } +} + // <- - meta.class + +extern(C): +struct the_c_struct; + +class MyClass { +// <- storage.type +} + +string sA = r"$"; +// ^ punctuation.definition.string.end + +void func() +in { + assert(true); +} +do { +// <- meta.function keyword.control +} diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index b2a798eae4..6563c65378 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -255,3 +255,24 @@ extern(1) // ^ keyword.operator.assignment.d // ^ variable.other.constant.d // ^ punctuation.terminator.d + + int a; +//^^^ storage.type.d +// ^ variable.other.d +// ^ punctuation.terminator.d + foo[string] b = 123; +//^^^ storage.type.d +// ^ keyword.operator.other.d +// ^^^^^^ storage.type.d +// ^ keyword.operator.other.d +// ^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^ constant.numeric.d +// ^ punctuation.terminator.d + bar* some_long_Name; +//^^^ storage.type.d +// ^ keyword.operator.pointer.d +// ^^^^^^^^^^^^^^ variable.other.d +// ^ punctuation.terminator.d + +//TODO: Test for functions From 2b6488af08f357130eb9e79ae1fb39e44a4201df Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 11:02:07 +1100 Subject: [PATCH 010/108] Rename all contexts to match usage --- D/D.sublime-syntax | 135 +++++++++++++++++++++++---------------------- 1 file changed, 70 insertions(+), 65 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 49107d64a2..4767e62a58 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -28,11 +28,11 @@ contexts: main: - match: '^#!.*$' scope: comment.line.shebang.d - set: main-after-shebang + set: main-after-shebang-in - match: '(?=.)' - set: main-after-shebang - main-after-shebang: - - include: comment + set: main-after-shebang-in + main-after-shebang-in: + - include: comment-in - include: attribute-specifier - match: '\b(module)\s+({{identifier}})(;)' scope: meta.module.d @@ -40,19 +40,19 @@ contexts: 1: keyword.control.module.d 2: entity.name.namespace.d 3: punctuation.terminator.d - set: module-context + set: module-context-in - match: '\s' - match: (?=.) - set: module-context - module-context: + set: module-context-in + module-context-in: - match: '\b(module)\b' # - match: /\*\*/ # scope: comment.block.empty.d punctuation.definition.comment.d # - include: scope:text.html.javadoc - include: attribute-specifier - - include: comment - - include: declaration - - include: all-types + - include: comment-in + - include: declaration-in + - include: all-types-in - match: |- (?x)^\s* ((?:\b(private|package|protected|public|export|static|final|native|synchronized|abstract)\b\s*)*) # modifier @@ -93,7 +93,7 @@ contexts: captures: 1: storage.modifier.d pop: true - - include: all-types + - include: all-types-in - match: '(?<=\})' pop: true - include: $top_level_main @@ -121,7 +121,7 @@ contexts: captures: 1: storage.modifier.d pop: true - - include: all-types + - include: all-types-in - match: |- (?x)^\s* ((?:\b(private|package|protected|public|export|static|final|native|synchronized|abstract|threadsafe|transient|shared|__gshared)\b\s*)*) # modifier @@ -201,9 +201,9 @@ contexts: scope: constant.language.d - match: \b(this|super)\b scope: variable.language.d - - include: number - - include: character - - include: string + - include: number-in + - include: character-in + - include: string-in - match: (==|!=|<=|>=|<>|<|>) scope: keyword.operator.comparison.d - match: (\-\-|\+\+) @@ -226,14 +226,14 @@ contexts: scope: support.type.pthread.c - match: \b(int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t|intmax_t|intmax_t|uintmax_t|uintmax_t)\b scope: support.type.stdint.c - all-types: - - include: support-type-built-ins-d - - include: support-type-d - - include: storage-type-d - constant_placeholder: + all-types-in: + - include: support-type-built-ins-in + - include: support-type-in + - include: storage-type-d-in + constant_placeholder-in: - match: '(?i:%(\([a-z_]+\))?#?0?\-?[ ]?\+?([0-9]*|\*)(\.([0-9]*|\*))?[hL]?[a-z%])' scope: constant.other.placeholder.d - function_assertions: + function_assertions-in: - match: '(in|out)\s*(?=\{)' captures: 1: keyword.control.statement.d @@ -250,13 +250,13 @@ contexts: pop: true - match: '(?<=\})' pop: true - statement-remainder: + statement-remainder-in: - match: \( push: - meta_scope: meta.definition.param-list.d - match: (?=\)) pop: true - - include: all-types + - include: all-types-in - match: (throws) captures: 1: keyword.other.class-fns.d @@ -266,14 +266,15 @@ contexts: captures: 1: keyword.other.class-fns.d pop: true - - include: all-types - storage-type-d: + - include: all-types-in + storage-type-d-in: - match: '\b(void|byte|short|char|int|long|float|double|boolean|([a-z]\w+\.)*[A-Z]\w+(?![\(\.]))\b' scope: storage.type.d - function-context: - - include: comment - - include: declaration - comment: + + function-context-in: + - include: comment-in + - include: declaration-in + comment-in: - match: /\* scope: punctuation.definition.comment.d push: @@ -285,8 +286,8 @@ contexts: scope: comment.line.double-slash.d captures: 1: punctuation.definition.comment.d - - include: nested_comment - nested_comment: + - include: nested-comment + nested-comment: - match: /\+ scope: punctuation.definition.comment.d push: @@ -294,8 +295,8 @@ contexts: - match: \+/ scope: punctuation.definition.comment.d pop: true - - include: nested_comment - number: + - include: nested-comment + number-in: # TODO: Hex floats - match: |- (?x) @@ -315,14 +316,14 @@ contexts: captures: 1: constant.numeric.d 15: storage.type.integer.d - character: + character-in: - match: \'(?:({{escape_sequence}})|[^\\'])\' scope: string.quoted.single.d captures: 1: constant.character.escape.d - match: \'.*\' scope: invalid.illegal.d - string: + string-in: # Regular string - match: '"' scope: punctuation.definition.string.begin.d @@ -440,12 +441,12 @@ contexts: - match: '}' scope: punctuation.definition.string.end.d pop: true - - include: module-context - attribute-specifier: - - include: attribute + - include: module-context-in + attribute-specifier-in: + - include: attribute-in - match: ':' scope: punctuation.section.d - attribute: + attribute-in: - match: '\b({{attributes}})\b' scope: storage.modifier.d - match: '(@)' @@ -490,7 +491,7 @@ contexts: scope: variable.other.constant.d pop: true uda: - - include: module-context + - include: module-context-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -507,12 +508,12 @@ contexts: - match: '[^\s]' scope: invalid.illegal.d align-attribute: - - include: module-context + - include: module-context-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true deprecated-attribute: - - include: module-context + - include: module-context-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -537,13 +538,13 @@ contexts: - match: '\b({{name}})\b' scope: variable.function.d set: - - include: module-context + - include: module-context-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - match: '[^\s]' scope: invalid.illegal.d - import: + import-in: - match: '\b(import)\b' scope: keyword.control.import.d push: import-list @@ -653,7 +654,7 @@ contexts: # TODO: Ranges - match: '{{type_look_ahead}}' push: type - - include: value + - include: value-in - match: '\]' scope: keyword.operator.other.d pop: true @@ -666,10 +667,10 @@ contexts: # TODO - match: '.' pop: true - declaration: - - include: import - - include: function-or-variable - function-or-variable: + declaration-in: + - include: import-in + - include: function-or-variable-in + function-or-variable-in: - match: '{{type_look_ahead}}' push: [function-or-variable-after-type, type] function-or-variable-after-type: @@ -678,7 +679,7 @@ contexts: 1: variable.other.d 2: keyword.operator.assignment.d set: - - include: value + - include: value-in - match: '\;' scope: punctuation.terminator.d pop: true @@ -694,14 +695,18 @@ contexts: - match: '(?=[^\s])' pop: true function-definition: - - match: '\{' + - match: '{' scope: punctuation.section.block.begin.d - push: function-context + set: + - include: function-context-in + - match: '}' + scope: punctuation.section.block.end.d + pop: true - match: ';' pop: true - value: - - include: number - - include: string + value-in: + - include: number-in + - include: string-in function-argument-definition-list: - match: '\(' scope: punctuation.section.group.start.d @@ -731,23 +736,23 @@ contexts: pop: true - match: '[^\s]' scope: invalid.illegal.d - support-type-built-ins-classes-d: + support-type-built-ins-classes-in: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b scope: support.type.built-ins.classes.d - support-type-built-ins-d: - - include: support-type-built-ins-exceptions-d - - include: support-type-built-ins-classes-d - - include: support-type-built-ins-interfaces-d - - include: support-type-built-ins-structs-d - support-type-built-ins-exceptions-d: + support-type-built-ins-in: + - include: support-type-built-ins-exceptions-in + - include: support-type-built-ins-classes-in + - include: support-type-built-ins-interfaces-in + - include: support-type-built-ins-structs-in + support-type-built-ins-exceptions-in: - match: \b(AddressException|ArrayBoundsError|ArrayBoundsException|AssertError|AssertException|Base64CharException|Base64Exception|BzipClosedException|BzipException|ClusterEmptyException|ClusterFullException|ConvError|ConvOverflowError|ConversionException|CorruptedIteratorException|DatabaseException|DateParseError|Exception|FTPException|FiberException|FileException|FinalizeException|FormatError|HostException|IOException|IllegalArgumentException|IllegalElementException|InvalidKeyException|InvalidTypeException|LocaleException|ModuleCtorError|NoSuchElementException|OpenException|OpenRJException|OutOfMemoryException|PlatformException|ProcessCreateException|ProcessException|ProcessForkException|ProcessKillException|ProcessWaitException|ReadException|RegExpException|RegexException|RegistryException|SeekException|SharedLibException|SocketAcceptException|SocketException|StdioException|StreamException|StreamFileException|StringException|SwitchError|SwitchException|SyncException|TextException|ThreadError|ThreadException|UnboxException|UnicodeException|UtfException|VariantTypeMismatchException|Win32Exception|WriteException|XmlException|ZipChecksumException|ZipException|ZipExhaustedException|ZipNotSupportedException|ZlibClosedException|ZlibException|OurUnwindException|SysError)\b scope: support.type.built-ins.exceptions.d - support-type-built-ins-interfaces-d: + support-type-built-ins-interfaces-in: - match: \b(Buffered|HttpParamsView|ICache|IChannel|IClassFactory|ICluster|IConduit|IConsumer|IEvent|IHierarchy|ILevel|IListener|IMessage|IMessageLoader|IOStream|IReadable|ISelectable|ISelectionSet|ISelector|IServer|IUnknown|IWritable|IXmlPrinter|InputStream|OutputStream|PathView|VfsFile|VfsFiles|VfsFolder|VfsFolderEntry|VfsFolders|VfsHost|VfsSync|ZipReader|ZipWriter)\b scope: support.type.built-ins.interfaces.d - support-type-built-ins-structs-d: + support-type-built-ins-structs-in: - match: \b(ABC|ABCFLOAT|ACCEL|ACCESSTIMEOUT|ACCESS_ALLOWED_ACE|ACCESS_DENIED_ACE|ACE_HEADER|ACL|ACL_REVISION_INFORMATION|ACL_SIZE_INFORMATION|ACTION_HEADER|ADAPTER_STATUS|ADDJOB_INFO_1|ANIMATIONINFO|APPBARDATA|Argument|Atomic|Attribute|BITMAP|BITMAPCOREHEADER|BITMAPCOREINFO|BITMAPINFO|BITMAPINFOHEADER|BITMAPV4HEADER|BLOB|BROWSEINFO|BY_HANDLE_FILE_INFORMATION|Bar|Baz|BitArray|Box|BracketResult|ByteSwap|CANDIDATEFORM|CANDIDATELIST|CBTACTIVATESTRUCT|CBT_CREATEWND|CHARFORMAT|CHARRANGE|CHARSET|CHARSETINFO|CHAR_INFO|CIDA|CIEXYZ|CIEXYZTRIPLE|CLIENTCREATESTRUCT|CMINVOKECOMMANDINFO|COLORADJUSTMENT|COLORMAP|COMMCONFIG|COMMPROP|COMMTIMEOUTS|COMPAREITEMSTRUCT|COMPCOLOR|COMPOSITIONFORM|COMSTAT|CONNECTDLGSTRUCT|CONSOLE_CURSOR_INFO|CONTEXT|CONVCONTEXT|CONVINFO|COORD|COPYDATASTRUCT|CPINFO|CPLINFO|CREATESTRUCT|CREATE_PROCESS_DEBUG_INFO|CREATE_THREAD_DEBUG_INFO|CRITICAL_SECTION|CRITICAL_SECTION_DEBUG|CURRENCYFMT|CURSORSHAPE|CWPRETSTRUCT|CWPSTRUCT|CharClass|CharRange|Clock|CodePage|Console|DATATYPES_INFO_1|DCB|DDEACK|DDEADVISE|DDEDATA|DDELN|DDEML_MSG_HOOK_DATA|DDEPOKE|DDEUP|DEBUGHOOKINFO|DEBUG_EVENT|DELETEITEMSTRUCT|DEVMODE|DEVNAMES|DEV_BROADCAST_HDR|DEV_BROADCAST_OEM|DEV_BROADCAST_PORT|DEV_BROADCAST_VOLUME|DIBSECTION|DIR|DISCDLGSTRUCT|DISK_GEOMETRY|DISK_PERFORMANCE|DOCINFO|DOC_INFO_1|DOC_INFO_2|DRAGLISTINFO|DRAWITEMSTRUCT|DRAWTEXTPARAMS|DRIVER_INFO_1|DRIVER_INFO_2|DRIVER_INFO_3|DRIVE_LAYOUT_INFORMATION|Date|DateParse|DateTime|DirEntry|DynArg|EDITSTREAM|EMPTYRECORD|EMR|EMRABORTPATH|EMRANGLEARC|EMRARC|EMRBITBLT|EMRCREATEBRUSHINDIRECT|EMRCREATECOLORSPACE|EMRCREATEDIBPATTERNBRUSHPT|EMRCREATEMONOBRUSH|EMRCREATEPALETTE|EMRCREATEPEN|EMRELLIPSE|EMREOF|EMREXCLUDECLIPRECT|EMREXTCREATEFONTINDIRECTW|EMREXTCREATEPEN|EMREXTFLOODFILL|EMREXTSELECTCLIPRGN|EMREXTTEXTOUTA|EMRFILLPATH|EMRFILLRGN|EMRFORMAT|EMRFRAMERGN|EMRGDICOMMENT|EMRINVERTRGN|EMRLINETO|EMRMASKBLT|EMRMODIFYWORLDTRANSFORM|EMROFFSETCLIPRGN|EMRPLGBLT|EMRPOLYDRAW|EMRPOLYDRAW16|EMRPOLYLINE|EMRPOLYLINE16|EMRPOLYPOLYLINE|EMRPOLYPOLYLINE16|EMRPOLYTEXTOUTA|EMRRESIZEPALETTE|EMRRESTOREDC|EMRROUNDRECT|EMRSCALEVIEWPORTEXTEX|EMRSELECTCLIPPATH|EMRSELECTCOLORSPACE|EMRSELECTOBJECT|EMRSELECTPALETTE|EMRSETARCDIRECTION|EMRSETBKCOLOR|EMRSETCOLORADJUSTMENT|EMRSETDIBITSTODEVICE|EMRSETMAPPERFLAGS|EMRSETMITERLIMIT|EMRSETPALETTEENTRIES|EMRSETPIXELV|EMRSETVIEWPORTEXTEX|EMRSETVIEWPORTORGEX|EMRSETWORLDTRANSFORM|EMRSTRETCHBLT|EMRSTRETCHDIBITS|EMRTEXT|ENCORRECTTEXT|ENDROPFILES|ENHMETAHEADER|ENHMETARECORD|ENOLEOPFAILED|ENPROTECTED|ENSAVECLIPBOARD|ENUMLOGFONT|ENUMLOGFONTEX|ENUM_SERVICE_STATUS|EVENTLOGRECORD|EVENTMSG|EXCEPTION_DEBUG_INFO|EXCEPTION_POINTERS|EXCEPTION_RECORD|EXIT_PROCESS_DEBUG_INFO|EXIT_THREAD_DEBUG_INFO|EXTLOGFONT|EXTLOGPEN|EXT_BUTTON|EmptySlot|EndOfCDRecord|Environment|FILETIME|FILTERKEYS|FINDREPLACE|FINDTEXTEX|FIND_NAME_BUFFER|FIND_NAME_HEADER|FIXED|FLOATING_SAVE_AREA|FMS_GETDRIVEINFO|FMS_GETFILESEL|FMS_LOAD|FMS_TOOLBARLOAD|FOCUS_EVENT_RECORD|FONTSIGNATURE|FORMATRANGE|FORMAT_PARAMETERS|FORM_INFO_1|FileConst|FileHeader|FileRoots|FileSystem|FoldingCaseData|Foo|FtpConnectionDetail|FtpFeature|FtpFileInfo|FtpResponse|GC|GCP_RESULTS|GCStats|GENERIC_MAPPING|GLYPHMETRICS|GLYPHMETRICSFLOAT|GROUP_INFO_2|GUID|HANDLETABLE|HD_HITTESTINFO|HD_ITEM|HD_LAYOUT|HD_NOTIFY|HELPINFO|HELPWININFO|HIGHCONTRAST|HSZPAIR|HeaderElement|HttpConst|HttpHeader|HttpHeaderName|HttpResponses|HttpStatus|HttpToken|ICONINFO|ICONMETRICS|IMAGEINFO|IMAGE_DOS_HEADER|INPUT_RECORD|ITEMIDLIST|IeeeFlags|Interface|JOB_INFO_1|JOB_INFO_2|KERNINGPAIR|LANA_ENUM|LAYERPLANEDESCRIPTOR|LDT_ENTRY|LIST_ENTRY|LOAD_DLL_DEBUG_INFO|LOCALESIGNATURE|LOCALGROUP_INFO_0|LOCALGROUP_MEMBERS_INFO_0|LOCALGROUP_MEMBERS_INFO_3|LOGBRUSH|LOGCOLORSPACE|LOGFONT|LOGFONTA|LOGFONTW|LOGPALETTE|LOGPEN|LUID_AND_ATTRIBUTES|LV_COLUMN|LV_DISPINFO|LV_FINDINFO|LV_HITTESTINFO|LV_ITEM|LV_KEYDOWN|LocalFileHeader|MAT2|MD5_CTX|MDICREATESTRUCT|MEASUREITEMSTRUCT|MEMORYSTATUS|MEMORY_BASIC_INFORMATION|MENUEX_TEMPLATE_HEADER|MENUEX_TEMPLATE_ITEM|MENUITEMINFO|MENUITEMTEMPLATE|MENUITEMTEMPLATEHEADER|MENUTEMPLATE|MENU_EVENT_RECORD|METAFILEPICT|METARECORD|MINIMIZEDMETRICS|MINMAXINFO|MODEMDEVCAPS|MODEMSETTINGS|MONCBSTRUCT|MONCONVSTRUCT|MONERRSTRUCT|MONHSZSTRUCT|MONITOR_INFO_1|MONITOR_INFO_2|MONLINKSTRUCT|MONMSGSTRUCT|MOUSEHOOKSTRUCT|MOUSEKEYS|MOUSE_EVENT_RECORD|MSG|MSGBOXPARAMS|MSGFILTER|MULTIKEYHELP|NAME_BUFFER|NCB|NCCALCSIZE_PARAMS|NDDESHAREINFO|NETCONNECTINFOSTRUCT|NETINFOSTRUCT|NETRESOURCE|NEWCPLINFO|NEWTEXTMETRIC|NEWTEXTMETRICEX|NMHDR|NM_LISTVIEW|NM_TREEVIEW|NM_UPDOWNW|NONCLIENTMETRICS|NS_SERVICE_INFO|NUMBERFMT|OFNOTIFY|OFSTRUCT|OPENFILENAME|OPENFILENAMEA|OPENFILENAMEW|OSVERSIONINFO|OUTLINETEXTMETRIC|OUTPUT_DEBUG_STRING_INFO|OVERLAPPED|OffsetTypeInfo|PAINTSTRUCT|PALETTEENTRY|PANOSE|PARAFORMAT|PARTITION_INFORMATION|PERF_COUNTER_BLOCK|PERF_COUNTER_DEFINITION|PERF_DATA_BLOCK|PERF_INSTANCE_DEFINITION|PERF_OBJECT_TYPE|PIXELFORMATDESCRIPTOR|POINT|POINTFLOAT|POINTFX|POINTL|POINTS|POLYTEXT|PORT_INFO_1|PORT_INFO_2|PREVENT_MEDIA_REMOVAL|PRINTER_DEFAULTS|PRINTER_INFO_1|PRINTER_INFO_2|PRINTER_INFO_3|PRINTER_INFO_4|PRINTER_INFO_5|PRINTER_NOTIFY_INFO|PRINTER_NOTIFY_INFO_DATA|PRINTER_NOTIFY_OPTIONS|PRINTER_NOTIFY_OPTIONS_TYPE|PRINTPROCESSOR_INFO_1|PRIVILEGE_SET|PROCESS_HEAPENTRY|PROCESS_INFORMATION|PROPSHEETHEADER|PROPSHEETHEADER_U1|PROPSHEETHEADER_U2|PROPSHEETHEADER_U3|PROPSHEETPAGE|PROPSHEETPAGE_U1|PROPSHEETPAGE_U2|PROTOCOL_INFO|PROVIDOR_INFO_1|PSHNOTIFY|PUNCTUATION|PassByCopy|PassByRef|Phase1Info|PropertyConfigurator|QUERY_SERVICE_CONFIG|QUERY_SERVICE_LOCK_STATUS|RASAMB|RASCONN|RASCONNSTATUS|RASDIALEXTENSIONS|RASDIALPARAMS|RASENTRYNAME|RASPPPIP|RASPPPIPX|RASPPPNBF|RASTERIZER_STATUS|REASSIGN_BLOCKS|RECT|RECTL|REMOTE_NAME_INFO|REPASTESPECIAL|REQRESIZE|RGBQUAD|RGBTRIPLE|RGNDATA|RGNDATAHEADER|RIP_INFO|Runtime|SCROLLINFO|SECURITY_ATTRIBUTES|SECURITY_DESCRIPTOR|SECURITY_QUALITY_OF_SERVICE|SELCHANGE|SERIALKEYS|SERVICE_ADDRESS|SERVICE_ADDRESSES|SERVICE_INFO|SERVICE_STATUS|SERVICE_TABLE_ENTRY|SERVICE_TYPE_INFO_ABS|SERVICE_TYPE_VALUE_ABS|SESSION_BUFFER|SESSION_HEADER|SET_PARTITION_INFORMATION|SHFILEINFO|SHFILEOPSTRUCT|SHITEMID|SHNAMEMAPPING|SID|SID_AND_ATTRIBUTES|SID_IDENTIFIER_AUTHORITY|SINGLE_LIST_ENTRY|SIZE|SMALL_RECT|SOUNDSENTRY|STARTUPINFO|STICKYKEYS|STRRET|STYLEBUF|STYLESTRUCT|SYSTEMTIME|SYSTEM_AUDIT_ACE|SYSTEM_INFO|SYSTEM_INFO_U|SYSTEM_POWER_STATUS|Signal|SjLj_Function_Context|SpecialCaseData|TAPE_ERASE|TAPE_GET_DRIVE_PARAMETERS|TAPE_GET_MEDIA_PARAMETERS|TAPE_GET_POSITION|TAPE_PREPARE|TAPE_SET_DRIVE_PARAMETERS|TAPE_SET_MEDIA_PARAMETERS|TAPE_SET_POSITION|TAPE_WRITE_MARKS|TBADDBITMAP|TBBUTTON|TBNOTIFY|TBSAVEPARAMS|TCHOOSECOLOR|TCHOOSEFONT|TC_HITTESTINFO|TC_ITEM|TC_ITEMHEADER|TC_KEYDOWN|TEXTMETRIC|TEXTMETRICA|TEXTRANGE|TFINDTEXT|TIME_ZONE_INFORMATION|TOGGLEKEYS|TOKEN_CONTROL|TOKEN_DEFAULT_DACL|TOKEN_GROUPS|TOKEN_OWNER|TOKEN_PRIMARY_GROUP|TOKEN_PRIVILEGES|TOKEN_SOURCE|TOKEN_STATISTICS|TOKEN_USER|TOOLINFO|TOOLTIPTEXT|TPAGESETUPDLG|TPMPARAMS|TRANSMIT_FILE_BUFFERS|TREEITEM|TSMALLPOINT|TTHITTESTINFO|TTPOLYCURVE|TTPOLYGONHEADER|TVARIANT|TV_DISPINFO|TV_HITTESTINFO|TV_INSERTSTRUCT|TV_ITEM|TV_KEYDOWN|TV_SORTCB|Time|TimeOfDay|TimeSpan|Tuple|UDACCEL|ULARGE_INTEGER|UNIVERSAL_NAME_INFO|UNLOAD_DLL_DEBUG_INFO|USEROBJECTFLAGS|USER_INFO_0|USER_INFO_2|USER_INFO_3|UnicodeData|VALENT|VA_LIST|VERIFY_INFORMATION|VS_FIXEDFILEINFO|Variant|VfsFilterInfo|WIN32_FILE_ATTRIBUTE_DATA|WIN32_FIND_DATA|WIN32_FIND_DATAW|WIN32_STREAM_ID|WINDOWINFO|WINDOWPLACEMENT|WINDOWPOS|WINDOW_BUFFER_SIZE_RECORD|WNDCLASS|WNDCLASSA|WNDCLASSEX|WNDCLASSEXA|WSADATA|WallClock|XFORM|ZipEntryInfo)\b scope: support.type.built-ins.structs.d - support-type-d: + support-type-in: - match: '\b((?:tango|std)\.[\w\.]+)\b' scope: support.type.d From e02d1c2781b5c2a1ccb0db155eb8e23407976d71 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 12:14:37 +1100 Subject: [PATCH 011/108] Implement alias parsing --- D/D.sublime-syntax | 75 +++++++++++++++++++++++++++++++++++------ D/tests/syntax_test_d.d | 47 +++++++++++++++++++++++--- 2 files changed, 107 insertions(+), 15 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 4767e62a58..387a8a70c6 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -20,6 +20,7 @@ variables: type_ctor: 'const|immutable|inout|shared' type2_look_ahead: '(?=\*|\[|\bdelegate\b|\bfunction\b)' + attribute_lookahead: '(?={{attributes}}|@)' attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' at_attributes: 'disable|nogc|property|safe|system|trusted' @@ -33,7 +34,7 @@ contexts: set: main-after-shebang-in main-after-shebang-in: - include: comment-in - - include: attribute-specifier + - include: attribute-specifier-in - match: '\b(module)\s+({{identifier}})(;)' scope: meta.module.d captures: @@ -49,10 +50,8 @@ contexts: # - match: /\*\*/ # scope: comment.block.empty.d punctuation.definition.comment.d # - include: scope:text.html.javadoc - - include: attribute-specifier + - include: attribute-specifier-in - include: comment-in - - include: declaration-in - - include: all-types-in - match: |- (?x)^\s* ((?:\b(private|package|protected|public|export|static|final|native|synchronized|abstract)\b\s*)*) # modifier @@ -179,8 +178,8 @@ contexts: scope: storage.modifier.d - match: \b(template|interface|class|enum|struct|union)\b scope: storage.type.d - - match: \b(ushort|int|uint|long|ulong|float|void|byte|ubyte|double|bit|char|wchar|ucent|cent|short|bool|dchar|real|ireal|ifloat|idouble|creal|cfloat|cdouble|string)\b - scope: storage.type.d + # - match: \b(ushort|int|uint|long|ulong|float|void|byte|ubyte|double|bit|char|wchar|ucent|cent|short|bool|dchar|real|ireal|ifloat|idouble|creal|cfloat|cdouble|string)\b + # scope: storage.type.d - match: \b(try|catch|finally|throw)\b scope: keyword.control.exception.d - match: \b(return|break|case|continue|default|do|while|for|switch|if|else)\b @@ -193,8 +192,6 @@ contexts: scope: keyword.control.repeat.d - match: \b(version|return|with|invariant|body|scope|in|out|inout|asm|mixin|function|delegate)\b scope: keyword.control.statement.d - - match: \b(alias|typedef)\b - scope: keyword.control.alias.d - match: \b(true|false)\b scope: constant.language.boolean.d - match: \b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|null)\b @@ -226,6 +223,7 @@ contexts: scope: support.type.pthread.c - match: \b(int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t|intmax_t|intmax_t|uintmax_t|uintmax_t)\b scope: support.type.stdint.c + - include: declaration-in all-types-in: - include: support-type-built-ins-in - include: support-type-in @@ -436,7 +434,7 @@ contexts: - match: 'q{' scope: punctuation.definition.string.begin.d push: - - meta_scope: string.unquoted.embedded.d.d + - meta_scope: string.unquoted.embedded.d - meta_content_scope: source.d - match: '}' scope: punctuation.definition.string.end.d @@ -508,7 +506,7 @@ contexts: - match: '[^\s]' scope: invalid.illegal.d align-attribute: - - include: module-context-in + - include: value-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -669,6 +667,7 @@ contexts: pop: true declaration-in: - include: import-in + - include: alias-in - include: function-or-variable-in function-or-variable-in: - match: '{{type_look_ahead}}' @@ -736,6 +735,62 @@ contexts: pop: true - match: '[^\s]' scope: invalid.illegal.d + alias-in: + - match: '\b(alias)\b' + scope: keyword.control.alias.d + push: + - match: '{{attribute_lookahead}}' + set: [alias-old, type] + - match: '\b({{name}})\s*(?=\(|=)' + captures: + 1: entity.name.type.d + set: alias-new + - match: '{{type_look_ahead}}' + set: [alias-old, type] + - match: '[^\s]' + scope: invalid.illegal.d + alias-old: + - match: '\b({{name}})\b' + scope: entity.name.type.d + set: + - match: ',' + scope: punctuation.separator.sequence.d + set: alias-old + - include: end-of-line + - match: '[^\s]' + scope: invalid.illegal.d + - match: '[^\s]' + scope: invalid.illegal.d + alias-new: + - match: '\(' + # TODO: template aliases + pop: true + - match: '(?==)' + set: alias-new-assign + - match: '[^\s]' + scope: invalid.illegal.d + alias-new-assign: + - match: '=' + scope: keyword.operator.assignment.d + set: [alias-new-after-type, type] + - match: '[^\s]' + scope: invalid.illegal.d + alias-new-after-type: + - include: end-of-line + - match: ',' + scope: punctuation.separator.sequence.d + set: + - match: '\b{{name}}\b' + scope: entity.name.type.d + set: alias-new + - match: '[^\s]' + scope: invalid.illegal.d + - match: '[^\s]' + scope: invalid.illegal.d + end-of-line: + - match: ';' + scope: punctuation.terminator.d + pop: true support-type-built-ins-classes-in: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b scope: support.type.built-ins.classes.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 6563c65378..0251b214ae 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -50,7 +50,7 @@ SQL_1"; // ^^^ string.quoted.double.raw.d punctuation.definition.string.end.d auto deliminatedBad = q"SQL\ // ^ string.quoted.double.raw.d punctuation.definition.string.begin.d invalid.illegal.d -SQL" +SQL"; auto deliminatedNested = q"(f("))" + q"{f{"}}" + q"[f["]]" + q">"; // ^^^ punctuation.definition.string.begin.d // ^^^^^^^^^ string.quoted.double.raw.d @@ -73,7 +73,7 @@ auto stringPostfix = ``c + ""w + q"//"d; // ^ string.quoted.double.d storage.type.string.d // ^ string.quoted.double.raw.d storage.type.string.d auto tokenString = q{ -// ^^ string.unquoted.embedded.d.d punctuation.definition.string.begin.d +// ^^ string.unquoted.embedded.d punctuation.definition.string.begin.d this is // ^^^^ source.d variable.language.d // ^^ source.d keyword.other.d @@ -81,7 +81,7 @@ auto tokenString = q{ __TIME__ // ^^^^^^^^ source.d constant.language.d }; -// <- string.unquoted.embedded.d.d punctuation.definition.string.end.d +// <- string.unquoted.embedded.d punctuation.definition.string.end.d auto c = 'a'; @@ -187,7 +187,6 @@ extern(1) // ^ punctuation.definition.annotation.end.d // ^^^^^ keyword.other.alignment.d // ^ punctuation.definition.annotation.begin.d -// ^ keyword.operator.arithmetic.d // ^ constant.numeric.d // ^ punctuation.definition.annotation.end.d deprecated @@ -199,7 +198,7 @@ extern(1) // ^ punctuation.definition.annotation.end.d // ^^^^^^^^^^ keyword.other.deprecated.d // ^ punctuation.definition.annotation.begin.d -// ^^^^ string.unquoted.embedded.d.d source.d storage.type.d +// ^^^^ string.unquoted.embedded.d source.d storage.type.d // ^ punctuation.definition.annotation.end.d private protected public export package //^^^^^^^ storage.modifier.access-control.d @@ -256,6 +255,44 @@ extern(1) // ^ variable.other.constant.d // ^ punctuation.terminator.d + alias foo = int; +//^^^^^ keyword.control.alias.d +// ^^^ entity.name.type.d +// ^ keyword.operator.assignment.d +// ^^^ storage.type.d +// ^ punctuation.terminator.d + alias Foo = const int[string], bar = long; +//^^^^^ keyword.control.alias.d +// ^^^ entity.name.type.d +// ^ keyword.operator.assignment.d +// ^^^ storage.type.d +// ^ keyword.operator.other.d +// ^^^^^^ storage.type.d +// ^ keyword.operator.other.d +// ^ punctuation.separator.sequence.d +// ^^^ entity.name.type.d +// ^ keyword.operator.assignment.d +// ^^^^ storage.type.d +// ^ punctuation.terminator.d + alias int a; +//^^^^^ keyword.control.alias.d +// ^^^ storage.type.d +// ^ entity.name.type.d +// ^ punctuation.terminator.d + alias const foo[string] long_name, foo, b; +//^^^^^ keyword.control.alias.d +// ^^^^^ storage.modifier.d +// ^^^ storage.type.d +// ^ keyword.operator.other.d +// ^^^^^^ storage.type.d +// ^ keyword.operator.other.d +// ^^^^^^^^^ entity.name.type.d +// ^ punctuation.separator.sequence.d +// ^^^ entity.name.type.d +// ^ punctuation.separator.sequence.d +// ^ entity.name.type.d +// ^ punctuation.terminator.d + int a; //^^^ storage.type.d // ^ variable.other.d From 0563c545f5ebfd7c487a65c81a6edfa0c9f702a9 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 13:56:28 +1100 Subject: [PATCH 012/108] Implement validation-less token parsing for token strings --- D/D.sublime-syntax | 33 ++++++++++++++++++++++++++++++--- D/tests/syntax_test_d.d | 32 +++++++++++++++++++++----------- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 387a8a70c6..7eb9bbbb33 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -24,7 +24,12 @@ variables: attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' at_attributes: 'disable|nogc|property|safe|system|trusted' - basic_types: 'bool|byte|ubyte|short|ushort|int|uint|long|ulong|cent|ucent|char|wchar|dchar|float|double|real|ifloat|idouble|ireal|cfloat|cdouble|creal|void' + 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' + language_constant: 'null|true|false|__FILE__|__FILE_FULL_PATH__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__' + langauge_variable: 'this|super' + reserved: '{{keyword}}|{{basic_type}}|{{language_constant}}|{{langauge_variable}}' + contexts: main: - match: '^#!.*$' @@ -319,7 +324,7 @@ contexts: scope: string.quoted.single.d captures: 1: constant.character.escape.d - - match: \'.*\' + - match: \'[^']*\' scope: invalid.illegal.d string-in: # Regular string @@ -439,7 +444,29 @@ contexts: - match: '}' scope: punctuation.definition.string.end.d pop: true - - include: module-context-in + - include: tokens-in + tokens-in: # Purely a set of un-verified tokens, for use in token string + - match: '\b({{keyword}})\b' + scope: keyword.d + - match: '\b({{basic_type}})\b' + scope: storage.type.d + - match: '\b({{language_constant}})\b' + scope: constant.language.d + - match: '\b({{langauge_variable}})\b' + scope: variable.language.d + - include: comment-in + - include: character-in + - include: string-in + - include: number-in + - match: '{{name}}' + - match: '(/|&|\||-|\+|<<|<>|>>|>>>||\*|%|\^|\^\^|~)=' + scope: keyword.operator.assignment.d + - match: '(/|<=|>=|==|!<>=|!<=|!>=|\.\.\.|\.\.|&|&&|\||\|\||-|--|\+|\+\+|<|<<|<>|>|>>|>>>|!|!<>|!<|!>|\(|\)|\[|\]|{|}|\?|,|;|:|\$|\*|%|\^|\^\^|~|@|=>|#)' + scope: keyword.operator.d + - match: '\.' + scope: keyword.operator.d + - match: '[^\s]' + scope: invalid.illegal.d attribute-specifier-in: - include: attribute-in - match: ':' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 0251b214ae..6b13fe4741 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -74,10 +74,19 @@ auto stringPostfix = ``c + ""w + q"//"d; // ^ string.quoted.double.raw.d storage.type.string.d auto tokenString = q{ // ^^ string.unquoted.embedded.d punctuation.definition.string.begin.d - this is + this is not real code 12 // ^^^^ source.d variable.language.d -// ^^ source.d keyword.other.d +// ^^ source.d keyword.d +// ^^^^^^^^^^^^^ string.unquoted.embedded.d source.d +// ^^^^ string.unquoted.embedded.d source.d storage.type.d +// ^^ string.unquoted.embedded.d source.d constant.numeric.d /*}*/ +// ^^ punctuation.definition.comment.d +// ^^ punctuation.definition.comment.d +// ^^^^^ source.d comment.block.d + '' 'a' +// ^^ source.d invalid.illegal.d +// ^^^ source.d string.quoted.single.d __TIME__ // ^^^^^^^^ source.d constant.language.d }; @@ -265,15 +274,16 @@ extern(1) //^^^^^ keyword.control.alias.d // ^^^ entity.name.type.d // ^ keyword.operator.assignment.d -// ^^^ storage.type.d -// ^ keyword.operator.other.d -// ^^^^^^ storage.type.d -// ^ keyword.operator.other.d -// ^ punctuation.separator.sequence.d -// ^^^ entity.name.type.d -// ^ keyword.operator.assignment.d -// ^^^^ storage.type.d -// ^ punctuation.terminator.d +// ^^^^^ storage.modifier.d +// ^^^ storage.type.d +// ^ keyword.operator.other.d +// ^^^^^^ storage.type.d +// ^ keyword.operator.other.d +// ^ punctuation.separator.sequence.d +// ^^^ entity.name.type.d +// ^ keyword.operator.assignment.d +// ^^^^ storage.type.d +// ^ punctuation.terminator.d alias int a; //^^^^^ keyword.control.alias.d // ^^^ storage.type.d From 561fb1f58f30f001abf919ab20dae5f94f8344fe Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 15:01:51 +1100 Subject: [PATCH 013/108] Implement non-templated aggregate parsing --- D/D.sublime-syntax | 260 +++++++++++++++++++++++----------------- D/tests/syntax_test_d.d | 82 +++++++++++-- 2 files changed, 220 insertions(+), 122 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 7eb9bbbb33..626c0ee997 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -57,75 +57,6 @@ contexts: # - include: scope:text.html.javadoc - include: attribute-specifier-in - include: comment-in - - match: |- - (?x)^\s* - ((?:\b(private|package|protected|public|export|static|final|native|synchronized|abstract)\b\s*)*) # modifier - (class|interface)\s+ - (\w+)\s* # identifier - (?:\(\s*([^\)]+)\s*\)|)\s* # Template type - (?: - \s*(:)\s* - (\w+) - (?:\s*,\s*(\w+))? - (?:\s*,\s*(\w+))? - (?:\s*,\s*(\w+))? - (?:\s*,\s*(\w+))? - (?:\s*,\s*(\w+))? - (?:\s*,\s*(\w+))? - )? # super class - captures: - 1: storage.modifier.d - 3: storage.type.d - 4: entity.name.type.class.d - 5: storage.type.template.d - 6: punctuation.separator.inheritance.d - 7: entity.other.inherited-class.d - 8: entity.other.inherited-class.d - 9: entity.other.inherited-class.d - 10: entity.other.inherited-class.d - 11: entity.other.inherited-class.d - 12: entity.other.inherited-class.d - 13: entity.other.inherited-class.d - push: - - meta_scope: meta.class.d - - match: \b(_|:)\b - captures: - 1: storage.modifier.d - push: - - meta_scope: meta.definition.class.extends.d - - match: "(?={)" - captures: - 1: storage.modifier.d - pop: true - - include: all-types-in - - match: '(?<=\})' - pop: true - - include: $top_level_main - - match: |- - (?x)^\s* - ((?:\b(private|package|protected|public|export|static|final|native|synchronized|abstract|const)\b\s*)*) # modifier - (struct)\s+ - (\w+)\s* # identifier - (?:\(\s*([^\)]+)\s*\)|)\s* # Template type - captures: - 1: storage.modifier.d - 3: storage.type.d - 4: entity.name.type.struct.d - 5: storage.type.template.d - push: - - meta_scope: meta.definition.struct.d - - match: "(?={|//|;)" - pop: true - - match: \b(_|:)\b - captures: - 1: storage.modifier.d - push: - - meta_scope: meta.definition.class.extends.d - - match: "(?={)" - captures: - 1: storage.modifier.d - pop: true - - include: all-types-in - match: |- (?x)^\s* ((?:\b(private|package|protected|public|export|static|final|native|synchronized|abstract|threadsafe|transient|shared|__gshared)\b\s*)*) # modifier @@ -181,8 +112,8 @@ contexts: scope: constant.other.d - match: \b(auto|static|override|final|const|abstract|volatile|synchronized|lazy|immutable|shared|__gshared|pure|nothrow|ref)\b scope: storage.modifier.d - - match: \b(template|interface|class|enum|struct|union)\b - scope: storage.type.d + # - match: \b(template|interface|class|enum|struct|union)\b + # scope: storage.type.d # - match: \b(ushort|int|uint|long|ulong|float|void|byte|ubyte|double|bit|char|wchar|ucent|cent|short|bool|dchar|real|ireal|ifloat|idouble|creal|cfloat|cdouble|string)\b # scope: storage.type.d - match: \b(try|catch|finally|throw)\b @@ -465,8 +396,7 @@ contexts: scope: keyword.operator.d - match: '\.' scope: keyword.operator.d - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal attribute-specifier-in: - include: attribute-in - match: ':' @@ -530,8 +460,7 @@ contexts: - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal align-attribute: - include: value-in - match: '\)' @@ -555,8 +484,7 @@ contexts: - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - - match: '.' - scope: invalid.illegal.d + - include: not-whitespace-illegal - match: '\b(package)\b' scope: storage.modifier.access-control.d pragma-attribute: @@ -567,8 +495,7 @@ contexts: - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal import-in: - match: '\b(import)\b' scope: keyword.control.import.d @@ -603,14 +530,10 @@ contexts: scope: punctuation.separator.sequence.d set: import-list - - match: '[^\s]' - scope: invalid.illegal.d - - match: '[^\s]' - scope: invalid.illegal.d - - match: '[^\s]' - scope: invalid.illegal.d - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal + - include: not-whitespace-illegal + - include: not-whitespace-illegal + - include: not-whitespace-illegal import-binding-list: - match: '\b({{identifier}})\b' scope: variable.other.constant.d @@ -634,14 +557,10 @@ contexts: scope: punctuation.separator.sequence.d set: import-binding-list - - match: '[^\s]' - scope: invalid.illegal.d - - match: '[^\s]' - scope: invalid.illegal.d - - match: '[^\s]' - scope: invalid.illegal.d - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal + - include: not-whitespace-illegal + - include: not-whitespace-illegal + - include: not-whitespace-illegal type: - match: '\b({{type_ctor}})\b' scope: storage.modifier.d @@ -657,8 +576,9 @@ contexts: - match: '\)' scope: punctuation.section.group.end.d pop: true - - match: '(?=[^\s])' - scope: invalid.illegal.d + - include: not-whitespace-illegal + # - match: '(?=[^\s])' + # scope: invalid.illegal.d basic-type: - match: '\b({{identifier_ref}})\b' scope: storage.type.d @@ -695,6 +615,7 @@ contexts: declaration-in: - include: import-in - include: alias-in + - include: aggregate-in - include: function-or-variable-in function-or-variable-in: - match: '{{type_look_ahead}}' @@ -752,16 +673,14 @@ contexts: - match: '\)' scope: punctuation.section.group.end.d pop: true - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal # - match: '\.\.\.' # TODO - match: ',' push: type - match: '\)' scope: punctuation.section.group.end.d pop: true - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal alias-in: - match: '\b(alias)\b' scope: keyword.control.alias.d @@ -774,8 +693,7 @@ contexts: set: alias-new - match: '{{type_look_ahead}}' set: [alias-old, type] - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal alias-old: - match: '\b({{name}})\b' scope: entity.name.type.d @@ -784,24 +702,20 @@ contexts: scope: punctuation.separator.sequence.d set: alias-old - include: end-of-line - - match: '[^\s]' - scope: invalid.illegal.d - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal + - include: not-whitespace-illegal alias-new: - match: '\(' # TODO: template aliases pop: true - match: '(?==)' set: alias-new-assign - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal alias-new-assign: - match: '=' scope: keyword.operator.assignment.d set: [alias-new-after-type, type] - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal alias-new-after-type: - include: end-of-line - match: ',' @@ -810,8 +724,128 @@ contexts: - match: '\b{{name}}\b' scope: entity.name.type.d set: alias-new - - match: '[^\s]' - scope: invalid.illegal.d + - include: not-whitespace-illegal + - include: not-whitespace-illegal + aggregate-in: + - include: class-in + - include: interface-in + - include: struct-in + - include: union-in + # TODO: Templated aggregates!! + class-in: + - match: '\b(class)\b' + scope: storage.type.class.d + push: + - match: '\b({{name}})\b' + scope: entity.name.class.d + set: + - include: end-of-line + - match: ':' + scope: punctuation.separator.mapping.d + set: [class-body, base-class-list] + - match: '(?={)' + set: class-body + - include: not-whitespace-illegal + - include: not-whitespace-illegal + base-class-list: + - match: '{{type_look_ahead}}' + set: [base-class-list-after, basic-type] + - include: not-whitespace-illegal + base-class-list-after: + - match: ',' + scope: punctuation.separator.sequence.d + set: base-class-list + - match: '(?={)' + pop: true + - include: not-whitespace-illegal + class-body: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + # TODO: Don't use module-context-in + - include: module-context-in + - include: not-whitespace-illegal + - include: not-whitespace-illegal + interface-in: + - match: '\b(interface)\b' + scope: storage.type.interface.d + push: + - match: '\b({{name}})\b' + scope: entity.name.interface.d + set: + - include: end-of-line + - match: ':' + scope: punctuation.separator.mapping.d + set: [interface-body, base-class-list] + - match: '(?={)' + set: interface-body + - include: not-whitespace-illegal + - include: not-whitespace-illegal + interface-body: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + # TODO: Don't use module-context-in + - include: module-context-in + - include: not-whitespace-illegal + - include: not-whitespace-illegal + struct-in: + - match: '\b(struct)\b' + scope: storage.type.struct.d + push: + - match: '\b({{name}})\b' + scope: entity.name.struct.d + set: + - include: end-of-line + - match: '(?={)' + set: struct-body + - include: not-whitespace-illegal + - match: '(?={)' + set: struct-body + - include: not-whitespace-illegal + struct-body: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + # TODO: Don't use module-context-in + - include: module-context-in + - include: not-whitespace-illegal + - include: not-whitespace-illegal + union-in: + - match: '\b(union)\b' + scope: storage.type.union.d + push: + - match: '\b({{name}})\b' + scope: entity.name.union.d + set: + - include: end-of-line + - match: '(?={)' + set: union-body + - include: not-whitespace-illegal + - match: '(?={)' + set: union-body + - include: not-whitespace-illegal + union-body: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + # TODO: Don't use module-context-in + - include: module-context-in + - include: not-whitespace-illegal + - include: not-whitespace-illegal + not-whitespace-illegal: - match: '[^\s]' scope: invalid.illegal.d end-of-line: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 6b13fe4741..1a22a7c977 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -200,27 +200,28 @@ extern(1) // ^ punctuation.definition.annotation.end.d deprecated //^^^^^^^^^^ keyword.other.deprecated.d - deprecated("message") deprecated(q{void}) + deprecated( "message") deprecated(q{void}) //^^^^^^^^^^ keyword.other.deprecated.d // ^ punctuation.definition.annotation.begin.d -// ^^^^^^^^^ string.quoted.double.d -// ^ punctuation.definition.annotation.end.d -// ^^^^^^^^^^ keyword.other.deprecated.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^ string.unquoted.embedded.d source.d storage.type.d -// ^ punctuation.definition.annotation.end.d +// ^^^^^^^^^ string.quoted.double.d +// ^ punctuation.definition.annotation.end.d +// ^^^^^^^^^^ keyword.other.deprecated.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^ string.unquoted.embedded.d source.d storage.type.d +// ^ punctuation.definition.annotation.end.d private protected public export package //^^^^^^^ storage.modifier.access-control.d // ^^^^^^^^^ storage.modifier.access-control.d // ^^^^^^ storage.modifier.access-control.d // ^^^^^^ storage.modifier.access-control.d // ^^^^^^^ storage.modifier.access-control.d - package(foo.bar.) + package(foo.bar. ) //^^^^^^^ storage.modifier.access-control.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ variable.other.constant.d // ^ invalid.illegal.d -// ^ punctuation.definition.annotation.end.d +// ^ - invalid.illegal.d +// ^ punctuation.definition.annotation.end.d pragma(f) pragma(test, void) //^^^^^^ keyword.other.pragma.d // ^ punctuation.definition.annotation.begin.d @@ -323,3 +324,66 @@ extern(1) // ^ punctuation.terminator.d //TODO: Test for functions + + class Foo; +//^^^^^ storage.type.class.d +// ^^^ entity.name.class.d +// ^ punctuation.terminator.d + + class Bar : Foo, b { +//^^^^^ storage.type.class.d +// ^^^ entity.name.class.d +// ^ punctuation.separator.mapping.d +// ^^^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^ storage.type.d +// ^ punctuation.section.block.begin.d + class b {} + //^^^^^ storage.type.class.d + // ^ entity.name.class.d + // ^ punctuation.section.block.begin.d + // ^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d + + interface S; +//^^^^^^^^^ storage.type.interface.d +// ^ entity.name.interface.d +// ^ punctuation.terminator.d + interface Foo: Bar, Baz { +//^^^^^^^^^ storage.type.interface.d +// ^^^ entity.name.interface.d +// ^ punctuation.separator.mapping.d +// ^^^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ punctuation.section.block.begin.d + interface c{} + //^^^^^^^^^ storage.type.interface.d + // ^ entity.name.interface.d + // ^ punctuation.section.block.begin.d + // ^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d + + struct Foo { +//^^^^^^ storage.type.struct.d +// ^^^ entity.name.struct.d +// ^ punctuation.section.block.begin.d + struct { + //^^^^^^ storage.type.struct.d + // ^ punctuation.section.block.begin.d + union {} + //^^^^^ storage.type.union.d + // ^ punctuation.section.block.begin.d + // ^ punctuation.section.block.end.d + } + //^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d + + union Foo {} +//^^^^^ storage.type.union.d +// ^^^ entity.name.union.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d From cd763de1eec905426586bfcf295179bceadbc134 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 15:51:18 +1100 Subject: [PATCH 014/108] Implement enum parsing --- D/D.sublime-syntax | 69 +++++++++++++++++++++++++++++++++++++++++ D/tests/syntax_test_d.d | 47 ++++++++++++++++++++++++++++ 2 files changed, 116 insertions(+) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 626c0ee997..3e977ff7e9 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -616,6 +616,7 @@ contexts: - include: import-in - include: alias-in - include: aggregate-in + - include: enum-in - include: function-or-variable-in function-or-variable-in: - match: '{{type_look_ahead}}' @@ -845,6 +846,74 @@ contexts: - include: module-context-in - include: not-whitespace-illegal - include: not-whitespace-illegal + enum-in: + - match: '\b(enum)\b' + scope: storage.type.enum.d + push: + - match: '\b({{name}})\b' + scope: entity.name.enum.d + set: + - include: end-of-line + - match: '(?={)' + set: enum-body + - match: ':' + scope: punctuation.separator.mapping.d + set: [enum-body, type] + - include: not-whitespace-illegal + - match: ':' + scope: punctuation.separator.mapping.d + set: [enum-body, type] + - match: '(?={)' + set: anonymous-enum-body + - include: not-whitespace-illegal + enum-body: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: comment-in + - match: '(?=\b({{name}})\b)' + push: enum-member + - include: not-whitespace-illegal + anonymous-enum-body: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: comment-in + - include: attribute-in + - match: '(?=\b({{name}})\s*(=|,|}|$))' + push: enum-member + - match: '{{type_look_ahead}}' + push: [enum-member, type] + - include: not-whitespace-illegal + enum-member: + - match: '\b({{name}})\b' + scope: entity.name.constant.d + set: + - include: comment-in + - match: '=' + scope: keyword.operator.assignment.d + set: + - include: value-in + - include: comment-in + - match: ',' + scope: punctuation.separator.sequence.d + pop: true + - match: '(?=})' + pop: true + - include: not-whitespace-illegal + - match: ',' + scope: punctuation.separator.sequence.d + pop: true + - match: '(?=})' + pop: true + - include: not-whitespace-illegal + - include: not-whitespace-illegal not-whitespace-illegal: - match: '[^\s]' scope: invalid.illegal.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 1a22a7c977..5f14a1680f 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -387,3 +387,50 @@ extern(1) // ^^^ entity.name.union.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + + enum Foo { +//^^^^ storage.type.enum.d +// ^^^ entity.name.enum.d +// ^ punctuation.section.block.begin.d + foo, + //^^^ entity.name.constant.d + // ^ punctuation.separator.sequence.d + bar = 2, + //^^^ entity.name.constant.d + // ^ keyword.operator.assignment.d + // ^ constant.numeric.d + // ^ punctuation.separator.sequence.d + } +//^ punctuation.section.block.end.d + enum Foo : int { a = 12 } +//^^^^ storage.type.enum.d +// ^^^ entity.name.enum.d +// ^ punctuation.separator.mapping.d +// ^^^ storage.type.d +// ^ punctuation.section.block.begin.d +// ^ entity.name.constant.d +// ^ keyword.operator.assignment.d +// ^^ constant.numeric.d +// ^ punctuation.section.block.end.d + enum : foo[stirng] { TEST } +//^^^^ storage.type.enum.d +// ^ punctuation.separator.mapping.d +// ^^^ storage.type.d +// ^ keyword.operator.other.d +// ^^^^^^ storage.type.d +// ^ keyword.operator.other.d +// ^ punctuation.section.block.begin.d +// ^^^^ entity.name.constant.d +// ^ punctuation.section.block.end.d + enum { int a = 12, +//^^^^ storage.type.enum.d +// ^ punctuation.section.block.begin.d +// ^^^ storage.type.d +// ^ entity.name.constant.d +// ^ keyword.operator.assignment.d +// ^^ constant.numeric.d +// ^ punctuation.separator.sequence.d + Foo + //^^^ entity.name.constant.d + } +//^ punctuation.section.block.end.d From c4ceaf69b104091996ab9b70a07c3c96ed3521f9 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 16:42:21 +1100 Subject: [PATCH 015/108] Implement conditional declaration parsing --- D/D.sublime-syntax | 111 ++++++++++++++++++++++++++++++++++------ D/tests/syntax_test_d.d | 67 ++++++++++++++++++++++++ 2 files changed, 163 insertions(+), 15 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 3e977ff7e9..98880ad4a3 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -55,6 +55,11 @@ contexts: # - match: /\*\*/ # scope: comment.block.empty.d punctuation.definition.comment.d # - include: scope:text.html.javadoc + - include: import-in + - include: alias-in + - include: aggregate-in + - include: enum-in + - include: conditional-declaration-in - include: attribute-specifier-in - include: comment-in - match: |- @@ -126,8 +131,8 @@ contexts: scope: keyword.control.branch.d - match: \b(while|for|foreach(_reverse)?)\b scope: keyword.control.repeat.d - - match: \b(version|return|with|invariant|body|scope|in|out|inout|asm|mixin|function|delegate)\b - scope: keyword.control.statement.d + # - match: \b(version|return|with|invariant|body|scope|in|out|inout|asm|mixin|function|delegate)\b + # scope: keyword.control.statement.d - match: \b(true|false)\b scope: constant.language.boolean.d - match: \b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|null)\b @@ -151,15 +156,15 @@ contexts: scope: keyword.other.d - match: \b(new|throws)\b scope: keyword.other.class-fns.d - - match: \b(deprecated|unittest|debug)\b - scope: keyword.other.debug.d + # - match: \b(deprecated|unittest|debug)\b + # scope: keyword.other.debug.d - match: \b(u_char|u_short|u_int|u_long|ushort|uint|u_quad_t|quad_t|qaddr_t|caddr_t|daddr_t|dev_t|fixpt_t|blkcnt_t|blksize_t|gid_t|in_addr_t|in_port_t|ino_t|key_t|mode_t|nlink_t|id_t|pid_t|off_t|segsz_t|swblk_t|uid_t|id_t|clock_t|size_t|ssize_t|time_t|useconds_t|suseconds_t)\b scope: support.type.sys-types.c - match: \b(pthread_attr_t|pthread_cond_t|pthread_condattr_t|pthread_mutex_t|pthread_mutexattr_t|pthread_once_t|pthread_rwlock_t|pthread_rwlockattr_t|pthread_t|pthread_key_t)\b scope: support.type.pthread.c - match: \b(int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t|intmax_t|intmax_t|uintmax_t|uintmax_t)\b scope: support.type.stdint.c - - include: declaration-in + - include: function-or-variable-in all-types-in: - include: support-type-built-ins-in - include: support-type-in @@ -205,9 +210,6 @@ contexts: - match: '\b(void|byte|short|char|int|long|float|double|boolean|([a-z]\w+\.)*[A-Z]\w+(?![\(\.]))\b' scope: storage.type.d - function-context-in: - - include: comment-in - - include: declaration-in comment-in: - match: /\* scope: punctuation.definition.comment.d @@ -612,12 +614,6 @@ contexts: # TODO - match: '.' pop: true - declaration-in: - - include: import-in - - include: alias-in - - include: aggregate-in - - include: enum-in - - include: function-or-variable-in function-or-variable-in: - match: '{{type_look_ahead}}' push: [function-or-variable-after-type, type] @@ -646,7 +642,7 @@ contexts: - match: '{' scope: punctuation.section.block.begin.d set: - - include: function-context-in + - include: module-context-in - match: '}' scope: punctuation.section.block.end.d pop: true @@ -914,6 +910,91 @@ contexts: pop: true - include: not-whitespace-illegal - include: not-whitespace-illegal + conditional-declaration-in: + - match: '\b(static)\s+(if)\b' + captures: + 1: keyword.control.conditional.d + 2: keyword.control.conditional.d + push: [conditional-declaration-body, condition] + - match: '\b(version)\b' + scope: keyword.control.conditional.d + push: [conditional-declaration-body, version-condition] + - match: '\b(debug)\b' + scope: keyword.control.conditional.d + push: [conditional-declaration-body, debug-condition] + conditional-declaration-body: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + set: + - match: '\b(else)\b' + scope: keyword.control.conditional.d + set: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: module-context-in + - match: ':' + scope: punctuation.section.block.begin.d + pop: true + - include: not-whitespace-illegal + - match: '(?=[^\s])' + pop: true + - include: module-context-in + - match: ':' + scope: punctuation.section.block.begin.d + pop: true + - include: not-whitespace-illegal + version-condition: + - match: '\(' + scope: punctuation.section.brackets.begin.d + set: + - match: '\b(unittest|assert)\b' + scope: keyword.d + set: version-condition-end + - match: '\b({{name}})\b' + scope: constant.other.d + set: version-condition-end + # TODO: Use proper integer literals here + - match: '\b([0-9]+)\b' + scope: constant.numeric.d + set: version-condition-end + - include: not-whitespace-illegal + - include: not-whitespace-illegal + version-condition-end: + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal + debug-condition: + - match: '\(' + scope: punctuation.section.brackets.begin.d + set: + - match: '\b({{name}})\b' + scope: constant.other.d + set: version-condition-end + # TODO: Use proper integer literals here + - match: '\b([0-9]+)\b' + scope: constant.numeric.d + set: version-condition-end + - include: not-whitespace-illegal + - match: '(?={|:)' + pop: true + - include: not-whitespace-illegal + condition: + - match: '\(' + scope: punctuation.section.brackets.begin.d + set: + - include: value-in + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal not-whitespace-illegal: - match: '[^\s]' scope: invalid.illegal.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 5f14a1680f..e53671ae14 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -434,3 +434,70 @@ extern(1) //^^^ entity.name.constant.d } //^ punctuation.section.block.end.d + + version(unittest) {} +//^^^^^^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^^^^^^^^ keyword.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + version(assert) {} +//^^^^^^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^^^^^^ keyword.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + version(foo) {} +//^^^^^^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^^^ constant.other.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + version(1): +//^^^^^^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d + + debug: +//^^^^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d + debug {} else {} +//^^^^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^^^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + debug(foo) {} else: +//^^^^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^^^ constant.other.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^^^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d + + static if (12 + 5): +//^^^^^^ keyword.control.conditional.d +// ^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^^ constant.numeric.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d + static if (true) {} else {} +//^^^^^^ keyword.control.conditional.d +// ^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^^^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d From a506b685103fa510c06c7342ed86e7a6a548baeb Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 17:06:22 +1100 Subject: [PATCH 016/108] Implement static foreach parsing --- D/D.sublime-syntax | 46 +++++++++++++++++++++++++++++++++++++++-- D/tests/syntax_test_d.d | 25 ++++++++++++++++++++++ 2 files changed, 69 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 98880ad4a3..0db1733549 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -60,6 +60,7 @@ contexts: - include: aggregate-in - include: enum-in - include: conditional-declaration-in + - include: static-foreach-in - include: attribute-specifier-in - include: comment-in - match: |- @@ -129,8 +130,8 @@ contexts: scope: keyword.control.conditional.d - match: \b(goto|break|continue)\b scope: keyword.control.branch.d - - match: \b(while|for|foreach(_reverse)?)\b - scope: keyword.control.repeat.d + # - match: \b(while|for|foreach(_reverse)?)\b + # scope: keyword.control.repeat.d # - match: \b(version|return|with|invariant|body|scope|in|out|inout|asm|mixin|function|delegate)\b # scope: keyword.control.statement.d - match: \b(true|false)\b @@ -986,6 +987,47 @@ contexts: - match: '(?={|:)' pop: true - include: not-whitespace-illegal + static-foreach-in: + - match: '\b(static)\s+(foreach|foreach_reverse)\b' + captures: + 1: keyword.control.flow.d + 2: keyword.control.flow.d + push: [static-foreach-block, foreach-condition] + static-foreach-block: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: module-context-in + - include: not-whitespace-illegal + foreach-condition: + - match: '\(' + scope: punctuation.section.brackets.begin.d + set: + - match: '\b({{name}})\s*(?=;)' + captures: + 1: variable.other.d + set: foreach-condition-end + - match: '{{type_look_ahead}}' + set: [foreach-condition-name, type] + - include: not-whitespace-illegal + - include: not-whitespace-illegal + foreach-condition-name: + - match: '\b({{name}})\b' + scope: variable.other.d + set: foreach-condition-end + - include: not-whitespace-illegal + foreach-condition-end: + - match: ';' + scope: punctuation.separator.sequence.d + set: + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: value-in + - include: not-whitespace-illegal condition: - match: '\(' scope: punctuation.section.brackets.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index e53671ae14..f3b859a88b 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -501,3 +501,28 @@ extern(1) // ^^^^ keyword.control.conditional.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + + static foreach (foo; 12 .. 3) { +//^^^^^^ keyword.control.flow.d +// ^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^^^ variable.other.d +// ^ punctuation.separator.sequence.d +// ^^ constant.numeric.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d + static foreach (int a; 123) { + //^^^^^^ keyword.control.flow.d + // ^^^^^^^ keyword.control.flow.d + // ^ punctuation.section.brackets.begin.d + // ^^^ storage.type.d + // ^ variable.other.d + // ^ punctuation.separator.sequence.d + // ^^^ constant.numeric.d + // ^ punctuation.section.brackets.end.d + // ^ punctuation.section.block.begin.d + } + //^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d From 8478fbfd2ded1b93e61de441f239d0d9d9df2505 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 17:13:00 +1100 Subject: [PATCH 017/108] Implement static assert --- D/D.sublime-syntax | 10 ++++++++++ D/tests/syntax_test_d.d | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 0db1733549..ec55b2ade4 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -61,6 +61,7 @@ contexts: - include: enum-in - include: conditional-declaration-in - include: static-foreach-in + - include: static-assert-in - include: attribute-specifier-in - include: comment-in - match: |- @@ -1002,6 +1003,12 @@ contexts: pop: true - include: module-context-in - include: not-whitespace-illegal + static-assert-in: + - match: '\b(static)\s+(assert)\b' + captures: + 1: keyword.control.conditional.d + 2: keyword.control.conditional.d + push: [expect-end-of-line, condition] foreach-condition: - match: '\(' scope: punctuation.section.brackets.begin.d @@ -1044,6 +1051,9 @@ contexts: - match: ';' scope: punctuation.terminator.d pop: true + expect-end-of-line: + - include: end-of-line + - include: not-whitespace-illegal support-type-built-ins-classes-in: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b scope: support.type.built-ins.classes.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index f3b859a88b..161ff186d1 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -526,3 +526,11 @@ extern(1) //^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + + static assert(12); +//^^^^^^ keyword.control.conditional.d +// ^^^^^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.terminator.d From d7c936885c850c71e78bdc760308c165ad6b4cb4 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 17:58:28 +1100 Subject: [PATCH 018/108] Implement constructor parsing --- D/D.sublime-syntax | 108 +++++++++++++++++----------------------- D/tests/syntax_test_d.d | 17 +++++++ 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index ec55b2ade4..cc471e7a7b 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -62,53 +62,10 @@ contexts: - include: conditional-declaration-in - include: static-foreach-in - include: static-assert-in + - include: constructor-in + - include: destructor-in - include: attribute-specifier-in - include: comment-in - - match: |- - (?x)^\s* - ((?:\b(private|package|protected|public|export|static|final|native|synchronized|abstract|threadsafe|transient|shared|__gshared)\b\s*)*) # modifier - (\b(this))\s* # identifier - (?!.*;) # abort if line has a ; - (?=\() - captures: - 1: storage.modifier.d - 3: entity.name.function.constructor.d - push: - - meta_scope: meta.function.d meta.function.constructor.d - - include: function_assertions - - include: $top_level_main - - match: |- - (?x) - (?: ^ # begin-of-line - | (?: (?|(?:\[\s*\])*)?|typeof\(.*?\)|const\(.*?\)\*?)\s* # type - # (\w+)\s* # identifier - # (?!.*;) # abort if line has a ; - # (?=\() - # captures: - # 1: storage.modifier.d - # 2: storage.type.d - # 3: entity.name.function.d - # push: - # - meta_scope: meta.function.d - # - include: function_assertions - # - include: $top_level_main - match: '\{' push: - meta_scope: meta.block.d @@ -637,30 +594,32 @@ contexts: - match: '\b({{name}})\s*(?=\(|$)' captures: 1: entity.name.function.d - set: [function-definition, function-argument-definition-list] + set: function-definition-begin - match: '(?=[^\s])' pop: true - function-definition: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - include: module-context-in - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - match: ';' - pop: true - value-in: - - include: number-in - - include: string-in + function-definition-begin: + - match: '(?=\()' + set: [function-definition-after-argument-list1, function-argument-definition-list] + - include: not-whitespace-illegal + function-definition-after-argument-list1: + - match: '(?=\()' + set: [function-definition-after-argument-list2, function-argument-definition-list] + - include: function-definition-after-argument-list2 + function-definition-after-argument-list2: + - include: attribute-specifier-in + - match: '(?={|;)' + set: function-definition + - include: not-whitespace-illegal function-argument-definition-list: - match: '\(' - scope: punctuation.section.group.start.d + scope: punctuation.section.group.begin.d set: - match: '{{type_look_ahead}}' set: [function-argument, type] - - match: '(?=[^\s])' - pop: true + - match: '\)' + scope: punctuation.section.group.end.d + pop: true + - include: not-whitespace-illegal function-argument: - match: '\b{{name}}\b' scope: variable.parameter.d @@ -680,6 +639,19 @@ contexts: scope: punctuation.section.group.end.d pop: true - include: not-whitespace-illegal + function-definition: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - include: module-context-in + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: end-of-line + - include: not-whitespace-illegal + value-in: + - include: number-in + - include: string-in alias-in: - match: '\b(alias)\b' scope: keyword.control.alias.d @@ -1009,6 +981,18 @@ contexts: 1: keyword.control.conditional.d 2: keyword.control.conditional.d push: [expect-end-of-line, condition] + constructor-in: + - match: '\b(this)\s*(?=\(|$)' + captures: + 1: entity.name.function.constructor.d + push: function-definition-begin + destructor-in: + - match: '(~)\s*(this)\s*(?=\(|$)' + captures: + 1: entity.name.function.destructor.d + 2: entity.name.function.destructor.d + push: function-definition-begin + foreach-condition: - match: '\(' scope: punctuation.section.brackets.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 161ff186d1..6528ac7582 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -534,3 +534,20 @@ extern(1) // ^^ constant.numeric.d // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d + + this(int foo) { +//^^^^ entity.name.function.constructor.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^^^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d + ~this() @disable; +//^^^^^ entity.name.function.destructor.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^^^ storage.attribute.d +// ^ punctuation.terminator.d From 79a6bb3b6c17f9c1c95c904c2f2f78f81eed241f Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 18:03:50 +1100 Subject: [PATCH 019/108] Fix meta_scope for token strings --- D/D.sublime-syntax | 5 ++--- D/tests/syntax_test_d.d | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index cc471e7a7b..4889ce9571 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -329,12 +329,11 @@ contexts: pop: true # Token string - match: 'q{' - scope: punctuation.definition.string.begin.d + scope: string.unquoted.embedded.d punctuation.definition.string.begin.d push: - - meta_scope: string.unquoted.embedded.d - meta_content_scope: source.d - match: '}' - scope: punctuation.definition.string.end.d + scope: string.unquoted.embedded.d punctuation.definition.string.end.d pop: true - include: tokens-in tokens-in: # Purely a set of un-verified tokens, for use in token string diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 6528ac7582..3e9282a775 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -77,9 +77,9 @@ auto tokenString = q{ this is not real code 12 // ^^^^ source.d variable.language.d // ^^ source.d keyword.d -// ^^^^^^^^^^^^^ string.unquoted.embedded.d source.d -// ^^^^ string.unquoted.embedded.d source.d storage.type.d -// ^^ string.unquoted.embedded.d source.d constant.numeric.d +// ^^^^^^^^^^^^^ source.d +// ^^^^ source.d storage.type.d +// ^^ source.d constant.numeric.d /*}*/ // ^^ punctuation.definition.comment.d // ^^ punctuation.definition.comment.d @@ -207,7 +207,7 @@ extern(1) // ^ punctuation.definition.annotation.end.d // ^^^^^^^^^^ keyword.other.deprecated.d // ^ punctuation.definition.annotation.begin.d -// ^^^^ string.unquoted.embedded.d source.d storage.type.d +// ^^^^ source.d storage.type.d // ^ punctuation.definition.annotation.end.d private protected public export package //^^^^^^^ storage.modifier.access-control.d From 7d2ecc8d113e963516f4ef8b39a3b86284ffbdab Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 18:33:29 +1100 Subject: [PATCH 020/108] Add function parsing tests --- D/D.sublime-syntax | 2 ++ D/tests/syntax_test_d.d | 51 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 4889ce9571..5942e662fb 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -624,6 +624,7 @@ contexts: scope: variable.parameter.d set: - match: ',' + scope: punctuation.separator.sequence.d set: [function-argument, type] - match: '=' # TODO @@ -633,6 +634,7 @@ contexts: - include: not-whitespace-illegal # - match: '\.\.\.' # TODO - match: ',' + scope: punctuation.separator.sequence.d push: type - match: '\)' scope: punctuation.section.group.end.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 3e9282a775..343f912122 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -323,8 +323,6 @@ extern(1) // ^^^^^^^^^^^^^^ variable.other.d // ^ punctuation.terminator.d -//TODO: Test for functions - class Foo; //^^^^^ storage.type.class.d // ^^^ entity.name.class.d @@ -535,6 +533,55 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d + int[string] foo() { +//^^^ storage.type.d +// ^ keyword.operator.other.d +// ^^^^^^ storage.type.d +// ^ keyword.operator.other.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d + void bar(); + //^^^^ storage.type.d + // ^^^ entity.name.function.d + // ^ punctuation.section.group.begin.d + // ^ punctuation.section.group.end.d + // ^ punctuation.terminator.d + int[] map(int[] array, ) { + //^^^ storage.type.d + // ^^ keyword.operator.other.d + // ^^^ entity.name.function.d + // ^ punctuation.section.group.begin.d + // ^^^ storage.type.d + // ^^ keyword.operator.other.d + // ^^^^^ variable.parameter.d + // ^ punctuation.separator.sequence.d + // ^ + // ^ punctuation.section.block.begin.d + } + //^ punctuation.section.block.end.d + T[] map(T, void fn)(T[] array) { + //^ storage.type.d + // ^^ keyword.operator.other.d + // ^^^ entity.name.function.d + // ^ punctuation.section.group.begin.d + // ^ storage.type.d + // ^ punctuation.separator.sequence.d + // ^^^^ storage.type.d + // ^^ variable.parameter.d + // ^ punctuation.section.group.end.d + // ^ punctuation.section.group.begin.d + // ^ storage.type.d + // ^^ keyword.operator.other.d + // ^^^^^ variable.parameter.d + // ^ punctuation.section.group.end.d + // ^ punctuation.section.block.begin.d + } + //^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d + this(int foo) { //^^^^ entity.name.function.constructor.d // ^ punctuation.section.group.begin.d From 67d24138a3330606a62cd492a7b7c9016cf94712 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 18:54:34 +1100 Subject: [PATCH 021/108] Implement invariant parsing --- D/D.sublime-syntax | 43 +++++++++++++++++++++++++++++++++++++++-- D/tests/syntax_test_d.d | 19 ++++++++++++++++++ 2 files changed, 60 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 5942e662fb..38cf73eb42 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -64,6 +64,7 @@ contexts: - include: static-assert-in - include: constructor-in - include: destructor-in + - include: invariant-in - include: attribute-specifier-in - include: comment-in - match: '\{' @@ -981,7 +982,7 @@ contexts: captures: 1: keyword.control.conditional.d 2: keyword.control.conditional.d - push: [expect-end-of-line, condition] + push: [expect-end-of-line, assert-arguments] constructor-in: - match: '\b(this)\s*(?=\(|$)' captures: @@ -993,7 +994,27 @@ contexts: 1: entity.name.function.destructor.d 2: entity.name.function.destructor.d push: function-definition-begin - + invariant-in: + - match: '\b(invariant)\b' + scope: keyword.control.flow.d + push: + - match: '(?=\()' + set: [invariant-block, assert-arguments] + - match: '(?={)' + set: invariant-block + - include: not-whitespace-illegal + invariant-block: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - include: module-context-in + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - match: ';' + scope: punctuation.terminator.d + pop: true + - include: not-whitespace-illegal foreach-condition: - match: '\(' scope: punctuation.section.brackets.begin.d @@ -1020,6 +1041,24 @@ contexts: pop: true - include: value-in - include: not-whitespace-illegal + assert-arguments: + - match: '\(' + scope: punctuation.section.brackets.begin.d + set: + - include: value-in + - match: ',' + scope: punctuation.separator.sequence.d + set: + - include: value-in + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal + - include: not-whitespace-illegal condition: - match: '\(' scope: punctuation.section.brackets.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 343f912122..cfe736216f 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -598,3 +598,22 @@ extern(1) // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ storage.attribute.d // ^ punctuation.terminator.d + + invariant(0, "test") { +//^^^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.separator.sequence.d +// ^^^^^^ string.quoted.double.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d + invariant(); + //^^^^^^^^^ keyword.control.flow.d + // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.brackets.end.d + invariant {} + //^^^^^^^^^ keyword.control.flow.d + // ^ punctuation.section.block.begin.d + // ^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d From 551cb3c61e27211dda41a7602b925407a93f6c57 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 19:00:53 +1100 Subject: [PATCH 022/108] Make comment inclusion implicit with prototype --- D/D.sublime-syntax | 21 ++++++++++++++------- D/tests/syntax_test_d.d | 13 ++++++------- 2 files changed, 20 insertions(+), 14 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 38cf73eb42..167d4ec35d 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -31,14 +31,17 @@ variables: reserved: '{{keyword}}|{{basic_type}}|{{language_constant}}|{{langauge_variable}}' contexts: + prototype: + - include: comment-in + main: + - meta_include_prototype: false - match: '^#!.*$' scope: comment.line.shebang.d set: main-after-shebang-in - match: '(?=.)' set: main-after-shebang-in main-after-shebang-in: - - include: comment-in - include: attribute-specifier-in - match: '\b(module)\s+({{identifier}})(;)' scope: meta.module.d @@ -66,7 +69,6 @@ contexts: - include: destructor-in - include: invariant-in - include: attribute-specifier-in - - include: comment-in - match: '\{' push: - meta_scope: meta.block.d @@ -224,6 +226,7 @@ contexts: - match: '"' scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.d - match: '(")({{string_postfix}})' captures: @@ -238,6 +241,7 @@ contexts: - match: r" scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(")({{string_postfix}})' captures: @@ -248,6 +252,7 @@ contexts: - match: "`" scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.backtick.d - match: '(`)({{string_postfix}})' captures: @@ -258,6 +263,7 @@ contexts: - match: x" scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(")({{string_postfix}})' captures: @@ -274,6 +280,7 @@ contexts: captures: 2: invalid.illegal.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(^\1")({{string_postfix}})' captures: @@ -284,6 +291,7 @@ contexts: - match: 'q"\[' scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(\]")({{string_postfix}})' captures: @@ -293,6 +301,7 @@ contexts: - match: 'q"\(' scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(\)")({{string_postfix}})' captures: @@ -302,6 +311,7 @@ contexts: - match: 'q"<' scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(>")({{string_postfix}})' captures: @@ -311,6 +321,7 @@ contexts: - match: 'q"{' scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(}")({{string_postfix}})' captures: @@ -321,6 +332,7 @@ contexts: - match: 'q"(.)' scope: punctuation.definition.string.begin.d push: + - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(\1"|\1(.))({{string_postfix}})' captures: @@ -346,7 +358,6 @@ contexts: scope: constant.language.d - match: '\b({{langauge_variable}})\b' scope: variable.language.d - - include: comment-in - include: character-in - include: string-in - include: number-in @@ -845,7 +856,6 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - - include: comment-in - match: '(?=\b({{name}})\b)' push: enum-member - include: not-whitespace-illegal @@ -856,7 +866,6 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - - include: comment-in - include: attribute-in - match: '(?=\b({{name}})\s*(=|,|}|$))' push: enum-member @@ -867,12 +876,10 @@ contexts: - match: '\b({{name}})\b' scope: entity.name.constant.d set: - - include: comment-in - match: '=' scope: keyword.operator.assignment.d set: - include: value-in - - include: comment-in - match: ',' scope: punctuation.separator.sequence.d pop: true diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index cfe736216f..48b4c8e452 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -18,19 +18,19 @@ module foo.a.b1_3; +/ //^^ comment.block.nested.d punctuation.definition.comment.d -auto wysiwyg = r"foo \n\"; +auto wysiwyg = r"f// \n\"; // ^^ punctuation.definition.string.begin.d // ^^^^^^^^^^ string.quoted.double.raw.d // ^ punctuation.definition.string.end.d -auto wysiwygAlt = `foo\n\`; +auto wysiwygAlt = `f//\n\`; // ^ punctuation.definition.string.begin.d // ^^^^^^^^ string.quoted.double.raw.backtick.d // ^ punctuation.definition.string.end.d -auto doubleQuoted = "c:\'\"\?\\\0\a\b\f\n\r\t\v\x0B\2\12\762\u0feb\Uabcdef98\""; +auto doubleQuoted = "c://\'\"\?\\\0\a\b\f\n\r\t\v\x0B\2\12\762\u0feb\Uabcdef98\""; // ^ punctuation.definition.string.begin.d -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.d -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.character.escape.d -// ^ punctuation.definition.string.end.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.character.escape.d +// ^ punctuation.definition.string.end.d auto invalidEscape = "\p"; // ^^ string.quoted.double.d invalid.illegal.unknown-escape.d auto hexString = x"00 ba @@ -92,7 +92,6 @@ auto tokenString = q{ }; // <- string.unquoted.embedded.d punctuation.definition.string.end.d - auto c = 'a'; // ^^^ string.quoted.single.d c = 'Ó'; From 2bc84455bac20dea7ab0f9221deab9ba43ccd999 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 19:10:32 +1100 Subject: [PATCH 023/108] Implement unittest parsing --- D/D.sublime-syntax | 14 ++++++++++++++ D/tests/syntax_test_d.d | 11 +++++++++++ 2 files changed, 25 insertions(+) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 167d4ec35d..54b0bf2276 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -68,6 +68,7 @@ contexts: - include: constructor-in - include: destructor-in - include: invariant-in + - include: unittest-in - include: attribute-specifier-in - match: '\{' push: @@ -1022,6 +1023,19 @@ contexts: scope: punctuation.terminator.d pop: true - include: not-whitespace-illegal + unittest-in: + - match: '\b(unittest)\b' + scope: keyword.control.conditional.d + push: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - include: module-context-in + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: not-whitespace-illegal + foreach-condition: - match: '\(' scope: punctuation.section.brackets.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 48b4c8e452..80f49643ca 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -616,3 +616,14 @@ extern(1) // ^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + + unittest { +//^^^^^^^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d + unittest { + //^^^^^^^^ keyword.control.conditional.d + // ^ punctuation.section.block.begin.d + } + //^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d From af536c0c32c4bb75432bfafef83ef729011b2730 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Fri, 18 Jan 2019 19:35:02 +1100 Subject: [PATCH 024/108] Implement special case alias this parsing --- D/D.sublime-syntax | 6 ++++++ D/tests/syntax_test_d.d | 10 ++++++++++ 2 files changed, 16 insertions(+) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 54b0bf2276..c03d236571 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -667,6 +667,12 @@ contexts: - include: number-in - include: string-in alias-in: + - match: '\b(alias)\s+({{identifier}})\s+(this)(;)' + captures: + 1: keyword.control.alias.d + 2: variable.d + 3: constant.language.d + 4: punctuation.terminator.d - match: '\b(alias)\b' scope: keyword.control.alias.d push: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 80f49643ca..75fe0e6e64 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -302,6 +302,16 @@ extern(1) // ^ punctuation.separator.sequence.d // ^ entity.name.type.d // ^ punctuation.terminator.d + alias foo this; +//^^^^^ keyword.control.alias.d +// ^^^ variable.d +// ^^^^ constant.language.d +// ^ punctuation.terminator.d + alias foo.bar.baz this; +//^^^^^ keyword.control.alias.d +// ^^^^^^^^^^^ variable.d +// ^^^^ constant.language.d +// ^ punctuation.terminator.d int a; //^^^ storage.type.d From c243559ba18c306ea9e4bd03a3b7b72d2a9a8154 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 19 Jan 2019 13:21:19 +1100 Subject: [PATCH 025/108] Implement version and debug spec parsing --- D/D.sublime-syntax | 15 +++++++++++++++ D/tests/syntax_test_d.d | 11 +++++++++++ 2 files changed, 26 insertions(+) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index c03d236571..ae954691c5 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -62,6 +62,7 @@ contexts: - include: alias-in - include: aggregate-in - include: enum-in + - include: specification-in - include: conditional-declaration-in - include: static-foreach-in - include: static-assert-in @@ -1041,6 +1042,20 @@ contexts: scope: punctuation.section.block.end.d pop: true - include: not-whitespace-illegal + specification-in: + - match: '\b(version|debug)\s*(=)' + captures: + 1: keyword.control.conditional.d + 2: keyword.operator.assignment.d + push: + - match: '\b{{name}}\b' + scope: entity.name.constant.d + set: expect-end-of-line + # TODO: Use proper integer literals here + - match: '[0-9]+' + scope: constant.numeric.d + set: expect-end-of-line + - include: not-whitespace-illegal foreach-condition: - match: '\(' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 75fe0e6e64..b4d6405aba 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -490,6 +490,17 @@ extern(1) // ^^^^ keyword.control.conditional.d // ^ punctuation.section.block.begin.d + debug = 2; +//^^^^^ keyword.control.conditional.d +// ^ keyword.operator.assignment.d +// ^ constant.numeric.d +// ^ punctuation.terminator.d + version = foo; +//^^^^^^^ keyword.control.conditional.d +// ^ keyword.operator.assignment.d +// ^^^ entity.name.constant.d +// ^ punctuation.terminator.d + static if (12 + 5): //^^^^^^ keyword.control.conditional.d // ^^ keyword.control.conditional.d From e546000217d2d21392a7d17d742bfc16cd95d875 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 19 Jan 2019 23:55:39 +1100 Subject: [PATCH 026/108] Implement template and mixin parsing --- D/D.sublime-syntax | 44 +++++++++++++++++++++++++++++ D/tests/syntax_test_d.d | 62 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 106 insertions(+) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index ae954691c5..8d0e49d229 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -70,6 +70,8 @@ contexts: - include: destructor-in - include: invariant-in - include: unittest-in + - include: template-in + - include: mixin-in - include: attribute-specifier-in - match: '\{' push: @@ -632,6 +634,7 @@ contexts: - match: '\)' scope: punctuation.section.group.end.d pop: true + - include: not-whitespace-illegal - include: not-whitespace-illegal function-argument: - match: '\b{{name}}\b' @@ -1056,6 +1059,47 @@ contexts: scope: constant.numeric.d set: expect-end-of-line - include: not-whitespace-illegal + template-in: + - match: '\b(template)\b' + scope: storage.type.d + push: template + template: + - match: '\b({{name}})\b' + scope: entity.name.template.d + set: template-definition-begin + - include: not-whitespace-illegal + template-definition-begin: + - match: '(?=\()' + set: [template-definition-after-argument-list, function-argument-definition-list] + - include: not-whitespace-illegal + template-definition-after-argument-list: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: module-context-in + - include: not-whitespace-illegal + mixin-in: + - match: '\b(mixin)\b' + scope: keyword.control.d + push: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: + - match: '\)' + scope: punctuation.section.parens.end.d + set: + - match: ';' + scope: punctuation.terminator.d + pop: true + - include: value-in + - match: '\b(template)\b' + scope: storage.type.d + set: template + # TODO: Template + - include: not-whitespace-illegal foreach-condition: - match: '\(' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index b4d6405aba..f9054874bf 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -601,6 +601,26 @@ extern(1) //^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + VeryLongTypeNameThatWillForceALineWrapWith80WidthLines +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ storage.type.d + veryLongFunctionNameToHelpWithTheLineWrappingThing +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.function.d + ( +//^ punctuation.section.group.begin.d + int aVeryLongArgumentName, + //^^^ storage.type.d + // ^^^^^^^^^^^^^^^^^^^^^ variable.parameter.d + // ^ punctuation.separator.sequence.d + ) +//^ punctuation.section.group.end.d + { +//^ punctuation.section.block.begin.d + int a; + //^^^ storage.type.d + // ^ variable.other.d + // ^ punctuation.terminator.d + } +//^ punctuation.section.block.end.d this(int foo) { //^^^^ entity.name.function.constructor.d @@ -648,3 +668,45 @@ extern(1) //^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + + template foo(T, A) { +//^^^^^^^^ storage.type.d +// ^^^ entity.name.template.d +// ^ punctuation.section.group.begin.d +// ^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^ storage.type.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d + template a(size_t f) { + //^^^^^^^^ storage.type.d + // ^ entity.name.template.d + // ^ punctuation.section.group.begin.d + // ^^^^^^ storage.type.d + // ^ variable.parameter.d + // ^ punctuation.section.group.end.d + // ^ punctuation.section.block.begin.d + } + //^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d + + mixin template f(int a) { +//^^^^^ keyword.control.d +// ^^^^^^^^ storage.type.d +// ^ entity.name.template.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d + mixin("foo"); +//^^^^^ keyword.control.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.definition.string.begin.d +// ^^^^^ string.quoted.double.d +// ^ punctuation.definition.string.end.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d From aa78501f6b93f3bc4e600e9d6381d63eb810dca3 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sun, 20 Jan 2019 00:18:25 +1100 Subject: [PATCH 027/108] Fix static if else block not allowing an else static if --- D/D.sublime-syntax | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 8d0e49d229..9729df348d 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -422,7 +422,8 @@ contexts: scope: variable.other.constant.d pop: true uda: - - include: module-context-in + # TODO: Use function call here + - include: value-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -936,7 +937,8 @@ contexts: - match: ':' scope: punctuation.section.block.begin.d pop: true - - include: not-whitespace-illegal + - match: '(?=[^\s])' + pop: true - match: '(?=[^\s])' pop: true - include: module-context-in From 0ce5bc6100bb367279a286c16ff11589e46ad5cf Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sun, 20 Jan 2019 16:10:59 +1100 Subject: [PATCH 028/108] Bit of a refactor and add parsing for conditionals, loops and other flow statements --- D/D.sublime-syntax | 177 +++++++++++++++++++++++++++++++--------- D/tests/syntax_test_d.d | 164 ++++++++++++++++++++++++++++++++++++- 2 files changed, 299 insertions(+), 42 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 9729df348d..e156728d3e 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -30,6 +30,8 @@ variables: langauge_variable: 'this|super' reserved: '{{keyword}}|{{basic_type}}|{{language_constant}}|{{langauge_variable}}' + block_statement_loohahead: '(?={)' + contexts: prototype: - include: comment-in @@ -49,18 +51,17 @@ contexts: 1: keyword.control.module.d 2: entity.name.namespace.d 3: punctuation.terminator.d - set: module-context-in + set: statement-list-in - match: '\s' - match: (?=.) - set: module-context-in - module-context-in: - - match: '\b(module)\b' - # - match: /\*\*/ - # scope: comment.block.empty.d punctuation.definition.comment.d - # - include: scope:text.html.javadoc + set: statement-list-in + statement-list-in: - include: import-in - include: alias-in - - include: aggregate-in + - include: class-in + - include: interface-in + - include: struct-in + - include: union-in - include: enum-in - include: specification-in - include: conditional-declaration-in @@ -72,13 +73,37 @@ contexts: - include: unittest-in - include: template-in - include: mixin-in + - include: block-statement-in + - include: statement-label-in + - include: conditional-in + - include: loop-in + - include: flow-statement-in - include: attribute-specifier-in - - match: '\{' - push: - - meta_scope: meta.block.d - - match: '\}' + # TODO: Remote these + - include: number-in + - include: character-in + - include: string-in + + - include: function-or-variable-in + # - include: not-whitespace-illegal + block-statement-in: + - match: '{{block_statement_loohahead}}' + push: block-statement + block-statement: + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d pop: true - - include: $top_level_main + - include: statement-list-in + - include: not-whitespace-illegal + optional-block-statement: + - match: '{{block_statement_loohahead}}' + set: block-statement + - match: '(?=[^\s])' + pop: true + module-context-in: - match: '\b([A-Z][A-Z0-9_]+)\b' scope: constant.other.d - match: \b(auto|static|override|final|const|abstract|volatile|synchronized|lazy|immutable|shared|__gshared|pure|nothrow|ref)\b @@ -105,9 +130,7 @@ contexts: scope: constant.language.d - match: \b(this|super)\b scope: variable.language.d - - include: number-in - - include: character-in - - include: string-in + - match: (==|!=|<=|>=|<>|<|>) scope: keyword.operator.comparison.d - match: (\-\-|\+\+) @@ -177,6 +200,10 @@ contexts: scope: storage.type.d comment-in: + # - match: /\*\*/ + # scope: comment.block.empty.d punctuation.definition.comment.d + # - include: scope:text.html.javadoc + - match: /\* scope: punctuation.definition.comment.d push: @@ -376,7 +403,7 @@ contexts: attribute-specifier-in: - include: attribute-in - match: ':' - scope: punctuation.section.d + scope: punctuation.separator.d attribute-in: - match: '\b({{attributes}})\b' scope: storage.modifier.d @@ -444,7 +471,7 @@ contexts: scope: punctuation.definition.annotation.end.d pop: true deprecated-attribute: - - include: module-context-in + - include: statement-list-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -468,7 +495,7 @@ contexts: - match: '\b({{name}})\b' scope: variable.function.d set: - - include: module-context-in + - include: statement-list-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -662,7 +689,7 @@ contexts: - match: '{' scope: punctuation.section.block.begin.d set: - - include: module-context-in + - include: statement-list-in - match: '}' scope: punctuation.section.block.end.d pop: true @@ -722,11 +749,6 @@ contexts: set: alias-new - include: not-whitespace-illegal - include: not-whitespace-illegal - aggregate-in: - - include: class-in - - include: interface-in - - include: struct-in - - include: union-in # TODO: Templated aggregates!! class-in: - match: '\b(class)\b' @@ -761,8 +783,8 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - # TODO: Don't use module-context-in - - include: module-context-in + # TODO: Don't use statement-list-in + - include: statement-list-in - include: not-whitespace-illegal - include: not-whitespace-illegal interface-in: @@ -787,8 +809,8 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - # TODO: Don't use module-context-in - - include: module-context-in + # TODO: Don't use statement-list-in + - include: statement-list-in - include: not-whitespace-illegal - include: not-whitespace-illegal struct-in: @@ -812,8 +834,8 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - # TODO: Don't use module-context-in - - include: module-context-in + # TODO: Don't use statement-list-in + - include: statement-list-in - include: not-whitespace-illegal - include: not-whitespace-illegal union-in: @@ -837,8 +859,8 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - # TODO: Don't use module-context-in - - include: module-context-in + # TODO: Don't use statement-list-in + - include: statement-list-in - include: not-whitespace-illegal - include: not-whitespace-illegal enum-in: @@ -933,7 +955,7 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - - include: module-context-in + - include: statement-list-in - match: ':' scope: punctuation.section.block.begin.d pop: true @@ -941,7 +963,7 @@ contexts: pop: true - match: '(?=[^\s])' pop: true - - include: module-context-in + - include: statement-list-in - match: ':' scope: punctuation.section.block.begin.d pop: true @@ -995,7 +1017,7 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - - include: module-context-in + - include: statement-list-in - include: not-whitespace-illegal static-assert-in: - match: '\b(static)\s+(assert)\b' @@ -1027,7 +1049,7 @@ contexts: - match: '{' scope: punctuation.section.block.begin.d set: - - include: module-context-in + - include: statement-list-in - match: '}' scope: punctuation.section.block.end.d pop: true @@ -1042,7 +1064,7 @@ contexts: - match: '{' scope: punctuation.section.block.begin.d set: - - include: module-context-in + - include: statement-list-in - match: '}' scope: punctuation.section.block.end.d pop: true @@ -1081,7 +1103,7 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - - include: module-context-in + - include: statement-list-in - include: not-whitespace-illegal mixin-in: - match: '\b(mixin)\b' @@ -1102,8 +1124,85 @@ contexts: set: template # TODO: Template - include: not-whitespace-illegal + statement-label-in: + - match: '\b({{name}})\s*(:)' + captures: + 1: entity.name.label.d + 2: punctuation.separator.d + conditional-in: + - match: '\bif\b' + scope: keyword.control.conditional.d + push: [conditional-else, optional-block-statement, condition] + - match: '\belse\b' + scope: keyword.control.conditional.d + push: optional-block-statement + conditional-else: + - match: '\b(else)\b' + scope: keyword.control.conditional.d + set: optional-block-statement + - match: '(?=[^\s])' + pop: true + loop-in: + - match: '\bwhile\b' + scope: keyword.control.flow.d + push: [optional-block-statement, condition] + - match: '\bdo\b' + scope: keyword.control.flow.d + push: optional-block-statement + - match: '\bfor\b' + scope: keyword.control.flow.d + push: [optional-block-statement, for-condition] + - match: '\b(foreach|foreach_reverse)\b' + scope: keyword.control.flow.d + push: [optional-block-statement, foreach-condition] + flow-statement-in: + - match: '\b(continue|break)\b' + scope: keyword.control.flow.d + push: + - match: \b{{name}}\b + scope: variable.other.constant.d + set: expect-end-of-line + - include: expect-end-of-line + - match: '\breturn\b' + scope: keyword.control.flow.d + push: + - include: end-of-line + - include: value-in + - match: '\bgoto\b' + scope: keyword.control.flow.d + push: + - match: '\bdefault\b' + scope: keyword.control.flow.d + set: expect-end-of-line + - match: '\bcase\b' + scope: keyword.control.flow.d + set: + - include: end-of-line + - include: value-in + - match: '\b{{name}}\b' + scope: variable.other.constant.d + set: expect-end-of-line + - include: not-whitespace-illegal + for-condition: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: + - match: ';' + scope: punctuation.separator.sequence.d + set: + - match: ';' + scope: punctuation.separator.sequence.d + set: + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true + - include: value-in + - include: value-in + - include: value-in + - include: not-whitespace-illegal foreach-condition: + # TODO: Handle multiple variables - match: '\(' scope: punctuation.section.brackets.begin.d set: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index f9054874bf..fab2f792b9 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -149,10 +149,10 @@ hex = 0X1; @foo: //^ punctuation.definition.annotation.begin.d // ^^^ variable.other.constant.d -// ^ punctuation.section.d - @(void)@safer@Foo(2, 4)@property +// ^ punctuation.separator.d + @("oo")@safer@Foo(2, 4)@property //^^ punctuation.definition.annotation.begin.d -// ^^^^ storage.type.d +// ^^^^ string.quoted.double.d // ^ punctuation.definition.annotation.begin.d // ^^^^^ variable.other.constant.d // ^ punctuation.definition.annotation.begin.d @@ -519,6 +519,24 @@ extern(1) // ^^^^ keyword.control.conditional.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + static if (0) { +//^^^^^^ keyword.control.conditional.d +// ^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d + } else static if (1) { +//^ punctuation.section.block.end.d +// ^^^^ keyword.control.conditional.d +// ^^^^^^ keyword.control.conditional.d +// ^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d static foreach (foo; 12 .. 3) { //^^^^^^ keyword.control.flow.d @@ -710,3 +728,143 @@ extern(1) // ^ punctuation.definition.string.end.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d + + foo: +//^^^ entity.name.label.d +// ^ punctuation.separator.d + + if (2) { +//^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d + if (1) {} else {} +//^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^^^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + if (1) 1; + if (1) {} else 1; +//^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^^^^ keyword.control.conditional.d +// ^ constant.numeric.d + + while (2) 1; +//^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ constant.numeric.d + while (2) +//^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d + { +//^ punctuation.section.block.begin.d + do 2; + //^^ keyword.control.flow.d + // ^ constant.numeric.d + while (3); + //^^^^^ keyword.control.flow.d + // ^ punctuation.section.brackets.begin.d + // ^ constant.numeric.d + // ^ punctuation.section.brackets.end.d + do + //^^ keyword.control.flow.d + { + //^ punctuation.section.block.begin.d + } while (1); + //^ punctuation.section.block.end.d + // ^^^^^ keyword.control.flow.d + // ^ punctuation.section.brackets.begin.d + // ^ constant.numeric.d + // ^ punctuation.section.brackets.end.d + } +//^ punctuation.section.block.end.d + for (1; 2; 3) { +//^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.d +// ^ punctuation.separator.sequence.d +// ^ constant.numeric.d +// ^ punctuation.separator.sequence.d +// ^ constant.numeric.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d + foreach (int a; 2) { +//^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^^^ storage.type.d +// ^ variable.other.d +// ^ punctuation.separator.sequence.d +// ^ constant.numeric.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d + foreach_reverse (int a; 2) { + //^^^^^^^^^^^^^^^ keyword.control.flow.d + // ^ punctuation.section.brackets.begin.d + // ^^^ storage.type.d + // ^ variable.other.d + // ^ punctuation.separator.sequence.d + // ^ constant.numeric.d + // ^ punctuation.section.brackets.end.d + // ^ punctuation.section.block.begin.d + } + //^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d + + continue; +//^^^^^^^^ keyword.control.flow.d +// ^ punctuation.terminator.d + continue foo; +//^^^^^^^^ keyword.control.flow.d +// ^^^ variable.other.constant.d +// ^ punctuation.terminator.d + break; +//^^^^^ keyword.control.flow.d +// ^ punctuation.terminator.d + break foo; +//^^^^^ keyword.control.flow.d +// ^^^ variable.other.constant.d +// ^ punctuation.terminator.d + return; +//^^^^^^ keyword.control.flow.d +// ^ punctuation.terminator.d + return 2; +//^^^^^^ keyword.control.flow.d +// ^ constant.numeric.d +// ^ punctuation.terminator.d + goto foo; +//^^^^ keyword.control.flow.d +// ^^^ variable.other.constant.d +// ^ punctuation.terminator.d + goto default; +//^^^^ keyword.control.flow.d +// ^^^^^^^ keyword.control.flow.d +// ^ punctuation.terminator.d + goto case; +//^^^^ keyword.control.flow.d +// ^^^^ keyword.control.flow.d +// ^ punctuation.terminator.d + goto case 2; +//^^^^ keyword.control.flow.d +// ^^^^ keyword.control.flow.d +// ^ constant.numeric.d +// ^ punctuation.terminator.d From ed980b167507f0fd1198b0a955e0329c054f850d Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 21 Jan 2019 10:19:42 +1100 Subject: [PATCH 029/108] Implement with, synchronized, try/catch/finally, throw and scope statements --- D/D.sublime-syntax | 70 ++++++++++++++++++++++++++++++++++++ D/tests/syntax_test_d.d | 80 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index e156728d3e..837ec13ef7 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -78,6 +78,11 @@ contexts: - include: conditional-in - include: loop-in - include: flow-statement-in + - include: with-in + - include: synchronized-in + - include: try-in + - include: throw-in + - include: scope-in - include: attribute-specifier-in # TODO: Remote these - include: number-in @@ -1183,6 +1188,71 @@ contexts: scope: variable.other.constant.d set: expect-end-of-line - include: not-whitespace-illegal + with-in: + - match: '\bwith\b' + scope: keyword.other.with.d + push: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: + - match: '\)' + scope: punctuation.section.parens.end.d + set: optional-block-statement + - include: value-in + - include: not-whitespace-illegal + synchronized-in: + - match: '\bsynchronized\b' + scope: keyword.other.synchronized.d + push: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: + - match: '\)' + scope: punctuation.section.parens.end.d + set: optional-block-statement + - include: value-in + - match: '(?=[^\s])' + set: optional-block-statement + try-in: + - match: '\btry\b' + scope: keyword.control.flow.d + push: optional-block-statement + - match: '\bcatch\b' + scope: keyword.control.flow.d + push: [optional-block-statement, catch-arguments] + - match: '\bfinally\b' + scope: keyword.control.flow.d + push: optional-block-statement + catch-arguments: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [catch-arguments-after, type] + - include: not-whitespace-illegal + catch-arguments-after: + - match: '\b{{name}}\b' + scope: variable.parameter.d + set: + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true + - include: not-whitespace-illegal + - include: not-whitespace-illegal + throw-in: + - match: '\bthrow\b' + scope: keyword.control.flow.d + push: + - match: ';' + scope: punctuation.terminator.d + pop: true + - include: value-in + scope-in: + - match: '\b(scope)\s*(\()(exit|success|failure)(\))' + captures: + 1: keyword.control.flow.d + 2: punctuation.section.parens.begin.d + 3: keyword.control.flow.d + 4: punctuation.section.parens.end.d + push: optional-block-statement for-condition: - match: '\(' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index fab2f792b9..a10c4ac2bf 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -868,3 +868,83 @@ extern(1) // ^^^^ keyword.control.flow.d // ^ constant.numeric.d // ^ punctuation.terminator.d + + with (2) {} +//^^^^ keyword.other.with.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + with (2) 3; +//^^^^ keyword.other.with.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.parens.end.d +// ^ constant.numeric.d + + synchronized (3) {} +//^^^^^^^^^^^^ keyword.other.synchronized.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + synchronized(3); +//^^^^^^^^^^^^ keyword.other.synchronized.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.d +// ^ punctuation.section.parens.end.d + + try { +//^^^ keyword.control.flow.d +// ^ punctuation.section.block.begin.d + } catch (int a) { +//^ punctuation.section.block.end.d +// ^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d + } catch (Throwable; foo a) { +//^ punctuation.section.block.end.d +// ^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^^^^ storage.type.d +// ^ invalid.illegal.d +// ^^^ variable.parameter.d +// ^ invalid.illegal.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d + finally { +//^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d + throw 3; +//^^^^^ keyword.control.flow.d +// ^ constant.numeric.d + + scope (exit) {} +//^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + scope(failure) {} +//^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + scope(success) 2; +//^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.end.d +// ^ constant.numeric.d From 4ed36e049e2c5e392f325dbc19749281d47d64b9 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 21 Jan 2019 10:35:11 +1100 Subject: [PATCH 030/108] Implement asm statement --- D/D.sublime-syntax | 18 +++++++++++++++++- D/tests/syntax_test_d.d | 18 ++++++++++++++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 837ec13ef7..669f631574 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -83,6 +83,7 @@ contexts: - include: try-in - include: throw-in - include: scope-in + - include: asm-in - include: attribute-specifier-in # TODO: Remote these - include: number-in @@ -400,8 +401,10 @@ contexts: - match: '{{name}}' - match: '(/|&|\||-|\+|<<|<>|>>|>>>||\*|%|\^|\^\^|~)=' scope: keyword.operator.assignment.d - - match: '(/|<=|>=|==|!<>=|!<=|!>=|\.\.\.|\.\.|&|&&|\||\|\||-|--|\+|\+\+|<|<<|<>|>|>>|>>>|!|!<>|!<|!>|\(|\)|\[|\]|{|}|\?|,|;|:|\$|\*|%|\^|\^\^|~|@|=>|#)' + - match: '(/|<=|>=|==|!<>=|!<=|!>=|\.\.\.|\.\.|&|&&|\||\|\||-|--|\+|\+\+|<|<<|<>|>|>>|>>>|!|!<>|!<|!>|\(|\)|\[|\]|{|}|\?|,|:|\$|\*|%|\^|\^\^|~|@|=>|#)' scope: keyword.operator.d + - match: ';' + scope: punctuation.terminator.d - match: '\.' scope: keyword.operator.d - include: not-whitespace-illegal @@ -1253,6 +1256,19 @@ contexts: 3: keyword.control.flow.d 4: punctuation.section.parens.end.d push: optional-block-statement + asm-in: + - match: '\basm\b' + scope: keyword.declaration.asm.d + push: + - include: attribute-in + - match: '{' + scope: punctuation.section.block.begin.d + set: + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: tokens-in + - include: not-whitespace-illegal for-condition: - match: '\(' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index a10c4ac2bf..a62ef77806 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -948,3 +948,21 @@ extern(1) // ^^^^^^^ keyword.control.flow.d // ^ punctuation.section.parens.end.d // ^ constant.numeric.d + + asm { +//^^^ keyword.declaration.asm.d +// ^ punctuation.section.block.begin.d + foo; // foo +// ^ punctuation.terminator.d +// ^^^^^^ comment.line.double-slash.d + foo bar; +// ^ punctuation.terminator.d + } +//^ punctuation.section.block.end.d + asm nothrow @safe {} +//^^^ keyword.declaration.asm.d +// ^^^^^^^ storage.modifier.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^ storage.attribute.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d From e2a6af71f072282e86a0a33b1aad2e97448ffcae Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 21 Jan 2019 11:01:07 +1100 Subject: [PATCH 031/108] Fix tests --- D/tests/syntax_test_d.d | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index a62ef77806..bbb8b699ed 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -163,18 +163,17 @@ hex = 0X1; // ^ punctuation.definition.annotation.end.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^^ storage.attribute.d - static shared const immutable auto final synchronized __gshared nothrow pure ref + static shared const immutable auto final __gshared nothrow pure ref //^^^^^^ storage.modifier.d // ^^^^^^ storage.modifier.d // ^^^^^ storage.modifier.d // ^^^^^^^^^ storage.modifier.d // ^^^^ storage.modifier.d // ^^^^^ storage.modifier.d -// ^^^^^^^^^^^^ storage.modifier.d -// ^^^^^^^^^ storage.modifier.d -// ^^^^^^^ storage.modifier.d -// ^^^^ storage.modifier.d -// ^^^ storage.modifier.d +// ^^^^^^^^^ storage.modifier.d +// ^^^^^^^ storage.modifier.d +// ^^^^ storage.modifier.d +// ^^^ storage.modifier.d extern(C) extern (C++, foo.a) //^^^^^^ keyword.other.external.d // ^ punctuation.definition.annotation.begin.d From 81a86f5b4f1fd8e02e727e97b9f58a3a70cffbe1 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 21 Jan 2019 12:12:43 +1100 Subject: [PATCH 032/108] Reimplement number parsing, fixing any inconsistencies --- D/D.sublime-syntax | 120 ++++++++++++++++++++++-------- D/tests/syntax_test_d.d | 159 +++++++++++++++++++++++++--------------- 2 files changed, 189 insertions(+), 90 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 669f631574..0469e9b42e 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -17,9 +17,16 @@ variables: string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' + hex_or_under: '(?:{{hex_char}}|_)' type_ctor: 'const|immutable|inout|shared' type2_look_ahead: '(?=\*|\[|\bdelegate\b|\bfunction\b)' + integer_lookahead: '(?=\b[0-9])' + integer_suffix: 'L[uU]|[uU]L|[LuU]' + integer_float_suffix: '[fF]i?|i' + float_suffix: '[fFL]i?|i' + float_exponent: '[eE][+\-]?[0-9]+' + attribute_lookahead: '(?={{attributes}}|@)' attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' at_attributes: 'disable|nogc|property|safe|system|trusted' @@ -232,25 +239,84 @@ contexts: pop: true - include: nested-comment number-in: - # TODO: Hex floats - - match: |- - (?x) - ( - (\b0[xX]{{hex_char}}+(_{{hex_char}}+)*) # 0x0, 0X0, 0x000_000 - | - (\b0[bB][01]+(_[01]+)*) - | - ( - (\b[0-9]+(_[0-9]+)*\.?([0-9]+_[0-9]+)?[0-9]*) # 0.0, 0_0.0, 0.0_0 - | - (\.[0-9]+(_[0-9]+)*) # .0, .0_0 - )((e|E)(\+|-)?[0-9]+)? # 0e+5 - ) - (L[uU]|[uU]L|[LuU])? # 0l, 0U, 0Lu, 0UL - \b + - match: '(?=(\b|\.)[0-9])' + push: number + number: + - include: floating-point-opt + - include: integer-opt + - include: not-whitespace-illegal + integer: + - include: integer-opt + - include: not-whitespace-illegal + integer-opt: + - match: '\b(0|[1-9][0-9_]*)({{integer_suffix}})?\b' + captures: + 1: constant.numeric.integer.d + 2: storage.type.integer.d + pop: true + - match: '\b(0[bB])([01][01_]*)({{integer_suffix}})?\b' + captures: + 1: storage.modifier.d + 2: constant.numeric.binary.d + 3: storage.type.integer.d + pop: true + - match: '\b(0[xX])({{hex_char}}(?:_|{{hex_char}})*)({{integer_suffix}})?\b' + captures: + 1: storage.modifier.d + 2: constant.numeric.hex.d + 3: storage.type.integer.d + pop: true + floating-point: + - include: floating-point-opt + - include: not-whitespace-illegal + floating-point-opt: + - match: '\b(0[xX])({{hex_or_under}}*\.?{{hex_or_under}}+)([pP][+\-]?[0-9]+)({{float_suffix}})?\b' + captures: + 1: storage.modifier.d + 2: constant.numeric.float.d + 3: constant.numeric.float.d + 4: storage.type.float.d + pop: true + - match: '\b(0|[1-9][0-9_]*)({{integer_float_suffix}})\b' + captures: + 1: constant.numeric.float.d + 2: storage.type.float.d + pop: true + - match: '\b(0[bB])([01][01_]*)({{integer_float_suffix}})\b' captures: - 1: constant.numeric.d - 15: storage.type.integer.d + 1: storage.modifier.d + 2: constant.numeric.float.d + 3: storage.type.float.d + pop: true + - match: '\b(0[xX])({{hex_char}}{{hex_or_under}}*)({{integer_float_suffix}})\b' + captures: + 1: storage.modifier.d + 2: constant.numeric.float.d + 3: storage.type.float.d + pop: true + - match: '\b([0-9][0-9_]*\.[0-9][0-9_]*)({{float_exponent}})?({{float_suffix}})?\b' + captures: + 1: constant.numeric.float.d + 2: constant.numeric.float.d + 3: storage.type.float.d + pop: true + - match: '\b([0-9][0-9_]*\.)({{float_suffix}})?' + captures: + 1: constant.numeric.float.d + 2: storage.type.float.d + pop: true + - match: '(\.[0-9][0-9_]*)({{float_exponent}})?({{float_suffix}})?\b' + captures: + 1: constant.numeric.float.d + 2: constant.numeric.float.d + 3: storage.type.float.d + pop: true + - match: '\b([0-9][0-9_]*)({{float_exponent}})({{float_suffix}})?\b' + captures: + 1: constant.numeric.float.d + 2: constant.numeric.float.d + 3: storage.type.float.d + pop: true character-in: - match: \'(?:({{escape_sequence}})|[^\\'])\' scope: string.quoted.single.d @@ -986,10 +1052,8 @@ contexts: - match: '\b({{name}})\b' scope: constant.other.d set: version-condition-end - # TODO: Use proper integer literals here - - match: '\b([0-9]+)\b' - scope: constant.numeric.d - set: version-condition-end + - match: '{{integer_lookahead}}' + set: [version-condition-end, integer] - include: not-whitespace-illegal - include: not-whitespace-illegal version-condition-end: @@ -1004,10 +1068,8 @@ contexts: - match: '\b({{name}})\b' scope: constant.other.d set: version-condition-end - # TODO: Use proper integer literals here - - match: '\b([0-9]+)\b' - scope: constant.numeric.d - set: version-condition-end + - match: '{{integer_lookahead}}' + set: [version-condition-end, integer] - include: not-whitespace-illegal - match: '(?={|:)' pop: true @@ -1086,10 +1148,8 @@ contexts: - match: '\b{{name}}\b' scope: entity.name.constant.d set: expect-end-of-line - # TODO: Use proper integer literals here - - match: '[0-9]+' - scope: constant.numeric.d - set: expect-end-of-line + - match: '{{integer_lookahead}}' + set: [expect-end-of-line, integer] - include: not-whitespace-illegal template-in: - match: '\b(template)\b' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index bbb8b699ed..3584731094 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -79,7 +79,7 @@ auto tokenString = q{ // ^^ source.d keyword.d // ^^^^^^^^^^^^^ source.d // ^^^^ source.d storage.type.d -// ^^ source.d constant.numeric.d +// ^^ source.d constant.numeric.integer.d /*}*/ // ^^ punctuation.definition.comment.d // ^^ punctuation.definition.comment.d @@ -110,41 +110,80 @@ c = ''; c = '''; // ^^ invalid.illegal.d -auto dec = 2_0_000; -// ^^^^^^^ constant.numeric.d +auto dec = 2_0__000; +// ^^^^^^^^ constant.numeric.integer.d dec = 1L; -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ storage.type.integer.d dec = 1u; -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ storage.type.integer.d dec = 1U; -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ storage.type.integer.d dec = 1Lu; -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^^ storage.type.integer.d dec = 1LU; -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^^ storage.type.integer.d dec = 1uL; -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^^ storage.type.integer.d dec = 1UL; -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^^ storage.type.integer.d auto bin = 0b1; -// ^^^ constant.numeric.d -bin = 0b10_1; -// ^^^^^^ constant.numeric.d +// ^^ storage.modifier.d +// ^ constant.numeric.binary.d +bin = 0b10__1; +// ^^ storage.modifier.d +// ^^^^^ constant.numeric.binary.d bin = 0B1; -// ^^^ constant.numeric.d +// ^^ storage.modifier.d +// ^ constant.numeric.binary.d auto hex = 0xF; -// ^^^ constant.numeric.d +// ^^ storage.modifier.d +// ^ constant.numeric.hex.d hex = 0x012_3; -// ^^^^^^^ constant.numeric.d +// ^^ storage.modifier.d +// ^^^^^ constant.numeric.hex.d hex = 0X1; -// ^^^ constant.numeric.d +// ^^ storage.modifier.d +// ^ constant.numeric.hex.d + +auto f = 0_.0_; +// ^^^ constant.numeric.float.d +f = 0_.; +// ^^ constant.numeric.float.d +f = .123_1243; +// ^^^^^^^^^ constant.numeric.float.d +f = 2313472389742e1i; +// ^^^^^^^^^^^^^^^ constant.numeric.float.d +// ^ storage.type.float.d +f = 3423.2e-45; +// ^^^^^^^^^ constant.numeric.float.d +f = .4E+4L; +// ^^^^^ constant.numeric.float.d +// ^ storage.type.float.d +f = 1f; +// ^ constant.numeric.float.d +// ^ storage.type.float.d +f = 0x123f; +// ^^ storage.modifier.d +// ^^^ constant.numeric.float.d +// ^ storage.type.float.d +f = 0b10101101f; +// ^^ storage.modifier.d +// ^^^^^^^^ constant.numeric.float.d +// ^ storage.type.float.d +f = 0x.1aFp2; +// ^^ storage.modifier.d +// ^^^^^^ constant.numeric.float.d +f = 0xF.AP-2f; +// ^^ storage.modifier.d +// ^^^^^^ constant.numeric.float.d +// ^ storage.type.float.d @foo: //^ punctuation.definition.annotation.begin.d @@ -158,8 +197,8 @@ hex = 0X1; // ^ punctuation.definition.annotation.begin.d // ^^^ variable.function.d // ^ punctuation.definition.annotation.begin.d -// ^ constant.numeric.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d +// ^ constant.numeric.integer.d // ^ punctuation.definition.annotation.end.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^^ storage.attribute.d @@ -190,11 +229,11 @@ extern(1) align(1) align(foo * 2) //^^^^^ keyword.other.alignment.d // ^ punctuation.definition.annotation.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.definition.annotation.end.d // ^^^^^ keyword.other.alignment.d // ^ punctuation.definition.annotation.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.definition.annotation.end.d deprecated //^^^^^^^^^^ keyword.other.deprecated.d @@ -323,7 +362,7 @@ extern(1) // ^ keyword.operator.other.d // ^ variable.other.d // ^ keyword.operator.assignment.d -// ^^^ constant.numeric.d +// ^^^ constant.numeric.integer.d // ^ punctuation.terminator.d bar* some_long_Name; //^^^ storage.type.d @@ -404,7 +443,7 @@ extern(1) bar = 2, //^^^ entity.name.constant.d // ^ keyword.operator.assignment.d - // ^ constant.numeric.d + // ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d } //^ punctuation.section.block.end.d @@ -416,7 +455,7 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ entity.name.constant.d // ^ keyword.operator.assignment.d -// ^^ constant.numeric.d +// ^^ constant.numeric.integer.d // ^ punctuation.section.block.end.d enum : foo[stirng] { TEST } //^^^^ storage.type.enum.d @@ -434,7 +473,7 @@ extern(1) // ^^^ storage.type.d // ^ entity.name.constant.d // ^ keyword.operator.assignment.d -// ^^ constant.numeric.d +// ^^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d Foo //^^^ entity.name.constant.d @@ -465,7 +504,7 @@ extern(1) version(1): //^^^^^^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d @@ -492,7 +531,7 @@ extern(1) debug = 2; //^^^^^ keyword.control.conditional.d // ^ keyword.operator.assignment.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.terminator.d version = foo; //^^^^^^^ keyword.control.conditional.d @@ -504,8 +543,8 @@ extern(1) //^^^^^^ keyword.control.conditional.d // ^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d -// ^^ constant.numeric.d -// ^ constant.numeric.d +// ^^ constant.numeric.integer.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d static if (true) {} else {} @@ -522,7 +561,7 @@ extern(1) //^^^^^^ keyword.control.conditional.d // ^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d } else static if (1) { @@ -531,7 +570,7 @@ extern(1) // ^^^^^^ keyword.control.conditional.d // ^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d } @@ -543,8 +582,8 @@ extern(1) // ^ punctuation.section.brackets.begin.d // ^^^ variable.other.d // ^ punctuation.separator.sequence.d -// ^^ constant.numeric.d -// ^ constant.numeric.d +// ^^ constant.numeric.integer.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d static foreach (int a; 123) { @@ -554,7 +593,7 @@ extern(1) // ^^^ storage.type.d // ^ variable.other.d // ^ punctuation.separator.sequence.d - // ^^^ constant.numeric.d + // ^^^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d } @@ -566,7 +605,7 @@ extern(1) //^^^^^^ keyword.control.conditional.d // ^^^^^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d -// ^^ constant.numeric.d +// ^^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d @@ -659,7 +698,7 @@ extern(1) invariant(0, "test") { //^^^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d // ^^^^^^ string.quoted.double.d // ^ punctuation.section.brackets.end.d @@ -735,7 +774,7 @@ extern(1) if (2) { //^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d } @@ -743,7 +782,7 @@ extern(1) if (1) {} else {} //^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -754,33 +793,33 @@ extern(1) if (1) {} else 1; //^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d while (2) 1; //^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d while (2) //^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d { //^ punctuation.section.block.begin.d do 2; //^^ keyword.control.flow.d - // ^ constant.numeric.d + // ^ constant.numeric.integer.d while (3); //^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d - // ^ constant.numeric.d + // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d do //^^ keyword.control.flow.d @@ -790,18 +829,18 @@ extern(1) //^ punctuation.section.block.end.d // ^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d - // ^ constant.numeric.d + // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d } //^ punctuation.section.block.end.d for (1; 2; 3) { //^^^ keyword.control.flow.d // ^ punctuation.section.parens.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d } @@ -812,7 +851,7 @@ extern(1) // ^^^ storage.type.d // ^ variable.other.d // ^ punctuation.separator.sequence.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d foreach_reverse (int a; 2) { @@ -821,7 +860,7 @@ extern(1) // ^^^ storage.type.d // ^ variable.other.d // ^ punctuation.separator.sequence.d - // ^ constant.numeric.d + // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d } @@ -848,7 +887,7 @@ extern(1) // ^ punctuation.terminator.d return 2; //^^^^^^ keyword.control.flow.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.terminator.d goto foo; //^^^^ keyword.control.flow.d @@ -865,34 +904,34 @@ extern(1) goto case 2; //^^^^ keyword.control.flow.d // ^^^^ keyword.control.flow.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.terminator.d with (2) {} //^^^^ keyword.other.with.d // ^ punctuation.section.parens.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d with (2) 3; //^^^^ keyword.other.with.d // ^ punctuation.section.parens.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d synchronized (3) {} //^^^^^^^^^^^^ keyword.other.synchronized.d // ^ punctuation.section.parens.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d synchronized(3); //^^^^^^^^^^^^ keyword.other.synchronized.d // ^ punctuation.section.parens.begin.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d try { @@ -925,7 +964,7 @@ extern(1) //^ punctuation.section.block.end.d throw 3; //^^^^^ keyword.control.flow.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d scope (exit) {} //^^^^^ keyword.control.flow.d @@ -946,7 +985,7 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^^^^^^^ keyword.control.flow.d // ^ punctuation.section.parens.end.d -// ^ constant.numeric.d +// ^ constant.numeric.integer.d asm { //^^^ keyword.declaration.asm.d From 2fb74124dc46ab0125dc68b29f7161b3241cb883 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 21 Jan 2019 13:57:24 +1100 Subject: [PATCH 033/108] Implement aggregate template parsing --- D/D.sublime-syntax | 68 +++++++++++++++++++++++++---------------- D/tests/syntax_test_d.d | 47 ++++++++++++++++++++++++++++ 2 files changed, 89 insertions(+), 26 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 0469e9b42e..506dac882f 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -831,14 +831,19 @@ contexts: - match: '\b({{name}})\b' scope: entity.name.class.d set: - - include: end-of-line - - match: ':' - scope: punctuation.separator.mapping.d - set: [class-body, base-class-list] - - match: '(?={)' - set: class-body - - include: not-whitespace-illegal + - match: '(?=\()' + set: [class-after, function-argument-definition-list] + - match: '(?=[^\s])' + set: class-after - include: not-whitespace-illegal + class-after: + - include: end-of-line + - match: ':' + scope: punctuation.separator.mapping.d + set: [class-body, base-class-list] + - match: '(?={)' + set: class-body + - include: not-whitespace-illegal base-class-list: - match: '{{type_look_ahead}}' set: [base-class-list-after, basic-type] @@ -857,7 +862,6 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - # TODO: Don't use statement-list-in - include: statement-list-in - include: not-whitespace-illegal - include: not-whitespace-illegal @@ -868,14 +872,19 @@ contexts: - match: '\b({{name}})\b' scope: entity.name.interface.d set: - - include: end-of-line - - match: ':' - scope: punctuation.separator.mapping.d - set: [interface-body, base-class-list] - - match: '(?={)' - set: interface-body - - include: not-whitespace-illegal + - match: '(?=\()' + set: [interface-after, function-argument-definition-list] + - match: '(?=[^\s])' + set: interface-after - include: not-whitespace-illegal + interface-after: + - include: end-of-line + - match: ':' + scope: punctuation.separator.mapping.d + set: [interface-body, base-class-list] + - match: '(?={)' + set: interface-body + - include: not-whitespace-illegal interface-body: - match: '{' scope: punctuation.section.block.begin.d @@ -883,7 +892,6 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - # TODO: Don't use statement-list-in - include: statement-list-in - include: not-whitespace-illegal - include: not-whitespace-illegal @@ -894,13 +902,18 @@ contexts: - match: '\b({{name}})\b' scope: entity.name.struct.d set: - - include: end-of-line - - match: '(?={)' - set: struct-body - - include: not-whitespace-illegal + - match: '(?=\()' + set: [struct-after, function-argument-definition-list] + - match: '(?=[^\s])' + set: struct-after - match: '(?={)' set: struct-body - include: not-whitespace-illegal + struct-after: + - include: end-of-line + - match: '(?={)' + set: struct-body + - include: not-whitespace-illegal struct-body: - match: '{' scope: punctuation.section.block.begin.d @@ -908,7 +921,6 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - # TODO: Don't use statement-list-in - include: statement-list-in - include: not-whitespace-illegal - include: not-whitespace-illegal @@ -919,13 +931,18 @@ contexts: - match: '\b({{name}})\b' scope: entity.name.union.d set: - - include: end-of-line - - match: '(?={)' - set: union-body - - include: not-whitespace-illegal + - match: '(?=\()' + set: [union-after, function-argument-definition-list] + - match: '(?=[^\s])' + set: union-after - match: '(?={)' set: union-body - include: not-whitespace-illegal + union-after: + - include: end-of-line + - match: '(?={)' + set: union-body + - include: not-whitespace-illegal union-body: - match: '{' scope: punctuation.section.block.begin.d @@ -933,7 +950,6 @@ contexts: - match: '}' scope: punctuation.section.block.end.d pop: true - # TODO: Don't use statement-list-in - include: statement-list-in - include: not-whitespace-illegal - include: not-whitespace-illegal diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 3584731094..2a8168ee66 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -390,6 +390,18 @@ extern(1) // ^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + class b(T, int s) { +//^^^^^ storage.type.class.d +// ^ entity.name.class.d +// ^ punctuation.section.group.begin.d +// ^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d interface S; //^^^^^^^^^ storage.type.interface.d @@ -410,6 +422,18 @@ extern(1) // ^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + interface A(T, float f) { +//^^^^^^^^^ storage.type.interface.d +// ^ entity.name.interface.d +// ^ punctuation.section.group.begin.d +// ^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d struct Foo { //^^^^^^ storage.type.struct.d @@ -426,12 +450,35 @@ extern(1) //^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + struct F(int a, T) { +//^^^^^^ storage.type.struct.d +// ^ entity.name.struct.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^ storage.type.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d union Foo {} //^^^^^ storage.type.union.d // ^^^ entity.name.union.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + union Test(string s, F) {} +//^^^^^ storage.type.union.d +// ^^^^ entity.name.union.d +// ^ punctuation.section.group.begin.d +// ^^^^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^ storage.type.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d enum Foo { //^^^^ storage.type.enum.d From 35ba040a7efd74a95752fa27590dbc9f564c12d5 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 21 Jan 2019 16:56:30 +1100 Subject: [PATCH 034/108] Fix doc comment ligatures --- D/D.sublime-syntax | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 506dac882f..10822d14f9 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -217,20 +217,20 @@ contexts: # scope: comment.block.empty.d punctuation.definition.comment.d # - include: scope:text.html.javadoc - - match: /\* + - match: /\*\*? scope: punctuation.definition.comment.d push: - meta_scope: comment.block.d - match: \*/ scope: punctuation.definition.comment.d pop: true - - match: (//).*$ + - match: (///?).*$ scope: comment.line.double-slash.d captures: 1: punctuation.definition.comment.d - include: nested-comment nested-comment: - - match: /\+ + - match: /\+\+? scope: punctuation.definition.comment.d push: - meta_scope: comment.block.nested.d From 303472f20473f0b00aea3bceec5499fc86ec65a7 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 12:14:11 +1100 Subject: [PATCH 035/108] Implement initial proper value parsing with heavy validation STASH --- D/D.sublime-syntax | 664 ++++++++++++++++++++++++++-------------- D/tests/syntax_test_d.d | 236 +++++++++++--- 2 files changed, 613 insertions(+), 287 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 10822d14f9..03dca09c00 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -13,26 +13,30 @@ variables: identifier: '{{name}}(?:\.{{name}})*' std_identifier: '(?:std|core)\.{{identifier}}' identifier_ref: '\.?{{identifier}}' - type_look_ahead: '(?=\b({{identifier_ref}}))' string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' hex_or_under: '(?:{{hex_char}}|_)' + type_ctor: 'const|immutable|inout|shared' + type_look_ahead: '(?=\b({{identifier_ref}}))' type2_look_ahead: '(?=\*|\[|\bdelegate\b|\bfunction\b)' + number_lookahead: '(?=(\b|\.)[0-9])' integer_lookahead: '(?=\b[0-9])' integer_suffix: 'L[uU]|[uU]L|[LuU]' integer_float_suffix: '[fF]i?|i' float_suffix: '[fFL]i?|i' float_exponent: '[eE][+\-]?[0-9]+' + character_lookahead: (?=') + string_lookahead: '(?=`|[rxq]?"|q{)' attribute_lookahead: '(?={{attributes}}|@)' attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' at_attributes: 'disable|nogc|property|safe|system|trusted' 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' + 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' language_constant: 'null|true|false|__FILE__|__FILE_FULL_PATH__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__' langauge_variable: 'this|super' reserved: '{{keyword}}|{{basic_type}}|{{language_constant}}|{{langauge_variable}}' @@ -92,13 +96,8 @@ contexts: - include: scope-in - include: asm-in - include: attribute-specifier-in - # TODO: Remote these - - include: number-in - - include: character-in - - include: string-in - - - include: function-or-variable-in - # - include: not-whitespace-illegal + - include: end-of-line-in + - include: value-or-declaration-in block-statement-in: - match: '{{block_statement_loohahead}}' push: block-statement @@ -117,56 +116,11 @@ contexts: - match: '(?=[^\s])' pop: true module-context-in: - - match: '\b([A-Z][A-Z0-9_]+)\b' - scope: constant.other.d - - match: \b(auto|static|override|final|const|abstract|volatile|synchronized|lazy|immutable|shared|__gshared|pure|nothrow|ref)\b - scope: storage.modifier.d - # - match: \b(template|interface|class|enum|struct|union)\b - # scope: storage.type.d - # - match: \b(ushort|int|uint|long|ulong|float|void|byte|ubyte|double|bit|char|wchar|ucent|cent|short|bool|dchar|real|ireal|ifloat|idouble|creal|cfloat|cdouble|string)\b - # scope: storage.type.d - - match: \b(try|catch|finally|throw)\b - scope: keyword.control.exception.d - - match: \b(return|break|case|continue|default|do|while|for|switch|if|else)\b - scope: keyword.control.d - - match: \b(if|else|switch|iftype)\b - scope: keyword.control.conditional.d - - match: \b(goto|break|continue)\b - scope: keyword.control.branch.d - # - match: \b(while|for|foreach(_reverse)?)\b - # scope: keyword.control.repeat.d - # - match: \b(version|return|with|invariant|body|scope|in|out|inout|asm|mixin|function|delegate)\b - # scope: keyword.control.statement.d - - match: \b(true|false)\b - scope: constant.language.boolean.d - - match: \b(__FILE__|__LINE__|__DATE__|__TIME__|__TIMESTAMP__|null)\b - scope: constant.language.d - - match: \b(this|super)\b - scope: variable.language.d - - - match: (==|!=|<=|>=|<>|<|>) - scope: keyword.operator.comparison.d - - match: (\-\-|\+\+) - scope: keyword.operator.increment-decrement.d - - match: (\-|\+|\*|\/|~|%) - scope: keyword.operator.arithmetic.d - - match: (!|&&|\|\|) - scope: keyword.operator.logical.d + # TODO - match: \b(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)\b scope: keyword.operator.overload.d - match: \b(new|delete|typeof|typeid|cast|align|is)\b scope: keyword.other.d - - match: \b(new|throws)\b - scope: keyword.other.class-fns.d - # - match: \b(deprecated|unittest|debug)\b - # scope: keyword.other.debug.d - - match: \b(u_char|u_short|u_int|u_long|ushort|uint|u_quad_t|quad_t|qaddr_t|caddr_t|daddr_t|dev_t|fixpt_t|blkcnt_t|blksize_t|gid_t|in_addr_t|in_port_t|ino_t|key_t|mode_t|nlink_t|id_t|pid_t|off_t|segsz_t|swblk_t|uid_t|id_t|clock_t|size_t|ssize_t|time_t|useconds_t|suseconds_t)\b - scope: support.type.sys-types.c - - match: \b(pthread_attr_t|pthread_cond_t|pthread_condattr_t|pthread_mutex_t|pthread_mutexattr_t|pthread_once_t|pthread_rwlock_t|pthread_rwlockattr_t|pthread_t|pthread_key_t)\b - scope: support.type.pthread.c - - match: \b(int8_t|int16_t|int32_t|int64_t|uint8_t|uint16_t|uint32_t|uint64_t|int_least8_t|int_least16_t|int_least32_t|int_least64_t|uint_least8_t|uint_least16_t|uint_least32_t|uint_least64_t|int_fast8_t|int_fast16_t|int_fast32_t|int_fast64_t|uint_fast8_t|uint_fast16_t|uint_fast32_t|uint_fast64_t|intptr_t|uintptr_t|intmax_t|intmax_t|uintmax_t|uintmax_t)\b - scope: support.type.stdint.c - - include: function-or-variable-in all-types-in: - include: support-type-built-ins-in - include: support-type-in @@ -216,7 +170,6 @@ contexts: # - match: /\*\*/ # scope: comment.block.empty.d punctuation.definition.comment.d # - include: scope:text.html.javadoc - - match: /\*\*? scope: punctuation.definition.comment.d push: @@ -239,11 +192,13 @@ contexts: pop: true - include: nested-comment number-in: - - match: '(?=(\b|\.)[0-9])' + - match: '{{number_lookahead}}' push: number - number: + number-opt: - include: floating-point-opt - include: integer-opt + number: + - include: number-opt - include: not-whitespace-illegal integer: - include: integer-opt @@ -300,7 +255,7 @@ contexts: 2: constant.numeric.float.d 3: storage.type.float.d pop: true - - match: '\b([0-9][0-9_]*\.)({{float_suffix}})?' + - match: '\b([0-9][0-9_]*\.(?!\.))({{float_suffix}})?' captures: 1: constant.numeric.float.d 2: storage.type.float.d @@ -318,17 +273,29 @@ contexts: 3: storage.type.float.d pop: true character-in: + - match: '{{character_lookahead}}' + push: character + character: - match: \'(?:({{escape_sequence}})|[^\\'])\' scope: string.quoted.single.d captures: 1: constant.character.escape.d + pop: true - match: \'[^']*\' scope: invalid.illegal.d + pop: true + - include: not-whitespace-illegal-pop string-in: + - match: '{{string_lookahead}}' + push: string + string: + - include: string-opt + - include: not-whitespace-illegal + string-opt: # Regular string - match: '"' scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.d - match: '(")({{string_postfix}})' @@ -343,7 +310,7 @@ contexts: # Wysiwyg string - match: r" scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(")({{string_postfix}})' @@ -354,7 +321,7 @@ contexts: # Alternate Wysiwyg string - match: "`" scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.backtick.d - match: '(`)({{string_postfix}})' @@ -365,7 +332,7 @@ contexts: # Deprecated Hex string - match: x" scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(")({{string_postfix}})' @@ -382,7 +349,7 @@ contexts: scope: punctuation.definition.string.begin.d captures: 2: invalid.illegal.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(^\1")({{string_postfix}})' @@ -393,7 +360,7 @@ contexts: # Nested Deliminated string - match: 'q"\[' scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(\]")({{string_postfix}})' @@ -403,7 +370,7 @@ contexts: pop: true - match: 'q"\(' scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(\)")({{string_postfix}})' @@ -413,7 +380,7 @@ contexts: pop: true - match: 'q"<' scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(>")({{string_postfix}})' @@ -423,7 +390,7 @@ contexts: pop: true - match: 'q"{' scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(}")({{string_postfix}})' @@ -434,7 +401,7 @@ contexts: # Other deliminated string - match: 'q"(.)' scope: punctuation.definition.string.begin.d - push: + set: - meta_include_prototype: false - meta_scope: string.quoted.double.raw.d - match: '(\1"|\1(.))({{string_postfix}})' @@ -446,8 +413,7 @@ contexts: # Token string - match: 'q{' scope: string.unquoted.embedded.d punctuation.definition.string.begin.d - push: - - meta_content_scope: source.d + set: - match: '}' scope: string.unquoted.embedded.d punctuation.definition.string.end.d pop: true @@ -489,45 +455,50 @@ contexts: 1: keyword.other.external.d 2: punctuation.definition.annotation.begin.d push: extern-attribute - - match: '\b(align)\s*(\()' - captures: - 1: keyword.other.alignment.d - 2: punctuation.definition.annotation.begin.d - push: align-attribute - - match: '\b(deprecated)\s*(\()' - captures: - 1: keyword.other.deprecated.d - 2: punctuation.definition.annotation.begin.d - push: deprecated-attribute + - match: '\b(align)\b' + scope: keyword.other.alignment.d + push: + - match: '\(' + scope: punctuation.definition.annotation.begin.d + set: [align-attribute-after, value] + - match: '(?=[^\s])' + pop: true - match: '\b(deprecated)\b' scope: keyword.other.deprecated.d + push: + - match: '\(' + scope: punctuation.definition.annotation.begin.d + set: [deprecated-attribute-after, value] + - match: '(?=[^\s])' + pop: true - include: visibility-attributes - - match: '\b(pragma)\s*(\()' - captures: - 1: keyword.other.pragma.d - 2: punctuation.definition.annotation.begin.d - push: pragma-attribute + - match: '\b(pragma)\b' + scope: keyword.other.pragma.d + push: + - match: '\(' + scope: punctuation.definition.annotation.begin.d + set: pragma-attribute + - include: not-whitespace-illegal at-attribute: - match: '({{at_attributes}})\b' scope: storage.attribute.d pop: true - match: '\(' scope: punctuation.definition.annotation.begin.d - set: uda + set: [uda-after, value-list] - match: '({{name}})\s*(\()' captures: 1: variable.function.d 2: punctuation.definition.annotation.begin.d - set: uda + set: [uda-after, value-list] - match: '({{name}})\b' scope: variable.other.constant.d pop: true - uda: - # TODO: Use function call here - - include: value-in + uda-after: - match: '\)' scope: punctuation.definition.annotation.end.d pop: true + - include: not-whitespace-illegal extern-attribute: - match: '(C\+\+|C|D|Windows|System|Objective-C)' scope: string.other.d @@ -539,13 +510,11 @@ contexts: scope: punctuation.definition.annotation.end.d pop: true - include: not-whitespace-illegal - align-attribute: - - include: value-in + align-attribute-after: - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - deprecated-attribute: - - include: statement-list-in + deprecated-attribute-after: - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -569,13 +538,21 @@ contexts: - match: '\b({{name}})\b' scope: variable.function.d set: - - include: statement-list-in - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - - include: not-whitespace-illegal + - match: ',' + scope: punctuation.separator.sequence.d + set: [pragma-attribute-after, value-list] + - include: not-whitespace-illegal + - include: not-whitespace-illegal-pop + pragma-attribute-after: + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + - include: not-whitespace-illegal-pop import-in: - - match: '\b(import)\b' + - match: '\b(import)(?!\s*\()\b' scope: keyword.control.import.d push: import-list import-list: @@ -672,37 +649,29 @@ contexts: - match: '\*' scope: keyword.operator.pointer.d - match: '\[' - scope: keyword.operator.other.d - push: - # TODO: Ranges - - match: '{{type_look_ahead}}' - push: type - - include: value-in - - match: '\]' - scope: keyword.operator.other.d - pop: true + scope: punctuation.section.brackets.begin.d + push: [basic-type2-after-brackets, value-list] - match: '\b(delegate|function)\b' scope: keyword.other.d push: function-pointer-type - match: '(?=[^\s])' pop: true + basic-type2-after-brackets: + - match: '\]' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal-pop + function-pointer-type: # TODO - match: '.' pop: true - function-or-variable-in: - - match: '{{type_look_ahead}}' - push: [function-or-variable-after-type, type] function-or-variable-after-type: - match: '\b({{name}})\s*(=)' captures: 1: variable.other.d 2: keyword.operator.assignment.d - set: - - include: value-in - - match: '\;' - scope: punctuation.terminator.d - pop: true + set: [expect-end-of-line, value] - match: '\b({{name}})\s*(;)' captures: 1: variable.other.d @@ -760,18 +729,261 @@ contexts: pop: true - include: not-whitespace-illegal function-definition: + - meta_scope: meta.function.d - match: '{' scope: punctuation.section.block.begin.d set: - - include: statement-list-in + - meta_scope: meta.function.d - match: '}' scope: punctuation.section.block.end.d pop: true + - include: statement-list-in - include: end-of-line - include: not-whitespace-illegal - value-in: - - include: number-in - - include: string-in + value-or-declaration-in: + - match: '\s' + - match: '(?=(!|~|\+|\-|\*|&|cast|delete|new|import|mixin|[0-9]|\[|\(|{{name}}\s*\(|{{string_lookahead}}|{{language_constant}}|{{langauge_variable}}))' + push: [maybe-end-of-line, value] + - match: '(?=({{name}}|\]|\))(\s+{{name}}))' + push: [function-or-variable-after-type, type] + - match: '(?=[^\s])' + push: [maybe-end-of-line, first-value] + value-or-declaration: + - match: '\s' + - match: '(?=(!|~|\+|\-|\*|&|cast|delete|new|import|mixin|[0-9]|\[|\(|{{name}}\s*\(|{{string_lookahead}}|{{language_constant}}|{{langauge_variable}}))' + set: value + - match: '(?=({{name}}|\]|\))(\s+{{name}}))' + set: [function-or-variable-after-type, type] + - match: '(?=[^\s])' + set: first-value + # The first value in an expression ending with a * is always a function/variable definition, otherwise it could be either + # We highlight as if it were a value, but switch to a definition if it turns out to be one + first-value: + # - meta_scope: first-value + - match: '\b({{basic_type}})\b' + scope: storage.type.d + set: first-value-after + - match: '\b({{name}})\b' + scope: variable.other.d + set: first-value-after + - include: not-whitespace-illegal + first-value-after: + # - meta_scope: first-value-after + - match: '\.' + scope: punctuation.accessor.dot.d + set: + - match: '{{identifier}}' + scope: variable.other.d + set: first-value-after + - match: '!' + scope: keyword.operator.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [first-value-parens-after, value-list] + - match: '(?=[^\s])' + set: value + - match: '\[' + scope: punctuation.section.brackets.begin.d + set: [first-value-bracket-after, value-list] + - match: '(?=\*)' + set: [function-or-variable-after-type, basic-type2] + - match: '(?={{name}}\s*([;=\(]|$))' + set: function-or-variable-after-type + - match: '(?=[^\s])' + set: value-after + first-value-bracket-after: + - match: '\]' + scope: punctuation.section.brackets.end.d + set: first-value-after + - include: not-whitespace-illegal + first-value-parens-after: + - match: '\)' + scope: punctuation.section.parens.end.d + set: first-value-after + - include: not-whitespace-illegal + value: + # - meta_scope: value + - match: '!' + scope: keyword.operator.logical.d + set: value + - match: '~' + scope: keyword.operator.bitwise.d + set: value + - match: '(\+\+|--|\+|-)' + scope: keyword.operator.arithmetic.d + set: value + - match: '(\*|&)' + scope: keyword.operator.bitwise.d + set: value + - match: '\bcast\b' + scope: keyword.operator.word.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [cast-after, type] + - include: not-whitespace-illegal + - match: '\bdelete\b' + scope: keyword.operator.word.d + set: value + - match: '\bnew\b' + scope: keyword.operator.word.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [new-after-parens, value-list] + - match: '(?=[^\s])' + set: new-after + - match: '\bimport\b' + scope: keyword.declaration.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [new-after-parens, value] + - include: not-whitespace-illegal + - match: '\bmixin\b' + scope: keyword.other.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [new-after-parens, value-list] + - include: not-whitespace-illegal + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [new-after-parens, value] + - match: '{{number_lookahead}}' + set: [value-after, number] + - match: '{{character_lookahead}}' + set: [value-after, character] + - match: '{{string_lookahead}}' + set: [value-after, string] + - match: '\b({{language_constant}})\b' + scope: constant.language.d + set: value-after + - match: '\b({{langauge_variable}})\b' + scope: variable.language.d + set: value-after + - match: '\b({{basic_type}})\b' + scope: storage.type.d + set: value-after + - match: '\b({{name}})\b' + scope: variable.other.d + set: value-after + - include: not-whitespace-illegal + cast-after: + - match: '\)' + scope: punctuation.section.parens.end.d + set: value + - include: not-whitespace-illegal + new-after-parens: + - match: '\)' + scope: punctuation.section.parens.end.d + set: new-after + - include: not-whitespace-illegal + new-after: + - match: '\bclass\b' + scope: storage.type.class.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [new-anonymous-after-args, value-list] + - match: '(?={)' + set: class-body + - match: '(?=[^\s])' + set: [class-body, base-class-list] + - match: (?=[^\s]) + set: [new-after-named, type] + - include: not-whitespace-illegal + new-after-named: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [value-parens-after, value-list] + - match: (?=[^\s]) + set: value-after + new-anonymous-after-args: + - match: '\)' + scope: punctuation.section.parens.end.d + set: + - match: '(?={)' + set: class-body + - match: '(?=[^\s])' + set: [class-body, base-class-list] + - include: not-whitespace-illegal + value-after: + # - meta_scope: value-after + - match: '\.\.' + scope: keyword.operator.d + set: value + - match: '\.' + scope: punctuation.accessor.dot.d + set: + - match: '{{identifier}}' + scope: variable.other.d + set: value-after + - match: '!' + scope: keyword.operator.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [value-parens-after, value-list] + - match: '(?=[^\s])' + set: value + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [value-parens-after, value-list] + - match: '\[' + scope: punctuation.section.brackets.begin.d + set: [value-bracket-after, value-list] + - match: '(\+\+|--)' + scope: keyword.operator.arithmetic.d + set: value-after + - match: '(==|!=|is|!is|<|<=|>|>=|in|!in)' + scope: keyword.operator.comparison.d + set: value + - match: '(\+|-|\*|/|%|&|\||\^\^|\^|~|<<|>>>|>>)?=' + scope: keyword.operator.assignment.d + set: value + - match: '(&&|\|\|)' + scope: keyword.operator.logical.d + set: value + - match: '(\+|\-|~|\*|/|%|\^\^)' + scope: keyword.operator.arithmetic.d + set: value + - match: '(<<|>>>|>>|\||\^|&)' + scope: keyword.operator.bitwise.d + set: value + - match: '\?' + scope: keyword.operator.logical.d + set: [value-condition-after, value] + - match: '(?=[^\s])' + pop: true + value-condition-after: + - match: ':' + scope: keyword.operator.logical.d + set: value + - include: not-whitespace-illegal + value-parens-after: + - match: '\)' + scope: punctuation.section.parens.end.d + set: value-after + - include: not-whitespace-illegal + value-bracket-after: + - match: '\]' + scope: punctuation.section.brackets.end.d + set: value-after + - include: not-whitespace-illegal + value-list: + - match: '(?=\)|}|])' + pop: true + - match: '(?=[^\s])' + set: [value-list-after, value] + value-list-after: + - match: '(?=\)|}|])' + pop: true + - match: ',' + scope: punctuation.separator.sequence.d + set: value-list + - include: not-whitespace-illegal alias-in: - match: '\b(alias)\s+({{identifier}})\s+(this)(;)' captures: @@ -863,7 +1075,6 @@ contexts: scope: punctuation.section.block.end.d pop: true - include: statement-list-in - - include: not-whitespace-illegal - include: not-whitespace-illegal interface-in: - match: '\b(interface)\b' @@ -893,7 +1104,6 @@ contexts: scope: punctuation.section.block.end.d pop: true - include: statement-list-in - - include: not-whitespace-illegal - include: not-whitespace-illegal struct-in: - match: '\b(struct)\b' @@ -922,7 +1132,6 @@ contexts: scope: punctuation.section.block.end.d pop: true - include: statement-list-in - - include: not-whitespace-illegal - include: not-whitespace-illegal union-in: - match: '\b(union)\b' @@ -951,7 +1160,6 @@ contexts: scope: punctuation.section.block.end.d pop: true - include: statement-list-in - - include: not-whitespace-illegal - include: not-whitespace-illegal enum-in: - match: '\b(enum)\b' @@ -1002,14 +1210,7 @@ contexts: set: - match: '=' scope: keyword.operator.assignment.d - set: - - include: value-in - - match: ',' - scope: punctuation.separator.sequence.d - pop: true - - match: '(?=})' - pop: true - - include: not-whitespace-illegal + set: [enum-member-after, value] - match: ',' scope: punctuation.separator.sequence.d pop: true @@ -1017,6 +1218,13 @@ contexts: pop: true - include: not-whitespace-illegal - include: not-whitespace-illegal + enum-member-after: + - match: ',' + scope: punctuation.separator.sequence.d + pop: true + - match: '(?=})' + pop: true + - include: not-whitespace-illegal-pop conditional-declaration-in: - match: '\b(static)\s+(if)\b' captures: @@ -1095,16 +1303,7 @@ contexts: captures: 1: keyword.control.flow.d 2: keyword.control.flow.d - push: [static-foreach-block, foreach-condition] - static-foreach-block: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in - - include: not-whitespace-illegal + push: [block-statement, foreach-arguments] static-assert-in: - match: '\b(static)\s+(assert)\b' captures: @@ -1135,10 +1334,10 @@ contexts: - match: '{' scope: punctuation.section.block.begin.d set: - - include: statement-list-in - match: '}' scope: punctuation.section.block.end.d pop: true + - include: statement-list-in - match: ';' scope: punctuation.terminator.d pop: true @@ -1150,10 +1349,10 @@ contexts: - match: '{' scope: punctuation.section.block.begin.d set: - - include: statement-list-in - match: '}' scope: punctuation.section.block.end.d pop: true + - include: statement-list-in - include: not-whitespace-illegal specification-in: - match: '\b(version|debug)\s*(=)' @@ -1190,24 +1389,11 @@ contexts: - include: statement-list-in - include: not-whitespace-illegal mixin-in: - - match: '\b(mixin)\b' - scope: keyword.control.d - push: - - match: '\(' - scope: punctuation.section.parens.begin.d - set: - - match: '\)' - scope: punctuation.section.parens.end.d - set: - - match: ';' - scope: punctuation.terminator.d - pop: true - - include: value-in - - match: '\b(template)\b' - scope: storage.type.d - set: template - # TODO: Template - - include: not-whitespace-illegal + - match: '\b(mixin)\s+(template)\b' + captures: + 1: keyword.control.d + 2: storage.type.d + push: template statement-label-in: - match: '\b({{name}})\s*(:)' captures: @@ -1235,10 +1421,10 @@ contexts: push: optional-block-statement - match: '\bfor\b' scope: keyword.control.flow.d - push: [optional-block-statement, for-condition] + push: [optional-block-statement, for-arguments] - match: '\b(foreach|foreach_reverse)\b' scope: keyword.control.flow.d - push: [optional-block-statement, foreach-condition] + push: [optional-block-statement, foreach-arguments] flow-statement-in: - match: '\b(continue|break)\b' scope: keyword.control.flow.d @@ -1251,7 +1437,8 @@ contexts: scope: keyword.control.flow.d push: - include: end-of-line - - include: value-in + - match: '(?=[^\s])' + set: [expect-end-of-line, value] - match: '\bgoto\b' scope: keyword.control.flow.d push: @@ -1262,7 +1449,8 @@ contexts: scope: keyword.control.flow.d set: - include: end-of-line - - include: value-in + - match: '(?=[^\s])' + set: [expect-end-of-line, value] - match: '\b{{name}}\b' scope: variable.other.constant.d set: expect-end-of-line @@ -1273,25 +1461,27 @@ contexts: push: - match: '\(' scope: punctuation.section.parens.begin.d - set: - - match: '\)' - scope: punctuation.section.parens.end.d - set: optional-block-statement - - include: value-in - - include: not-whitespace-illegal + set: [with-after, value] + - include: not-whitespace-illegal-pop + with-after: + - match: '\)' + scope: punctuation.section.parens.end.d + set: optional-block-statement + - include: not-whitespace-illegal-pop synchronized-in: - match: '\bsynchronized\b' scope: keyword.other.synchronized.d push: - match: '\(' scope: punctuation.section.parens.begin.d - set: - - match: '\)' - scope: punctuation.section.parens.end.d - set: optional-block-statement - - include: value-in + set: [synchronized-after, value] - match: '(?=[^\s])' set: optional-block-statement + synchronized-after: + - match: '\)' + scope: punctuation.section.parens.end.d + set: optional-block-statement + - include: not-whitespace-illegal-pop try-in: - match: '\btry\b' scope: keyword.control.flow.d @@ -1319,13 +1509,9 @@ contexts: throw-in: - match: '\bthrow\b' scope: keyword.control.flow.d - push: - - match: ';' - scope: punctuation.terminator.d - pop: true - - include: value-in + push: [expect-end-of-line, value] scope-in: - - match: '\b(scope)\s*(\()(exit|success|failure)(\))' + - match: '\b(scope)\s*(\()\s*(exit|success|failure)\s*(\))' captures: 1: keyword.control.flow.d 2: punctuation.section.parens.begin.d @@ -1346,80 +1532,80 @@ contexts: - include: tokens-in - include: not-whitespace-illegal - for-condition: + for-arguments: - match: '\(' scope: punctuation.section.parens.begin.d set: - - match: ';' - scope: punctuation.separator.sequence.d - set: - - match: ';' - scope: punctuation.separator.sequence.d - set: - - match: '\)' - scope: punctuation.section.parens.end.d - pop: true - - include: value-in - - include: value-in - - include: value-in - - include: not-whitespace-illegal - foreach-condition: - # TODO: Handle multiple variables + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true + - include: statement-list-in + - include: not-whitespace-illegal-pop + foreach-arguments: - match: '\(' scope: punctuation.section.brackets.begin.d - set: - - match: '\b({{name}})\s*(?=;)' - captures: - 1: variable.other.d - set: foreach-condition-end - - match: '{{type_look_ahead}}' - set: [foreach-condition-name, type] - - include: not-whitespace-illegal + set: [foreach-arguments-end, foreach-parameter-list] - include: not-whitespace-illegal - foreach-condition-name: + foreach-parameter-list: + - match: '(?=;)' + pop: true + - match: '(?=\b{{name}}\s*[;,])' + set: foreach-parameter-after-type + - match: '(?=[^\s])' + set: [foreach-parameter-after-type, type] + foreach-parameter-after-type: - match: '\b({{name}})\b' - scope: variable.other.d - set: foreach-condition-end - - include: not-whitespace-illegal - foreach-condition-end: - - match: ';' - scope: punctuation.separator.sequence.d + scope: variable.parameter.d set: - - match: '\)' - scope: punctuation.section.brackets.end.d + - match: ',' + scope: punctuation.separator.sequence.d + set: foreach-parameter-list + - match: '(?=;)' pop: true - - include: value-in - - include: not-whitespace-illegal + - include: not-whitespace-illegal-pop + - include: not-whitespace-illegal-pop + foreach-arguments-end: + - match: ';' + scope: punctuation.separator.sequence.d + set: [foreach-arguments-after, value] + - include: not-whitespace-illegal-pop + foreach-arguments-after: + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal-pop + assert-arguments: - match: '\(' scope: punctuation.section.brackets.begin.d - set: - - include: value-in - - match: ',' - scope: punctuation.separator.sequence.d - set: - - include: value-in - - match: '\)' - scope: punctuation.section.brackets.end.d - pop: true - - include: not-whitespace-illegal - - match: '\)' - scope: punctuation.section.brackets.end.d - pop: true - - include: not-whitespace-illegal + set: [assert-arguments-after, value-list] - include: not-whitespace-illegal + assert-arguments-after: + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal-pop + condition: - match: '\(' scope: punctuation.section.brackets.begin.d - set: - - include: value-in - - match: '\)' - scope: punctuation.section.brackets.end.d - pop: true - - include: not-whitespace-illegal + set: [condition-after, value] + - include: not-whitespace-illegal-pop + condition-after: + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal-pop not-whitespace-illegal: - match: '[^\s]' scope: invalid.illegal.d + not-whitespace-illegal-pop: + - match: '[^\s]' + scope: invalid.illegal.d + pop: true + end-of-line-in: + - match: ';' + scope: punctuation.terminator.d end-of-line: - match: ';' scope: punctuation.terminator.d @@ -1427,6 +1613,10 @@ contexts: expect-end-of-line: - include: end-of-line - include: not-whitespace-illegal + maybe-end-of-line: + - include: end-of-line + - match: '(?=[^\s])' + pop: true support-type-built-ins-classes-in: - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b scope: support.type.built-ins.classes.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 2a8168ee66..4ea1056c8b 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -75,20 +75,19 @@ auto stringPostfix = ``c + ""w + q"//"d; auto tokenString = q{ // ^^ string.unquoted.embedded.d punctuation.definition.string.begin.d this is not real code 12 -// ^^^^ source.d variable.language.d -// ^^ source.d keyword.d -// ^^^^^^^^^^^^^ source.d -// ^^^^ source.d storage.type.d -// ^^ source.d constant.numeric.integer.d +// ^^^^ variable.language.d +// ^^ keyword.d +// ^^^^ storage.type.d +// ^^ constant.numeric.integer.d /*}*/ // ^^ punctuation.definition.comment.d // ^^ punctuation.definition.comment.d -// ^^^^^ source.d comment.block.d +// ^^^^^ comment.block.d '' 'a' -// ^^ source.d invalid.illegal.d -// ^^^ source.d string.quoted.single.d +// ^^ invalid.illegal.d +// ^^^ string.quoted.single.d __TIME__ -// ^^^^^^^^ source.d constant.language.d +// ^^^^^^^^ constant.language.d }; // <- string.unquoted.embedded.d punctuation.definition.string.end.d @@ -226,15 +225,18 @@ f = 0xF.AP-2f; // ^ punctuation.definition.annotation.end.d extern(1) // ^ invalid.illegal.d - align(1) align(foo * 2) + align align(1) align(foo * 2) //^^^^^ keyword.other.alignment.d -// ^ punctuation.definition.annotation.begin.d -// ^ constant.numeric.integer.d -// ^ punctuation.definition.annotation.end.d -// ^^^^^ keyword.other.alignment.d -// ^ punctuation.definition.annotation.begin.d -// ^ constant.numeric.integer.d -// ^ punctuation.definition.annotation.end.d +// ^^^^^ keyword.other.alignment.d +// ^ punctuation.definition.annotation.begin.d +// ^ constant.numeric.integer.d +// ^ punctuation.definition.annotation.end.d +// ^^^^^ keyword.other.alignment.d +// ^ punctuation.definition.annotation.begin.d +// ^^^ variable.other.d +// ^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ punctuation.definition.annotation.end.d deprecated //^^^^^^^^^^ keyword.other.deprecated.d deprecated( "message") deprecated(q{void}) @@ -314,9 +316,9 @@ extern(1) // ^ keyword.operator.assignment.d // ^^^^^ storage.modifier.d // ^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.begin.d // ^^^^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.end.d // ^ punctuation.separator.sequence.d // ^^^ entity.name.type.d // ^ keyword.operator.assignment.d @@ -331,9 +333,9 @@ extern(1) //^^^^^ keyword.control.alias.d // ^^^^^ storage.modifier.d // ^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.begin.d // ^^^^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.end.d // ^^^^^^^^^ entity.name.type.d // ^ punctuation.separator.sequence.d // ^^^ entity.name.type.d @@ -356,16 +358,16 @@ extern(1) // ^ variable.other.d // ^ punctuation.terminator.d foo[string] b = 123; -//^^^ storage.type.d -// ^ keyword.operator.other.d +//^^^ variable.other.d +// ^ punctuation.section.brackets.begin.d // ^^^^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.end.d // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ constant.numeric.integer.d // ^ punctuation.terminator.d bar* some_long_Name; -//^^^ storage.type.d +//^^^ variable.other.d // ^ keyword.operator.pointer.d // ^^^^^^^^^^^^^^ variable.other.d // ^ punctuation.terminator.d @@ -504,13 +506,13 @@ extern(1) // ^ keyword.operator.assignment.d // ^^ constant.numeric.integer.d // ^ punctuation.section.block.end.d - enum : foo[stirng] { TEST } + enum : foo[string] { TEST } //^^^^ storage.type.enum.d // ^ punctuation.separator.mapping.d // ^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.begin.d // ^^^^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d // ^^^^ entity.name.constant.d // ^ punctuation.section.block.end.d @@ -585,12 +587,13 @@ extern(1) // ^ keyword.operator.assignment.d // ^^^ entity.name.constant.d // ^ punctuation.terminator.d - + int foo = true; static if (12 + 5): //^^^^^^ keyword.control.conditional.d // ^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d // ^^ constant.numeric.integer.d +// ^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d @@ -623,26 +626,21 @@ extern(1) } //^ punctuation.section.block.end.d - static foreach (foo; 12 .. 3) { + static foreach (int foo, f; 12..3) { //^^^^^^ keyword.control.flow.d // ^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d -// ^^^ variable.other.d -// ^ punctuation.separator.sequence.d -// ^^ constant.numeric.integer.d -// ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d -// ^ punctuation.section.block.begin.d static foreach (int a; 123) { //^^^^^^ keyword.control.flow.d // ^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d // ^^^ storage.type.d - // ^ variable.other.d + // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d + // ^ } //^ punctuation.section.block.end.d } @@ -655,12 +653,21 @@ extern(1) // ^^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d + static assert(12, "foobar"); +//^^^^^^ keyword.control.conditional.d +// ^^^^^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^^ constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^^^^^^^^ string.quoted.double.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.terminator.d int[string] foo() { //^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.begin.d // ^^^^^^ storage.type.d -// ^ keyword.operator.other.d +// ^ punctuation.section.brackets.end.d // ^^^ entity.name.function.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d @@ -673,11 +680,13 @@ extern(1) // ^ punctuation.terminator.d int[] map(int[] array, ) { //^^^ storage.type.d - // ^^ keyword.operator.other.d + // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.brackets.end.d // ^^^ entity.name.function.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d - // ^^ keyword.operator.other.d + // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.brackets.end.d // ^^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ @@ -685,8 +694,9 @@ extern(1) } //^ punctuation.section.block.end.d T[] map(T, void fn)(T[] array) { - //^ storage.type.d - // ^^ keyword.operator.other.d + //^ variable.other.d + // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.brackets.end.d // ^^^ entity.name.function.d // ^ punctuation.section.group.begin.d // ^ storage.type.d @@ -696,7 +706,8 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.group.begin.d // ^ storage.type.d - // ^^ keyword.operator.other.d + // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.brackets.end.d // ^^^^^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d @@ -705,7 +716,7 @@ extern(1) } //^ punctuation.section.block.end.d VeryLongTypeNameThatWillForceALineWrapWith80WidthLines -//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ storage.type.d +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.other.d veryLongFunctionNameToHelpWithTheLineWrappingThing //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.function.d ( @@ -806,7 +817,7 @@ extern(1) } //^ punctuation.section.block.end.d mixin("foo"); -//^^^^^ keyword.control.d +//^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^ punctuation.definition.string.begin.d // ^^^^^ string.quoted.double.d @@ -884,19 +895,30 @@ extern(1) //^^^ keyword.control.flow.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.separator.sequence.d +// ^ punctuation.terminator.d // ^ constant.numeric.integer.d -// ^ punctuation.separator.sequence.d +// ^ punctuation.terminator.d // ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d } +//^ punctuation.section.block.end.d + for(int a;;12) { +//^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^^^ storage.type.d +// ^ variable.other.d +// ^^ punctuation.terminator.d +// ^^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d + } //^ punctuation.section.block.end.d foreach (int a; 2) { //^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d // ^^^ storage.type.d -// ^ variable.other.d +// ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d @@ -905,7 +927,7 @@ extern(1) //^^^^^^^^^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d // ^^^ storage.type.d - // ^ variable.other.d + // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d @@ -1051,3 +1073,117 @@ extern(1) // ^^^^ storage.attribute.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + + f a = new (12, "foo") string[12]("foo", "bar")[14]; +//^ storage.type.d +// ^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^ keyword.operator.word.d +// ^ punctuation.section.parens.begin.d +// ^^ constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^^^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d +// ^^^^^^ storage.type.d +// ^ punctuation.section.brackets.begin.d +// ^^ constant.numeric.integer.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.begin.d +// ^^^^^ string.quoted.double.d +// ^ punctuation.separator.sequence.d +// ^^^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.brackets.begin.d +// ^^ constant.numeric.integer.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.terminator.d + + mixin("a") = (12 ^^ 4) % 5 / (3++ + --4) ~ "foo"; +//^^^^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d +// ^ keyword.operator.assignment.d +// ^ punctuation.section.parens.begin.d +// ^^ constant.numeric.integer.d +// ^^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ keyword.operator.arithmetic.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.integer.d +// ^^ keyword.operator.arithmetic.d +// ^ keyword.operator.arithmetic.d +// ^^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ keyword.operator.arithmetic.d +// ^^^^^ string.quoted.double.d +// ^ punctuation.terminator.d + + auto f = foo ? 12 : 15; +//^^^^ storage.modifier.d +// ^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^ variable.other.d +// ^ keyword.operator.logical.d +// ^^ constant.numeric.integer.d +// ^ keyword.operator.logical.d +// ^^ constant.numeric.integer.d +// ^ punctuation.terminator.d + + auto c = new class(12) T, Bar { +//^^^^ storage.modifier.d +// ^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^ keyword.operator.word.d +// ^^^^^ storage.type.class.d +// ^ punctuation.section.parens.begin.d +// ^^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ punctuation.section.block.begin.d + private int foo; + //^^^^^^^ storage.modifier.access-control.d + // ^^^ storage.type.d + // ^^^ variable.other.d + // ^ punctuation.terminator.d + + this(int num) { + //^^^^ entity.name.function.constructor.d + // ^ punctuation.section.group.begin.d + // ^^^ storage.type.d + // ^^^ variable.parameter.d + // ^ punctuation.section.group.end.d + // ^ punctuation.section.block.begin.d + this.foo = num; + //^^^^ variable.language.d + // ^ punctuation.accessor.dot.d + // ^^^ variable.other.d + // ^ keyword.operator.assignment.d + // ^^^ variable.other.d + // ^ punctuation.terminator.d + } + //^ punctuation.section.block.end.d + + override int foo() { + //^^^^^^^^ storage.modifier.d + // ^^^ storage.type.d + // ^^^ entity.name.function.d + // ^ punctuation.section.group.begin.d + // ^ punctuation.section.group.end.d + // ^ punctuation.section.block.begin.d + return num * 3; + //^^^^^^ keyword.control.flow.d + // ^^^ variable.other.d + // ^ keyword.operator.arithmetic.d + // ^ constant.numeric.integer.d + // ^ punctuation.terminator.d + } + //^ punctuation.section.block.end.d + } +//^ punctuation.section.block.end.d From d502658bba64699ddbb99a080a2aae93e45664f3 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 14:08:34 +1100 Subject: [PATCH 036/108] Fix some expression and type parsing inconsistencies --- D/D.sublime-syntax | 112 ++++++++++++++++++++++++++++------------ D/tests/syntax_test_d.d | 66 +++++++++++++++++++++-- 2 files changed, 139 insertions(+), 39 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 03dca09c00..a0d7b6e851 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -20,7 +20,6 @@ variables: type_ctor: 'const|immutable|inout|shared' type_look_ahead: '(?=\b({{identifier_ref}}))' - type2_look_ahead: '(?=\*|\[|\bdelegate\b|\bfunction\b)' number_lookahead: '(?=(\b|\.)[0-9])' integer_lookahead: '(?=\b[0-9])' @@ -38,8 +37,8 @@ variables: 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' language_constant: 'null|true|false|__FILE__|__FILE_FULL_PATH__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__' - langauge_variable: 'this|super' - reserved: '{{keyword}}|{{basic_type}}|{{language_constant}}|{{langauge_variable}}' + language_variable: 'this|super' + reserved: '{{keyword}}|{{basic_type}}|{{language_constant}}|{{language_variable}}' block_statement_loohahead: '(?={)' @@ -425,7 +424,7 @@ contexts: scope: storage.type.d - match: '\b({{language_constant}})\b' scope: constant.language.d - - match: '\b({{langauge_variable}})\b' + - match: '\b({{language_variable}})\b' scope: variable.language.d - include: character-in - include: string-in @@ -637,11 +636,7 @@ contexts: basic-type: - match: '\b({{identifier_ref}})\b' scope: storage.type.d - set: - - match: '{{type2_look_ahead}}' - set: basic-type2 - - match: '(?=[^\s])' - pop: true + set: basic-type2 # TODO: More basic types - match: '(?=[^\s])' pop: true @@ -654,6 +649,14 @@ contexts: - match: '\b(delegate|function)\b' scope: keyword.other.d push: function-pointer-type + - match: '!' + scope: keyword.operator.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [basic-type2-after-parens, value-list] + - match: '(?=[^\s])' + set: value - match: '(?=[^\s])' pop: true basic-type2-after-brackets: @@ -661,28 +664,23 @@ contexts: scope: punctuation.section.brackets.end.d pop: true - include: not-whitespace-illegal-pop + basic-type2-after-parens: + - match: '\)' + scope: punctuation.section.brackets.end.d + pop: true + - include: not-whitespace-illegal-pop function-pointer-type: # TODO - match: '.' pop: true function-or-variable-after-type: - - match: '\b({{name}})\s*(=)' - captures: - 1: variable.other.d - 2: keyword.operator.assignment.d - set: [expect-end-of-line, value] - - match: '\b({{name}})\s*(;)' - captures: - 1: variable.other.d - 2: punctuation.terminator.d - pop: true - match: '\b({{name}})\s*(?=\(|$)' captures: 1: entity.name.function.d set: function-definition-begin - match: '(?=[^\s])' - pop: true + set: variable-definition-begin function-definition-begin: - match: '(?=\()' set: [function-definition-after-argument-list1, function-argument-definition-list] @@ -740,18 +738,34 @@ contexts: - include: statement-list-in - include: end-of-line - include: not-whitespace-illegal + variable-definition-begin: + - match: '\b{{name}}\b' + scope: variable.other.d + set: + - match: '(?=,)' + set: variable-definition-after + - match: '=' + scope: keyword.operator.assignment.d + set: [variable-definition-after, value] + - include: expect-end-of-line + - include: not-whitespace-illegal-pop + variable-definition-after: + - match: ',' + scope: punctuation.separator.sequence.d + set: variable-definition-begin + - include: expect-end-of-line value-or-declaration-in: - match: '\s' - - match: '(?=(!|~|\+|\-|\*|&|cast|delete|new|import|mixin|[0-9]|\[|\(|{{name}}\s*\(|{{string_lookahead}}|{{language_constant}}|{{langauge_variable}}))' - push: [maybe-end-of-line, value] + - match: '(?=(!|~|\+|\-|\*|&|cast|delete|new|import|mixin|[0-9]|\[|\(|{{name}}\s*\(|{{string_lookahead}}|{{language_constant}}|{{language_variable}}))' + push: [maybe-end-of-line, value-list] - match: '(?=({{name}}|\]|\))(\s+{{name}}))' push: [function-or-variable-after-type, type] - match: '(?=[^\s])' push: [maybe-end-of-line, first-value] value-or-declaration: - match: '\s' - - match: '(?=(!|~|\+|\-|\*|&|cast|delete|new|import|mixin|[0-9]|\[|\(|{{name}}\s*\(|{{string_lookahead}}|{{language_constant}}|{{langauge_variable}}))' - set: value + - match: '(?=(!|~|\+|\-|\*|&|cast|delete|new|import|mixin|[0-9]|\[|\(|{{name}}\s*\(|{{string_lookahead}}|{{language_constant}}|{{language_variable}}))' + set: value-list - match: '(?=({{name}}|\]|\))(\s+{{name}}))' set: [function-or-variable-after-type, type] - match: '(?=[^\s])' @@ -759,7 +773,7 @@ contexts: # The first value in an expression ending with a * is always a function/variable definition, otherwise it could be either # We highlight as if it were a value, but switch to a definition if it turns out to be one first-value: - # - meta_scope: first-value + - meta_scope: first-value - match: '\b({{basic_type}})\b' scope: storage.type.d set: first-value-after @@ -768,7 +782,7 @@ contexts: set: first-value-after - include: not-whitespace-illegal first-value-after: - # - meta_scope: first-value-after + - meta_scope: first-value-after - match: '\.' scope: punctuation.accessor.dot.d set: @@ -786,12 +800,15 @@ contexts: - match: '\[' scope: punctuation.section.brackets.begin.d set: [first-value-bracket-after, value-list] + - match: ',' + scope: punctuation.separator.sequence.d + set: value-list - match: '(?=\*)' set: [function-or-variable-after-type, basic-type2] - match: '(?={{name}}\s*([;=\(]|$))' set: function-or-variable-after-type - match: '(?=[^\s])' - set: value-after + set: [value-list-after, value-after] first-value-bracket-after: - match: '\]' scope: punctuation.section.brackets.end.d @@ -803,7 +820,7 @@ contexts: set: first-value-after - include: not-whitespace-illegal value: - # - meta_scope: value + - meta_scope: value - match: '!' scope: keyword.operator.logical.d set: value @@ -851,6 +868,11 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [new-after-parens, value] + - match: '(?={)' + set: [value-after, block-statement] + - match: '\[' + scope: punctuation.section.brackets.begin.d + set: [value-bracket-after, value-array-list] - match: '{{number_lookahead}}' set: [value-after, number] - match: '{{character_lookahead}}' @@ -860,7 +882,10 @@ contexts: - match: '\b({{language_constant}})\b' scope: constant.language.d set: value-after - - match: '\b({{langauge_variable}})\b' + - match: '\b({{language_variable}})\b' + scope: variable.language.d + set: value-after + - match: '\$' scope: variable.language.d set: value-after - match: '\b({{basic_type}})\b' @@ -910,7 +935,7 @@ contexts: set: [class-body, base-class-list] - include: not-whitespace-illegal value-after: - # - meta_scope: value-after + - meta_scope: value-after - match: '\.\.' scope: keyword.operator.d set: value @@ -973,23 +998,41 @@ contexts: set: value-after - include: not-whitespace-illegal value-list: - - match: '(?=\)|}|])' + - meta_scope: value-list + - match: '(?=\)|}|]|;)' pop: true - match: '(?=[^\s])' set: [value-list-after, value] value-list-after: - - match: '(?=\)|}|])' + - match: '(?=\)|}|]|;)' pop: true - match: ',' scope: punctuation.separator.sequence.d set: value-list - include: not-whitespace-illegal + value-array-list: + - match: '(?=\])' + pop: true + - match: '(?=[^\s])' + set: [value-array-list-after, value] + value-array-list-after: + - match: ':' + scope: punctuation.separator.mapping.key-value.d + set: [value-array-list-after-value, value] + - include: value-array-list-after-value + value-array-list-after-value: + - match: '(?=\])' + pop: true + - match: ',' + scope: punctuation.separator.sequence.d + set: value-array-list + - include: not-whitespace-illegal alias-in: - match: '\b(alias)\s+({{identifier}})\s+(this)(;)' captures: 1: keyword.control.alias.d 2: variable.d - 3: constant.language.d + 3: keyword.control.alias.d 4: punctuation.terminator.d - match: '\b(alias)\b' scope: keyword.control.alias.d @@ -1551,6 +1594,7 @@ contexts: pop: true - match: '(?=\b{{name}}\s*[;,])' set: foreach-parameter-after-type + - include: attribute-in - match: '(?=[^\s])' set: [foreach-parameter-after-type, type] foreach-parameter-after-type: @@ -1612,7 +1656,7 @@ contexts: pop: true expect-end-of-line: - include: end-of-line - - include: not-whitespace-illegal + - include: not-whitespace-illegal-pop maybe-end-of-line: - include: end-of-line - match: '(?=[^\s])' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 4ea1056c8b..f58f48ed65 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -310,7 +310,7 @@ extern(1) // ^ keyword.operator.assignment.d // ^^^ storage.type.d // ^ punctuation.terminator.d - alias Foo = const int[string], bar = long; + alias Foo = const int[string], bar = long!int; //^^^^^ keyword.control.alias.d // ^^^ entity.name.type.d // ^ keyword.operator.assignment.d @@ -323,7 +323,9 @@ extern(1) // ^^^ entity.name.type.d // ^ keyword.operator.assignment.d // ^^^^ storage.type.d -// ^ punctuation.terminator.d +// ^ keyword.operator.d +// ^^^ value value-after storage.type.d +// ^ punctuation.terminator.d alias int a; //^^^^^ keyword.control.alias.d // ^^^ storage.type.d @@ -345,12 +347,12 @@ extern(1) alias foo this; //^^^^^ keyword.control.alias.d // ^^^ variable.d -// ^^^^ constant.language.d +// ^^^^ keyword.control.alias.d // ^ punctuation.terminator.d alias foo.bar.baz this; //^^^^^ keyword.control.alias.d // ^^^^^^^^^^^ variable.d -// ^^^^ constant.language.d +// ^^^^ keyword.control.alias.d // ^ punctuation.terminator.d int a; @@ -1185,5 +1187,59 @@ extern(1) // ^ punctuation.terminator.d } //^ punctuation.section.block.end.d - } + }; //^ punctuation.section.block.end.d +// ^ punctuation.terminator.d + + foreach (ref a; foo) {} +//^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^^^ storage.modifier.d +// ^ variable.parameter.d +// ^ value punctuation.separator.sequence.d +// ^^^ value value-after variable.other.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + + int a = 2, b = 3; +//^^^ storage.type.d +// ^ variable.other.d +// ^ value keyword.operator.assignment.d +// ^ value-after constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^ variable.other.d +// ^ value keyword.operator.assignment.d +// ^ value-after constant.numeric.integer.d +// ^ punctuation.terminator.d + + a = "foo", b = "bar"; +//^ first-value first-value-after variable.other.d +// ^ value-after value keyword.operator.assignment.d +// ^^^^^ value-after string.quoted.double.d +// ^ value-list punctuation.separator.sequence.d +// ^ value value-after variable.other.d +// ^ value-after value keyword.operator.assignment.d +// ^^^^^ value-after string.quoted.double.d +// ^ punctuation.terminator.d + + string[] f = [ +//^^^^^^ first-value first-value-after storage.type.d +// ^ first-value-after value-list punctuation.section.brackets.begin.d +// ^ first-value-after punctuation.section.brackets.end.d +// ^ variable.other.d +// ^ value keyword.operator.assignment.d +// ^ value punctuation.section.brackets.begin.d + 1: 2, + //^ value-after constant.numeric.integer.d + // ^ value punctuation.separator.mapping.key-value.d + // ^ value-after constant.numeric.integer.d + // ^ punctuation.separator.sequence.d + "foo", + //^^^^^ value-after string.quoted.double.d + // ^ punctuation.separator.sequence.d + "bar", + //^^^^^ value-after string.quoted.double.d + // ^ punctuation.separator.sequence.d + ]; +//^ value-after punctuation.section.brackets.end.d From 97aba5fb771f916037c1c0564104648062ac414e Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 15:17:22 +1100 Subject: [PATCH 037/108] Fix more minor inconsistencies and implement switch parsing --- D/D.sublime-syntax | 103 +++++++++++++---------- D/tests/syntax_test_d.d | 178 ++++++++++++++++++++++++++++++++-------- 2 files changed, 202 insertions(+), 79 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index a0d7b6e851..74217d9d26 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -33,13 +33,16 @@ variables: attribute_lookahead: '(?={{attributes}}|@)' attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' at_attributes: 'disable|nogc|property|safe|system|trusted' + parameter_attributes: 'in|lazy|out' 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' - language_constant: 'null|true|false|__FILE__|__FILE_FULL_PATH__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__' + 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}}' + 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: '(?={)' contexts: @@ -84,7 +87,6 @@ contexts: - include: template-in - include: mixin-in - include: block-statement-in - - include: statement-label-in - include: conditional-in - include: loop-in - include: flow-statement-in @@ -94,6 +96,8 @@ contexts: - include: throw-in - include: scope-in - include: asm-in + - include: switch-in + - include: statement-label-in - include: attribute-specifier-in - include: end-of-line-in - include: value-or-declaration-in @@ -114,12 +118,6 @@ contexts: set: block-statement - match: '(?=[^\s])' pop: true - module-context-in: - # TODO - - match: \b(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)\b - scope: keyword.operator.overload.d - - match: \b(new|delete|typeof|typeid|cast|align|is)\b - scope: keyword.other.d all-types-in: - include: support-type-built-ins-in - include: support-type-in @@ -443,6 +441,10 @@ contexts: - include: attribute-in - match: ':' scope: punctuation.separator.d + parameter-attribute-in: + - include: attribute-in + - match: '\b({{parameter_attributes}})\b' + scope: storage.modifier.d attribute-in: - match: '\b({{attributes}})\b' scope: storage.modifier.d @@ -675,6 +677,10 @@ contexts: - match: '.' pop: true function-or-variable-after-type: + - match: '\b({{operator_overloads}})\s*(?=\(|$)' + captures: + 1: keyword.operator.overload.d + set: function-definition-begin - match: '\b({{name}})\s*(?=\(|$)' captures: 1: entity.name.function.d @@ -699,26 +705,33 @@ contexts: scope: punctuation.section.group.begin.d set: - match: '{{type_look_ahead}}' - set: [function-argument, type] + set: [function-argument, function-argument-or-type] - match: '\)' scope: punctuation.section.group.end.d pop: true - include: not-whitespace-illegal - include: not-whitespace-illegal + function-argument-or-type: + - include: parameter-attribute-in + - match: '(?={{name}}\s*[,=\)\.])' + pop: true + - include: type function-argument: - match: '\b{{name}}\b' scope: variable.parameter.d set: + - match: '\.\.\.' + scope: keyword.operator.d - match: ',' scope: punctuation.separator.sequence.d - set: [function-argument, type] + set: [function-argument, function-argument-or-type] - match: '=' - # TODO + scope: keyword.operator.assignment.d + push: value - match: '\)' scope: punctuation.section.group.end.d pop: true - include: not-whitespace-illegal - # - match: '\.\.\.' # TODO - match: ',' scope: punctuation.separator.sequence.d push: type @@ -727,7 +740,6 @@ contexts: pop: true - include: not-whitespace-illegal function-definition: - - meta_scope: meta.function.d - match: '{' scope: punctuation.section.block.begin.d set: @@ -773,7 +785,7 @@ contexts: # The first value in an expression ending with a * is always a function/variable definition, otherwise it could be either # We highlight as if it were a value, but switch to a definition if it turns out to be one first-value: - - meta_scope: first-value + # - meta_scope: first-value - match: '\b({{basic_type}})\b' scope: storage.type.d set: first-value-after @@ -782,7 +794,7 @@ contexts: set: first-value-after - include: not-whitespace-illegal first-value-after: - - meta_scope: first-value-after + # - meta_scope: first-value-after - match: '\.' scope: punctuation.accessor.dot.d set: @@ -796,7 +808,7 @@ contexts: scope: punctuation.section.parens.begin.d set: [first-value-parens-after, value-list] - match: '(?=[^\s])' - set: value + set: first-value - match: '\[' scope: punctuation.section.brackets.begin.d set: [first-value-bracket-after, value-list] @@ -820,7 +832,7 @@ contexts: set: first-value-after - include: not-whitespace-illegal value: - - meta_scope: value + # - meta_scope: value - match: '!' scope: keyword.operator.logical.d set: value @@ -935,7 +947,7 @@ contexts: set: [class-body, base-class-list] - include: not-whitespace-illegal value-after: - - meta_scope: value-after + # - meta_scope: value-after - match: '\.\.' scope: keyword.operator.d set: value @@ -1217,6 +1229,9 @@ contexts: - match: ':' scope: punctuation.separator.mapping.d set: [enum-body, type] + - match: '=' + scope: keyword.operator.assignment.d + set: [expect-end-of-line, value] - include: not-whitespace-illegal - match: ':' scope: punctuation.separator.mapping.d @@ -1269,11 +1284,6 @@ contexts: pop: true - include: not-whitespace-illegal-pop conditional-declaration-in: - - match: '\b(static)\s+(if)\b' - captures: - 1: keyword.control.conditional.d - 2: keyword.control.conditional.d - push: [conditional-declaration-body, condition] - match: '\b(version)\b' scope: keyword.control.conditional.d push: [conditional-declaration-body, version-condition] @@ -1574,6 +1584,33 @@ contexts: pop: true - include: tokens-in - include: not-whitespace-illegal + switch-in: + - match: '\bswitch\b' + scope: keyword.control.flow.d + push: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [switch-after, value] + - match: '\bcase\b' + scope: keyword.control.flow.d + push: [case-after, value] + - match: '\bdefault\b' + scope: keyword.control.flow.d + push: + - match: ':' + scope: punctuation.section.block.begin.d + pop: true + - include: not-whitespace-illegal-pop + switch-after: + - match: '\)' + scope: punctuation.section.parens.end.d + set: block-statement + - include: not-whitespace-illegal-pop + case-after: + - match: ':' + scope: punctuation.section.block.begin.d + pop: true + - include: not-whitespace-illegal-pop for-arguments: - match: '\(' @@ -1661,23 +1698,3 @@ contexts: - include: end-of-line - match: '(?=[^\s])' pop: true - support-type-built-ins-classes-in: - - match: \b(AbstractServer|ArchiveMember|ArgParser|Barrier|BomSniffer|Buffer|BufferInput|BufferOutput|BufferSlice|BufferedFile|BufferedStream|BzipInput|BzipOutput|CFile|CacheInvalidatee|CacheInvalidator|CacheServer|CacheThread|Certificate|CertificateStore|CertificateStoreCtx|ChunkInput|ChunkOutput|ClassInfo|Cluster|ClusterCache|ClusterQueue|ClusterThread|CmdParser|ComObject|Compress|Condition|Conduit|Cookie|CookieParser|CookieStack|CounterInput|CounterOutput|DataFileInput|DataFileOutput|DataInput|DataOutput|Database|DatagramConduit|DeviceConduit|DigestInput|DigestOutput|DocPrinter|Document|DummyInputStream|DummyOutputStream|EndianInput|EndianOutput|EndianProtocol|EndianStream|EventSeekInputStream|EventSeekOutputStream|FTPConnection|Fiber|Field|File|FileConduit|FileFolder|FileGroup|FileInput|FileOutput|FilePath|FileScan|FilterStream|Foo|FormatOutput|GreedyInput|GreedyOutput|Gregorian|GrowBuffer|HeapCopy|HeapSlice|Hierarchy|HttpClient|HttpCookies|HttpCookiesView|HttpGet|HttpHeaders|HttpHeadersView|HttpParams|HttpPost|HttpStack|HttpTokens|HttpTriplet|IPv4Address|IUnknown|InputFilter|InternetAddress|InternetHost|Layout|LineInput|LineIterator|LinkedFolder|Log|MapInput|MapOutput|MappedBuffer|Md2|Md4|MemoryQueue|MemoryStream|MmFile|MmFileStream|ModuleInfo|MulticastConduit|Mutex|NativeProtocol|NetCall|NetHost|NetworkAlert|NetworkCache|NetworkCall|NetworkClient|NetworkCombo|NetworkMessage|NetworkQueue|NetworkRegistry|NetworkTask|NotImplemented|Object|Observer|OutBuffer|OutputFilter|PersistQueue|Pipe|PipeConduit|Print|PrivateKey|Process|Properties|Protocol|ProtocolReader|ProtocolWriter|PublicKey|PullParser|QueueFile|QueueServer|QueueThread|QueuedCache|QuoteIterator|Random|Range|ReadWriteMutex|Reader|Record|RegExp|RegExpT|RegexIterator|RollCall|SSLCtx|SSLServerSocket|SSLSocketConduit|SaxParser|SelectionKey|Semaphore|ServerSocket|ServerThread|Service|SimpleIterator|SliceInputStream|SliceSeekInputStream|SliceSeekOutputStream|SliceStream|SnoopInput|SnoopOutput|Socket|SocketConduit|SocketListener|SocketSet|SocketStream|Sprint|Stream|StreamIterator|TArrayStream|TaskServer|TaskThread|TcpSocket|Telnet|TempFile|Text|TextFileInput|TextFileOutput|TextView|Thread|ThreadGroup|ThreadLocal|ThreadPool|Token|TypeInfo|TypeInfo_AC|TypeInfo_Aa|TypeInfo_Ab|TypeInfo_Ac|TypeInfo_Ad|TypeInfo_Ae|TypeInfo_Af|TypeInfo_Ag|TypeInfo_Ah|TypeInfo_Ai|TypeInfo_Aj|TypeInfo_Ak|TypeInfo_Al|TypeInfo_Am|TypeInfo_Ao|TypeInfo_Ap|TypeInfo_Aq|TypeInfo_Ar|TypeInfo_Array|TypeInfo_As|TypeInfo_AssociativeArray|TypeInfo_At|TypeInfo_Au|TypeInfo_Av|TypeInfo_Aw|TypeInfo_C|TypeInfo_Class|TypeInfo_D|TypeInfo_Delegate|TypeInfo_Enum|TypeInfo_Function|TypeInfo_Interface|TypeInfo_P|TypeInfo_Pointer|TypeInfo_StaticArray|TypeInfo_Struct|TypeInfo_Tuple|TypeInfo_Typedef|TypeInfo_a|TypeInfo_b|TypeInfo_c|TypeInfo_d|TypeInfo_e|TypeInfo_f|TypeInfo_g|TypeInfo_h|TypeInfo_i|TypeInfo_j|TypeInfo_k|TypeInfo_l|TypeInfo_m|TypeInfo_o|TypeInfo_p|TypeInfo_q|TypeInfo_r|TypeInfo_s|TypeInfo_t|TypeInfo_u|TypeInfo_v|TypeInfo_w|TypedInput|TypedOutput|URIerror|UdpSocket|UnCompress|UniText|UnicodeBom|UnicodeFile|UnknownAddress|Uri|UtfInput|UtfOutput|VirtualFolder|WrapSeekInputStream|WrapSeekOutputStream|Writer|XmlPrinter|ZipArchive|ZipBlockReader|ZipBlockWriter|ZipEntry|ZipEntryVerifier|ZipFile|ZipFileGroup|ZipFolder|ZipSubFolder|ZipSubFolderEntry|ZipSubFolderGroup|ZlibInput|ZlibOutput)\b - scope: support.type.built-ins.classes.d - support-type-built-ins-in: - - include: support-type-built-ins-exceptions-in - - include: support-type-built-ins-classes-in - - include: support-type-built-ins-interfaces-in - - include: support-type-built-ins-structs-in - support-type-built-ins-exceptions-in: - - match: \b(AddressException|ArrayBoundsError|ArrayBoundsException|AssertError|AssertException|Base64CharException|Base64Exception|BzipClosedException|BzipException|ClusterEmptyException|ClusterFullException|ConvError|ConvOverflowError|ConversionException|CorruptedIteratorException|DatabaseException|DateParseError|Exception|FTPException|FiberException|FileException|FinalizeException|FormatError|HostException|IOException|IllegalArgumentException|IllegalElementException|InvalidKeyException|InvalidTypeException|LocaleException|ModuleCtorError|NoSuchElementException|OpenException|OpenRJException|OutOfMemoryException|PlatformException|ProcessCreateException|ProcessException|ProcessForkException|ProcessKillException|ProcessWaitException|ReadException|RegExpException|RegexException|RegistryException|SeekException|SharedLibException|SocketAcceptException|SocketException|StdioException|StreamException|StreamFileException|StringException|SwitchError|SwitchException|SyncException|TextException|ThreadError|ThreadException|UnboxException|UnicodeException|UtfException|VariantTypeMismatchException|Win32Exception|WriteException|XmlException|ZipChecksumException|ZipException|ZipExhaustedException|ZipNotSupportedException|ZlibClosedException|ZlibException|OurUnwindException|SysError)\b - scope: support.type.built-ins.exceptions.d - support-type-built-ins-interfaces-in: - - match: \b(Buffered|HttpParamsView|ICache|IChannel|IClassFactory|ICluster|IConduit|IConsumer|IEvent|IHierarchy|ILevel|IListener|IMessage|IMessageLoader|IOStream|IReadable|ISelectable|ISelectionSet|ISelector|IServer|IUnknown|IWritable|IXmlPrinter|InputStream|OutputStream|PathView|VfsFile|VfsFiles|VfsFolder|VfsFolderEntry|VfsFolders|VfsHost|VfsSync|ZipReader|ZipWriter)\b - scope: support.type.built-ins.interfaces.d - support-type-built-ins-structs-in: - - match: \b(ABC|ABCFLOAT|ACCEL|ACCESSTIMEOUT|ACCESS_ALLOWED_ACE|ACCESS_DENIED_ACE|ACE_HEADER|ACL|ACL_REVISION_INFORMATION|ACL_SIZE_INFORMATION|ACTION_HEADER|ADAPTER_STATUS|ADDJOB_INFO_1|ANIMATIONINFO|APPBARDATA|Argument|Atomic|Attribute|BITMAP|BITMAPCOREHEADER|BITMAPCOREINFO|BITMAPINFO|BITMAPINFOHEADER|BITMAPV4HEADER|BLOB|BROWSEINFO|BY_HANDLE_FILE_INFORMATION|Bar|Baz|BitArray|Box|BracketResult|ByteSwap|CANDIDATEFORM|CANDIDATELIST|CBTACTIVATESTRUCT|CBT_CREATEWND|CHARFORMAT|CHARRANGE|CHARSET|CHARSETINFO|CHAR_INFO|CIDA|CIEXYZ|CIEXYZTRIPLE|CLIENTCREATESTRUCT|CMINVOKECOMMANDINFO|COLORADJUSTMENT|COLORMAP|COMMCONFIG|COMMPROP|COMMTIMEOUTS|COMPAREITEMSTRUCT|COMPCOLOR|COMPOSITIONFORM|COMSTAT|CONNECTDLGSTRUCT|CONSOLE_CURSOR_INFO|CONTEXT|CONVCONTEXT|CONVINFO|COORD|COPYDATASTRUCT|CPINFO|CPLINFO|CREATESTRUCT|CREATE_PROCESS_DEBUG_INFO|CREATE_THREAD_DEBUG_INFO|CRITICAL_SECTION|CRITICAL_SECTION_DEBUG|CURRENCYFMT|CURSORSHAPE|CWPRETSTRUCT|CWPSTRUCT|CharClass|CharRange|Clock|CodePage|Console|DATATYPES_INFO_1|DCB|DDEACK|DDEADVISE|DDEDATA|DDELN|DDEML_MSG_HOOK_DATA|DDEPOKE|DDEUP|DEBUGHOOKINFO|DEBUG_EVENT|DELETEITEMSTRUCT|DEVMODE|DEVNAMES|DEV_BROADCAST_HDR|DEV_BROADCAST_OEM|DEV_BROADCAST_PORT|DEV_BROADCAST_VOLUME|DIBSECTION|DIR|DISCDLGSTRUCT|DISK_GEOMETRY|DISK_PERFORMANCE|DOCINFO|DOC_INFO_1|DOC_INFO_2|DRAGLISTINFO|DRAWITEMSTRUCT|DRAWTEXTPARAMS|DRIVER_INFO_1|DRIVER_INFO_2|DRIVER_INFO_3|DRIVE_LAYOUT_INFORMATION|Date|DateParse|DateTime|DirEntry|DynArg|EDITSTREAM|EMPTYRECORD|EMR|EMRABORTPATH|EMRANGLEARC|EMRARC|EMRBITBLT|EMRCREATEBRUSHINDIRECT|EMRCREATECOLORSPACE|EMRCREATEDIBPATTERNBRUSHPT|EMRCREATEMONOBRUSH|EMRCREATEPALETTE|EMRCREATEPEN|EMRELLIPSE|EMREOF|EMREXCLUDECLIPRECT|EMREXTCREATEFONTINDIRECTW|EMREXTCREATEPEN|EMREXTFLOODFILL|EMREXTSELECTCLIPRGN|EMREXTTEXTOUTA|EMRFILLPATH|EMRFILLRGN|EMRFORMAT|EMRFRAMERGN|EMRGDICOMMENT|EMRINVERTRGN|EMRLINETO|EMRMASKBLT|EMRMODIFYWORLDTRANSFORM|EMROFFSETCLIPRGN|EMRPLGBLT|EMRPOLYDRAW|EMRPOLYDRAW16|EMRPOLYLINE|EMRPOLYLINE16|EMRPOLYPOLYLINE|EMRPOLYPOLYLINE16|EMRPOLYTEXTOUTA|EMRRESIZEPALETTE|EMRRESTOREDC|EMRROUNDRECT|EMRSCALEVIEWPORTEXTEX|EMRSELECTCLIPPATH|EMRSELECTCOLORSPACE|EMRSELECTOBJECT|EMRSELECTPALETTE|EMRSETARCDIRECTION|EMRSETBKCOLOR|EMRSETCOLORADJUSTMENT|EMRSETDIBITSTODEVICE|EMRSETMAPPERFLAGS|EMRSETMITERLIMIT|EMRSETPALETTEENTRIES|EMRSETPIXELV|EMRSETVIEWPORTEXTEX|EMRSETVIEWPORTORGEX|EMRSETWORLDTRANSFORM|EMRSTRETCHBLT|EMRSTRETCHDIBITS|EMRTEXT|ENCORRECTTEXT|ENDROPFILES|ENHMETAHEADER|ENHMETARECORD|ENOLEOPFAILED|ENPROTECTED|ENSAVECLIPBOARD|ENUMLOGFONT|ENUMLOGFONTEX|ENUM_SERVICE_STATUS|EVENTLOGRECORD|EVENTMSG|EXCEPTION_DEBUG_INFO|EXCEPTION_POINTERS|EXCEPTION_RECORD|EXIT_PROCESS_DEBUG_INFO|EXIT_THREAD_DEBUG_INFO|EXTLOGFONT|EXTLOGPEN|EXT_BUTTON|EmptySlot|EndOfCDRecord|Environment|FILETIME|FILTERKEYS|FINDREPLACE|FINDTEXTEX|FIND_NAME_BUFFER|FIND_NAME_HEADER|FIXED|FLOATING_SAVE_AREA|FMS_GETDRIVEINFO|FMS_GETFILESEL|FMS_LOAD|FMS_TOOLBARLOAD|FOCUS_EVENT_RECORD|FONTSIGNATURE|FORMATRANGE|FORMAT_PARAMETERS|FORM_INFO_1|FileConst|FileHeader|FileRoots|FileSystem|FoldingCaseData|Foo|FtpConnectionDetail|FtpFeature|FtpFileInfo|FtpResponse|GC|GCP_RESULTS|GCStats|GENERIC_MAPPING|GLYPHMETRICS|GLYPHMETRICSFLOAT|GROUP_INFO_2|GUID|HANDLETABLE|HD_HITTESTINFO|HD_ITEM|HD_LAYOUT|HD_NOTIFY|HELPINFO|HELPWININFO|HIGHCONTRAST|HSZPAIR|HeaderElement|HttpConst|HttpHeader|HttpHeaderName|HttpResponses|HttpStatus|HttpToken|ICONINFO|ICONMETRICS|IMAGEINFO|IMAGE_DOS_HEADER|INPUT_RECORD|ITEMIDLIST|IeeeFlags|Interface|JOB_INFO_1|JOB_INFO_2|KERNINGPAIR|LANA_ENUM|LAYERPLANEDESCRIPTOR|LDT_ENTRY|LIST_ENTRY|LOAD_DLL_DEBUG_INFO|LOCALESIGNATURE|LOCALGROUP_INFO_0|LOCALGROUP_MEMBERS_INFO_0|LOCALGROUP_MEMBERS_INFO_3|LOGBRUSH|LOGCOLORSPACE|LOGFONT|LOGFONTA|LOGFONTW|LOGPALETTE|LOGPEN|LUID_AND_ATTRIBUTES|LV_COLUMN|LV_DISPINFO|LV_FINDINFO|LV_HITTESTINFO|LV_ITEM|LV_KEYDOWN|LocalFileHeader|MAT2|MD5_CTX|MDICREATESTRUCT|MEASUREITEMSTRUCT|MEMORYSTATUS|MEMORY_BASIC_INFORMATION|MENUEX_TEMPLATE_HEADER|MENUEX_TEMPLATE_ITEM|MENUITEMINFO|MENUITEMTEMPLATE|MENUITEMTEMPLATEHEADER|MENUTEMPLATE|MENU_EVENT_RECORD|METAFILEPICT|METARECORD|MINIMIZEDMETRICS|MINMAXINFO|MODEMDEVCAPS|MODEMSETTINGS|MONCBSTRUCT|MONCONVSTRUCT|MONERRSTRUCT|MONHSZSTRUCT|MONITOR_INFO_1|MONITOR_INFO_2|MONLINKSTRUCT|MONMSGSTRUCT|MOUSEHOOKSTRUCT|MOUSEKEYS|MOUSE_EVENT_RECORD|MSG|MSGBOXPARAMS|MSGFILTER|MULTIKEYHELP|NAME_BUFFER|NCB|NCCALCSIZE_PARAMS|NDDESHAREINFO|NETCONNECTINFOSTRUCT|NETINFOSTRUCT|NETRESOURCE|NEWCPLINFO|NEWTEXTMETRIC|NEWTEXTMETRICEX|NMHDR|NM_LISTVIEW|NM_TREEVIEW|NM_UPDOWNW|NONCLIENTMETRICS|NS_SERVICE_INFO|NUMBERFMT|OFNOTIFY|OFSTRUCT|OPENFILENAME|OPENFILENAMEA|OPENFILENAMEW|OSVERSIONINFO|OUTLINETEXTMETRIC|OUTPUT_DEBUG_STRING_INFO|OVERLAPPED|OffsetTypeInfo|PAINTSTRUCT|PALETTEENTRY|PANOSE|PARAFORMAT|PARTITION_INFORMATION|PERF_COUNTER_BLOCK|PERF_COUNTER_DEFINITION|PERF_DATA_BLOCK|PERF_INSTANCE_DEFINITION|PERF_OBJECT_TYPE|PIXELFORMATDESCRIPTOR|POINT|POINTFLOAT|POINTFX|POINTL|POINTS|POLYTEXT|PORT_INFO_1|PORT_INFO_2|PREVENT_MEDIA_REMOVAL|PRINTER_DEFAULTS|PRINTER_INFO_1|PRINTER_INFO_2|PRINTER_INFO_3|PRINTER_INFO_4|PRINTER_INFO_5|PRINTER_NOTIFY_INFO|PRINTER_NOTIFY_INFO_DATA|PRINTER_NOTIFY_OPTIONS|PRINTER_NOTIFY_OPTIONS_TYPE|PRINTPROCESSOR_INFO_1|PRIVILEGE_SET|PROCESS_HEAPENTRY|PROCESS_INFORMATION|PROPSHEETHEADER|PROPSHEETHEADER_U1|PROPSHEETHEADER_U2|PROPSHEETHEADER_U3|PROPSHEETPAGE|PROPSHEETPAGE_U1|PROPSHEETPAGE_U2|PROTOCOL_INFO|PROVIDOR_INFO_1|PSHNOTIFY|PUNCTUATION|PassByCopy|PassByRef|Phase1Info|PropertyConfigurator|QUERY_SERVICE_CONFIG|QUERY_SERVICE_LOCK_STATUS|RASAMB|RASCONN|RASCONNSTATUS|RASDIALEXTENSIONS|RASDIALPARAMS|RASENTRYNAME|RASPPPIP|RASPPPIPX|RASPPPNBF|RASTERIZER_STATUS|REASSIGN_BLOCKS|RECT|RECTL|REMOTE_NAME_INFO|REPASTESPECIAL|REQRESIZE|RGBQUAD|RGBTRIPLE|RGNDATA|RGNDATAHEADER|RIP_INFO|Runtime|SCROLLINFO|SECURITY_ATTRIBUTES|SECURITY_DESCRIPTOR|SECURITY_QUALITY_OF_SERVICE|SELCHANGE|SERIALKEYS|SERVICE_ADDRESS|SERVICE_ADDRESSES|SERVICE_INFO|SERVICE_STATUS|SERVICE_TABLE_ENTRY|SERVICE_TYPE_INFO_ABS|SERVICE_TYPE_VALUE_ABS|SESSION_BUFFER|SESSION_HEADER|SET_PARTITION_INFORMATION|SHFILEINFO|SHFILEOPSTRUCT|SHITEMID|SHNAMEMAPPING|SID|SID_AND_ATTRIBUTES|SID_IDENTIFIER_AUTHORITY|SINGLE_LIST_ENTRY|SIZE|SMALL_RECT|SOUNDSENTRY|STARTUPINFO|STICKYKEYS|STRRET|STYLEBUF|STYLESTRUCT|SYSTEMTIME|SYSTEM_AUDIT_ACE|SYSTEM_INFO|SYSTEM_INFO_U|SYSTEM_POWER_STATUS|Signal|SjLj_Function_Context|SpecialCaseData|TAPE_ERASE|TAPE_GET_DRIVE_PARAMETERS|TAPE_GET_MEDIA_PARAMETERS|TAPE_GET_POSITION|TAPE_PREPARE|TAPE_SET_DRIVE_PARAMETERS|TAPE_SET_MEDIA_PARAMETERS|TAPE_SET_POSITION|TAPE_WRITE_MARKS|TBADDBITMAP|TBBUTTON|TBNOTIFY|TBSAVEPARAMS|TCHOOSECOLOR|TCHOOSEFONT|TC_HITTESTINFO|TC_ITEM|TC_ITEMHEADER|TC_KEYDOWN|TEXTMETRIC|TEXTMETRICA|TEXTRANGE|TFINDTEXT|TIME_ZONE_INFORMATION|TOGGLEKEYS|TOKEN_CONTROL|TOKEN_DEFAULT_DACL|TOKEN_GROUPS|TOKEN_OWNER|TOKEN_PRIMARY_GROUP|TOKEN_PRIVILEGES|TOKEN_SOURCE|TOKEN_STATISTICS|TOKEN_USER|TOOLINFO|TOOLTIPTEXT|TPAGESETUPDLG|TPMPARAMS|TRANSMIT_FILE_BUFFERS|TREEITEM|TSMALLPOINT|TTHITTESTINFO|TTPOLYCURVE|TTPOLYGONHEADER|TVARIANT|TV_DISPINFO|TV_HITTESTINFO|TV_INSERTSTRUCT|TV_ITEM|TV_KEYDOWN|TV_SORTCB|Time|TimeOfDay|TimeSpan|Tuple|UDACCEL|ULARGE_INTEGER|UNIVERSAL_NAME_INFO|UNLOAD_DLL_DEBUG_INFO|USEROBJECTFLAGS|USER_INFO_0|USER_INFO_2|USER_INFO_3|UnicodeData|VALENT|VA_LIST|VERIFY_INFORMATION|VS_FIXEDFILEINFO|Variant|VfsFilterInfo|WIN32_FILE_ATTRIBUTE_DATA|WIN32_FIND_DATA|WIN32_FIND_DATAW|WIN32_STREAM_ID|WINDOWINFO|WINDOWPLACEMENT|WINDOWPOS|WINDOW_BUFFER_SIZE_RECORD|WNDCLASS|WNDCLASSA|WNDCLASSEX|WNDCLASSEXA|WSADATA|WallClock|XFORM|ZipEntryInfo)\b - scope: support.type.built-ins.structs.d - support-type-in: - - match: '\b((?:tango|std)\.[\w\.]+)\b' - scope: support.type.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index f58f48ed65..387de7e8fd 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -324,7 +324,7 @@ extern(1) // ^ keyword.operator.assignment.d // ^^^^ storage.type.d // ^ keyword.operator.d -// ^^^ value value-after storage.type.d +// ^^^ storage.type.d // ^ punctuation.terminator.d alias int a; //^^^^^ keyword.control.alias.d @@ -398,7 +398,7 @@ extern(1) //^^^^^ storage.type.class.d // ^ entity.name.class.d // ^ punctuation.section.group.begin.d -// ^ storage.type.d +// ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^ storage.type.d // ^ variable.parameter.d @@ -430,7 +430,7 @@ extern(1) //^^^^^^^^^ storage.type.interface.d // ^ entity.name.interface.d // ^ punctuation.section.group.begin.d -// ^ storage.type.d +// ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^^^ storage.type.d // ^ variable.parameter.d @@ -461,7 +461,7 @@ extern(1) // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d -// ^ storage.type.d +// ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d } @@ -479,7 +479,7 @@ extern(1) // ^^^^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d -// ^ storage.type.d +// ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -591,16 +591,16 @@ extern(1) // ^ punctuation.terminator.d int foo = true; static if (12 + 5): -//^^^^^^ keyword.control.conditional.d +//^^^^^^ storage.modifier.d // ^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d // ^^ constant.numeric.integer.d // ^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d -// ^ punctuation.section.block.begin.d +// ^ punctuation.separator.d static if (true) {} else {} -//^^^^^^ keyword.control.conditional.d +//^^^^^^ storage.modifier.d // ^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d @@ -610,7 +610,7 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d static if (0) { -//^^^^^^ keyword.control.conditional.d +//^^^^^^ storage.modifier.d // ^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d // ^ constant.numeric.integer.d @@ -619,7 +619,7 @@ extern(1) } else static if (1) { //^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d -// ^^^^^^ keyword.control.conditional.d +// ^^^^^^ storage.modifier.d // ^^ keyword.control.conditional.d // ^ punctuation.section.brackets.begin.d // ^ constant.numeric.integer.d @@ -701,7 +701,7 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^^^ entity.name.function.d // ^ punctuation.section.group.begin.d - // ^ storage.type.d + // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^^ storage.type.d // ^^ variable.parameter.d @@ -737,6 +737,91 @@ extern(1) // ^ punctuation.terminator.d } //^ punctuation.section.block.end.d + void foo(T)(ref T[] a) {} +//^^^^ storage.type.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.modifier.d +// ^ storage.type.d +// ^ value-list punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + void f(T..., string[] B...)(ref T[] a...) {} +//^^^^ storage.type.d +// ^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^^^ keyword.operator.d +// ^ punctuation.separator.sequence.d +// ^^^^^^ storage.type.d +// ^ value-list punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^ variable.parameter.d +// ^^^ keyword.operator.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.modifier.d +// ^ storage.type.d +// ^ value-list punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^ variable.parameter.d +// ^^^ keyword.operator.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + void f(T = int)(T[] a = [1, 2, 3]) {} +//^^^^ storage.type.d +// ^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ keyword.operator.assignment.d +// ^^^ storage.type.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.group.begin.d +// ^ storage.type.d +// ^ value-list punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^ variable.parameter.d +// ^ keyword.operator.assignment.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^ constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + void foo(in int a, out int f) {} +//^^^^ storage.type.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^^ storage.modifier.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.modifier.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + void opEquals(int a) {} +//^^^^ storage.type.d +// ^^^^^^^^ keyword.operator.overload.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d this(int foo) { //^^^^ entity.name.function.constructor.d @@ -789,9 +874,9 @@ extern(1) //^^^^^^^^ storage.type.d // ^^^ entity.name.template.d // ^ punctuation.section.group.begin.d -// ^ storage.type.d +// ^ variable.parameter.d // ^ punctuation.separator.sequence.d -// ^ storage.type.d +// ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d template a(size_t f) { @@ -1196,8 +1281,8 @@ extern(1) // ^ punctuation.section.brackets.begin.d // ^^^ storage.modifier.d // ^ variable.parameter.d -// ^ value punctuation.separator.sequence.d -// ^^^ value value-after variable.other.d +// ^ punctuation.separator.sequence.d +// ^^^ variable.other.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -1205,41 +1290,62 @@ extern(1) int a = 2, b = 3; //^^^ storage.type.d // ^ variable.other.d -// ^ value keyword.operator.assignment.d -// ^ value-after constant.numeric.integer.d +// ^ keyword.operator.assignment.d +// ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d // ^ variable.other.d -// ^ value keyword.operator.assignment.d -// ^ value-after constant.numeric.integer.d +// ^ keyword.operator.assignment.d +// ^ constant.numeric.integer.d // ^ punctuation.terminator.d a = "foo", b = "bar"; -//^ first-value first-value-after variable.other.d -// ^ value-after value keyword.operator.assignment.d -// ^^^^^ value-after string.quoted.double.d +//^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^^^ string.quoted.double.d // ^ value-list punctuation.separator.sequence.d -// ^ value value-after variable.other.d -// ^ value-after value keyword.operator.assignment.d -// ^^^^^ value-after string.quoted.double.d +// ^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^^^ string.quoted.double.d // ^ punctuation.terminator.d string[] f = [ -//^^^^^^ first-value first-value-after storage.type.d -// ^ first-value-after value-list punctuation.section.brackets.begin.d -// ^ first-value-after punctuation.section.brackets.end.d +//^^^^^^ storage.type.d +// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d // ^ variable.other.d -// ^ value keyword.operator.assignment.d -// ^ value punctuation.section.brackets.begin.d +// ^ keyword.operator.assignment.d +// ^ punctuation.section.brackets.begin.d 1: 2, - //^ value-after constant.numeric.integer.d - // ^ value punctuation.separator.mapping.key-value.d - // ^ value-after constant.numeric.integer.d + //^ constant.numeric.integer.d + // ^ punctuation.separator.mapping.key-value.d + // ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d "foo", - //^^^^^ value-after string.quoted.double.d + //^^^^^ string.quoted.double.d // ^ punctuation.separator.sequence.d "bar", - //^^^^^ value-after string.quoted.double.d + //^^^^^ string.quoted.double.d // ^ punctuation.separator.sequence.d ]; -//^ value-after punctuation.section.brackets.end.d +//^ punctuation.section.brackets.end.d + + switch (2 * 3) +//^^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.integer.d +// ^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d + { +//^ punctuation.section.block.begin.d + case 2 ^^ 2: + //^^^^ keyword.control.flow.d + // ^ constant.numeric.integer.d + // ^^ keyword.operator.arithmetic.d + // ^ constant.numeric.integer.d + // ^ punctuation.section.block.begin.d + default: + //^^^^^^^ keyword.control.flow.d + // ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d From 66a10aa2ff50f83dc40ef3f971b9bf8fd155f4ec Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 16:24:26 +1100 Subject: [PATCH 038/108] Implement typeof parsing --- D/D.sublime-syntax | 87 ++++++++++++++++++++++++++++++++++------- D/tests/syntax_test_d.d | 51 ++++++++++++++++++++++++ 2 files changed, 123 insertions(+), 15 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 74217d9d26..1d6b854a64 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -30,6 +30,9 @@ variables: character_lookahead: (?=') string_lookahead: '(?=`|[rxq]?"|q{)' + definitely_value_lookahead: '(?=(!|~|\+|\-|\*|&|\bcast\b|\bdelete\b|\bnew\b|\bimport\b|\bmixin\b|\bis\b|[0-9]|\[|\(|{{string_lookahead}}|\b({{language_constant}})\b|\b({{language_variable}})\b))' + definitely_declaration_lookahead: '(?=({{name}}|\]|\))(\s+{{name}}))' + attribute_lookahead: '(?={{attributes}}|@)' attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' at_attributes: 'disable|nogc|property|safe|system|trusted' @@ -43,6 +46,8 @@ variables: 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' + type_specialization: 'struct|union|class|interface|enum|__vector|function|delegate|super|const|immutable|inout|shared|return|__parameters' + block_statement_loohahead: '(?={)' contexts: @@ -636,6 +641,12 @@ contexts: # - match: '(?=[^\s])' # scope: invalid.illegal.d basic-type: + - match: '\btypeof\b' + scope: keyword.other.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [basic-type2, basic-type2-after-parens, value] - match: '\b({{identifier_ref}})\b' scope: storage.type.d set: basic-type2 @@ -703,13 +714,14 @@ contexts: function-argument-definition-list: - match: '\(' scope: punctuation.section.group.begin.d - set: - - match: '{{type_look_ahead}}' - set: [function-argument, function-argument-or-type] - - match: '\)' - scope: punctuation.section.group.end.d - pop: true - - include: not-whitespace-illegal + set: function-argument-definition-list-content + - include: not-whitespace-illegal + function-argument-definition-list-content: + - match: '{{type_look_ahead}}' + set: [function-argument, function-argument-or-type] + - match: '\)' + scope: punctuation.section.group.end.d + pop: true - include: not-whitespace-illegal function-argument-or-type: - include: parameter-attribute-in @@ -768,17 +780,17 @@ contexts: - include: expect-end-of-line value-or-declaration-in: - match: '\s' - - match: '(?=(!|~|\+|\-|\*|&|cast|delete|new|import|mixin|[0-9]|\[|\(|{{name}}\s*\(|{{string_lookahead}}|{{language_constant}}|{{language_variable}}))' + - match: '{{definitely_value_lookahead}}' push: [maybe-end-of-line, value-list] - - match: '(?=({{name}}|\]|\))(\s+{{name}}))' + - match: '{{definitely_declaration_lookahead}}' push: [function-or-variable-after-type, type] - match: '(?=[^\s])' push: [maybe-end-of-line, first-value] value-or-declaration: - match: '\s' - - match: '(?=(!|~|\+|\-|\*|&|cast|delete|new|import|mixin|[0-9]|\[|\(|{{name}}\s*\(|{{string_lookahead}}|{{language_constant}}|{{language_variable}}))' + - match: '{{definitely_value_lookahead}}' set: value-list - - match: '(?=({{name}}|\]|\))(\s+{{name}}))' + - match: '{{definitely_declaration_lookahead}}' set: [function-or-variable-after-type, type] - match: '(?=[^\s])' set: first-value @@ -786,13 +798,21 @@ contexts: # We highlight as if it were a value, but switch to a definition if it turns out to be one first-value: # - meta_scope: first-value + - match: '\btypeof\b' + scope: keyword.other.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [first-value-parens-after, value] - match: '\b({{basic_type}})\b' scope: storage.type.d set: first-value-after - match: '\b({{name}})\b' scope: variable.other.d set: first-value-after - - include: not-whitespace-illegal + - include: not-whitespace-illegal-pop + # - match: '(?=[^\s])' + # set: value first-value-after: # - meta_scope: first-value-after - match: '\.' @@ -868,18 +888,31 @@ contexts: set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [new-after-parens, value] + set: [value-parens-after, value] - include: not-whitespace-illegal - match: '\bmixin\b' scope: keyword.other.d set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [new-after-parens, value-list] + set: [value-parens-after, value-list] - include: not-whitespace-illegal + - match: '\bis\b' + scope: keyword.other.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [value-after, is-after-type, type] + - include: not-whitespace-illegal-pop + - match: '\btypeof\b' + scope: keyword.other.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [value-parens-after, value] - match: '\(' scope: punctuation.section.parens.begin.d - set: [new-after-parens, value] + set: [value-parens-after, value] - match: '(?={)' set: [value-after, block-statement] - match: '\[' @@ -946,6 +979,30 @@ contexts: - match: '(?=[^\s])' set: [class-body, base-class-list] - include: not-whitespace-illegal + is-after-type: + - match: '\b({{name}})\b' + scope: variable.parameter.d + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true + - match: '\=\=|:' + scope: keyword.operator.logical.d + set: [is-after, type-specialization] + is-after: + - match: ',' + scope: punctuation.separator.sequence.d + set: function-argument-definition-list-content + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true + - include: not-whitespace-illegal + type-specialization: + - match: '\b({{type_specialization}})\b' + scope: storage.type.d + pop: true + - match: '(?=[^\s])' + set: type + - include: not-whitespace-illegal-pop value-after: # - meta_scope: value-after - match: '\.\.' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 387de7e8fd..5c369969eb 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -822,6 +822,13 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + caster foo() {} +//^^^^^^ storage.type.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ meta.function.d punctuation.section.block.begin.d +// ^ meta.function.d punctuation.section.block.end.d this(int foo) { //^^^^ entity.name.function.constructor.d @@ -1349,3 +1356,47 @@ extern(1) // ^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d + + is(int T == class, T, int foo); +//^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^^ keyword.operator.logical.d +// ^^^^^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^^^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.terminator.d + is(int : foo); +//^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ storage.type.d +// ^ keyword.operator.logical.d +// ^^^ storage.type.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + is(T); +//^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^ storage.type.d +// ^ punctuation.section.parens.end.d + + typeof(2) a(typeof('f') b); +//^^^^^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^^^^^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ string.quoted.single.d +// ^ punctuation.section.brackets.end.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.terminator.d +// ^ From 1b47eb15ae892243f5655334ac35f6861fc4cd7e Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 16:37:22 +1100 Subject: [PATCH 039/108] Fix some more edge cases --- D/D.sublime-syntax | 33 ++++++++++++++------------------- D/tests/syntax_test_d.d | 29 ++++++++++++++++++++++++++--- 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 1d6b854a64..2e560621d4 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -257,7 +257,7 @@ contexts: 2: constant.numeric.float.d 3: storage.type.float.d pop: true - - match: '\b([0-9][0-9_]*\.(?!\.))({{float_suffix}})?' + - match: '\b([0-9][0-9_]*\.(?!\.|\s*[a-zA-Z]))({{float_suffix}})?' captures: 1: constant.numeric.float.d 2: storage.type.float.d @@ -853,6 +853,7 @@ contexts: - include: not-whitespace-illegal value: # - meta_scope: value + - include: attribute-in - match: '!' scope: keyword.operator.logical.d set: value @@ -1014,14 +1015,6 @@ contexts: - match: '{{identifier}}' scope: variable.other.d set: value-after - - match: '!' - scope: keyword.operator.d - set: - - match: '\(' - scope: punctuation.section.parens.begin.d - set: [value-parens-after, value-list] - - match: '(?=[^\s])' - set: value - match: '\(' scope: punctuation.section.parens.begin.d set: [value-parens-after, value-list] @@ -1031,9 +1024,17 @@ contexts: - match: '(\+\+|--)' scope: keyword.operator.arithmetic.d set: value-after - - match: '(==|!=|is|!is|<|<=|>|>=|in|!in)' + - match: '(==|!=|\bis\b|!is\b|<=|<|>=|>|\bin\b|!in\b)' scope: keyword.operator.comparison.d set: value + - match: '!' + scope: keyword.operator.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [value-parens-after, value-list] + - match: '(?=[^\s])' + set: value - match: '(\+|-|\*|/|%|&|\||\^\^|\^|~|<<|>>>|>>)?=' scope: keyword.operator.assignment.d set: value @@ -1343,10 +1344,10 @@ contexts: conditional-declaration-in: - match: '\b(version)\b' scope: keyword.control.conditional.d - push: [conditional-declaration-body, version-condition] + push: [optional-block-statement, version-condition] - match: '\b(debug)\b' scope: keyword.control.conditional.d - push: [conditional-declaration-body, debug-condition] + push: [optional-block-statement, debug-condition] conditional-declaration-body: - match: '{' scope: punctuation.section.block.begin.d @@ -1512,16 +1513,10 @@ contexts: conditional-in: - match: '\bif\b' scope: keyword.control.conditional.d - push: [conditional-else, optional-block-statement, condition] + push: [optional-block-statement, condition] - match: '\belse\b' scope: keyword.control.conditional.d push: optional-block-statement - conditional-else: - - match: '\b(else)\b' - scope: keyword.control.conditional.d - set: optional-block-statement - - match: '(?=[^\s])' - pop: true loop-in: - match: '\bwhile\b' scope: keyword.control.flow.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 5c369969eb..45e03a3af0 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -557,11 +557,11 @@ extern(1) // ^ punctuation.section.brackets.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d -// ^ punctuation.section.block.begin.d +// ^ punctuation.separator.d debug: //^^^^^ keyword.control.conditional.d -// ^ punctuation.section.block.begin.d +// ^ punctuation.separator.d debug {} else {} //^^^^^ keyword.control.conditional.d // ^ punctuation.section.block.begin.d @@ -577,7 +577,7 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d -// ^ punctuation.section.block.begin.d +// ^ punctuation.separator.d debug = 2; //^^^^^ keyword.control.conditional.d @@ -1400,3 +1400,26 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.terminator.d // ^ + + 3 != 3 && "s" !in [2]; +//^ constant.numeric.integer.d +// ^^ keyword.operator.comparison.d +// ^ constant.numeric.integer.d +// ^^ keyword.operator.logical.d +// ^^^ string.quoted.double.d +// ^^^ keyword.operator.comparison.d +// ^ punctuation.section.brackets.begin.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.terminator.d + + AliasSeq!(immutable char, int); +//^^^^^^^^ variable.other.d +// ^ keyword.operator.d +// ^ value-list punctuation.section.parens.begin.d +// ^^^^^^^^^ storage.modifier.d +// ^^^^ storage.type.d +// ^ value-list punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d From 37dfe2c070969989d4c62f720cf9432ea12e9896 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 16:53:38 +1100 Subject: [PATCH 040/108] Fix typeof(return) --- D/D.sublime-syntax | 9 +++++++-- D/tests/syntax_test_d.d | 6 ++++++ 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 2e560621d4..bf3c9cd307 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -646,7 +646,7 @@ contexts: set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [basic-type2, basic-type2-after-parens, value] + set: [basic-type2, basic-type2-after-parens, typeof-value] - match: '\b({{identifier_ref}})\b' scope: storage.type.d set: basic-type2 @@ -682,6 +682,11 @@ contexts: scope: punctuation.section.brackets.end.d pop: true - include: not-whitespace-illegal-pop + typeof-value: + - match: '\breturn\b' + scope: keyword.other.d + pop: true + - include: value function-pointer-type: # TODO @@ -803,7 +808,7 @@ contexts: set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [first-value-parens-after, value] + set: [first-value-parens-after, typeof-value] - match: '\b({{basic_type}})\b' scope: storage.type.d set: first-value-after diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 45e03a3af0..cb5b9866e5 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1400,6 +1400,12 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.terminator.d // ^ + typeof(return); +//^^^^^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^ keyword.other.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d 3 != 3 && "s" !in [2]; //^ constant.numeric.integer.d From c3e956eca0e72b16b80eaf7c6fe320c644a093d3 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 17:00:10 +1100 Subject: [PATCH 041/108] Initial lambda parsing implementation --- D/D.sublime-syntax | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index bf3c9cd307..f9317cf16a 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -420,7 +420,8 @@ contexts: scope: string.unquoted.embedded.d punctuation.definition.string.end.d pop: true - include: tokens-in - tokens-in: # Purely a set of un-verified tokens, for use in token string + # Purely a set of un-verified tokens, for use in token string + tokens-in: - match: '\b({{keyword}})\b' scope: keyword.d - match: '\b({{basic_type}})\b' @@ -915,7 +916,19 @@ contexts: set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [value-parens-after, value] + set: [value-parens-after, typeof-value] + - match: '(\()\s*(\))' + captures: + 1: punctuation.section.parens.begin.d + 2: punctuation.section.parens.end.d + set: + - include: attribute-in + - match: '=>' + scope: keyword.operator.lambda.d + set: value + - match: '(?={)' + set: [value-after, block-statement] + - include: not-whitespace-illegal-pop - match: '\(' scope: punctuation.section.parens.begin.d set: [value-parens-after, value] @@ -942,6 +955,11 @@ contexts: - match: '\b({{basic_type}})\b' scope: storage.type.d set: value-after + - match: '\b({{name}})\s*(=>)' + captures: + 1: variable.parameter.d + 2: keyword.operator.lambda.d + set: value - match: '\b({{name}})\b' scope: variable.other.d set: value-after From 0498955b74f42144479942d31baa895f2f8fcb02 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 17:22:28 +1100 Subject: [PATCH 042/108] Fix auto declarations --- D/D.sublime-syntax | 7 +++++-- D/tests/syntax_test_d.d | 41 ++++++++++++++++++++++++++++++----------- 2 files changed, 35 insertions(+), 13 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index f9317cf16a..0ea9dbcefd 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -31,10 +31,10 @@ variables: string_lookahead: '(?=`|[rxq]?"|q{)' definitely_value_lookahead: '(?=(!|~|\+|\-|\*|&|\bcast\b|\bdelete\b|\bnew\b|\bimport\b|\bmixin\b|\bis\b|[0-9]|\[|\(|{{string_lookahead}}|\b({{language_constant}})\b|\b({{language_variable}})\b))' - definitely_declaration_lookahead: '(?=({{name}}|\]|\))(\s+{{name}}))' + definitely_declaration_lookahead: '(?=({{name}}|\]|\))(\s+{{name}})|\bauto\b)' attribute_lookahead: '(?={{attributes}}|@)' - attributes: 'static|abstract|final|override|synchronized|auto|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' + attributes: 'static|abstract|final|override|synchronized|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' at_attributes: 'disable|nogc|property|safe|system|trusted' parameter_attributes: 'in|lazy|out' @@ -648,6 +648,9 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [basic-type2, basic-type2-after-parens, typeof-value] + - match: '\bauto\b' + scope: keyword.other.d + pop: true - match: '\b({{identifier_ref}})\b' scope: storage.type.d set: basic-type2 diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index cb5b9866e5..72b45e1e76 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -201,17 +201,16 @@ f = 0xF.AP-2f; // ^ punctuation.definition.annotation.end.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^^ storage.attribute.d - static shared const immutable auto final __gshared nothrow pure ref + static shared const immutable final __gshared nothrow pure ref //^^^^^^ storage.modifier.d // ^^^^^^ storage.modifier.d // ^^^^^ storage.modifier.d // ^^^^^^^^^ storage.modifier.d -// ^^^^ storage.modifier.d -// ^^^^^ storage.modifier.d -// ^^^^^^^^^ storage.modifier.d -// ^^^^^^^ storage.modifier.d -// ^^^^ storage.modifier.d -// ^^^ storage.modifier.d +// ^^^^^ storage.modifier.d +// ^^^^^^^^^ storage.modifier.d +// ^^^^^^^ storage.modifier.d +// ^^^^ storage.modifier.d +// ^^^ storage.modifier.d extern(C) extern (C++, foo.a) //^^^^^^ keyword.other.external.d // ^ punctuation.definition.annotation.begin.d @@ -373,6 +372,19 @@ extern(1) // ^ keyword.operator.pointer.d // ^^^^^^^^^^^^^^ variable.other.d // ^ punctuation.terminator.d + auto foo = 3; +//^^^^ keyword.other.d +// ^^^ variable.other.d +// ^ keyword.operator.assignment.d +// ^ constant.numeric.integer.d +// ^ punctuation.terminator.d + auto +//^^^^ keyword.other.d + asjfaisdjaksdjaklsjdnaskjjks = 3; +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.other.d +// ^ keyword.operator.assignment.d +// ^ constant.numeric.integer.d +// ^ punctuation.terminator.d class Foo; //^^^^^ storage.type.class.d @@ -827,8 +839,15 @@ extern(1) // ^^^ entity.name.function.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d -// ^ meta.function.d punctuation.section.block.begin.d -// ^ meta.function.d punctuation.section.block.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + auto foo() {} +//^^^^ keyword.other.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d this(int foo) { //^^^^ entity.name.function.constructor.d @@ -1218,7 +1237,7 @@ extern(1) // ^ punctuation.terminator.d auto f = foo ? 12 : 15; -//^^^^ storage.modifier.d +//^^^^ keyword.other.d // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ variable.other.d @@ -1229,7 +1248,7 @@ extern(1) // ^ punctuation.terminator.d auto c = new class(12) T, Bar { -//^^^^ storage.modifier.d +//^^^^ keyword.other.d // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ keyword.operator.word.d From b1459aef76077153b3771a1cce1140223068bc55 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 17:53:14 +1100 Subject: [PATCH 043/108] Implement parsing of single enum assignments and template constraints --- D/D.sublime-syntax | 113 ++++++++++++---------------------------- D/tests/syntax_test_d.d | 31 +++++++++++ 2 files changed, 65 insertions(+), 79 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 0ea9dbcefd..6ad63418e6 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -717,8 +717,8 @@ contexts: - include: function-definition-after-argument-list2 function-definition-after-argument-list2: - include: attribute-specifier-in - - match: '(?={|;)' - set: function-definition + - match: '(?={|;|\bif\b)' + set: optional-template-body-block - include: not-whitespace-illegal function-argument-definition-list: - match: '\(' @@ -760,15 +760,12 @@ contexts: scope: punctuation.section.group.end.d pop: true - include: not-whitespace-illegal - function-definition: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - meta_scope: meta.function.d - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in + optional-template-body-block: + - match: '{{block_statement_loohahead}}' + set: block-statement + - match: '\bif\b' + scope: keyword.control.conditional.d + set: [block-statement, condition] - include: end-of-line - include: not-whitespace-illegal variable-definition-begin: @@ -985,9 +982,9 @@ contexts: scope: punctuation.section.parens.begin.d set: [new-anonymous-after-args, value-list] - match: '(?={)' - set: class-body + set: optional-template-body-block - match: '(?=[^\s])' - set: [class-body, base-class-list] + set: [optional-template-body-block, base-class-list] - match: (?=[^\s]) set: [new-after-named, type] - include: not-whitespace-illegal @@ -1002,9 +999,9 @@ contexts: scope: punctuation.section.parens.end.d set: - match: '(?={)' - set: class-body + set: optional-template-body-block - match: '(?=[^\s])' - set: [class-body, base-class-list] + set: [optional-template-body-block, base-class-list] - include: not-whitespace-illegal is-after-type: - match: '\b({{name}})\b' @@ -1153,9 +1150,8 @@ contexts: - include: not-whitespace-illegal - include: not-whitespace-illegal alias-new: - - match: '\(' - # TODO: template aliases - pop: true + - match: '(?=\()' + push: function-argument-definition-list - match: '(?==)' set: alias-new-assign - include: not-whitespace-illegal @@ -1191,10 +1187,9 @@ contexts: - include: end-of-line - match: ':' scope: punctuation.separator.mapping.d - set: [class-body, base-class-list] - - match: '(?={)' - set: class-body - - include: not-whitespace-illegal + set: [optional-template-body-block, base-class-list] + - match: '(?=[^\s])' + set: optional-template-body-block base-class-list: - match: '{{type_look_ahead}}' set: [base-class-list-after, basic-type] @@ -1206,15 +1201,6 @@ contexts: - match: '(?={)' pop: true - include: not-whitespace-illegal - class-body: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in - - include: not-whitespace-illegal interface-in: - match: '\b(interface)\b' scope: storage.type.interface.d @@ -1231,18 +1217,9 @@ contexts: - include: end-of-line - match: ':' scope: punctuation.separator.mapping.d - set: [interface-body, base-class-list] + set: [optional-template-body-block, base-class-list] - match: '(?={)' - set: interface-body - - include: not-whitespace-illegal - interface-body: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in + set: optional-template-body-block - include: not-whitespace-illegal struct-in: - match: '\b(struct)\b' @@ -1252,26 +1229,12 @@ contexts: scope: entity.name.struct.d set: - match: '(?=\()' - set: [struct-after, function-argument-definition-list] + set: [optional-template-body-block, function-argument-definition-list] - match: '(?=[^\s])' - set: struct-after + set: optional-template-body-block - match: '(?={)' - set: struct-body + set: optional-template-body-block - include: not-whitespace-illegal - struct-after: - - include: end-of-line - - match: '(?={)' - set: struct-body - - include: not-whitespace-illegal - struct-body: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in - - include: not-whitespace-illegal union-in: - match: '\b(union)\b' scope: storage.type.union.d @@ -1280,26 +1243,12 @@ contexts: scope: entity.name.union.d set: - match: '(?=\()' - set: [union-after, function-argument-definition-list] + set: [optional-template-body-block, function-argument-definition-list] - match: '(?=[^\s])' - set: union-after + set: optional-template-body-block - match: '(?={)' - set: union-body + set: optional-template-body-block - include: not-whitespace-illegal - union-after: - - include: end-of-line - - match: '(?={)' - set: union-body - - include: not-whitespace-illegal - union-body: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in - - include: not-whitespace-illegal enum-in: - match: '\b(enum)\b' scope: storage.type.enum.d @@ -1313,9 +1262,8 @@ contexts: - match: ':' scope: punctuation.separator.mapping.d set: [enum-body, type] - - match: '=' - scope: keyword.operator.assignment.d - set: [expect-end-of-line, value] + - match: '(?==|\()' + set: enum-assignment - include: not-whitespace-illegal - match: ':' scope: punctuation.separator.mapping.d @@ -1333,6 +1281,13 @@ contexts: - match: '(?=\b({{name}})\b)' push: enum-member - include: not-whitespace-illegal + enum-assignment: + - match: '=' + scope: keyword.operator.assignment.d + set: [expect-end-of-line, value] + - match: '(?=\()' + push: function-argument-definition-list + - include: not-whitespace-illegal-pop anonymous-enum-body: - match: '{' scope: punctuation.section.block.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 72b45e1e76..18a60dfaa8 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -353,6 +353,15 @@ extern(1) // ^^^^^^^^^^^ variable.d // ^^^^ keyword.control.alias.d // ^ punctuation.terminator.d + alias F(x) = foo; +//^^^^^ keyword.control.alias.d +// ^ entity.name.type.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ keyword.operator.assignment.d +// ^^^ storage.type.d +// ^ punctuation.terminator.d int a; //^^^ storage.type.d @@ -542,6 +551,28 @@ extern(1) //^^^ entity.name.constant.d } //^ punctuation.section.block.end.d + enum f = 12; +//^^^^ storage.type.enum.d +// ^ entity.name.enum.d +// ^ keyword.operator.assignment.d +// ^^ constant.numeric.integer.d +// ^ punctuation.terminator.d + enum f(x, int t) = cast(x)t; +//^^^^ storage.type.enum.d +// ^ entity.name.enum.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ keyword.operator.assignment.d +// ^^^^ keyword.operator.word.d +// ^ punctuation.section.parens.begin.d +// ^ storage.type.d +// ^ punctuation.section.parens.end.d +// ^ variable.other.d +// ^ punctuation.terminator.d version(unittest) {} //^^^^^^^ keyword.control.conditional.d From 553c4e022b6f0ceec31c8ef1cb1ccb19cd0a7804 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 22:33:05 +1100 Subject: [PATCH 044/108] Properly implement lambda parsing --- D/D.sublime-syntax | 46 ++++++++++++++++---- D/tests/syntax_test_d.d | 93 ++++++++++++++++++++++++++++++++++++----- 2 files changed, 119 insertions(+), 20 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 6ad63418e6..2d008805c6 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -817,8 +817,6 @@ contexts: scope: variable.other.d set: first-value-after - include: not-whitespace-illegal-pop - # - match: '(?=[^\s])' - # set: value first-value-after: # - meta_scope: first-value-after - match: '\.' @@ -930,8 +928,8 @@ contexts: set: [value-after, block-statement] - include: not-whitespace-illegal-pop - match: '\(' - scope: punctuation.section.parens.begin.d - set: [value-parens-after, value] + scope: punctuation.section.group.begin.d + set: [value-group-after, value] - match: '(?={)' set: [value-after, block-statement] - match: '\[' @@ -1027,12 +1025,34 @@ contexts: - match: '(?=[^\s])' set: type - include: not-whitespace-illegal-pop + value-group-after: + - match: '\)' + scope: punctuation.section.group.end.d + set: value-group-after-parens + - match: '\b({{name}})\b' + scope: variable.parameter.d + set: value-group-after + - match: ',' + scope: punctuation.separator.sequence.d + set: [value-group-after-parens, function-argument] + - match: '\.\.\.' + scope: keyword.operator.d + - include: not-whitespace-illegal + value-group-after-parens: + - include: attribute-in + - match: (?={) + set: [value-after, block-statement] + - match: '=>' + scope: keyword.operator.lambda.d + set: value + - match: (?=[^\s]) + set: value-after value-after: # - meta_scope: value-after - - match: '\.\.' + - match: '\.\.(?!\.)' scope: keyword.operator.d set: value - - match: '\.' + - match: '\.(?!\.\.)' scope: punctuation.accessor.dot.d set: - match: '{{identifier}}' @@ -1058,13 +1078,21 @@ contexts: set: [value-parens-after, value-list] - match: '(?=[^\s])' set: value - - match: '(\+|-|\*|/|%|&|\||\^\^|\^|~|<<|>>>|>>)?=' + - match: '(\+|-|/|%|\*|&|\||\^\^|\^|~|<<|>>>|>>)?=' scope: keyword.operator.assignment.d set: value - match: '(&&|\|\|)' scope: keyword.operator.logical.d set: value - - match: '(\+|\-|~|\*|/|%|\^\^)' + # This can also be a pointer in some situations + - match: \* + scope: keyword.operator.arithmetic.d + set: + - match: '(?=\))' + pop: true + - match: '(?=[^\s])' + set: value + - match: '(\+|\-|~|/|%|\^\^)' scope: keyword.operator.arithmetic.d set: value - match: '(<<|>>>|>>|\||\^|&)' @@ -1091,7 +1119,7 @@ contexts: set: value-after - include: not-whitespace-illegal value-list: - - meta_scope: value-list + # - meta_scope: value-list - match: '(?=\)|}|]|;)' pop: true - match: '(?=[^\s])' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 18a60dfaa8..e345d4cb4c 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -789,7 +789,7 @@ extern(1) // ^ punctuation.section.group.begin.d // ^^^ storage.modifier.d // ^ storage.type.d -// ^ value-list punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d @@ -803,7 +803,7 @@ extern(1) // ^^^ keyword.operator.d // ^ punctuation.separator.sequence.d // ^^^^^^ storage.type.d -// ^ value-list punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ variable.parameter.d // ^^^ keyword.operator.d @@ -811,7 +811,7 @@ extern(1) // ^ punctuation.section.group.begin.d // ^^^ storage.modifier.d // ^ storage.type.d -// ^ value-list punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ variable.parameter.d // ^^^ keyword.operator.d @@ -828,7 +828,7 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.group.begin.d // ^ storage.type.d -// ^ value-list punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ variable.parameter.d // ^ keyword.operator.assignment.d @@ -1248,21 +1248,21 @@ extern(1) // ^^^ string.quoted.double.d // ^ punctuation.section.parens.end.d // ^ keyword.operator.assignment.d -// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.group.begin.d // ^^ constant.numeric.integer.d // ^^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d -// ^ punctuation.section.parens.end.d +// ^ punctuation.section.group.end.d // ^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d // ^ keyword.operator.arithmetic.d -// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.group.begin.d // ^ constant.numeric.integer.d // ^^ keyword.operator.arithmetic.d // ^ keyword.operator.arithmetic.d // ^^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d -// ^ punctuation.section.parens.end.d +// ^ punctuation.section.group.end.d // ^ keyword.operator.arithmetic.d // ^^^^^ string.quoted.double.d // ^ punctuation.terminator.d @@ -1359,7 +1359,7 @@ extern(1) //^ variable.other.d // ^ keyword.operator.assignment.d // ^^^^^ string.quoted.double.d -// ^ value-list punctuation.separator.sequence.d +// ^ punctuation.separator.sequence.d // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^^^ string.quoted.double.d @@ -1457,6 +1457,66 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d + () @trusted => 2; +//^ punctuation.section.parens.begin.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^^^ storage.attribute.d +// ^^ keyword.operator.lambda.d +// ^ constant.numeric.integer.d +// ^ punctuation.terminator.d + (a => 2); +//^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^^ keyword.operator.lambda.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.group.end.d +// ^ punctuation.terminator.d + (foo) @trusted => foo(3); +//^ punctuation.section.group.begin.d +// ^^^ variable.other.d +// ^ punctuation.section.group.end.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^^^ storage.attribute.d +// ^^ keyword.operator.lambda.d +// ^^^ variable.other.d +// ^ punctuation.section.parens.begin.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + (foo..., bar) @safe {}; +//^ punctuation.section.group.begin.d +// ^^^ variable.other.d +// ^^^ keyword.operator.d +// ^ punctuation.separator.sequence.d +// ^^^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^ storage.attribute.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^ punctuation.terminator.d + (foo) {} (); +//^ punctuation.section.group.begin.d +// ^^^ variable.other.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + (int foo) pure @safe {}; +//^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^^^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^^^^ storage.modifier.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^ storage.attribute.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^ punctuation.terminator.d + 3 != 3 && "s" !in [2]; //^ constant.numeric.integer.d // ^^ keyword.operator.comparison.d @@ -1472,10 +1532,21 @@ extern(1) AliasSeq!(immutable char, int); //^^^^^^^^ variable.other.d // ^ keyword.operator.d -// ^ value-list punctuation.section.parens.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^^^^^^ storage.modifier.d // ^^^^ storage.type.d -// ^ value-list punctuation.separator.sequence.d +// ^ punctuation.separator.sequence.d // ^^^ storage.type.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d + + cast(Unqual!T*)foo; +//^^^^ keyword.operator.word.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^ storage.type.d +// ^ keyword.operator.d +// ^ variable.other.d +// ^ keyword.operator.arithmetic.d +// ^ punctuation.section.parens.end.d +// ^^^ variable.other.d +// ^ punctuation.terminator.d From 8a25a0e3f7ec2c1f742e3cd153da51e7bc1b8e04 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 22 Jan 2019 23:01:49 +1100 Subject: [PATCH 045/108] Fix some more small inconsistencies --- D/D.sublime-syntax | 28 ++++++++++++------ D/tests/syntax_test_d.d | 65 ++++++++++++++++++++++++++++++++--------- 2 files changed, 71 insertions(+), 22 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 2d008805c6..941b7c9526 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -12,14 +12,14 @@ variables: name: '[[:alpha:]_][[:alnum:]_]*' identifier: '{{name}}(?:\.{{name}})*' std_identifier: '(?:std|core)\.{{identifier}}' - identifier_ref: '\.?{{identifier}}' + identifier_ref: '(\b|\.){{identifier}}\b' string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' hex_or_under: '(?:{{hex_char}}|_)' type_ctor: 'const|immutable|inout|shared' - type_look_ahead: '(?=\b({{identifier_ref}}))' + type_look_ahead: '(?={{identifier_ref}})' number_lookahead: '(?=(\b|\.)[0-9])' integer_lookahead: '(?=\b[0-9])' @@ -651,7 +651,7 @@ contexts: - match: '\bauto\b' scope: keyword.other.d pop: true - - match: '\b({{identifier_ref}})\b' + - match: '{{identifier_ref}}' scope: storage.type.d set: basic-type2 # TODO: More basic types @@ -734,7 +734,7 @@ contexts: - include: not-whitespace-illegal function-argument-or-type: - include: parameter-attribute-in - - match: '(?={{name}}\s*[,=\)\.])' + - match: '(?={{name}}\s*[,=:\)\.])' pop: true - include: type function-argument: @@ -749,6 +749,9 @@ contexts: - match: '=' scope: keyword.operator.assignment.d push: value + - match: ':' + scope: keyword.operator.assignment.d + push: value - match: '\)' scope: punctuation.section.group.end.d pop: true @@ -813,7 +816,7 @@ contexts: - match: '\b({{basic_type}})\b' scope: storage.type.d set: first-value-after - - match: '\b({{name}})\b' + - match: '{{identifier_ref}}' scope: variable.other.d set: first-value-after - include: not-whitespace-illegal-pop @@ -958,7 +961,7 @@ contexts: 1: variable.parameter.d 2: keyword.operator.lambda.d set: value - - match: '\b({{name}})\b' + - match: '{{identifier_ref}}' scope: variable.other.d set: value-after - include: not-whitespace-illegal @@ -1088,7 +1091,7 @@ contexts: - match: \* scope: keyword.operator.arithmetic.d set: - - match: '(?=\))' + - match: '(?=\)|,)' pop: true - match: '(?=[^\s])' set: value @@ -1281,7 +1284,7 @@ contexts: - match: '\b(enum)\b' scope: storage.type.enum.d push: - - match: '\b({{name}})\b' + - match: '\b({{name}})(?=\s*({|:|=|\(|$))\b' scope: entity.name.enum.d set: - include: end-of-line @@ -1298,7 +1301,8 @@ contexts: set: [enum-body, type] - match: '(?={)' set: anonymous-enum-body - - include: not-whitespace-illegal + - match: '(?=[^\s])' + push: type enum-body: - match: '{' scope: punctuation.section.block.begin.d @@ -1514,6 +1518,9 @@ contexts: 1: keyword.control.d 2: storage.type.d push: template + - match: '\b(mixin)\s+(?!\()' + scope: keyword.control.d + push: [expect-end-of-line, value] statement-label-in: - match: '\b({{name}})\s*(:)' captures: @@ -1619,6 +1626,9 @@ contexts: scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true - include: not-whitespace-illegal throw-in: - match: '\bthrow\b' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index e345d4cb4c..6fdb2876b4 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -573,6 +573,22 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ variable.other.d // ^ punctuation.terminator.d + enum bool[] foo = 12; +//^^^^ storage.type.enum.d +// ^^^^ storage.type.d +// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^^^ entity.name.enum.d +// ^ keyword.operator.assignment.d +// ^^ constant.numeric.integer.d +// ^ punctuation.terminator.d + enum bool +//^^^^ storage.type.enum.d +// ^^^^ entity.name.enum.d + { +//^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d version(unittest) {} //^^^^^^^ keyword.control.conditional.d @@ -879,6 +895,21 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + void foo(A : int, string a : "s") {} +//^^^^ storage.type.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ keyword.operator.assignment.d +// ^^^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^^^^ storage.type.d +// ^ variable.parameter.d +// ^ keyword.operator.assignment.d +// ^^^ string.quoted.double.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d this(int foo) { //^^^^ entity.name.function.constructor.d @@ -960,6 +991,14 @@ extern(1) // ^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d + mixin Foo!("foo"); +//^^^^^ keyword.other.d +// ^^^ variable.other.d +// ^ keyword.operator.d +// ^ punctuation.section.parens.begin.d +// ^^^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d mixin("foo"); //^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d @@ -1529,18 +1568,18 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d - AliasSeq!(immutable char, int); -//^^^^^^^^ variable.other.d -// ^ keyword.operator.d -// ^ punctuation.section.parens.begin.d -// ^^^^^^^^^ storage.modifier.d -// ^^^^ storage.type.d -// ^ punctuation.separator.sequence.d -// ^^^ storage.type.d -// ^ punctuation.section.parens.end.d -// ^ punctuation.terminator.d + .AliasSeq!(immutable char, int); +//^^^^^^^^^ variable.other.d +// ^ keyword.operator.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^^^^ storage.modifier.d +// ^^^^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d - cast(Unqual!T*)foo; + cast(Unqual!T*).foo; //^^^^ keyword.operator.word.d // ^ punctuation.section.parens.begin.d // ^^^^^^ storage.type.d @@ -1548,5 +1587,5 @@ extern(1) // ^ variable.other.d // ^ keyword.operator.arithmetic.d // ^ punctuation.section.parens.end.d -// ^^^ variable.other.d -// ^ punctuation.terminator.d +// ^^^^ variable.other.d +// ^ punctuation.terminator.d From e96ecc5f495d467ef53813955c0fb1f00376ece3 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 10:47:10 +1100 Subject: [PATCH 046/108] Implement function type parsing and fix small inconsistencies --- D/D.sublime-syntax | 99 ++++++++++++++++------ D/tests/syntax_test_d.d | 176 ++++++++++++++++++++++++++++++---------- 2 files changed, 211 insertions(+), 64 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 941b7c9526..8bc064938e 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -495,11 +495,11 @@ contexts: set: [uda-after, value-list] - match: '({{name}})\s*(\()' captures: - 1: variable.function.d + 1: storage.type.d 2: punctuation.definition.annotation.begin.d set: [uda-after, value-list] - match: '({{name}})\b' - scope: variable.other.constant.d + scope: storage.type.d pop: true uda-after: - match: '\)' @@ -665,15 +665,21 @@ contexts: push: [basic-type2-after-brackets, value-list] - match: '\b(delegate|function)\b' scope: keyword.other.d - push: function-pointer-type + set: [basic-type2, function-type] - match: '!' scope: keyword.operator.d set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [basic-type2-after-parens, value-list] + set: [basic-type2, basic-type2-after-parens, value-list] - match: '(?=[^\s])' set: value + - match: '\.(?!\.\.)' + scope: storage.type.d + set: + - match: '\b({{name}})\b' + scope: storage.type.d + set: basic-type2 - match: '(?=[^\s])' pop: true basic-type2-after-brackets: @@ -692,10 +698,58 @@ contexts: pop: true - include: value - function-pointer-type: - # TODO - - match: '.' + function-type: + - match: (?=\() + set: [function-type-after, function-type-argument-definition-list] + - include: not-whitespace-illegal-pop + function-type-after: + - include: attribute-in + - match: '(?=[^\s])' + pop: true + # Function type arguments are slightly different to regular function + # arguments. With regular arguments a standalone "name" is asssumed to be a + # template argument, but with function types they must be a type. + function-type-argument-definition-list: + - match: '\(' + scope: punctuation.section.group.begin.d + set: + - match: '{{type_look_ahead}}' + set: [function-type-argument, function-type-argument-type] + - match: '\)' + scope: punctuation.section.group.end.d + pop: true + - include: not-whitespace-illegal + - include: not-whitespace-illegal + function-type-argument-type: + - include: parameter-attribute-in + - include: type + function-type-argument: + - match: '\b{{name}}\b' + scope: variable.parameter.d + set: + - match: '\.\.\.' + scope: keyword.operator.d + - match: ',' + scope: punctuation.separator.sequence.d + set: [function-type-argument, function-type-argument-type] + - match: '=' + scope: keyword.operator.assignment.d + push: value + - match: ':' + scope: keyword.operator.assignment.d + push: value + - match: '\)' + scope: punctuation.section.group.end.d + pop: true + - include: not-whitespace-illegal + - match: ',' + scope: punctuation.separator.sequence.d + push: function-type-argument-type + - match: '\)' + scope: punctuation.section.group.end.d pop: true + - include: not-whitespace-illegal + function-or-variable-after-type: - match: '\b({{operator_overloads}})\s*(?=\(|$)' captures: @@ -734,7 +788,7 @@ contexts: - include: not-whitespace-illegal function-argument-or-type: - include: parameter-attribute-in - - match: '(?={{name}}\s*[,=:\)\.])' + - match: '(?={{name}}\s*([,=:\)]|\.\.\.))' pop: true - include: type function-argument: @@ -806,7 +860,7 @@ contexts: # The first value in an expression ending with a * is always a function/variable definition, otherwise it could be either # We highlight as if it were a value, but switch to a definition if it turns out to be one first-value: - # - meta_scope: first-value + - meta_scope: first-value - match: '\btypeof\b' scope: keyword.other.d set: @@ -819,9 +873,11 @@ contexts: - match: '{{identifier_ref}}' scope: variable.other.d set: first-value-after - - include: not-whitespace-illegal-pop + - match: '(?=[^\s])' + set: value + # - include: not-whitespace-illegal-pop first-value-after: - # - meta_scope: first-value-after + - meta_scope: first-value-after - match: '\.' scope: punctuation.accessor.dot.d set: @@ -844,6 +900,9 @@ contexts: set: value-list - match: '(?=\*)' set: [function-or-variable-after-type, basic-type2] + - match: '\b(function|delegate)\b' + scope: keyword.other.d + set: [function-or-variable-after-type, basic-type2, function-type] - match: '(?={{name}}\s*([;=\(]|$))' set: function-or-variable-after-type - match: '(?=[^\s])' @@ -859,7 +918,7 @@ contexts: set: first-value-after - include: not-whitespace-illegal value: - # - meta_scope: value + - meta_scope: value - include: attribute-in - match: '!' scope: keyword.operator.logical.d @@ -1029,6 +1088,9 @@ contexts: set: type - include: not-whitespace-illegal-pop value-group-after: + - match: '\b(function|delegate)\b' + scope: keyword.other.d + set: [value-group-after, basic-type2, function-type] - match: '\)' scope: punctuation.section.group.end.d set: value-group-after-parens @@ -1051,7 +1113,7 @@ contexts: - match: (?=[^\s]) set: value-after value-after: - # - meta_scope: value-after + - meta_scope: value-after - match: '\.\.(?!\.)' scope: keyword.operator.d set: value @@ -1501,16 +1563,7 @@ contexts: - include: not-whitespace-illegal template-definition-begin: - match: '(?=\()' - set: [template-definition-after-argument-list, function-argument-definition-list] - - include: not-whitespace-illegal - template-definition-after-argument-list: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in + set: [optional-template-body-block, function-argument-definition-list] - include: not-whitespace-illegal mixin-in: - match: '\b(mixin)\s+(template)\b' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 6fdb2876b4..528a2c8e36 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -186,15 +186,15 @@ f = 0xF.AP-2f; @foo: //^ punctuation.definition.annotation.begin.d -// ^^^ variable.other.constant.d +// ^^^ storage.type.d // ^ punctuation.separator.d @("oo")@safer@Foo(2, 4)@property //^^ punctuation.definition.annotation.begin.d // ^^^^ string.quoted.double.d // ^ punctuation.definition.annotation.begin.d -// ^^^^^ variable.other.constant.d +// ^^^^^ storage.type.d // ^ punctuation.definition.annotation.begin.d -// ^^^ variable.function.d +// ^^^ storage.type.d // ^ punctuation.definition.annotation.begin.d // ^ constant.numeric.integer.d // ^ constant.numeric.integer.d @@ -979,6 +979,23 @@ extern(1) //^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + template foo(T) if (is(T : class)) {} +//^^^^^^^^ storage.type.d +// ^^^ entity.name.template.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^^ keyword.control.conditional.d +// ^ value punctuation.section.brackets.begin.d +// ^^ value keyword.other.d +// ^ value-after punctuation.section.parens.begin.d +// ^ value-after storage.type.d +// ^ value-after keyword.operator.logical.d +// ^^^^^ value-after storage.type.d +// ^ value-after punctuation.section.parens.end.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d mixin template f(int a) { //^^^^^ keyword.control.d @@ -992,7 +1009,7 @@ extern(1) } //^ punctuation.section.block.end.d mixin Foo!("foo"); -//^^^^^ keyword.other.d +//^^^^^ keyword.control.d // ^^^ variable.other.d // ^ keyword.operator.d // ^ punctuation.section.parens.begin.d @@ -1280,43 +1297,28 @@ extern(1) // ^^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d - - mixin("a") = (12 ^^ 4) % 5 / (3++ + --4) ~ "foo"; -//^^^^^ keyword.other.d -// ^ punctuation.section.parens.begin.d -// ^^^ string.quoted.double.d -// ^ punctuation.section.parens.end.d -// ^ keyword.operator.assignment.d -// ^ punctuation.section.group.begin.d -// ^^ constant.numeric.integer.d -// ^^ keyword.operator.arithmetic.d -// ^ constant.numeric.integer.d -// ^ punctuation.section.group.end.d -// ^ keyword.operator.arithmetic.d -// ^ constant.numeric.integer.d -// ^ keyword.operator.arithmetic.d -// ^ punctuation.section.group.begin.d -// ^ constant.numeric.integer.d -// ^^ keyword.operator.arithmetic.d -// ^ keyword.operator.arithmetic.d -// ^^ keyword.operator.arithmetic.d -// ^ constant.numeric.integer.d -// ^ punctuation.section.group.end.d -// ^ keyword.operator.arithmetic.d -// ^^^^^ string.quoted.double.d -// ^ punctuation.terminator.d - - auto f = foo ? 12 : 15; -//^^^^ keyword.other.d -// ^ variable.other.d -// ^ keyword.operator.assignment.d -// ^^^ variable.other.d -// ^ keyword.operator.logical.d -// ^^ constant.numeric.integer.d -// ^ keyword.operator.logical.d -// ^^ constant.numeric.integer.d -// ^ punctuation.terminator.d - + i = new Foo(); +//^ first-value first-value-after variable.other.d +// ^ value-after value keyword.operator.assignment.d +// ^^^ value keyword.operator.word.d +// ^^^ storage.type.d +// ^ punctuation.section.parens.begin.d +// ^ value-after punctuation.section.parens.end.d +// ^ punctuation.terminator.double + new(1, 2, 3) string[12]; +//^^^ value keyword.operator.word.d +// ^ punctuation.section.parens.begin.d +// ^ value-after constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^ value-after constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^ value-after constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^^^^^^ storage.type.d +// ^ punctuation.section.brackets.begin.d +// ^^ value-after constant.numeric.integer.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.terminator.d auto c = new class(12) T, Bar { //^^^^ keyword.other.d // ^ variable.other.d @@ -1372,6 +1374,42 @@ extern(1) //^ punctuation.section.block.end.d // ^ punctuation.terminator.d + mixin("a") = (12 ^^ 4) % 5 / (3++ + --4) ~ "foo"; +//^^^^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d +// ^ keyword.operator.assignment.d +// ^ punctuation.section.group.begin.d +// ^^ constant.numeric.integer.d +// ^^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.group.end.d +// ^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ keyword.operator.arithmetic.d +// ^ punctuation.section.group.begin.d +// ^ constant.numeric.integer.d +// ^^ keyword.operator.arithmetic.d +// ^ keyword.operator.arithmetic.d +// ^^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.group.end.d +// ^ keyword.operator.arithmetic.d +// ^^^^^ string.quoted.double.d +// ^ punctuation.terminator.d + + auto f = foo ? 12 : 15; +//^^^^ keyword.other.d +// ^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^ variable.other.d +// ^ keyword.operator.logical.d +// ^^ constant.numeric.integer.d +// ^ keyword.operator.logical.d +// ^^ constant.numeric.integer.d +// ^ punctuation.terminator.d + foreach (ref a; foo) {} //^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d @@ -1556,6 +1594,62 @@ extern(1) // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d + void delegate(int a ..., foo) foo; +//^^^^ storage.type.d +// ^^^^^^^^ keyword.other.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^^^ keyword.operator.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ punctuation.section.group.end.d +// ^^^ variable.other.d +// ^ punctuation.terminator.d + void delegate()[] foo() {} +//^^^^ storage.type.d +// ^^^^^^^^ keyword.other.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + (void function(int foo)).sizeof; +//^ punctuation.section.group.begin.d +// ^^^^ storage.type.d +// ^^^^^^^^ keyword.other.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^^^ variable.parameter.d +// ^^ punctuation.section.group.end.d +// ^ punctuation.accessor.dot.d +// ^^^^^^ variable.other.d +// ^ punctuation.terminator.d + void fn(int delegate(ref Foo, scope float function(int a)) f); +//^^^^ storage.type.d +// ^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^^^^^^^^ keyword.other.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.modifier.d +// ^^^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^^^ storage.modifier.d +// ^^^^^ storage.type.d +// ^^^^^^^^ keyword.other.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^^ punctuation.section.group.end.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.terminator.d + 3 != 3 && "s" !in [2]; //^ constant.numeric.integer.d // ^^ keyword.operator.comparison.d From b487bd2fc7627784bfb31089cdd6fba4eda51d49 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 10:58:41 +1100 Subject: [PATCH 047/108] Implement __traits parsing and fix small inconsistency with debug --- D/D.sublime-syntax | 17 ++++++++++++++--- D/tests/syntax_test_d.d | 30 +++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 4 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 8bc064938e..00d9c4bb2b 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -30,7 +30,7 @@ variables: character_lookahead: (?=') string_lookahead: '(?=`|[rxq]?"|q{)' - definitely_value_lookahead: '(?=(!|~|\+|\-|\*|&|\bcast\b|\bdelete\b|\bnew\b|\bimport\b|\bmixin\b|\bis\b|[0-9]|\[|\(|{{string_lookahead}}|\b({{language_constant}})\b|\b({{language_variable}})\b))' + definitely_value_lookahead: '(?=(!|~|\+|\-|\*|&|\bcast\b|\bdelete\b|\bnew\b|\bimport\b|\bmixin\b|\bis\b|__traits|[0-9]|\[|\(|{{string_lookahead}}|\b({{language_constant}})\b|\b({{language_variable}})\b))' definitely_declaration_lookahead: '(?=({{name}}|\]|\))(\s+{{name}})|\bauto\b)' attribute_lookahead: '(?={{attributes}}|@)' @@ -977,6 +977,18 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [value-parens-after, typeof-value] + - match: '\b__traits\b' + scope: keyword.other.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: + - match: '\b{{name}}\b' + scope: variable.function.d + set: + - match: ',' + scope: punctuation.separator.sequence.d + set: [value-parens-after, value-list] - match: '(\()\s*(\))' captures: 1: punctuation.section.parens.begin.d @@ -1481,9 +1493,8 @@ contexts: - match: '{{integer_lookahead}}' set: [version-condition-end, integer] - include: not-whitespace-illegal - - match: '(?={|:)' + - match: '(?=[^\s])' pop: true - - include: not-whitespace-illegal static-foreach-in: - match: '\b(static)\s+(foreach|foreach_reverse)\b' captures: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 528a2c8e36..620589299b 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -637,6 +637,11 @@ extern(1) // ^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d // ^ punctuation.separator.d + debug foo bar; +//^^^^^ keyword.control.conditional.d +// ^^^ storage.type.d +// ^^^ variable.other.d +// ^ punctuation.terminator.d debug = 2; //^^^^^ keyword.control.conditional.d @@ -1304,7 +1309,7 @@ extern(1) // ^^^ storage.type.d // ^ punctuation.section.parens.begin.d // ^ value-after punctuation.section.parens.end.d -// ^ punctuation.terminator.double +// ^ punctuation.terminator.d new(1, 2, 3) string[12]; //^^^ value keyword.operator.word.d // ^ punctuation.section.parens.begin.d @@ -1650,6 +1655,29 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.terminator.d + __traits(foo, a); +//^^^^^^^^ value keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ variable.function.d +// ^ punctuation.separator.sequence.d +// ^ value value-after variable.other.d +// ^ value-after punctuation.section.parens.end.d +// ^ punctuation.terminator.d + values ~= toValue(__traits(getMember, this, primaryKey)); +//^^^^^^ first-value first-value-after variable.other.d +// ^^ value-after value keyword.operator.assignment.d +// ^^^^^^^ value value-after variable.other.d +// ^ value-after punctuation.section.parens.begin.d +// ^^^^^^^^ value keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^^^^ variable.function.d +// ^ punctuation.separator.sequence.d +// ^^^^ value value-after variable.language.d +// ^ punctuation.separator.sequence.d +// ^^^^^^^^^^ value value-after variable.other.d +// ^^ value-after punctuation.section.parens.end.d +// ^ punctuation.terminator.d + 3 != 3 && "s" !in [2]; //^ constant.numeric.integer.d // ^^ keyword.operator.comparison.d From 1c4e62178446b07221bd02179d513ea85151cce9 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 12:54:15 +1100 Subject: [PATCH 048/108] Fix some remaining inconsistencies --- D/D.sublime-syntax | 254 +++++++++++++++++++-------------------- D/tests/syntax_test_d.d | 256 ++++++++++++++++++++++++++++++++++------ 2 files changed, 338 insertions(+), 172 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 00d9c4bb2b..eb54016424 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -18,7 +18,6 @@ variables: hex_char: '[0-9a-fA-F]' hex_or_under: '(?:{{hex_char}}|_)' - type_ctor: 'const|immutable|inout|shared' type_look_ahead: '(?={{identifier_ref}})' number_lookahead: '(?=(\b|\.)[0-9])' @@ -31,12 +30,15 @@ variables: string_lookahead: '(?=`|[rxq]?"|q{)' definitely_value_lookahead: '(?=(!|~|\+|\-|\*|&|\bcast\b|\bdelete\b|\bnew\b|\bimport\b|\bmixin\b|\bis\b|__traits|[0-9]|\[|\(|{{string_lookahead}}|\b({{language_constant}})\b|\b({{language_variable}})\b))' - definitely_declaration_lookahead: '(?=({{name}}|\]|\))(\s+{{name}})|\bauto\b)' + definitely_declaration_lookahead: '(?=({{name}}|\]|\))(\s+{{name}})|\b({{type_qualifier}})\b)' - attribute_lookahead: '(?={{attributes}}|@)' - attributes: 'static|abstract|final|override|synchronized|scope|const|immutable|inout|shared|__gshared|nothrow|pure|ref|return' + type_qualifier: 'const|immutable|inout|shared' + type_qualifier_lookahead: '(?=\b({{type_qualifier}})\b)' + attribute_lookahead: '(?=@|\b({{attributes}}|extern|align|deprecated|pragma|private|protected|public|export|package)\b)' + attributes: 'static|abstract|final|override|synchronized|scope|__gshared|nothrow|pure|ref|return|auto' at_attributes: 'disable|nogc|property|safe|system|trusted' - parameter_attributes: 'in|lazy|out' + parameter_attribute_lookahead: '(?=\b({{parameter_attribute}})\b)' + parameter_attribute: 'in|lazy|out' 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' @@ -46,7 +48,8 @@ variables: 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' - type_specialization: 'struct|union|class|interface|enum|__vector|function|delegate|super|const|immutable|inout|shared|return|__parameters' + type_specialization_keyword: '__vector|function|delegate|super|return|__parameters' + type_specialization_storage: 'struct|union|class|interface|enum' block_statement_loohahead: '(?={)' @@ -102,8 +105,8 @@ contexts: - include: scope-in - include: asm-in - include: switch-in - - include: statement-label-in - include: attribute-specifier-in + - include: statement-label-in - include: end-of-line-in - include: value-or-declaration-in block-statement-in: @@ -123,51 +126,11 @@ contexts: set: block-statement - match: '(?=[^\s])' pop: true - all-types-in: - - include: support-type-built-ins-in - - include: support-type-in - - include: storage-type-d-in - constant_placeholder-in: - - match: '(?i:%(\([a-z_]+\))?#?0?\-?[ ]?\+?([0-9]*|\*)(\.([0-9]*|\*))?[hL]?[a-z%])' - scope: constant.other.placeholder.d - function_assertions-in: - - match: '(in|out)\s*(?=\{)' - captures: - 1: keyword.control.statement.d - push: - - match: '\{' # Push onto the stack for blocks so that } pops functions/methods/classes properly - push: - - meta_scope: meta.block.d - - match: '\}' - pop: true - - include: $top_level_main - - match: (in|out) - scope: keyword.control.statement.d - - match: (?=body|do) - pop: true - - match: '(?<=\})' + optional-block-statement-or-label: + - match: ':' + scope: punctuation.separator.d pop: true - statement-remainder-in: - - match: \( - push: - - meta_scope: meta.definition.param-list.d - - match: (?=\)) - pop: true - - include: all-types-in - - match: (throws) - captures: - 1: keyword.other.class-fns.d - push: - - meta_scope: meta.definition.throws.d - - match: "(?={)" - captures: - 1: keyword.other.class-fns.d - pop: true - - include: all-types-in - storage-type-d-in: - - match: '\b(void|byte|short|char|int|long|float|double|boolean|([a-z]\w+\.)*[A-Z]\w+(?![\(\.]))\b' - scope: storage.type.d - + - include: optional-block-statement comment-in: # - match: /\*\*/ # scope: comment.block.empty.d punctuation.definition.comment.d @@ -436,7 +399,7 @@ contexts: - match: '{{name}}' - match: '(/|&|\||-|\+|<<|<>|>>|>>>||\*|%|\^|\^\^|~)=' scope: keyword.operator.assignment.d - - match: '(/|<=|>=|==|!<>=|!<=|!>=|\.\.\.|\.\.|&|&&|\||\|\||-|--|\+|\+\+|<|<<|<>|>|>>|>>>|!|!<>|!<|!>|\(|\)|\[|\]|{|}|\?|,|:|\$|\*|%|\^|\^\^|~|@|=>|#)' + - match: '(/|<=|>=|==|!<>=|!<=|!>=|\.\.\.|\.\.|&|&&|\||\|\||-|--|\+|\+\+|<|<<|<>|>|>>|>>>|!|!<>|!<|!>|\(|\)|\[|\]|\{|\}|\?|,|:|\$|\*|%|\^|\^\^|~|@|=>|#)' scope: keyword.operator.d - match: ';' scope: punctuation.terminator.d @@ -444,27 +407,70 @@ contexts: scope: keyword.operator.d - include: not-whitespace-illegal attribute-specifier-in: - - include: attribute-in + - match: '{{attribute_lookahead}}' + push: [attribute-specifier-after, attribute] + - match: '\b({{type_qualifier}})\b(?!\s*\()' + scope: storage.modifier.d + push: attribute-specifier-after + attribute-specifier-after: - match: ':' scope: punctuation.separator.d + pop: true + - match: '{{block_statement_loohahead}}' + set: block-statement + - match: '{{attribute_lookahead}}' + push: attribute + - match: '\b({{type_qualifier}})\b(?!\s*\()' + scope: storage.modifier.d + - match: '(?=\b({{reserved}})\b)' + pop: true + - match: '(?=\b{{name}}\b\s*[,=\()])' + set: [function-or-variable-after-type] + - match: '(?=[^\s])' + set: [function-or-variable-after-type, type] + - include: not-whitespace-illegal-pop parameter-attribute-in: + - match: '{{attribute_lookahead}}' + push: [parameter-attribute-after, attribute] + - match: '\b({{parameter_attribute}})\b' + scope: storage.modifier.d + push: parameter-attribute-after + - match: '\b({{type_qualifier}})\b(?!\s*\()' + scope: storage.modifier.d + push: parameter-attribute-after + parameter-attribute-after: + - match: '{{attribute_lookahead}}' + set: [parameter-attribute-after, attribute] + - match: '\b({{parameter_attribute}})\b' + scope: storage.modifier.d + set: parameter-attribute-after + - match: '\b({{type_qualifier}})\b(?!\s*\()' + scope: storage.modifier.d + set: parameter-attribute-after + - match: '(?=[^\s])' + pop: true + function-attribute-in: - include: attribute-in - - match: '\b({{parameter_attributes}})\b' + - match: '\b({{type_qualifier}})\b' scope: storage.modifier.d attribute-in: + - match: '{{attribute_lookahead}}' + push: attribute + attribute: - match: '\b({{attributes}})\b' scope: storage.modifier.d + pop: true - match: '(@)' scope: punctuation.definition.annotation.begin.d - push: at-attribute + set: at-attribute - match: '\b(extern)\s*(\()' captures: 1: keyword.other.external.d 2: punctuation.definition.annotation.begin.d - push: extern-attribute + set: extern-attribute - match: '\b(align)\b' scope: keyword.other.alignment.d - push: + set: - match: '\(' scope: punctuation.definition.annotation.begin.d set: [align-attribute-after, value] @@ -472,20 +478,37 @@ contexts: pop: true - match: '\b(deprecated)\b' scope: keyword.other.deprecated.d - push: + set: - match: '\(' scope: punctuation.definition.annotation.begin.d set: [deprecated-attribute-after, value] - match: '(?=[^\s])' pop: true - - include: visibility-attributes + - match: '\b(private|protected|public|export)\b' + scope: storage.modifier.access-control.d + pop: true + - match: '\b(package)\s*(\()' + captures: + 1: storage.modifier.access-control.d + 2: punctuation.definition.annotation.begin.d + set: + - match: '{{identifier}}' + scope: variable.other.constant.d + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + - include: not-whitespace-illegal + - match: '\b(package)\b' + scope: storage.modifier.access-control.d + pop: true - match: '\b(pragma)\b' scope: keyword.other.pragma.d - push: + set: - match: '\(' scope: punctuation.definition.annotation.begin.d set: pragma-attribute - include: not-whitespace-illegal + - include: not-whitespace-illegal-pop at-attribute: - match: '({{at_attributes}})\b' scope: storage.attribute.d @@ -525,22 +548,6 @@ contexts: - match: '\)' scope: punctuation.definition.annotation.end.d pop: true - visibility-attributes: - - match: '\b(private|protected|public|export)\b' - scope: storage.modifier.access-control.d - - match: '\b(package)\s*(\()' - captures: - 1: storage.modifier.access-control.d - 2: punctuation.definition.annotation.begin.d - push: - - match: '{{identifier}}' - scope: variable.other.constant.d - - match: '\)' - scope: punctuation.definition.annotation.end.d - pop: true - - include: not-whitespace-illegal - - match: '\b(package)\b' - scope: storage.modifier.access-control.d pragma-attribute: - match: '\b({{name}})\b' scope: variable.function.d @@ -624,7 +631,7 @@ contexts: - include: not-whitespace-illegal - include: not-whitespace-illegal type: - - match: '\b({{type_ctor}})\b' + - match: '\b({{type_qualifier}})\b' scope: storage.modifier.d set: - match: '\(' @@ -770,7 +777,7 @@ contexts: set: [function-definition-after-argument-list2, function-argument-definition-list] - include: function-definition-after-argument-list2 function-definition-after-argument-list2: - - include: attribute-specifier-in + - include: function-attribute-in - match: '(?={|;|\bif\b)' set: optional-template-body-block - include: not-whitespace-illegal @@ -860,7 +867,6 @@ contexts: # The first value in an expression ending with a * is always a function/variable definition, otherwise it could be either # We highlight as if it were a value, but switch to a definition if it turns out to be one first-value: - - meta_scope: first-value - match: '\btypeof\b' scope: keyword.other.d set: @@ -877,7 +883,6 @@ contexts: set: value # - include: not-whitespace-illegal-pop first-value-after: - - meta_scope: first-value-after - match: '\.' scope: punctuation.accessor.dot.d set: @@ -918,7 +923,6 @@ contexts: set: first-value-after - include: not-whitespace-illegal value: - - meta_scope: value - include: attribute-in - match: '!' scope: keyword.operator.logical.d @@ -994,7 +998,7 @@ contexts: 1: punctuation.section.parens.begin.d 2: punctuation.section.parens.end.d set: - - include: attribute-in + - include: function-attribute-in - match: '=>' scope: keyword.operator.lambda.d set: value @@ -1009,6 +1013,8 @@ contexts: - match: '\[' scope: punctuation.section.brackets.begin.d set: [value-bracket-after, value-array-list] + - match: '{{type_qualifier_lookahead}}' + set: [value-after, type] - match: '{{number_lookahead}}' set: [value-after, number] - match: '{{character_lookahead}}' @@ -1093,9 +1099,14 @@ contexts: pop: true - include: not-whitespace-illegal type-specialization: - - match: '\b({{type_specialization}})\b' - scope: storage.type.d - pop: true + - match: '\b(?:({{type_specialization_storage}})|({{type_specialization_keyword}}))\b' + captures: + 1: storage.type.d + 2: keyword.d + set: + - match: '(?=\))' + pop: true + - include: type-specialization - match: '(?=[^\s])' set: type - include: not-whitespace-illegal-pop @@ -1116,7 +1127,7 @@ contexts: scope: keyword.operator.d - include: not-whitespace-illegal value-group-after-parens: - - include: attribute-in + - include: function-attribute-in - match: (?={) set: [value-after, block-statement] - match: '=>' @@ -1125,7 +1136,6 @@ contexts: - match: (?=[^\s]) set: value-after value-after: - - meta_scope: value-after - match: '\.\.(?!\.)' scope: keyword.operator.d set: value @@ -1144,9 +1154,24 @@ contexts: - match: '(\+\+|--)' scope: keyword.operator.arithmetic.d set: value-after + - match: '(&&|\|\|)' + scope: keyword.operator.logical.d + set: value + - match: '(\+|-|/|%|\*|&|\||\^\^|\^|~|<<|>>>|>>)=' + scope: keyword.operator.assignment.d + set: value + - match: '(\+|\-|~|/|%|\^\^)' + scope: keyword.operator.arithmetic.d + set: value + - match: '(<<|>>>|>>|\||\^|&)' + scope: keyword.operator.bitwise.d + set: value - match: '(==|!=|\bis\b|!is\b|<=|<|>=|>|\bin\b|!in\b)' scope: keyword.operator.comparison.d set: value + - match: '=' + scope: keyword.operator.assignment.d + set: value - match: '!' scope: keyword.operator.d set: @@ -1155,26 +1180,14 @@ contexts: set: [value-parens-after, value-list] - match: '(?=[^\s])' set: value - - match: '(\+|-|/|%|\*|&|\||\^\^|\^|~|<<|>>>|>>)?=' - scope: keyword.operator.assignment.d - set: value - - match: '(&&|\|\|)' - scope: keyword.operator.logical.d - set: value # This can also be a pointer in some situations - match: \* scope: keyword.operator.arithmetic.d set: - - match: '(?=\)|,)' + - match: '(?=\)|,|;)' pop: true - match: '(?=[^\s])' set: value - - match: '(\+|\-|~|/|%|\^\^)' - scope: keyword.operator.arithmetic.d - set: value - - match: '(<<|>>>|>>|\||\^|&)' - scope: keyword.operator.bitwise.d - set: value - match: '\?' scope: keyword.operator.logical.d set: [value-condition-after, value] @@ -1263,7 +1276,7 @@ contexts: alias-new-assign: - match: '=' scope: keyword.operator.assignment.d - set: [alias-new-after-type, type] + set: [alias-new-after-type, value] - include: not-whitespace-illegal alias-new-after-type: - include: end-of-line @@ -1431,39 +1444,10 @@ contexts: conditional-declaration-in: - match: '\b(version)\b' scope: keyword.control.conditional.d - push: [optional-block-statement, version-condition] + push: [optional-block-statement-or-label, version-condition] - match: '\b(debug)\b' scope: keyword.control.conditional.d - push: [optional-block-statement, debug-condition] - conditional-declaration-body: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - match: '}' - scope: punctuation.section.block.end.d - set: - - match: '\b(else)\b' - scope: keyword.control.conditional.d - set: - - match: '{' - scope: punctuation.section.block.begin.d - set: - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in - - match: ':' - scope: punctuation.section.block.begin.d - pop: true - - match: '(?=[^\s])' - pop: true - - match: '(?=[^\s])' - pop: true - - include: statement-list-in - - match: ':' - scope: punctuation.section.block.begin.d - pop: true - - include: not-whitespace-illegal + push: [optional-block-statement-or-label, debug-condition] version-condition: - match: '\(' scope: punctuation.section.brackets.begin.d @@ -1593,10 +1577,10 @@ contexts: conditional-in: - match: '\bif\b' scope: keyword.control.conditional.d - push: [optional-block-statement, condition] + push: [optional-block-statement-or-label, condition] - match: '\belse\b' scope: keyword.control.conditional.d - push: optional-block-statement + push: optional-block-statement-or-label loop-in: - match: '\bwhile\b' scope: keyword.control.flow.d @@ -1766,7 +1750,7 @@ contexts: pop: true - match: '(?=\b{{name}}\s*[;,])' set: foreach-parameter-after-type - - include: attribute-in + - include: parameter-attribute-in - match: '(?=[^\s])' set: [foreach-parameter-after-type, type] foreach-parameter-after-type: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 620589299b..d6eedecb52 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -260,7 +260,7 @@ extern(1) // ^ invalid.illegal.d // ^ - invalid.illegal.d // ^ punctuation.definition.annotation.end.d - pragma(f) pragma(test, void) + pragma(f) pragma(test, void): //^^^^^^ keyword.other.pragma.d // ^ punctuation.definition.annotation.begin.d // ^ variable.function.d @@ -270,6 +270,9 @@ extern(1) // ^^^^ variable.function.d // ^^^^ storage.type.d // ^ punctuation.definition.annotation.end.d + private: +//^^^^^^^ storage.modifier.access-control.d +// ^ punctuation.separator.d import foo; //^^^^^^ keyword.control.import.d @@ -353,15 +356,24 @@ extern(1) // ^^^^^^^^^^^ variable.d // ^^^^ keyword.control.alias.d // ^ punctuation.terminator.d - alias F(x) = foo; + alias F(x) = foo*; //^^^^^ keyword.control.alias.d // ^ entity.name.type.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ keyword.operator.assignment.d -// ^^^ storage.type.d -// ^ punctuation.terminator.d +// ^^^ variable.other.d +// ^ keyword.operator.arithmetic.d +// ^ punctuation.terminator.d + alias rSave = a => a; +//^^^^^ keyword.control.alias.d +// ^^^^^ entity.name.type.d +// ^ keyword.operator.assignment.d +// ^ variable.parameter.d +// ^^ keyword.operator.lambda.d +// ^ variable.other.d +// ^ punctuation.terminator.d int a; //^^^ storage.type.d @@ -382,13 +394,13 @@ extern(1) // ^^^^^^^^^^^^^^ variable.other.d // ^ punctuation.terminator.d auto foo = 3; -//^^^^ keyword.other.d +//^^^^ storage.modifier.d // ^^^ variable.other.d // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d auto -//^^^^ keyword.other.d +//^^^^ storage.modifier.d asjfaisdjaksdjaklsjdnaskjjks = 3; //^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.other.d // ^ keyword.operator.assignment.d @@ -894,12 +906,58 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d auto foo() {} -//^^^^ keyword.other.d +//^^^^ storage.modifier.d // ^^^ entity.name.function.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + static foo() {} +//^^^^^^ storage.modifier.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + @property foo() {} +//^ punctuation.definition.annotation.begin.d +// ^^^^^^^^ storage.attribute.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + pure foo() {} +//^^^^ storage.modifier.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + const(string) foo(T)(ref const(int) a, auto ref T b) {} +//^^^^^ storage.modifier.d +// ^ punctuation.section.group.begin.d +// ^^^^^^ storage.type.d +// ^ punctuation.section.group.end.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.modifier.d +// ^^^^^ storage.modifier.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ punctuation.section.group.end.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^^ storage.modifier.d +// ^^^ storage.modifier.d +// ^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d void foo(A : int, string a : "s") {} //^^^^ storage.type.d // ^^^ entity.name.function.d @@ -915,6 +973,17 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + void foo() const inout @property {} +//^^^^ storage.type.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^^^^^ storage.modifier.d +// ^^^^^ storage.modifier.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^^^^ storage.attribute.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d this(int foo) { //^^^^ entity.name.function.constructor.d @@ -991,13 +1060,13 @@ extern(1) // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^^ keyword.control.conditional.d -// ^ value punctuation.section.brackets.begin.d -// ^^ value keyword.other.d -// ^ value-after punctuation.section.parens.begin.d -// ^ value-after storage.type.d -// ^ value-after keyword.operator.logical.d -// ^^^^^ value-after storage.type.d -// ^ value-after punctuation.section.parens.end.d +// ^ punctuation.section.brackets.begin.d +// ^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^ storage.type.d +// ^ keyword.operator.logical.d +// ^^^^^ storage.type.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -1141,6 +1210,16 @@ extern(1) //^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d + foreach (ref a; foo) {} +//^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^^^ storage.modifier.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^ variable.other.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d continue; //^^^^^^^^ keyword.control.flow.d @@ -1303,29 +1382,29 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d i = new Foo(); -//^ first-value first-value-after variable.other.d -// ^ value-after value keyword.operator.assignment.d -// ^^^ value keyword.operator.word.d +//^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^ keyword.operator.word.d // ^^^ storage.type.d // ^ punctuation.section.parens.begin.d -// ^ value-after punctuation.section.parens.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d new(1, 2, 3) string[12]; -//^^^ value keyword.operator.word.d +//^^^ keyword.operator.word.d // ^ punctuation.section.parens.begin.d -// ^ value-after constant.numeric.integer.d +// ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d -// ^ value-after constant.numeric.integer.d +// ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d -// ^ value-after constant.numeric.integer.d +// ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d // ^^^^^^ storage.type.d // ^ punctuation.section.brackets.begin.d -// ^^ value-after constant.numeric.integer.d +// ^^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d auto c = new class(12) T, Bar { -//^^^^ keyword.other.d +//^^^^ storage.modifier.d // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ keyword.operator.word.d @@ -1405,7 +1484,7 @@ extern(1) // ^ punctuation.terminator.d auto f = foo ? 12 : 15; -//^^^^ keyword.other.d +//^^^^ storage.modifier.d // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ variable.other.d @@ -1516,6 +1595,26 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^ storage.type.d // ^ punctuation.section.parens.end.d + is(T : immutable); +//^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^ storage.type.d +// ^ keyword.operator.logical.d +// ^^^^^^^^^ storage.modifier.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + is(immutable Range == immutable T[]); +//^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^^^^ storage.modifier.d +// ^^^^^ storage.type.d +// ^^ keyword.operator.logical.d +// ^^^^^^^^^ storage.modifier.d +// ^ storage.type.d +// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d typeof(2) a(typeof('f') b); //^^^^^^ keyword.other.d @@ -1654,28 +1753,31 @@ extern(1) // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ punctuation.terminator.d - + return () @trusted inout {}; +//^^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.parens.end.d __traits(foo, a); -//^^^^^^^^ value keyword.other.d +//^^^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^^^ variable.function.d // ^ punctuation.separator.sequence.d -// ^ value value-after variable.other.d -// ^ value-after punctuation.section.parens.end.d +// ^ variable.other.d +// ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d values ~= toValue(__traits(getMember, this, primaryKey)); -//^^^^^^ first-value first-value-after variable.other.d -// ^^ value-after value keyword.operator.assignment.d -// ^^^^^^^ value value-after variable.other.d -// ^ value-after punctuation.section.parens.begin.d -// ^^^^^^^^ value keyword.other.d +//^^^^^^ variable.other.d +// ^^ keyword.operator.assignment.d +// ^^^^^^^ variable.other.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^^ variable.function.d // ^ punctuation.separator.sequence.d -// ^^^^ value value-after variable.language.d +// ^^^^ variable.language.d // ^ punctuation.separator.sequence.d -// ^^^^^^^^^^ value value-after variable.other.d -// ^^ value-after punctuation.section.parens.end.d +// ^^^^^^^^^^ variable.other.d +// ^^ punctuation.section.parens.end.d // ^ punctuation.terminator.d 3 != 3 && "s" !in [2]; @@ -1689,6 +1791,19 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d + x *= 12345; + j ^^= 11; +//^ variable.other.d +// ^^^ keyword.operator.assignment.d +// ^^ constant.numeric.integer.d +// ^ punctuation.terminator.d + k ^^ 11 == j; +//^ variable.other.d +// ^^ keyword.operator.arithmetic.d +// ^^ constant.numeric.integer.d +// ^^ keyword.operator.comparison.d +// ^ variable.other.d +// ^ punctuation.terminator.d .AliasSeq!(immutable char, int); //^^^^^^^^^ variable.other.d @@ -1711,3 +1826,70 @@ extern(1) // ^ punctuation.section.parens.end.d // ^^^^ variable.other.d // ^ punctuation.terminator.d + + void toString(Writer)(ref Writer w, const ref FormatSpec!char fmt) {} +//^^^^ storage.type.d +// ^^^^^^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^^^^^^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.modifier.d +// ^^^^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^^^ storage.modifier.d +// ^^^ storage.modifier.d +// ^^^^^^^^^^ storage.type.d +// ^ keyword.operator.d +// ^^^^ storage.type.d +// ^^^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + + auto sc1 = const(S1)(); +//^^^^ storage.modifier.d +// ^^^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^^^ storage.modifier.d +// ^ punctuation.section.group.begin.d +// ^^ storage.type.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + + auto reference = new ubyte[](2048 + 1); +//^^^^ storage.modifier.d +// ^^^^^^^^^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^ keyword.operator.word.d +// ^^^^^ storage.type.d +// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.begin.d +// ^^^^ constant.numeric.integer.d +// ^ keyword.operator.arithmetic.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + + auto staticArray(size_t n, T)(scope T a) {} +//^^^^ storage.modifier.d +// ^^^^^^^^^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^^^^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.group.begin.d +// ^^^^^ storage.modifier.d +// ^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + + char[] buffer_, encoded_; From cc328082e977810541093587ce87b41940e739f1 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 15:09:07 +1100 Subject: [PATCH 049/108] Fix some more inconsistencies --- D/D.sublime-syntax | 73 +++++++++++++++------ D/tests/syntax_test_d.d | 136 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 187 insertions(+), 22 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index eb54016424..4266bb80d2 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -29,7 +29,7 @@ variables: character_lookahead: (?=') string_lookahead: '(?=`|[rxq]?"|q{)' - definitely_value_lookahead: '(?=(!|~|\+|\-|\*|&|\bcast\b|\bdelete\b|\bnew\b|\bimport\b|\bmixin\b|\bis\b|__traits|[0-9]|\[|\(|{{string_lookahead}}|\b({{language_constant}})\b|\b({{language_variable}})\b))' + definitely_value_lookahead: '(?=(!|~|\+|\-|\*|&|\bcast\b|\bdelete\b|\bnew\b|\bimport\b|\bmixin\b|\bis\b|\b__traits\b|\bfunction\b|\bdelegate\b|[0-9]|\[|\(|{{string_lookahead}}|\b({{language_constant}})\b|\b({{language_variable}})\b))' definitely_declaration_lookahead: '(?=({{name}}|\]|\))(\s+{{name}})|\b({{type_qualifier}})\b)' type_qualifier: 'const|immutable|inout|shared' @@ -424,6 +424,15 @@ contexts: scope: storage.modifier.d - match: '(?=\b({{reserved}})\b)' pop: true + - match: '\b(this)\s*(?=\(|$)' + captures: + 1: entity.name.function.constructor.d + set: function-definition-begin + - match: '(~)\s*(this)\s*(?=\(|$)' + captures: + 1: entity.name.function.destructor.d + 2: entity.name.function.destructor.d + push: function-definition-begin - match: '(?=\b{{name}}\b\s*[,=\()])' set: [function-or-variable-after-type] - match: '(?=[^\s])' @@ -710,7 +719,7 @@ contexts: set: [function-type-after, function-type-argument-definition-list] - include: not-whitespace-illegal-pop function-type-after: - - include: attribute-in + - include: function-attribute-in - match: '(?=[^\s])' pop: true # Function type arguments are slightly different to regular function @@ -881,7 +890,6 @@ contexts: set: first-value-after - match: '(?=[^\s])' set: value - # - include: not-whitespace-illegal-pop first-value-after: - match: '\.' scope: punctuation.accessor.dot.d @@ -908,7 +916,7 @@ contexts: - match: '\b(function|delegate)\b' scope: keyword.other.d set: [function-or-variable-after-type, basic-type2, function-type] - - match: '(?={{name}}\s*([;=\(]|$))' + - match: '(?={{name}}\s*([;=\(,]|$))' set: function-or-variable-after-type - match: '(?=[^\s])' set: [value-list-after, value-after] @@ -993,6 +1001,9 @@ contexts: - match: ',' scope: punctuation.separator.sequence.d set: [value-parens-after, value-list] + - match: '\b(function|delegate)\b' + scope: keyword.other.d + set: [value-after, function-definition-begin] - match: '(\()\s*(\))' captures: 1: punctuation.section.parens.begin.d @@ -1038,6 +1049,9 @@ contexts: 1: variable.parameter.d 2: keyword.operator.lambda.d set: value + - match: '{{identifier_ref}}(?=\s*\()' + scope: variable.function.d + set: value-after - match: '{{identifier_ref}}' scope: variable.other.d set: value-after @@ -1191,6 +1205,8 @@ contexts: - match: '\?' scope: keyword.operator.logical.d set: [value-condition-after, value] + - match: '(?=function|delegate)' + set: [value-after, basic-type2] - match: '(?=[^\s])' pop: true value-condition-after: @@ -1209,7 +1225,6 @@ contexts: set: value-after - include: not-whitespace-illegal value-list: - # - meta_scope: value-list - match: '(?=\)|}|]|;)' pop: true - match: '(?=[^\s])' @@ -1371,18 +1386,11 @@ contexts: - match: '\b(enum)\b' scope: storage.type.enum.d push: + - match: '(?=\b({{basic_type}})\b)' + push: type - match: '\b({{name}})(?=\s*({|:|=|\(|$))\b' scope: entity.name.enum.d - set: - - include: end-of-line - - match: '(?={)' - set: enum-body - - match: ':' - scope: punctuation.separator.mapping.d - set: [enum-body, type] - - match: '(?==|\()' - set: enum-assignment - - include: not-whitespace-illegal + set: enum-after - match: ':' scope: punctuation.separator.mapping.d set: [enum-body, type] @@ -1390,6 +1398,18 @@ contexts: set: anonymous-enum-body - match: '(?=[^\s])' push: type + enum-after: + - include: end-of-line + - match: '(?={)' + set: enum-body + - match: ':' + scope: punctuation.separator.mapping.d + set: [enum-body, type] + - match: '(?==|\()' + set: enum-assignment + - match: '\b({{name}})\b' + scope: entity.name.enum.d + - include: not-whitespace-illegal enum-body: - match: '{' scope: punctuation.section.block.begin.d @@ -1403,10 +1423,20 @@ contexts: enum-assignment: - match: '=' scope: keyword.operator.assignment.d - set: [expect-end-of-line, value] + set: [enum-assignment-after, value] - match: '(?=\()' push: function-argument-definition-list - include: not-whitespace-illegal-pop + enum-assignment-after: + - include: end-of-line + - match: ',' + scope: punctuation.separator.sequence.d + set: + - match: '\b({{name}})\b' + scope: entity.name.enum.d + set: enum-assignment + - include: not-whitespace-illegal-pop + - include: not-whitespace-illegal-pop anonymous-enum-body: - match: '{' scope: punctuation.section.block.begin.d @@ -1484,7 +1514,7 @@ contexts: captures: 1: keyword.control.flow.d 2: keyword.control.flow.d - push: [block-statement, foreach-arguments] + push: [optional-block-statement, foreach-arguments] static-assert-in: - match: '\b(static)\s+(assert)\b' captures: @@ -1566,9 +1596,14 @@ contexts: 1: keyword.control.d 2: storage.type.d push: template - - match: '\b(mixin)\s+(?!\()' + - match: '\b(mixin)(?!\s+\()' scope: keyword.control.d - push: [expect-end-of-line, value] + push: [mixin-after, value] + mixin-after: + - match: '\b({{name}})\b' + scope: variable.other.d + set: expect-end-of-line + - include: expect-end-of-line statement-label-in: - match: '\b({{name}})\s*(:)' captures: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index d6eedecb52..84ff5d036e 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -406,6 +406,14 @@ extern(1) // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d + char[] buffer_, encoded_; +//^^^^ storage.type.d +// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^^^^^^^ variable.other.d +// ^ punctuation.separator.sequence.d +// ^^^^^^^^ variable.other.d +// ^ punctuation.terminator.d class Foo; //^^^^^ storage.type.class.d @@ -594,13 +602,53 @@ extern(1) // ^ keyword.operator.assignment.d // ^^ constant.numeric.integer.d // ^ punctuation.terminator.d - enum bool + enum fool //^^^^ storage.type.enum.d // ^^^^ entity.name.enum.d { //^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d + enum uint a = 1, b = 2, exponentBits = 3; +//^^^^ storage.type.enum.d +// ^^^^ storage.type.d +// ^ entity.name.enum.d +// ^ keyword.operator.assignment.d +// ^ constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^ entity.name.enum.d +// ^ keyword.operator.assignment.d +// ^ constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^^^^^^^^^^^^ entity.name.enum.d +// ^ keyword.operator.assignment.d +// ^ constant.numeric.integer.d +// ^ punctuation.terminator.d + enum ulong +//^^^^ storage.type.enum.d +// ^^^^^ storage.type.d + a = 1 << 2, + //^ entity.name.enum.d + // ^ keyword.operator.assignment.d + // ^ constant.numeric.integer.d + // ^^ keyword.operator.bitwise.d + // ^ constant.numeric.integer.d + // ^ punctuation.separator.sequence.d + b = 1 << 3; + //^ entity.name.enum.d + // ^ keyword.operator.assignment.d + // ^ constant.numeric.integer.d + // ^^ keyword.operator.bitwise.d + // ^ constant.numeric.integer.d + // ^ punctuation.terminator.d + enum foo +//^^^^ storage.type.enum.d +// ^^^ entity.name.enum.d + bar = 2; + //^^^ entity.name.enum.d + // ^ keyword.operator.assignment.d + // ^ constant.numeric.integer.d + // ^ punctuation.terminator.d version(unittest) {} //^^^^^^^ keyword.control.conditional.d @@ -1002,6 +1050,23 @@ extern(1) // ^^^^^^^ storage.attribute.d // ^ punctuation.terminator.d + static this(int foo) {} +//^^^^^^ storage.modifier.d +// ^^^^ entity.name.function.constructor.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^^^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + static ~this() {} +//^^^^^^ storage.modifier.d +// ^^^^^ entity.name.function.destructor.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + invariant(0, "test") { //^^^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d @@ -1090,6 +1155,11 @@ extern(1) // ^^^^^ string.quoted.double.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d + mixin Template e; +//^^^^^ keyword.control.d +// ^^^^^^^^ variable.other.d +// ^ variable.other.d +// ^ punctuation.terminator.d mixin("foo"); //^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d @@ -1757,6 +1827,30 @@ extern(1) //^^^^^^ keyword.control.flow.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d + void delegate(int) shared dg1; +//^^^^ storage.type.d +// ^^^^^^^^ keyword.other.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ punctuation.section.group.end.d +// ^^^^^^ storage.modifier.d +// ^^^ variable.other.d +// ^ punctuation.terminator.d + function(int a, string b) @trusted {}; +//^^^^^^^^ keyword.other.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.definition.annotation.begin.d +// ^^^^^^^ storage.attribute.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^ punctuation.terminator.d + __traits(foo, a); //^^^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d @@ -1791,7 +1885,6 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d - x *= 12345; j ^^= 11; //^ variable.other.d // ^^^ keyword.operator.assignment.d @@ -1892,4 +1985,41 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d - char[] buffer_, encoded_; + static foreach (Sint; AliasSeq!(S, const S, immutable S)) +//^^^^^^ keyword.control.flow.d +// ^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^^^^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^^^^^^ variable.other.d +// ^ keyword.operator.d +// ^ punctuation.section.parens.begin.d +// ^ variable.other.d +// ^ punctuation.separator.sequence.d +// ^^^^^ storage.modifier.d +// ^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^^^^^^^ storage.modifier.d +// ^ storage.type.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.brackets.end.d + static foreach (Uint; AliasSeq!(U, const U, immutable U)) {} +//^^^^^^ keyword.control.flow.d +// ^^^^^^^ keyword.control.flow.d +// ^ punctuation.section.brackets.begin.d +// ^^^^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^^^^^^ variable.other.d +// ^ keyword.operator.d +// ^ punctuation.section.parens.begin.d +// ^ variable.other.d +// ^ punctuation.separator.sequence.d +// ^^^^^ storage.modifier.d +// ^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^^^^^^^ storage.modifier.d +// ^ storage.type.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d From 7792a51be824eed51a4616bb7f5f8adae6077b7d Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 15:11:54 +1100 Subject: [PATCH 050/108] Fix *= not being parsed correctly --- D/D.sublime-syntax | 2 +- D/tests/syntax_test_d.d | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 4266bb80d2..6f0a9a3819 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -911,7 +911,7 @@ contexts: - match: ',' scope: punctuation.separator.sequence.d set: value-list - - match: '(?=\*)' + - match: '(?=\*(?!=))' set: [function-or-variable-after-type, basic-type2] - match: '\b(function|delegate)\b' scope: keyword.other.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 84ff5d036e..1be09c8251 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1897,6 +1897,11 @@ extern(1) // ^^ keyword.operator.comparison.d // ^ variable.other.d // ^ punctuation.terminator.d + x *= 12345; +//^ variable.other.d +// ^^ keyword.operator.assignment.d +// ^^^^^ constant.numeric.integer.d +// ^ punctuation.terminator.d .AliasSeq!(immutable char, int); //^^^^^^^^^ variable.other.d From b29a9d01bd8b65dbb1e4c105d4671a1a8b8ce5b8 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 15:51:38 +1100 Subject: [PATCH 051/108] Implement function contract parsing --- D/D.sublime-syntax | 40 +++++++++++++++--- D/tests/syntax_test_d.d | 92 +++++++++++++++++++++++++++++++++++++++-- 2 files changed, 123 insertions(+), 9 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 6f0a9a3819..8cf6f2d980 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -787,8 +787,35 @@ contexts: - include: function-definition-after-argument-list2 function-definition-after-argument-list2: - include: function-attribute-in - - match: '(?={|;|\bif\b)' - set: optional-template-body-block + - match: '(?={|;|\bif\b|\bin\b|\bout\b|\bdo\b)' + set: function-definition-after-arguments + - include: not-whitespace-illegal + function-definition-after-arguments: + - match: '\bif\b' + scope: keyword.control.conditional.d + set: [function-definition-after-condition, condition] + - match: '(?=[^\s])' + set: function-definition-after-condition + function-definition-after-condition: + - match: '\b(in|out)\b' + scope: keyword.control.conditional.d + set: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [function-contract-after-value, value] + - match: '{{block_statement_loohahead}}' + set: [function-definition-after-condition, block-statement] + - include: not-whitespace-illegal + - match: '\bdo\b' + scope: keyword.other.d + set: block-statement + - match: '{{block_statement_loohahead}}' + set: block-statement + - include: expect-end-of-line + function-contract-after-value: + - match: '\)' + scope: punctuation.section.parens.end.d + set: function-definition-after-condition - include: not-whitespace-illegal function-argument-definition-list: - match: '\(' @@ -885,6 +912,9 @@ contexts: - match: '\b({{basic_type}})\b' scope: storage.type.d set: first-value-after + # Check for simple function call to highlight the identifier correctly + - match: '(?={{identifier_ref}}\s*\()' + set: value - match: '{{identifier_ref}}' scope: variable.other.d set: first-value-after @@ -970,7 +1000,7 @@ contexts: set: [value-parens-after, value] - include: not-whitespace-illegal - match: '\bmixin\b' - scope: keyword.other.d + scope: keyword.control.d set: - match: '\(' scope: punctuation.section.parens.begin.d @@ -1136,7 +1166,7 @@ contexts: set: value-group-after - match: ',' scope: punctuation.separator.sequence.d - set: [value-group-after-parens, function-argument] + set: [value-group-after-parens, function-argument, function-argument-or-type] - match: '\.\.\.' scope: keyword.operator.d - include: not-whitespace-illegal @@ -1596,7 +1626,7 @@ contexts: 1: keyword.control.d 2: storage.type.d push: template - - match: '\b(mixin)(?!\s+\()' + - match: '\b(mixin)(?!\s*\()' scope: keyword.control.d push: [mixin-after, value] mixin-after: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 1be09c8251..e3558ce8b9 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1032,6 +1032,70 @@ extern(1) // ^^^^^^^^ storage.attribute.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + void f() +//^^^^ storage.type.d +// ^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d + in(true) +//^^ keyword.control.conditional.d +// ^ punctuation.section.parens.begin.d +// ^^^^ constant.language.d +// ^ punctuation.section.parens.end.d + in(true || false) +//^^ keyword.control.conditional.d +// ^ punctuation.section.parens.begin.d +// ^^^^ constant.language.d +// ^^ keyword.operator.logical.d +// ^^^^^ constant.language.d +// ^ punctuation.section.parens.end.d + out(false || true) +//^^^ keyword.control.conditional.d +// ^ punctuation.section.parens.begin.d +// ^^^^^ constant.language.d +// ^^ keyword.operator.logical.d +// ^^^^ constant.language.d +// ^ punctuation.section.parens.end.d + {} +//^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + void f(A)() if (is(A : B)) +//^^^^ storage.type.d +// ^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d +// ^^ keyword.control.conditional.d +// ^ punctuation.section.brackets.begin.d +// ^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^ storage.type.d +// ^ keyword.operator.logical.d +// ^ storage.type.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.brackets.end.d + in {} +//^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d + out { +//^^^ keyword.control.conditional.d +// ^ punctuation.section.block.begin.d + assert(true); + //^^^^^^ variable.function.d + // ^ punctuation.section.parens.begin.d + // ^^^^ constant.language.d + // ^ punctuation.section.parens.end.d + // ^ punctuation.terminator.d + } +//^ punctuation.section.block.end.d + do { +//^^ keyword.other.d +// ^ punctuation.section.block.begin.d + } +//^ punctuation.section.block.end.d this(int foo) { //^^^^ entity.name.function.constructor.d @@ -1161,7 +1225,7 @@ extern(1) // ^ variable.other.d // ^ punctuation.terminator.d mixin("foo"); -//^^^^^ keyword.other.d +//^^^^^ keyword.control.d // ^ punctuation.section.parens.begin.d // ^ punctuation.definition.string.begin.d // ^^^^^ string.quoted.double.d @@ -1529,7 +1593,7 @@ extern(1) // ^ punctuation.terminator.d mixin("a") = (12 ^^ 4) % 5 / (3++ + --4) ~ "foo"; -//^^^^^ keyword.other.d +//^^^^^ keyword.control.d // ^ punctuation.section.parens.begin.d // ^^^ string.quoted.double.d // ^ punctuation.section.parens.end.d @@ -1730,7 +1794,7 @@ extern(1) // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ storage.attribute.d // ^^ keyword.operator.lambda.d -// ^^^ variable.other.d +// ^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d @@ -1766,6 +1830,21 @@ extern(1) // ^^^^ storage.attribute.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d +// ^ punctuation.terminator.d + (a, int b, c, int d) {}; +//^ punctuation.section.group.begin.d +// ^ variable.other.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d // ^ punctuation.terminator.d void delegate(int a ..., foo) foo; @@ -1862,7 +1941,7 @@ extern(1) values ~= toValue(__traits(getMember, this, primaryKey)); //^^^^^^ variable.other.d // ^^ keyword.operator.assignment.d -// ^^^^^^^ variable.other.d +// ^^^^^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d @@ -1902,6 +1981,11 @@ extern(1) // ^^ keyword.operator.assignment.d // ^^^^^ constant.numeric.integer.d // ^ punctuation.terminator.d + foo(); +//^^^ variable.function.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d .AliasSeq!(immutable char, int); //^^^^^^^^^ variable.other.d From 2f83a67a37b7d9ff208fc8202ce2bf5d89774433 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 16:38:50 +1100 Subject: [PATCH 052/108] Fixed remaining inconsistencies again --- D/D.sublime-syntax | 107 +++++++++++++++++++++++++++++++--------- D/tests/syntax_test_d.d | 89 ++++++++++++++++++++++++++++++++- 2 files changed, 171 insertions(+), 25 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 8cf6f2d980..a30a27295e 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -38,7 +38,7 @@ variables: attributes: 'static|abstract|final|override|synchronized|scope|__gshared|nothrow|pure|ref|return|auto' at_attributes: 'disable|nogc|property|safe|system|trusted' parameter_attribute_lookahead: '(?=\b({{parameter_attribute}})\b)' - parameter_attribute: 'in|lazy|out' + parameter_attribute: 'in|lazy|out|alias' 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' @@ -88,8 +88,7 @@ contexts: - include: conditional-declaration-in - include: static-foreach-in - include: static-assert-in - - include: constructor-in - - include: destructor-in + - include: constructions-in - include: invariant-in - include: unittest-in - include: template-in @@ -132,9 +131,6 @@ contexts: pop: true - include: optional-block-statement comment-in: - # - match: /\*\*/ - # scope: comment.block.empty.d punctuation.definition.comment.d - # - include: scope:text.html.javadoc - match: /\*\*? scope: punctuation.definition.comment.d push: @@ -399,12 +395,33 @@ contexts: - match: '{{name}}' - match: '(/|&|\||-|\+|<<|<>|>>|>>>||\*|%|\^|\^\^|~)=' scope: keyword.operator.assignment.d - - match: '(/|<=|>=|==|!<>=|!<=|!>=|\.\.\.|\.\.|&|&&|\||\|\||-|--|\+|\+\+|<|<<|<>|>|>>|>>>|!|!<>|!<|!>|\(|\)|\[|\]|\{|\}|\?|,|:|\$|\*|%|\^|\^\^|~|@|=>|#)' + - match: '(/|<=|>=|==|!<>=|!<=|!>=|\.\.\.|\.\.|&|&&|\||\|\||-|--|\+|\+\+|<|<<|<>|>|>>|>>>|!|!<>|!<|!>|\?|,|:|\$|\*|%|\^|\^\^|~|@|=>|#)' scope: keyword.operator.d - match: ';' scope: punctuation.terminator.d - match: '\.' scope: keyword.operator.d + - match: '\(' + scope: punctuation.section.parens.begin.d + push: + - match: '\)' + scope: punctuation.section.parens.end.d + pop: true + - include: tokens-in + - match: '\[' + scope: punctuation.section.brackets.begin.d + push: + - match: '\]' + scope: punctuation.section.brackets.end.d + pop: true + - include: tokens-in + - match: '\{' + scope: punctuation.section.braces.begin.d + push: + - match: '\}' + scope: punctuation.section.braces.end.d + pop: true + - include: tokens-in - include: not-whitespace-illegal attribute-specifier-in: - match: '{{attribute_lookahead}}' @@ -779,18 +796,17 @@ contexts: set: variable-definition-begin function-definition-begin: - match: '(?=\()' - set: [function-definition-after-argument-list1, function-argument-definition-list] + set: [function-definition-after-first-argument-list, function-argument-definition-list] - include: not-whitespace-illegal - function-definition-after-argument-list1: + function-definition-after-first-argument-list: + - match: '=' + scope: keyword.operator.assignment.d + set: [expect-end-of-line, value] - match: '(?=\()' - set: [function-definition-after-argument-list2, function-argument-definition-list] - - include: function-definition-after-argument-list2 - function-definition-after-argument-list2: - - include: function-attribute-in - - match: '(?={|;|\bif\b|\bin\b|\bout\b|\bdo\b)' - set: function-definition-after-arguments - - include: not-whitespace-illegal + set: [function-definition-after-arguments, function-argument-definition-list] + - include: function-definition-after-arguments function-definition-after-arguments: + - include: function-attribute-in - match: '\bif\b' scope: keyword.control.conditional.d set: [function-definition-after-condition, condition] @@ -914,7 +930,7 @@ contexts: set: first-value-after # Check for simple function call to highlight the identifier correctly - match: '(?={{identifier_ref}}\s*\()' - set: value + set: [value-list-after, value] - match: '{{identifier_ref}}' scope: variable.other.d set: first-value-after @@ -1418,6 +1434,8 @@ contexts: push: - match: '(?=\b({{basic_type}})\b)' push: type + - match: '{{type_qualifier_lookahead}}' + push: type - match: '\b({{name}})(?=\s*({|:|=|\(|$))\b' scope: entity.name.enum.d set: enum-after @@ -1551,17 +1569,49 @@ contexts: 1: keyword.control.conditional.d 2: keyword.control.conditional.d push: [expect-end-of-line, assert-arguments] - constructor-in: + constructions-in: + # Post-blit constructor + - match: '\b(this)\s*(\()\s*(this)\s*(\))' + captures: + 1: entity.name.function.post-blit.d + 2: punctuation.section.group.begin.d + 3: variable.language.d + 4: punctuation.section.group.end.d + push: function-definition-after-arguments - match: '\b(this)\s*(?=\(|$)' captures: 1: entity.name.function.constructor.d - push: function-definition-begin - destructor-in: - - match: '(~)\s*(this)\s*(?=\(|$)' + 2: punctuation.section.group.begin.d + push: constructor-argument-list + - match: '(~\s*this)\s*(\()\s*(\))' captures: 1: entity.name.function.destructor.d - 2: entity.name.function.destructor.d - push: function-definition-begin + 2: punctuation.section.group.begin.d + 3: punctuation.section.group.end.d + push: function-definition-after-arguments + # This could either be function/template parameters or arguments. Assume + # arguments and switch to parameters when possible + constructor-argument-list: + - match: '\(' + scope: punctuation.section.group.begin.d + set: + - match: '\)' + scope: punctuation.section.group.end.d + set: function-definition-after-first-argument-list + - match: '{{parameter_attribute_lookahead}}' + set: [function-definition-after-first-argument-list, function-argument-definition-list-content] + - match: '(?=[^\s])' + set: [constructor-argument-list-after-value, value] + - include: not-whitespace-illegal-pop + constructor-argument-list-after-value: + - match: ',' + scope: punctuation.separator.sequence.d + set: [constructor-argument-list-after-value, value] + - match: '\)' + scope: punctuation.section.group.end.d + set: function-definition-after-first-argument-list + - match: '(?=[^\s])' + set: [function-definition-after-first-argument-list, function-argument] invariant-in: - match: '\b(invariant)\b' scope: keyword.control.flow.d @@ -1793,7 +1843,16 @@ contexts: case-after: - match: ':' scope: punctuation.section.block.begin.d - pop: true + set: + - match: '\.\.(?!\.)' + scope: keyword.operator.d + set: + - match: '\bcase\b' + scope: keyword.control.flow.d + set: [case-after, value] + - include: not-whitespace-illegal-pop + - match: '(?=[^\s])' + pop: true - include: not-whitespace-illegal-pop for-arguments: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index e3558ce8b9..00d5b47bb0 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -624,6 +624,18 @@ extern(1) // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d + enum immutable(Char)[] seqBefore = "["; +//^^^^ storage.type.enum.d +// ^^^^^^^^^ storage.modifier.d +// ^ punctuation.section.group.begin.d +// ^^^^ storage.type.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.brackets.end.d +// ^^^^^^^^^ entity.name.enum.d +// ^ keyword.operator.assignment.d +// ^^^ string.quoted.double.d +// ^ punctuation.terminator.d enum ulong //^^^^ storage.type.enum.d // ^^^^^ storage.type.d @@ -1113,6 +1125,38 @@ extern(1) // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ storage.attribute.d // ^ punctuation.terminator.d + this(this) {} +//^^^^ entity.name.function.post-blit.d + this(1, 2, 3); +//^^^^ entity.name.function.constructor.d +// ^ punctuation.section.group.begin.d +// ^ constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^ constant.numeric.integer.d +// ^ punctuation.separator.sequence.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.group.end.d +// ^ punctuation.terminator.d + this(T)(T foo); +//^^^^ entity.name.function.constructor.d +// ^ punctuation.section.group.begin.d +// ^ variable.other.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.group.begin.d +// ^ storage.type.d +// ^^^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.terminator.d + this(in ref foo t) {} +//^^^^ entity.name.function.constructor.d +// ^ punctuation.section.group.begin.d +// ^^ storage.modifier.d +// ^^^ storage.modifier.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d static this(int foo) {} //^^^^^^ storage.modifier.d @@ -1199,6 +1243,24 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + @property foo(T) = { +//^ punctuation.definition.annotation.begin.d +// ^^^^^^^^ storage.attribute.d +// ^^^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ keyword.operator.assignment.d +// ^ punctuation.section.block.begin.d + T a; + //^ storage.type.d + // ^ variable.other.d + // ^ punctuation.terminator.d + }(); +//^ punctuation.section.block.end.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d mixin template f(int a) { //^^^^^ keyword.control.d @@ -1321,7 +1383,24 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d } -//^ punctuation.section.block.end.d + for (size_t i; !val.empty; val.popFront(), ++i) {} +//^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^ storage.type.d +// ^ variable.other.d +// ^ punctuation.terminator.d +// ^ keyword.operator.logical.d +// ^^^^^^^^^ variable.other.d +// ^ punctuation.terminator.d +// ^^^^^^^^^^^^ variable.function.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.separator.sequence.d +// ^^ keyword.operator.arithmetic.d +// ^ variable.other.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d foreach (int a; 2) { //^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d @@ -1696,6 +1775,14 @@ extern(1) // ^^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d // ^ punctuation.section.block.begin.d + case 2: .. case 4: + //^^^^ keyword.control.flow.d + // ^ constant.numeric.integer.d + // ^ punctuation.section.block.begin.d + // ^^ keyword.operator.d + // ^^^^ keyword.control.flow.d + // ^ constant.numeric.integer.d + // ^ punctuation.section.block.begin.d default: //^^^^^^^ keyword.control.flow.d // ^ punctuation.section.block.begin.d From af294cbbe70f354c7cc89d9aa13412a29fca35e6 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 16:56:42 +1100 Subject: [PATCH 053/108] Fix some function/delegate inconsistencies --- D/D.sublime-syntax | 32 ++++++++++++++++++++++---------- D/tests/syntax_test_d.d | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 10 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index a30a27295e..cdf125fea6 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -746,15 +746,17 @@ contexts: - match: '\(' scope: punctuation.section.group.begin.d set: - - match: '{{type_look_ahead}}' - set: [function-type-argument, function-type-argument-type] - match: '\)' scope: punctuation.section.group.end.d pop: true - - include: not-whitespace-illegal + - match: '(?=[^\s])' + set: [function-type-argument, function-type-argument-type] - include: not-whitespace-illegal function-type-argument-type: - include: parameter-attribute-in + - match: '\.\.\.' + scope: keyword.operator.d + pop: true - include: type function-type-argument: - match: '\b{{name}}\b' @@ -839,14 +841,16 @@ contexts: set: function-argument-definition-list-content - include: not-whitespace-illegal function-argument-definition-list-content: - - match: '{{type_look_ahead}}' - set: [function-argument, function-argument-or-type] - match: '\)' scope: punctuation.section.group.end.d pop: true - - include: not-whitespace-illegal + - match: '(?=[^\s])' + set: [function-argument, function-argument-or-type] function-argument-or-type: - include: parameter-attribute-in + - match: '\.\.\.' + scope: keyword.operator.d + pop: true - match: '(?={{name}}\s*([,=:\)]|\.\.\.))' pop: true - include: type @@ -959,9 +963,9 @@ contexts: set: value-list - match: '(?=\*(?!=))' set: [function-or-variable-after-type, basic-type2] - - match: '\b(function|delegate)\b' + - match: '(?=\b(function|delegate)\b)' + set: [value-list-after, value] scope: keyword.other.d - set: [function-or-variable-after-type, basic-type2, function-type] - match: '(?={{name}}\s*([;=\(,]|$))' set: function-or-variable-after-type - match: '(?=[^\s])' @@ -1049,7 +1053,11 @@ contexts: set: [value-parens-after, value-list] - match: '\b(function|delegate)\b' scope: keyword.other.d - set: [value-after, function-definition-begin] + set: + - match: '(?=\()' + set: [value-after, function-definition-begin] + - match: '(?=[^\s])' + set: [value-after, function-definition-begin, type] - match: '(\()\s*(\))' captures: 1: punctuation.section.parens.begin.d @@ -1064,7 +1072,11 @@ contexts: - include: not-whitespace-illegal-pop - match: '\(' scope: punctuation.section.group.begin.d - set: [value-group-after, value] + set: + - match: '{{parameter_attribute_lookahead}}' + set: [value-group-after-parens, function-argument, function-argument-or-type] + - match: '(?=[^\s])' + set: [value-group-after, value] - match: '(?={)' set: [value-after, block-statement] - match: '\[' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 00d5b47bb0..d841537089 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1108,6 +1108,13 @@ extern(1) // ^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d + void f(...); +//^^^^ storage.type.d +// ^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^^^ keyword.operator.d +// ^ punctuation.section.group.end.d +// ^ punctuation.terminator.d this(int foo) { //^^^^ entity.name.function.constructor.d @@ -1993,6 +2000,15 @@ extern(1) //^^^^^^ keyword.control.flow.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d + (in ref a) {}; +//^ punctuation.section.group.begin.d +// ^^ storage.modifier.d +// ^^^ storage.modifier.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^ punctuation.terminator.d void delegate(int) shared dg1; //^^^^ storage.type.d // ^^^^^^^^ keyword.other.d @@ -2016,6 +2032,24 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d + function size_t(foo a) {}; +//^^^^^^^^ keyword.other.d +// ^^^^^^ storage.type.d +// ^ punctuation.section.group.begin.d +// ^^^ storage.type.d +// ^ variable.parameter.d +// ^ punctuation.section.group.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d +// ^ punctuation.terminator.d + void delegate(...) f; +//^^^^ storage.type.d +// ^^^^^^^^ keyword.other.d +// ^ punctuation.section.group.begin.d +// ^^^ keyword.operator.d +// ^ punctuation.section.group.end.d +// ^ variable.other.d +// ^ punctuation.terminator.d __traits(foo, a); //^^^^^^^^ keyword.other.d From ef5bcae5b671fa2e46361c5a24dca7b2b6d33d1b Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 17:07:12 +1100 Subject: [PATCH 054/108] Some remaining small fixes --- D/D.sublime-syntax | 10 +++++----- D/tests/syntax_test_d.d | 24 ++++++++++++++++++++++++ 2 files changed, 29 insertions(+), 5 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index cdf125fea6..a0341c8ca8 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -433,6 +433,7 @@ contexts: - match: ':' scope: punctuation.separator.d pop: true + - include: end-of-line - match: '{{block_statement_loohahead}}' set: block-statement - match: '{{attribute_lookahead}}' @@ -454,7 +455,6 @@ contexts: set: [function-or-variable-after-type] - match: '(?=[^\s])' set: [function-or-variable-after-type, type] - - include: not-whitespace-illegal-pop parameter-attribute-in: - match: '{{attribute_lookahead}}' push: [parameter-attribute-after, attribute] @@ -947,7 +947,7 @@ contexts: - match: '{{identifier}}' scope: variable.other.d set: first-value-after - - match: '!' + - match: '!(?!=)' scope: keyword.operator.d set: - match: '\(' @@ -961,7 +961,7 @@ contexts: - match: ',' scope: punctuation.separator.sequence.d set: value-list - - match: '(?=\*(?!=))' + - match: '(?=\*(?!=)(?!{{name}}\s*[^,=\(]))' set: [function-or-variable-after-type, basic-type2] - match: '(?=\b(function|delegate)\b)' set: [value-list-after, value] @@ -1448,7 +1448,7 @@ contexts: push: type - match: '{{type_qualifier_lookahead}}' push: type - - match: '\b({{name}})(?=\s*({|:|=|\(|$))\b' + - match: '\b({{name}})(?=\s*({|:|=|\(|;|$))\b' scope: entity.name.enum.d set: enum-after - match: ':' @@ -1469,7 +1469,7 @@ contexts: set: enum-assignment - match: '\b({{name}})\b' scope: entity.name.enum.d - - include: not-whitespace-illegal + - include: expect-end-of-line enum-body: - match: '{' scope: punctuation.section.block.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index d841537089..3601108286 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -661,6 +661,8 @@ extern(1) // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d + enum Attr; +//^^^^ storage.type.enum.d version(unittest) {} //^^^^^^^ keyword.control.conditional.d @@ -1408,6 +1410,23 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + for (; a *b < cast(int)2;) {} +//^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.terminator.d +// ^ variable.other.d +// ^ keyword.operator.arithmetic.d +// ^ variable.other.d +// ^ keyword.operator.comparison.d +// ^^^^ keyword.operator.word.d +// ^ punctuation.section.parens.begin.d +// ^^^ storage.type.d +// ^ punctuation.section.parens.end.d +// ^ constant.numeric.integer.d +// ^ punctuation.terminator.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d foreach (int a; 2) { //^^^^^^^ keyword.control.flow.d // ^ punctuation.section.brackets.begin.d @@ -2107,6 +2126,11 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d + a != 2; +//^ variable.other.d +// ^^ keyword.operator.comparison.d +// ^ constant.numeric.integer.d +// ^ punctuation.terminator.d .AliasSeq!(immutable char, int); //^^^^^^^^^ variable.other.d From 6ffd4a7fc528488e453d7a2f146d20320579166b Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 17:44:14 +1100 Subject: [PATCH 055/108] Rework tmPreferences for D --- D/Completion Rules.tmPreferences | 12 + D/Indentation Rules.tmPreferences | 17 +- D/Symbol Index Hide Ctors.tmPreferences | 12 + ...mbol List-Method-Constructor.tmPreferences | 16 -- D/old_syntax_test.d | 205 ------------------ 5 files changed, 37 insertions(+), 225 deletions(-) create mode 100644 D/Completion Rules.tmPreferences create mode 100644 D/Symbol Index Hide Ctors.tmPreferences delete mode 100644 D/Symbol List-Method-Constructor.tmPreferences delete mode 100644 D/old_syntax_test.d diff --git a/D/Completion Rules.tmPreferences b/D/Completion Rules.tmPreferences new file mode 100644 index 0000000000..33f93cb542 --- /dev/null +++ b/D/Completion Rules.tmPreferences @@ -0,0 +1,12 @@ + + + + scope + source.d + settings + + cancelCompletion + ^\s*(\}?\s*(else|try|do|finally|synchonized|struct|union|unittest|debug)|(class|struct|interface|union)\s*[a-zA-Z_0-9]+*)$ + + + diff --git a/D/Indentation Rules.tmPreferences b/D/Indentation Rules.tmPreferences index 117ea29782..daaea0656f 100644 --- a/D/Indentation Rules.tmPreferences +++ b/D/Indentation Rules.tmPreferences @@ -8,15 +8,24 @@ settings decreaseIndentPattern - ^(.*\*/)?\s*\}([^}{"']*\{)?[;\s]*(//.*|/\*.*\*/\s*)?$|^\s*(public|private|protected):\s*$ + (?x) + ^ (.*\*/)? \s* \} .* $ + | ^ \s* (public|private|protected|package): \s* $ + increaseIndentPattern - ^.*\{[^}"']*$|^\s*(public|private|protected):\s*$ + (?x) + ^ .* \{ [^}"']* $ + | ^ \s* (public|private|protected|package): \s* $ + bracketIndentNextLinePattern (?x) - ^ \s* \b(if|while|else|foreach)\b [^;]* $ - | ^ \s* \b(for)\b .* $ + ^ \s* \b(if|while|else)\b [^;]* $ + | ^ \s* \b(for|foreach|foreach_reverse)\b .* $ + + indentSquareBrackets + diff --git a/D/Symbol Index Hide Ctors.tmPreferences b/D/Symbol Index Hide Ctors.tmPreferences new file mode 100644 index 0000000000..30ad118d09 --- /dev/null +++ b/D/Symbol Index Hide Ctors.tmPreferences @@ -0,0 +1,12 @@ + + + + scope + + settings + + showInIndexedSymbolList + 0 + + + diff --git a/D/Symbol List-Method-Constructor.tmPreferences b/D/Symbol List-Method-Constructor.tmPreferences deleted file mode 100644 index 6b0b1bb0df..0000000000 --- a/D/Symbol List-Method-Constructor.tmPreferences +++ /dev/null @@ -1,16 +0,0 @@ - - - - name - Symbol List: Method / Constructor - scope - source.d meta.block entity.name - settings - - showInSymbolList - 1 - symbolTransformation - s/^\s*([^\)]+)/ $1/; # pad - - - diff --git a/D/old_syntax_test.d b/D/old_syntax_test.d deleted file mode 100644 index 2b18a0139a..0000000000 --- a/D/old_syntax_test.d +++ /dev/null @@ -1,205 +0,0 @@ - - -shared static this() -// ^ storage.modifier -// ^ storage.modifier - ^ entity.name -{ -} - -__gshared int a = 5_000; -// ^ storage.modifier -// ^ storage.type -// ^ constant.numeric -shared int b = 5000; -// ^ storage.modifier -// ^ storage.type -// ^ constant.numeric - -int c = 0x0; -// ^ constant.numeric -int d = 0x0_00; -// ^ constant.numeric -float e = .0_0; -// ^ constant.numeric - -template testTemplate(X) -{ - static if (is(X)) - // ^ storage.modifier - // ^ keyword.control - { - enum test = true; - immutable int f = 0; - // ^ storage.modifier - // ^ storage.type - } - else static if (!is(X)) - // ^ keyword.control - // ^ storage.modifier - // ^ keyword.control - { - enum test = true; - string g = "test"; - // ^ storage.type - } - else - enum test = false; -} - -@safe pure nothrow @nogc unittest {} -// ^ storage.attribute -// ^ storage.modifier -// ^ storage.modifier -// ^ storage.attribute - -auto takeByRef(ref int h) - //^ storage.type -// ^ storage.modifier - //^ storage.type -{ - synchronized - // ^ storage.modifier - { - h += 1; - } -} - -void main(char[][] args) -// ^ meta.function entity.name.function -{ -// <- meta.function meta.block - foreach(argc, argv; args) - { - // <- meta.function meta.block meta.block - auto cl = new CmdLin(argc, argv); - // ^ keyword.other - // ^ meta.block - keyword.type - writefln("%s%s arg: %s", cl.argnum, cl.suffix, cl.argv); - delete cl; - // ^ keyword.other - } - - struct specs - { - int count, allocated; - } - - specs argspecs(char[][] args) - in { - // ^ meta.function meta.block meta.function meta.block - assert (args.length > 0); - } - out (result) { - assert(result.count == CmdLin.total); - // ^ meta.block - keyword.type - assert(result.allocated > 0); - } - body { - // ^ meta.function meta.block meta.function keyword.control.statement - // ^ meta.function meta.block meta.function meta.block - specs* s = new specs; - s.count = args.length; - s.allocated = typeof(args).sizeof; - foreach(argv; args) - s.allocated += argv.length * typeof(argv[0]).sizeof; - return *s; - } - - char[] argcmsg = "argc = %d".dup; - char[] allocmsg = "allocated = %d".dup; - writefln(argcmsg ~ ", " ~ allocmsg, - argspecs(args).count,argspecs(args).allocated); -} -// ^ source.d - -class CmdLin -{ -// <- meta.class meta.block - private { - // ^ meta.class meta.block meta.block - int _argc; - char[] _argv; - static uint _totalc; - } - - public: - this(int argc, char[] argv) - { - _argc = argc + 1; - _argv = argv; - _totalc++; - } - - ~this() - // ^ entity.name - { - } - - int argnum() - { - struct Foo { - } - return _argc; - } - - char[] argv() - { - return _argv; - } - - wchar[] suffix() - // ^ storage.type - // ^ entity.name - { - wchar[] suffix; - switch(_argc) - { - case 1: - suffix = "st"w.dup; - break; - case 2: - suffix = "nd"w.dup; - break; - case 3: - suffix = "rd"w.dup; - break; - default: - suffix = "th"w.dup; - } - return suffix; - } - - static typeof(_totalc) total() - // ^ storage.modifier - // ^ storage.type - // ^ entity.name - { - return _totalc; - } - - invariant - { - assert(_argc > 0); - assert(_totalc >= _argc); - } -} - // <- - meta.class - -extern(C): -struct the_c_struct; - -class MyClass { -// <- storage.type -} - -string sA = r"$"; -// ^ punctuation.definition.string.end - -void func() -in { - assert(true); -} -do { -// <- meta.function keyword.control -} From de44796355005f455934cd2587dd3c9f5963bb8a Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 18:06:52 +1100 Subject: [PATCH 056/108] Improve sublime-build files for D --- D/D Single File.sublime-build | 13 +++++++++++++ D/D dub.sublime-build | 7 +++++++ D/D.sublime-build | 13 ------------- 3 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 D/D Single File.sublime-build create mode 100644 D/D dub.sublime-build delete mode 100644 D/D.sublime-build diff --git a/D/D Single File.sublime-build b/D/D Single File.sublime-build new file mode 100644 index 0000000000..e2fd1d6d14 --- /dev/null +++ b/D/D Single File.sublime-build @@ -0,0 +1,13 @@ +{ + "shell_cmd": "dmd $file", + "file_regex": "^(.*?)\\(([0-9]+)(,[0-9]+)?\\)", + "selector": "source.d", + + "variants": + [ + { + "name": "Run", + "shell_cmd": "rdmd $file", + } + ] +} diff --git a/D/D dub.sublime-build b/D/D dub.sublime-build new file mode 100644 index 0000000000..95ade9a285 --- /dev/null +++ b/D/D dub.sublime-build @@ -0,0 +1,7 @@ +{ + "shell_cmd": "dub build", + "file_regex": "^(.*?)\\(([0-9]+)(,[0-9]+)?\\)", + "working_dir": "${folder:${project_path:${file_path}}}", + "selector": "source.d", + "keyfiles": ["dub.sdl", "dub.json"], +} diff --git a/D/D.sublime-build b/D/D.sublime-build deleted file mode 100644 index 6fff6da06d..0000000000 --- a/D/D.sublime-build +++ /dev/null @@ -1,13 +0,0 @@ -{ - "cmd": ["dmd", "$file"], - "file_regex": "^(.*?)\\(([0-9]+)\\)", - "selector": "source.d", - - "variants": - [ - { - "name": "Run", - "cmd": ["rdmd", "$file"], - } - ] -} From 19e55761dc99929a56af6c56396056520a7a0065 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 18:49:36 +1100 Subject: [PATCH 057/108] Fix destructor with attributes not being parsed correctly --- D/D.sublime-syntax | 23 +++++++++++------------ D/tests/syntax_test_d.d | 14 ++++++++++---- 2 files changed, 21 insertions(+), 16 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index a0341c8ca8..1cc370c469 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -40,6 +40,8 @@ variables: parameter_attribute_lookahead: '(?=\b({{parameter_attribute}})\b)' parameter_attribute: 'in|lazy|out|alias' + 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' language_constant: 'null|true|false|__FILE__|__FILE_FULL_PATH__|__MODULE__|__LINE__|__FUNCTION__|__PRETTY_FUNCTION__|__DATE__|__EOF__|__TIME__|__TIMESTAMP__|__VENDOR__|__VERSION__|__ctfe' @@ -442,15 +444,8 @@ contexts: scope: storage.modifier.d - match: '(?=\b({{reserved}})\b)' pop: true - - match: '\b(this)\s*(?=\(|$)' - captures: - 1: entity.name.function.constructor.d - set: function-definition-begin - - match: '(~)\s*(this)\s*(?=\(|$)' - captures: - 1: entity.name.function.destructor.d - 2: entity.name.function.destructor.d - push: function-definition-begin + - match: '{{construction_lookahead}}' + set: construction - match: '(?=\b{{name}}\b\s*[,=\()])' set: [function-or-variable-after-type] - match: '(?=[^\s])' @@ -1582,6 +1577,9 @@ contexts: 2: keyword.control.conditional.d push: [expect-end-of-line, assert-arguments] constructions-in: + - match: '{{construction_lookahead}}' + push: construction + construction: # Post-blit constructor - match: '\b(this)\s*(\()\s*(this)\s*(\))' captures: @@ -1589,18 +1587,19 @@ contexts: 2: punctuation.section.group.begin.d 3: variable.language.d 4: punctuation.section.group.end.d - push: function-definition-after-arguments + set: function-definition-after-arguments - match: '\b(this)\s*(?=\(|$)' captures: 1: entity.name.function.constructor.d 2: punctuation.section.group.begin.d - push: constructor-argument-list + set: constructor-argument-list - match: '(~\s*this)\s*(\()\s*(\))' captures: 1: entity.name.function.destructor.d 2: punctuation.section.group.begin.d 3: punctuation.section.group.end.d - push: function-definition-after-arguments + set: function-definition-after-arguments + - include: not-whitespace-illegal-pop # This could either be function/template parameters or arguments. Assume # arguments and switch to parameters when possible constructor-argument-list: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 3601108286..7100057a5b 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1167,7 +1167,7 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d - static this(int foo) {} + static this(int foo) { int b; } //^^^^^^ storage.modifier.d // ^^^^ entity.name.function.constructor.d // ^ punctuation.section.group.begin.d @@ -1175,14 +1175,20 @@ extern(1) // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d -// ^ punctuation.section.block.end.d - static ~this() {} +// ^^^ storage.type.d +// ^ variable.other.d +// ^ punctuation.terminator.d +// ^ punctuation.section.block.end.d + static ~this() { int a; } //^^^^^^ storage.modifier.d // ^^^^^ entity.name.function.destructor.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d -// ^ punctuation.section.block.end.d +// ^^^ storage.type.d +// ^ variable.other.d +// ^ punctuation.terminator.d +// ^ punctuation.section.block.end.d invariant(0, "test") { //^^^^^^^^^ keyword.control.flow.d From 6c2cc4f6d79d3e6ab7ec109d03e444896c2a4a60 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 19:01:30 +1100 Subject: [PATCH 058/108] Add DMD output parsing for building system --- D/D dub.sublime-build | 1 + D/DMD Output.sublime-syntax | 12 ++++++++++++ 2 files changed, 13 insertions(+) create mode 100644 D/DMD Output.sublime-syntax diff --git a/D/D dub.sublime-build b/D/D dub.sublime-build index 95ade9a285..f5a35db815 100644 --- a/D/D dub.sublime-build +++ b/D/D dub.sublime-build @@ -3,5 +3,6 @@ "file_regex": "^(.*?)\\(([0-9]+)(,[0-9]+)?\\)", "working_dir": "${folder:${project_path:${file_path}}}", "selector": "source.d", + "syntax": "Packages/D/DMD Output.sublime-syntax", "keyfiles": ["dub.sdl", "dub.json"], } diff --git a/D/DMD Output.sublime-syntax b/D/DMD Output.sublime-syntax new file mode 100644 index 0000000000..84016fd6d0 --- /dev/null +++ b/D/DMD Output.sublime-syntax @@ -0,0 +1,12 @@ +%YAML 1.2 +--- +name: DMD Output +hidden: true +scope: source.build_output +contexts: + main: + - match: '^(..[^:\n]*):([0-9]+):?([0-9]+)?:? ' + - match: '^(.*?)\([0-9]+(,[0-9]+)?\): ' + scope: entity.name.filename + - match: '\b(Warning|Error): ' + scope: message.error From 8cae9fa397ef636cd1492c334ab8b49f357b5993 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 23 Jan 2019 19:06:50 +1100 Subject: [PATCH 059/108] Fix main snippets --- D/Snippets/main-with-args.sublime-snippet | 4 ++-- D/Snippets/main.sublime-snippet | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/D/Snippets/main-with-args.sublime-snippet b/D/Snippets/main-with-args.sublime-snippet index 56e9ed9fbc..9af27f97a4 100644 --- a/D/Snippets/main-with-args.sublime-snippet +++ b/D/Snippets/main-with-args.sublime-snippet @@ -1,9 +1,9 @@ - maina source.d - void main(string[] args) { … } + int main(string[] args) { … } diff --git a/D/Snippets/main.sublime-snippet b/D/Snippets/main.sublime-snippet index 80f29be6ac..c4442e4e96 100644 --- a/D/Snippets/main.sublime-snippet +++ b/D/Snippets/main.sublime-snippet @@ -1,9 +1,9 @@ - main source.d - void main() { … } + int main() { … } From 51ebb7269dac17779116950cb7ca77907700ea97 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Thu, 24 Jan 2019 10:34:38 +1100 Subject: [PATCH 060/108] Fix out contracts not being parsed correctly --- D/D.sublime-syntax | 44 ++++++-- D/tests/syntax_test_d.d | 57 +++++++---- D/tests/syntax_test_old.d | 209 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 280 insertions(+), 30 deletions(-) create mode 100644 D/tests/syntax_test_old.d diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 1cc370c469..3ae59a1595 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -810,26 +810,48 @@ contexts: - match: '(?=[^\s])' set: function-definition-after-condition function-definition-after-condition: - - match: '\b(in|out)\b' + - match: '\bin\b' scope: keyword.control.conditional.d set: - - match: '\(' - scope: punctuation.section.parens.begin.d - set: [function-contract-after-value, value] + - match: '(?=\()' + set: [function-definition-after-condition, assert-arguments] - match: '{{block_statement_loohahead}}' set: [function-definition-after-condition, block-statement] - include: not-whitespace-illegal - - match: '\bdo\b' + - match: '\bout\b' + scope: keyword.control.conditional.d + push: function-out-contract + - match: '\b(do|body)\b' scope: keyword.other.d set: block-statement - match: '{{block_statement_loohahead}}' set: block-statement - - include: expect-end-of-line - function-contract-after-value: + - include: end-of-line + - include: not-whitespace-illegal-pop + function-out-contract: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: + - match: '{{name}}' + scope: variable.parameter.d + set: + - match: ';' + scope: punctuation.separator.sequence.d + set: [function-out-contract-after, value-list] + - match: '(?=[^\s])' + set: [block-statement, function-out-contract-after] + - match: ';' + scope: punctuation.separator.sequence.d + set: [function-out-contract-after, value-list] + - include: not-whitespace-illegal-pop + - match: '{{block_statement_loohahead}}' + set: block-statement + - include: not-whitespace-illegal-pop + function-out-contract-after: - match: '\)' scope: punctuation.section.parens.end.d - set: function-definition-after-condition - - include: not-whitespace-illegal + pop: true + - include: not-whitespace-illegal-pop function-argument-definition-list: - match: '\(' scope: punctuation.section.group.begin.d @@ -1912,12 +1934,12 @@ contexts: assert-arguments: - match: '\(' - scope: punctuation.section.brackets.begin.d + scope: punctuation.section.parens.begin.d set: [assert-arguments-after, value-list] - include: not-whitespace-illegal assert-arguments-after: - match: '\)' - scope: punctuation.section.brackets.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal-pop diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 7100057a5b..bb56ed79b8 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -789,18 +789,18 @@ extern(1) static assert(12); //^^^^^^ keyword.control.conditional.d // ^^^^^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d static assert(12, "foobar"); //^^^^^^ keyword.control.conditional.d // ^^^^^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d // ^^^^^^^^ string.quoted.double.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d int[string] foo() { @@ -1063,13 +1063,14 @@ extern(1) // ^^ keyword.operator.logical.d // ^^^^^ constant.language.d // ^ punctuation.section.parens.end.d - out(false || true) + out(; false || true) //^^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d -// ^^^^^ constant.language.d -// ^^ keyword.operator.logical.d -// ^^^^ constant.language.d -// ^ punctuation.section.parens.end.d +// ^ punctuation.separator.sequence.d +// ^^^^^ constant.language.d +// ^^ keyword.operator.logical.d +// ^^^^ constant.language.d +// ^ punctuation.section.parens.end.d {} //^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -1094,9 +1095,12 @@ extern(1) //^^ keyword.control.conditional.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d - out { + out (foo) { //^^^ keyword.control.conditional.d -// ^ punctuation.section.block.begin.d +// ^ punctuation.section.parens.begin.d +// ^^^ variable.parameter.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d assert(true); //^^^^^^ variable.function.d // ^ punctuation.section.parens.begin.d @@ -1105,11 +1109,26 @@ extern(1) // ^ punctuation.terminator.d } //^ punctuation.section.block.end.d - do { -//^^ keyword.other.d -// ^ punctuation.section.block.begin.d + body { +//^^^^ keyword.other.d +// ^ punctuation.section.block.begin.d } -//^ punctuation.section.block.end.d + void f() +//^^^^ storage.type.d +// ^ entity.name.function.d +// ^ punctuation.section.group.begin.d +// ^ punctuation.section.group.end.d + out (foo; foo == true) {} +//^^^ keyword.control.conditional.d +// ^ punctuation.section.parens.begin.d +// ^^^ variable.parameter.d +// ^ punctuation.separator.sequence.d +// ^^^ variable.other.d +// ^^ keyword.operator.comparison.d +// ^^^^ constant.language.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d void f(...); //^^^^ storage.type.d // ^ entity.name.function.d @@ -1192,16 +1211,16 @@ extern(1) invariant(0, "test") { //^^^^^^^^^ keyword.control.flow.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d // ^^^^^^ string.quoted.double.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d invariant(); //^^^^^^^^^ keyword.control.flow.d - // ^ punctuation.section.brackets.begin.d - // ^ punctuation.section.brackets.end.d + // ^ punctuation.section.parens.begin.d + // ^ punctuation.section.parens.end.d invariant {} //^^^^^^^^^ keyword.control.flow.d // ^ punctuation.section.block.begin.d diff --git a/D/tests/syntax_test_old.d b/D/tests/syntax_test_old.d new file mode 100644 index 0000000000..6243a5af27 --- /dev/null +++ b/D/tests/syntax_test_old.d @@ -0,0 +1,209 @@ +// SYNTAX TEST "Packages/D/D.sublime-syntax" + +module test; + +import std.stdio; + +shared static this() +// ^ storage.modifier +// ^ storage.modifier +// ^ entity.name +{ +} + +__gshared int a = 5_000; +// ^ storage.modifier +// ^ storage.type +// ^ constant.numeric +shared int b = 5000; +// ^ storage.modifier +// ^ storage.type +// ^ constant.numeric + +int c = 0x0; +// ^ constant.numeric +int d = 0x0_00; +// ^ constant.numeric +float e = .0_0; +// ^ constant.numeric + +template testTemplate(X) +{ + static if (is(X)) + // ^ storage.modifier + // ^ keyword.control + { + enum test = true; + immutable int f = 0; + // ^ storage.modifier + // ^ storage.type + } + else static if (!is(X)) + // ^ keyword.control + // ^ storage.modifier + // ^ keyword.control + { + enum test = true; + string g = "test"; + // ^ storage.type + } + else + enum test = false; +} + +@safe pure nothrow @nogc unittest {} +// ^ storage.attribute +// ^ storage.modifier +// ^ storage.modifier +// ^ storage.attribute + +auto takeByRef(ref int h) +// ^ storage.type +// ^ storage.modifier +// ^ storage.type +{ + synchronized + // ^ storage.modifier + { + h += 1; + } +} + +void main(char[][] args) +// ^ meta.function entity.name.function +{ +// <- meta.function meta.block + foreach(argc, argv; args) + { + // <- meta.function meta.block meta.block + auto cl = new CmdLin(argc, argv); + // ^ keyword.other + // ^ meta.block - keyword.type + writefln("%s%s arg: %s", cl.argnum, cl.suffix, cl.argv); + delete cl; + // ^ keyword.other + } + + struct specs + { + int count, allocated; + } + + specs argspecs(char[][] args) + in { + // ^ meta.function meta.block meta.function meta.block + assert (args.length > 0); + } + out (result) { + assert(result.count == CmdLin.total); + // ^ meta.block - keyword.type + assert(result.allocated > 0); + } + body { + // ^ meta.function meta.block meta.function keyword.control.statement + // ^ meta.function meta.block meta.function meta.block + specs* s = new specs; + s.count = args.length; + s.allocated = typeof(args).sizeof; + foreach(argv; args) + s.allocated += argv.length * typeof(argv[0]).sizeof; + return *s; + } + + char[] argcmsg = "argc = %d".dup; + char[] allocmsg = "allocated = %d".dup; + writefln(argcmsg ~ ", " ~ allocmsg, + argspecs(args).count,argspecs(args).allocated); +} +// ^ source.d + +class CmdLin +{ +// <- meta.class meta.block + private { + // ^ meta.class meta.block meta.block + int _argc; + char[] _argv; + static uint _totalc; + } + + public: + this(int argc, char[] argv) + { + _argc = argc + 1; + _argv = argv; + _totalc++; + } + + ~this() + // ^ entity.name + { + } + + int argnum() + { + struct Foo { + } + return _argc; + } + + char[] argv() + { + return _argv; + } + + wchar[] suffix() + // ^ storage.type + // ^ entity.name + { + wchar[] suffix; + switch(_argc) + { + case 1: + suffix = "st"w.dup; + break; + case 2: + suffix = "nd"w.dup; + break; + case 3: + suffix = "rd"w.dup; + break; + default: + suffix = "th"w.dup; + } + return suffix; + } + + static typeof(_totalc) total() + // ^ storage.modifier + // ^ storage.type + // ^ entity.name + { + return _totalc; + } + + invariant + { + assert(_argc > 0); + assert(_totalc >= _argc); + } +} + // <- - meta.class + +extern(C): +struct the_c_struct; + +class MyClass { +// <- storage.type +} + +string sA = r"$"; +// ^ punctuation.definition.string.end + +void func() +in { + assert(true); +} +do { +// <- meta.function keyword.control +} From edf762f62a7e4cc3b20eb9d56745426ac3dc6733 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Thu, 24 Jan 2019 10:41:07 +1100 Subject: [PATCH 061/108] Add back old tests, fixing matches where required --- D/D.sublime-syntax | 1 + D/tests/syntax_test_old.d | 30 +++++++++++++++--------------- 2 files changed, 16 insertions(+), 15 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 3ae59a1595..18c0b87866 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -117,6 +117,7 @@ contexts: - match: '{' scope: punctuation.section.block.begin.d set: + - meta_scope: meta.block.d - match: '}' scope: punctuation.section.block.end.d pop: true diff --git a/D/tests/syntax_test_old.d b/D/tests/syntax_test_old.d index 6243a5af27..4017ab5284 100644 --- a/D/tests/syntax_test_old.d +++ b/D/tests/syntax_test_old.d @@ -21,7 +21,7 @@ shared int b = 5000; // ^ constant.numeric int c = 0x0; -// ^ constant.numeric +// ^ constant.numeric int d = 0x0_00; // ^ constant.numeric float e = .0_0; @@ -58,30 +58,30 @@ template testTemplate(X) // ^ storage.attribute auto takeByRef(ref int h) -// ^ storage.type +// ^ storage.modifier // ^ storage.modifier // ^ storage.type { synchronized - // ^ storage.modifier + // ^ keyword.other { h += 1; } } void main(char[][] args) -// ^ meta.function entity.name.function +// ^ entity.name.function { -// <- meta.function meta.block +// <- meta.block foreach(argc, argv; args) { - // <- meta.function meta.block meta.block + // <- meta.block meta.block auto cl = new CmdLin(argc, argv); - // ^ keyword.other + // ^ keyword.operator.word // ^ meta.block - keyword.type writefln("%s%s arg: %s", cl.argnum, cl.suffix, cl.argv); delete cl; - // ^ keyword.other + // ^ keyword.operator.word } struct specs @@ -91,7 +91,7 @@ void main(char[][] args) specs argspecs(char[][] args) in { - // ^ meta.function meta.block meta.function meta.block + // ^ meta.block meta.block assert (args.length > 0); } out (result) { @@ -100,8 +100,8 @@ void main(char[][] args) assert(result.allocated > 0); } body { - // ^ meta.function meta.block meta.function keyword.control.statement - // ^ meta.function meta.block meta.function meta.block + // ^ meta.block keyword.other + // ^ meta.block meta.block specs* s = new specs; s.count = args.length; s.allocated = typeof(args).sizeof; @@ -119,9 +119,9 @@ void main(char[][] args) class CmdLin { -// <- meta.class meta.block +// <- meta.block private { - // ^ meta.class meta.block meta.block + // ^ meta.block meta.block int _argc; char[] _argv; static uint _totalc; @@ -176,7 +176,7 @@ class CmdLin static typeof(_totalc) total() // ^ storage.modifier - // ^ storage.type + // ^ meta.block.d keyword.other.d // ^ entity.name { return _totalc; @@ -205,5 +205,5 @@ in { assert(true); } do { -// <- meta.function keyword.control +// <- keyword.other } From f049ab73a66246507f5f6aea987b728b1f2fc425 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Thu, 24 Jan 2019 18:48:25 +1100 Subject: [PATCH 062/108] Fix not all entities being included in symbol list --- D/Symbol List.tmPreferences | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 D/Symbol List.tmPreferences diff --git a/D/Symbol List.tmPreferences b/D/Symbol List.tmPreferences new file mode 100644 index 0000000000..c832d733de --- /dev/null +++ b/D/Symbol List.tmPreferences @@ -0,0 +1,16 @@ + + + + name + Symbol List + scope + + settings + + showInSymbolList + 1 + showInIndexedSymbolList + 1 + + + From 02902356d754d7480d5c91d2fba1e354b9d2c51f Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 26 Jan 2019 22:23:59 +1100 Subject: [PATCH 063/108] Replace `[^\s]` with `\S` --- D/D.sublime-syntax | 108 ++++++++++++++++++++++----------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 18c0b87866..a671a896ab 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -126,7 +126,7 @@ contexts: optional-block-statement: - match: '{{block_statement_loohahead}}' set: block-statement - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true optional-block-statement-or-label: - match: ':' @@ -306,7 +306,7 @@ contexts: pop: true - match: '{{hex_char}}\s*{{hex_char}}' scope: constant.character.escape.d - - match: '[^\s]' + - match: '\S' scope: invalid.illegal.unknown-escape.d # Deliminated string with custom identifier - match: 'q"({{name}})(.*)$' @@ -449,7 +449,7 @@ contexts: set: construction - match: '(?=\b{{name}}\b\s*[,=\()])' set: [function-or-variable-after-type] - - match: '(?=[^\s])' + - match: '(?=\S)' set: [function-or-variable-after-type, type] parameter-attribute-in: - match: '{{attribute_lookahead}}' @@ -469,7 +469,7 @@ contexts: - match: '\b({{type_qualifier}})\b(?!\s*\()' scope: storage.modifier.d set: parameter-attribute-after - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true function-attribute-in: - include: attribute-in @@ -496,7 +496,7 @@ contexts: - match: '\(' scope: punctuation.definition.annotation.begin.d set: [align-attribute-after, value] - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true - match: '\b(deprecated)\b' scope: keyword.other.deprecated.d @@ -504,7 +504,7 @@ contexts: - match: '\(' scope: punctuation.definition.annotation.begin.d set: [deprecated-attribute-after, value] - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true - match: '\b(private|protected|public|export)\b' scope: storage.modifier.access-control.d @@ -659,16 +659,16 @@ contexts: - match: '\(' scope: punctuation.section.group.begin.d set: [basic-type2, type-storage-modifier-end, type] - - match: '(?=[^\s])' + - match: '(?=\S)' set: type - - match: '(?=[^\s])' + - match: '(?=\S)' set: basic-type type-storage-modifier-end: - match: '\)' scope: punctuation.section.group.end.d pop: true - include: not-whitespace-illegal - # - match: '(?=[^\s])' + # - match: '(?=\S)' # scope: invalid.illegal.d basic-type: - match: '\btypeof\b' @@ -684,7 +684,7 @@ contexts: scope: storage.type.d set: basic-type2 # TODO: More basic types - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true basic-type2: - match: '\*' @@ -701,7 +701,7 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [basic-type2, basic-type2-after-parens, value-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: value - match: '\.(?!\.\.)' scope: storage.type.d @@ -709,7 +709,7 @@ contexts: - match: '\b({{name}})\b' scope: storage.type.d set: basic-type2 - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true basic-type2-after-brackets: - match: '\]' @@ -733,7 +733,7 @@ contexts: - include: not-whitespace-illegal-pop function-type-after: - include: function-attribute-in - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true # Function type arguments are slightly different to regular function # arguments. With regular arguments a standalone "name" is asssumed to be a @@ -745,7 +745,7 @@ contexts: - match: '\)' scope: punctuation.section.group.end.d pop: true - - match: '(?=[^\s])' + - match: '(?=\S)' set: [function-type-argument, function-type-argument-type] - include: not-whitespace-illegal function-type-argument-type: @@ -790,7 +790,7 @@ contexts: captures: 1: entity.name.function.d set: function-definition-begin - - match: '(?=[^\s])' + - match: '(?=\S)' set: variable-definition-begin function-definition-begin: - match: '(?=\()' @@ -808,7 +808,7 @@ contexts: - match: '\bif\b' scope: keyword.control.conditional.d set: [function-definition-after-condition, condition] - - match: '(?=[^\s])' + - match: '(?=\S)' set: function-definition-after-condition function-definition-after-condition: - match: '\bin\b' @@ -839,7 +839,7 @@ contexts: - match: ';' scope: punctuation.separator.sequence.d set: [function-out-contract-after, value-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: [block-statement, function-out-contract-after] - match: ';' scope: punctuation.separator.sequence.d @@ -862,7 +862,7 @@ contexts: - match: '\)' scope: punctuation.section.group.end.d pop: true - - match: '(?=[^\s])' + - match: '(?=\S)' set: [function-argument, function-argument-or-type] function-argument-or-type: - include: parameter-attribute-in @@ -928,7 +928,7 @@ contexts: push: [maybe-end-of-line, value-list] - match: '{{definitely_declaration_lookahead}}' push: [function-or-variable-after-type, type] - - match: '(?=[^\s])' + - match: '(?=\S)' push: [maybe-end-of-line, first-value] value-or-declaration: - match: '\s' @@ -936,7 +936,7 @@ contexts: set: value-list - match: '{{definitely_declaration_lookahead}}' set: [function-or-variable-after-type, type] - - match: '(?=[^\s])' + - match: '(?=\S)' set: first-value # The first value in an expression ending with a * is always a function/variable definition, otherwise it could be either # We highlight as if it were a value, but switch to a definition if it turns out to be one @@ -956,7 +956,7 @@ contexts: - match: '{{identifier_ref}}' scope: variable.other.d set: first-value-after - - match: '(?=[^\s])' + - match: '(?=\S)' set: value first-value-after: - match: '\.' @@ -971,7 +971,7 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [first-value-parens-after, value-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: first-value - match: '\[' scope: punctuation.section.brackets.begin.d @@ -986,7 +986,7 @@ contexts: scope: keyword.other.d - match: '(?={{name}}\s*([;=\(,]|$))' set: function-or-variable-after-type - - match: '(?=[^\s])' + - match: '(?=\S)' set: [value-list-after, value-after] first-value-bracket-after: - match: '\]' @@ -1028,7 +1028,7 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [new-after-parens, value-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: new-after - match: '\bimport\b' scope: keyword.declaration.d @@ -1074,7 +1074,7 @@ contexts: set: - match: '(?=\()' set: [value-after, function-definition-begin] - - match: '(?=[^\s])' + - match: '(?=\S)' set: [value-after, function-definition-begin, type] - match: '(\()\s*(\))' captures: @@ -1093,7 +1093,7 @@ contexts: set: - match: '{{parameter_attribute_lookahead}}' set: [value-group-after-parens, function-argument, function-argument-or-type] - - match: '(?=[^\s])' + - match: '(?=\S)' set: [value-group-after, value] - match: '(?={)' set: [value-after, block-statement] @@ -1151,16 +1151,16 @@ contexts: set: [new-anonymous-after-args, value-list] - match: '(?={)' set: optional-template-body-block - - match: '(?=[^\s])' + - match: '(?=\S)' set: [optional-template-body-block, base-class-list] - - match: (?=[^\s]) + - match: (?=\S) set: [new-after-named, type] - include: not-whitespace-illegal new-after-named: - match: '\(' scope: punctuation.section.parens.begin.d set: [value-parens-after, value-list] - - match: (?=[^\s]) + - match: (?=\S) set: value-after new-anonymous-after-args: - match: '\)' @@ -1168,7 +1168,7 @@ contexts: set: - match: '(?={)' set: optional-template-body-block - - match: '(?=[^\s])' + - match: '(?=\S)' set: [optional-template-body-block, base-class-list] - include: not-whitespace-illegal is-after-type: @@ -1197,7 +1197,7 @@ contexts: - match: '(?=\))' pop: true - include: type-specialization - - match: '(?=[^\s])' + - match: '(?=\S)' set: type - include: not-whitespace-illegal-pop value-group-after: @@ -1223,7 +1223,7 @@ contexts: - match: '=>' scope: keyword.operator.lambda.d set: value - - match: (?=[^\s]) + - match: (?=\S) set: value-after value-after: - match: '\.\.(?!\.)' @@ -1268,7 +1268,7 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [value-parens-after, value-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: value # This can also be a pointer in some situations - match: \* @@ -1276,14 +1276,14 @@ contexts: set: - match: '(?=\)|,|;)' pop: true - - match: '(?=[^\s])' + - match: '(?=\S)' set: value - match: '\?' scope: keyword.operator.logical.d set: [value-condition-after, value] - match: '(?=function|delegate)' set: [value-after, basic-type2] - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true value-condition-after: - match: ':' @@ -1303,7 +1303,7 @@ contexts: value-list: - match: '(?=\)|}|]|;)' pop: true - - match: '(?=[^\s])' + - match: '(?=\S)' set: [value-list-after, value] value-list-after: - match: '(?=\)|}|]|;)' @@ -1315,7 +1315,7 @@ contexts: value-array-list: - match: '(?=\])' pop: true - - match: '(?=[^\s])' + - match: '(?=\S)' set: [value-array-list-after, value] value-array-list-after: - match: ':' @@ -1389,7 +1389,7 @@ contexts: set: - match: '(?=\()' set: [class-after, function-argument-definition-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: class-after - include: not-whitespace-illegal class-after: @@ -1397,7 +1397,7 @@ contexts: - match: ':' scope: punctuation.separator.mapping.d set: [optional-template-body-block, base-class-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: optional-template-body-block base-class-list: - match: '{{type_look_ahead}}' @@ -1419,7 +1419,7 @@ contexts: set: - match: '(?=\()' set: [interface-after, function-argument-definition-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: interface-after - include: not-whitespace-illegal interface-after: @@ -1439,7 +1439,7 @@ contexts: set: - match: '(?=\()' set: [optional-template-body-block, function-argument-definition-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: optional-template-body-block - match: '(?={)' set: optional-template-body-block @@ -1453,7 +1453,7 @@ contexts: set: - match: '(?=\()' set: [optional-template-body-block, function-argument-definition-list] - - match: '(?=[^\s])' + - match: '(?=\S)' set: optional-template-body-block - match: '(?={)' set: optional-template-body-block @@ -1474,7 +1474,7 @@ contexts: set: [enum-body, type] - match: '(?={)' set: anonymous-enum-body - - match: '(?=[^\s])' + - match: '(?=\S)' push: type enum-after: - include: end-of-line @@ -1585,7 +1585,7 @@ contexts: - match: '{{integer_lookahead}}' set: [version-condition-end, integer] - include: not-whitespace-illegal - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true static-foreach-in: - match: '\b(static)\s+(foreach|foreach_reverse)\b' @@ -1634,7 +1634,7 @@ contexts: set: function-definition-after-first-argument-list - match: '{{parameter_attribute_lookahead}}' set: [function-definition-after-first-argument-list, function-argument-definition-list-content] - - match: '(?=[^\s])' + - match: '(?=\S)' set: [constructor-argument-list-after-value, value] - include: not-whitespace-illegal-pop constructor-argument-list-after-value: @@ -1644,7 +1644,7 @@ contexts: - match: '\)' scope: punctuation.section.group.end.d set: function-definition-after-first-argument-list - - match: '(?=[^\s])' + - match: '(?=\S)' set: [function-definition-after-first-argument-list, function-argument] invariant-in: - match: '\b(invariant)\b' @@ -1755,7 +1755,7 @@ contexts: scope: keyword.control.flow.d push: - include: end-of-line - - match: '(?=[^\s])' + - match: '(?=\S)' set: [expect-end-of-line, value] - match: '\bgoto\b' scope: keyword.control.flow.d @@ -1767,7 +1767,7 @@ contexts: scope: keyword.control.flow.d set: - include: end-of-line - - match: '(?=[^\s])' + - match: '(?=\S)' set: [expect-end-of-line, value] - match: '\b{{name}}\b' scope: variable.other.constant.d @@ -1793,7 +1793,7 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [synchronized-after, value] - - match: '(?=[^\s])' + - match: '(?=\S)' set: optional-block-statement synchronized-after: - match: '\)' @@ -1885,7 +1885,7 @@ contexts: scope: keyword.control.flow.d set: [case-after, value] - include: not-whitespace-illegal-pop - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true - include: not-whitespace-illegal-pop @@ -1909,7 +1909,7 @@ contexts: - match: '(?=\b{{name}}\s*[;,])' set: foreach-parameter-after-type - include: parameter-attribute-in - - match: '(?=[^\s])' + - match: '(?=\S)' set: [foreach-parameter-after-type, type] foreach-parameter-after-type: - match: '\b({{name}})\b' @@ -1955,10 +1955,10 @@ contexts: pop: true - include: not-whitespace-illegal-pop not-whitespace-illegal: - - match: '[^\s]' + - match: '\S' scope: invalid.illegal.d not-whitespace-illegal-pop: - - match: '[^\s]' + - match: '\S' scope: invalid.illegal.d pop: true end-of-line-in: @@ -1973,5 +1973,5 @@ contexts: - include: not-whitespace-illegal-pop maybe-end-of-line: - include: end-of-line - - match: '(?=[^\s])' + - match: '(?=\S)' pop: true From c7a789e2a3c91a46019c36b933ecebf9451765c6 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 26 Jan 2019 22:25:40 +1100 Subject: [PATCH 064/108] Replace `(?=.)` with '' --- D/D.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index a671a896ab..9e77638494 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -64,7 +64,7 @@ contexts: - match: '^#!.*$' scope: comment.line.shebang.d set: main-after-shebang-in - - match: '(?=.)' + - match: '' set: main-after-shebang-in main-after-shebang-in: - include: attribute-specifier-in From 78effb9c2a4923d0830780294dfc24e769d53b94 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 26 Jan 2019 22:39:07 +1100 Subject: [PATCH 065/108] Add meta.namespace scope for files declaring a module name --- D/D.sublime-syntax | 6 ++++-- D/tests/syntax_test_d.d | 13 +++++++------ 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 9e77638494..1f46712c9e 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -69,12 +69,14 @@ contexts: main-after-shebang-in: - include: attribute-specifier-in - match: '\b(module)\s+({{identifier}})(;)' - scope: meta.module.d + # scope: meta.namespace.d captures: 1: keyword.control.module.d 2: entity.name.namespace.d 3: punctuation.terminator.d - set: statement-list-in + set: + - meta_scope: meta.namespace.d + - include: statement-list-in - match: '\s' - match: (?=.) set: statement-list-in diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index bb56ed79b8..b5402d14b4 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1,13 +1,14 @@ // SYNTAX TEST "Packages/D/D.sublime-syntax" module foo.a.b1_3; -// <- meta.module.d keyword.control.module.d - // <- meta.module.d keyword.control.module.d -//^^^^ meta.module.d keyword.control.module.d -// ^^^^^^^^^^ meta.module.d entity.name.namespace.d -// ^ meta.module.d punctuation.terminator.d +// <- meta.namespace.d keyword.control.module.d + // <- meta.namespace.d keyword.control.module.d +//^^^^ meta.namespace.d keyword.control.module.d +// ^^^^^^^^^^ meta.namespace.d entity.name.namespace.d +// ^ meta.namespace.d punctuation.terminator.d module foo.a.b1_3; -//^^^^^^^^^^^^^^^^^^ - meta.module.d +//^^^^^^ - keyword.control.module +// ^^^^^^^^^^ - entity.name.namespace /+ //^^ comment.block.nested.d punctuation.definition.comment.d From 8b65012015a8a3b19d756c9a85db39afbd55a9a4 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 26 Jan 2019 22:52:48 +1100 Subject: [PATCH 066/108] Improve shebang handling --- D/D.sublime-syntax | 7 +++++-- D/tests/syntax_test_shebang.d | 8 ++++---- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 1f46712c9e..2371d50cc4 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -61,8 +61,11 @@ contexts: main: - meta_include_prototype: false - - match: '^#!.*$' - scope: comment.line.shebang.d + - match: '^(#)!(.*)$' + scope: comment.line.number-sign.d + captures: + 1: punctuation.definition.comment.number-sign + 2: source.shell set: main-after-shebang-in - match: '' set: main-after-shebang-in diff --git a/D/tests/syntax_test_shebang.d b/D/tests/syntax_test_shebang.d index 84ac960208..84d105aec8 100644 --- a/D/tests/syntax_test_shebang.d +++ b/D/tests/syntax_test_shebang.d @@ -1,10 +1,10 @@ #! SYNTAX TEST "Packages/D/D.sublime-syntax" -#! <- comment.line.shebang.d - #! <- comment.line.shebang.d -#!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.shebang.d +#! <- comment.line.number-sign.d punctuation.definition.comment.number-sign + #! <- comment.line.number-sign.d +#!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.number-sign.d // foo #! ^^^ comment.line.double-slash.d #! foo -#! ^^^ - comment.line.shebang.d +#! ^^^ - comment.line.number-sign.d From 475a8a840e73cd3945037f2994216ef38a11c538 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 26 Jan 2019 22:54:19 +1100 Subject: [PATCH 067/108] s/keyword.control.module.d/keyword.declaration.module.d/g --- D/D.sublime-syntax | 2 +- D/tests/syntax_test_d.d | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 2371d50cc4..712704dfc4 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -74,7 +74,7 @@ contexts: - match: '\b(module)\s+({{identifier}})(;)' # scope: meta.namespace.d captures: - 1: keyword.control.module.d + 1: keyword.declaration.module.d 2: entity.name.namespace.d 3: punctuation.terminator.d set: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index b5402d14b4..8cf06729cb 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1,9 +1,9 @@ // SYNTAX TEST "Packages/D/D.sublime-syntax" module foo.a.b1_3; -// <- meta.namespace.d keyword.control.module.d - // <- meta.namespace.d keyword.control.module.d -//^^^^ meta.namespace.d keyword.control.module.d +// <- meta.namespace.d keyword.declaration.module.d + // <- meta.namespace.d keyword.declaration.module.d +//^^^^ meta.namespace.d keyword.declaration.module.d // ^^^^^^^^^^ meta.namespace.d entity.name.namespace.d // ^ meta.namespace.d punctuation.terminator.d module foo.a.b1_3; From e8b230d67f443b92e0cb3317a06ead22dbbda545 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Sat, 26 Jan 2019 22:57:08 +1100 Subject: [PATCH 068/108] Clean up parser a little --- D/D.sublime-syntax | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 712704dfc4..7264bba1c6 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -72,7 +72,6 @@ contexts: main-after-shebang-in: - include: attribute-specifier-in - match: '\b(module)\s+({{identifier}})(;)' - # scope: meta.namespace.d captures: 1: keyword.declaration.module.d 2: entity.name.namespace.d @@ -80,8 +79,7 @@ contexts: set: - meta_scope: meta.namespace.d - include: statement-list-in - - match: '\s' - - match: (?=.) + - match: (?=\S) set: statement-list-in statement-list-in: - include: import-in @@ -928,7 +926,6 @@ contexts: set: variable-definition-begin - include: expect-end-of-line value-or-declaration-in: - - match: '\s' - match: '{{definitely_value_lookahead}}' push: [maybe-end-of-line, value-list] - match: '{{definitely_declaration_lookahead}}' @@ -936,7 +933,6 @@ contexts: - match: '(?=\S)' push: [maybe-end-of-line, first-value] value-or-declaration: - - match: '\s' - match: '{{definitely_value_lookahead}}' set: value-list - match: '{{definitely_declaration_lookahead}}' From a1934d0b50bd3af51adbebb5ed51d3d6891100a7 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 4 Feb 2019 10:16:37 +1100 Subject: [PATCH 069/108] Fix indentation and improve spacing --- D/D.sublime-syntax | 78 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 7264bba1c6..9f6f805cb5 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -81,6 +81,7 @@ contexts: - include: statement-list-in - match: (?=\S) set: statement-list-in + statement-list-in: - include: import-in - include: alias-in @@ -113,6 +114,7 @@ contexts: - include: statement-label-in - include: end-of-line-in - include: value-or-declaration-in + block-statement-in: - match: '{{block_statement_loohahead}}' push: block-statement @@ -131,11 +133,13 @@ contexts: set: block-statement - match: '(?=\S)' pop: true + optional-block-statement-or-label: - match: ':' scope: punctuation.separator.d pop: true - include: optional-block-statement + comment-in: - match: /\*\*? scope: punctuation.definition.comment.d @@ -158,6 +162,7 @@ contexts: scope: punctuation.definition.comment.d pop: true - include: nested-comment + number-in: - match: '{{number_lookahead}}' push: number @@ -167,6 +172,7 @@ contexts: number: - include: number-opt - include: not-whitespace-illegal + integer: - include: integer-opt - include: not-whitespace-illegal @@ -188,6 +194,7 @@ contexts: 2: constant.numeric.hex.d 3: storage.type.integer.d pop: true + floating-point: - include: floating-point-opt - include: not-whitespace-illegal @@ -239,6 +246,7 @@ contexts: 2: constant.numeric.float.d 3: storage.type.float.d pop: true + character-in: - match: '{{character_lookahead}}' push: character @@ -252,6 +260,7 @@ contexts: scope: invalid.illegal.d pop: true - include: not-whitespace-illegal-pop + string-in: - match: '{{string_lookahead}}' push: string @@ -385,7 +394,8 @@ contexts: scope: string.unquoted.embedded.d punctuation.definition.string.end.d pop: true - include: tokens-in - # Purely a set of un-verified tokens, for use in token string + + # Purely a set of un-verified tokens tokens-in: - match: '\b({{keyword}})\b' scope: keyword.d @@ -429,6 +439,7 @@ contexts: pop: true - include: tokens-in - include: not-whitespace-illegal + attribute-specifier-in: - match: '{{attribute_lookahead}}' push: [attribute-specifier-after, attribute] @@ -454,6 +465,7 @@ contexts: set: [function-or-variable-after-type] - match: '(?=\S)' set: [function-or-variable-after-type, type] + parameter-attribute-in: - match: '{{attribute_lookahead}}' push: [parameter-attribute-after, attribute] @@ -474,13 +486,16 @@ contexts: set: parameter-attribute-after - match: '(?=\S)' pop: true + function-attribute-in: - include: attribute-in - match: '\b({{type_qualifier}})\b' scope: storage.modifier.d + attribute-in: - match: '{{attribute_lookahead}}' push: attribute + attribute: - match: '\b({{attributes}})\b' scope: storage.modifier.d @@ -590,6 +605,7 @@ contexts: scope: punctuation.definition.annotation.end.d pop: true - include: not-whitespace-illegal-pop + import-in: - match: '\b(import)(?!\s*\()\b' scope: keyword.control.import.d @@ -655,6 +671,7 @@ contexts: - include: not-whitespace-illegal - include: not-whitespace-illegal - include: not-whitespace-illegal + type: - match: '\b({{type_qualifier}})\b' scope: storage.modifier.d @@ -671,8 +688,7 @@ contexts: scope: punctuation.section.group.end.d pop: true - include: not-whitespace-illegal - # - match: '(?=\S)' - # scope: invalid.illegal.d + basic-type: - match: '\btypeof\b' scope: keyword.other.d @@ -686,9 +702,9 @@ contexts: - match: '{{identifier_ref}}' scope: storage.type.d set: basic-type2 - # TODO: More basic types - match: '(?=\S)' pop: true + basic-type2: - match: '\*' scope: keyword.operator.pointer.d @@ -724,6 +740,7 @@ contexts: scope: punctuation.section.brackets.end.d pop: true - include: not-whitespace-illegal-pop + typeof-value: - match: '\breturn\b' scope: keyword.other.d @@ -738,6 +755,7 @@ contexts: - include: function-attribute-in - match: '(?=\S)' pop: true + # Function type arguments are slightly different to regular function # arguments. With regular arguments a standalone "name" is asssumed to be a # template argument, but with function types they must be a type. @@ -901,6 +919,7 @@ contexts: scope: punctuation.section.group.end.d pop: true - include: not-whitespace-illegal + optional-template-body-block: - match: '{{block_statement_loohahead}}' set: block-statement @@ -909,6 +928,7 @@ contexts: set: [block-statement, condition] - include: end-of-line - include: not-whitespace-illegal + variable-definition-begin: - match: '\b{{name}}\b' scope: variable.other.d @@ -925,6 +945,7 @@ contexts: scope: punctuation.separator.sequence.d set: variable-definition-begin - include: expect-end-of-line + value-or-declaration-in: - match: '{{definitely_value_lookahead}}' push: [maybe-end-of-line, value-list] @@ -939,6 +960,7 @@ contexts: set: [function-or-variable-after-type, type] - match: '(?=\S)' set: first-value + # The first value in an expression ending with a * is always a function/variable definition, otherwise it could be either # We highlight as if it were a value, but switch to a definition if it turns out to be one first-value: @@ -999,6 +1021,7 @@ contexts: scope: punctuation.section.parens.end.d set: first-value-after - include: not-whitespace-illegal + value: - include: attribute-in - match: '!' @@ -1301,6 +1324,7 @@ contexts: scope: punctuation.section.brackets.end.d set: value-after - include: not-whitespace-illegal + value-list: - match: '(?=\)|}|]|;)' pop: true @@ -1313,6 +1337,7 @@ contexts: scope: punctuation.separator.sequence.d set: value-list - include: not-whitespace-illegal + value-array-list: - match: '(?=\])' pop: true @@ -1330,6 +1355,7 @@ contexts: scope: punctuation.separator.sequence.d set: value-array-list - include: not-whitespace-illegal + alias-in: - match: '\b(alias)\s+({{identifier}})\s+(this)(;)' captures: @@ -1380,7 +1406,7 @@ contexts: set: alias-new - include: not-whitespace-illegal - include: not-whitespace-illegal - # TODO: Templated aggregates!! + class-in: - match: '\b(class)\b' scope: storage.type.class.d @@ -1400,6 +1426,7 @@ contexts: set: [optional-template-body-block, base-class-list] - match: '(?=\S)' set: optional-template-body-block + base-class-list: - match: '{{type_look_ahead}}' set: [base-class-list-after, basic-type] @@ -1411,6 +1438,7 @@ contexts: - match: '(?={)' pop: true - include: not-whitespace-illegal + interface-in: - match: '\b(interface)\b' scope: storage.type.interface.d @@ -1431,6 +1459,7 @@ contexts: - match: '(?={)' set: optional-template-body-block - include: not-whitespace-illegal + struct-in: - match: '\b(struct)\b' scope: storage.type.struct.d @@ -1445,6 +1474,7 @@ contexts: - match: '(?={)' set: optional-template-body-block - include: not-whitespace-illegal + union-in: - match: '\b(union)\b' scope: storage.type.union.d @@ -1459,6 +1489,7 @@ contexts: - match: '(?={)' set: optional-template-body-block - include: not-whitespace-illegal + enum-in: - match: '\b(enum)\b' scope: storage.type.enum.d @@ -1489,6 +1520,7 @@ contexts: - match: '\b({{name}})\b' scope: entity.name.enum.d - include: expect-end-of-line + enum-body: - match: '{' scope: punctuation.section.block.begin.d @@ -1499,6 +1531,7 @@ contexts: - match: '(?=\b({{name}})\b)' push: enum-member - include: not-whitespace-illegal + enum-assignment: - match: '=' scope: keyword.operator.assignment.d @@ -1516,6 +1549,7 @@ contexts: set: enum-assignment - include: not-whitespace-illegal-pop - include: not-whitespace-illegal-pop + anonymous-enum-body: - match: '{' scope: punctuation.section.block.begin.d @@ -1529,6 +1563,7 @@ contexts: - match: '{{type_look_ahead}}' push: [enum-member, type] - include: not-whitespace-illegal + enum-member: - match: '\b({{name}})\b' scope: entity.name.constant.d @@ -1550,6 +1585,7 @@ contexts: - match: '(?=})' pop: true - include: not-whitespace-illegal-pop + conditional-declaration-in: - match: '\b(version)\b' scope: keyword.control.conditional.d @@ -1557,6 +1593,7 @@ contexts: - match: '\b(debug)\b' scope: keyword.control.conditional.d push: [optional-block-statement-or-label, debug-condition] + version-condition: - match: '\(' scope: punctuation.section.brackets.begin.d @@ -1576,6 +1613,7 @@ contexts: scope: punctuation.section.brackets.end.d pop: true - include: not-whitespace-illegal + debug-condition: - match: '\(' scope: punctuation.section.brackets.begin.d @@ -1588,18 +1626,21 @@ contexts: - include: not-whitespace-illegal - match: '(?=\S)' pop: true + static-foreach-in: - match: '\b(static)\s+(foreach|foreach_reverse)\b' captures: 1: keyword.control.flow.d 2: keyword.control.flow.d push: [optional-block-statement, foreach-arguments] + static-assert-in: - match: '\b(static)\s+(assert)\b' captures: 1: keyword.control.conditional.d 2: keyword.control.conditional.d push: [expect-end-of-line, assert-arguments] + constructions-in: - match: '{{construction_lookahead}}' push: construction @@ -1647,6 +1688,7 @@ contexts: set: function-definition-after-first-argument-list - match: '(?=\S)' set: [function-definition-after-first-argument-list, function-argument] + invariant-in: - match: '\b(invariant)\b' scope: keyword.control.flow.d @@ -1660,14 +1702,15 @@ contexts: - match: '{' scope: punctuation.section.block.begin.d set: - - match: '}' - scope: punctuation.section.block.end.d - pop: true - - include: statement-list-in + - match: '}' + scope: punctuation.section.block.end.d + pop: true + - include: statement-list-in - match: ';' scope: punctuation.terminator.d pop: true - include: not-whitespace-illegal + unittest-in: - match: '\b(unittest)\b' scope: keyword.control.conditional.d @@ -1680,6 +1723,7 @@ contexts: pop: true - include: statement-list-in - include: not-whitespace-illegal + specification-in: - match: '\b(version|debug)\s*(=)' captures: @@ -1692,6 +1736,7 @@ contexts: - match: '{{integer_lookahead}}' set: [expect-end-of-line, integer] - include: not-whitespace-illegal + template-in: - match: '\b(template)\b' scope: storage.type.d @@ -1705,6 +1750,7 @@ contexts: - match: '(?=\()' set: [optional-template-body-block, function-argument-definition-list] - include: not-whitespace-illegal + mixin-in: - match: '\b(mixin)\s+(template)\b' captures: @@ -1719,11 +1765,13 @@ contexts: scope: variable.other.d set: expect-end-of-line - include: expect-end-of-line + statement-label-in: - match: '\b({{name}})\s*(:)' captures: 1: entity.name.label.d 2: punctuation.separator.d + conditional-in: - match: '\bif\b' scope: keyword.control.conditional.d @@ -1731,6 +1779,7 @@ contexts: - match: '\belse\b' scope: keyword.control.conditional.d push: optional-block-statement-or-label + loop-in: - match: '\bwhile\b' scope: keyword.control.flow.d @@ -1744,6 +1793,7 @@ contexts: - match: '\b(foreach|foreach_reverse)\b' scope: keyword.control.flow.d push: [optional-block-statement, foreach-arguments] + flow-statement-in: - match: '\b(continue|break)\b' scope: keyword.control.flow.d @@ -1774,6 +1824,7 @@ contexts: scope: variable.other.constant.d set: expect-end-of-line - include: not-whitespace-illegal + with-in: - match: '\bwith\b' scope: keyword.other.with.d @@ -1787,6 +1838,7 @@ contexts: scope: punctuation.section.parens.end.d set: optional-block-statement - include: not-whitespace-illegal-pop + synchronized-in: - match: '\bsynchronized\b' scope: keyword.other.synchronized.d @@ -1801,6 +1853,7 @@ contexts: scope: punctuation.section.parens.end.d set: optional-block-statement - include: not-whitespace-illegal-pop + try-in: - match: '\btry\b' scope: keyword.control.flow.d @@ -1828,10 +1881,12 @@ contexts: scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal + throw-in: - match: '\bthrow\b' scope: keyword.control.flow.d push: [expect-end-of-line, value] + scope-in: - match: '\b(scope)\s*(\()\s*(exit|success|failure)\s*(\))' captures: @@ -1840,6 +1895,7 @@ contexts: 3: keyword.control.flow.d 4: punctuation.section.parens.end.d push: optional-block-statement + asm-in: - match: '\basm\b' scope: keyword.declaration.asm.d @@ -1853,6 +1909,7 @@ contexts: pop: true - include: tokens-in - include: not-whitespace-illegal + switch-in: - match: '\bswitch\b' scope: keyword.control.flow.d @@ -1899,6 +1956,7 @@ contexts: pop: true - include: statement-list-in - include: not-whitespace-illegal-pop + foreach-arguments: - match: '\(' scope: punctuation.section.brackets.begin.d @@ -1955,6 +2013,7 @@ contexts: scope: punctuation.section.brackets.end.d pop: true - include: not-whitespace-illegal-pop + not-whitespace-illegal: - match: '\S' scope: invalid.illegal.d @@ -1962,6 +2021,7 @@ contexts: - match: '\S' scope: invalid.illegal.d pop: true + end-of-line-in: - match: ';' scope: punctuation.terminator.d From 346b883839d64fc47bf84084e5e605fea7105a46 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 5 Feb 2019 11:25:47 +1100 Subject: [PATCH 070/108] Change storage.modifier to punctuation.definition.numeric for binary and hex prefixes --- D/D.sublime-syntax | 10 +++++----- D/tests/syntax_test_d.d | 20 ++++++++++---------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 9f6f805cb5..73d7fdee43 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -184,13 +184,13 @@ contexts: pop: true - match: '\b(0[bB])([01][01_]*)({{integer_suffix}})?\b' captures: - 1: storage.modifier.d + 1: punctuation.definition.numeric.binary.d 2: constant.numeric.binary.d 3: storage.type.integer.d pop: true - match: '\b(0[xX])({{hex_char}}(?:_|{{hex_char}})*)({{integer_suffix}})?\b' captures: - 1: storage.modifier.d + 1: punctuation.definition.numeric.hex.d 2: constant.numeric.hex.d 3: storage.type.integer.d pop: true @@ -201,7 +201,7 @@ contexts: floating-point-opt: - match: '\b(0[xX])({{hex_or_under}}*\.?{{hex_or_under}}+)([pP][+\-]?[0-9]+)({{float_suffix}})?\b' captures: - 1: storage.modifier.d + 1: punctuation.definition.numeric.hex.d 2: constant.numeric.float.d 3: constant.numeric.float.d 4: storage.type.float.d @@ -213,13 +213,13 @@ contexts: pop: true - match: '\b(0[bB])([01][01_]*)({{integer_float_suffix}})\b' captures: - 1: storage.modifier.d + 1: punctuation.definition.numeric.binary.d 2: constant.numeric.float.d 3: storage.type.float.d pop: true - match: '\b(0[xX])({{hex_char}}{{hex_or_under}}*)({{integer_float_suffix}})\b' captures: - 1: storage.modifier.d + 1: punctuation.definition.numeric.hex.d 2: constant.numeric.float.d 3: storage.type.float.d pop: true diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 8cf06729cb..ce1a89ad87 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -134,22 +134,22 @@ dec = 1UL; // ^ constant.numeric.integer.d // ^^ storage.type.integer.d auto bin = 0b1; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.binary.d // ^ constant.numeric.binary.d bin = 0b10__1; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.binary.d // ^^^^^ constant.numeric.binary.d bin = 0B1; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.binary.d // ^ constant.numeric.binary.d auto hex = 0xF; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.hex.d // ^ constant.numeric.hex.d hex = 0x012_3; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.hex.d // ^^^^^ constant.numeric.hex.d hex = 0X1; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.hex.d // ^ constant.numeric.hex.d auto f = 0_.0_; @@ -170,18 +170,18 @@ f = 1f; // ^ constant.numeric.float.d // ^ storage.type.float.d f = 0x123f; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.hex.d // ^^^ constant.numeric.float.d // ^ storage.type.float.d f = 0b10101101f; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.binary.d // ^^^^^^^^ constant.numeric.float.d // ^ storage.type.float.d f = 0x.1aFp2; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.hex.d // ^^^^^^ constant.numeric.float.d f = 0xF.AP-2f; -// ^^ storage.modifier.d +// ^^ punctuation.definition.numeric.hex.d // ^^^^^^ constant.numeric.float.d // ^ storage.type.float.d From 8464f4a11f5c04c2fe9219caf46f73a772ab29bc Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 5 Feb 2019 11:41:16 +1100 Subject: [PATCH 071/108] Make loop keywords use keyword.control.loop.d --- D/D.sublime-syntax | 12 +++++------ D/tests/syntax_test_d.d | 44 ++++++++++++++++++++--------------------- 2 files changed, 28 insertions(+), 28 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 73d7fdee43..0167db32d8 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1630,8 +1630,8 @@ contexts: static-foreach-in: - match: '\b(static)\s+(foreach|foreach_reverse)\b' captures: - 1: keyword.control.flow.d - 2: keyword.control.flow.d + 1: keyword.control.loop.d + 2: keyword.control.loop.d push: [optional-block-statement, foreach-arguments] static-assert-in: @@ -1782,16 +1782,16 @@ contexts: loop-in: - match: '\bwhile\b' - scope: keyword.control.flow.d + scope: keyword.control.loop.d push: [optional-block-statement, condition] - match: '\bdo\b' - scope: keyword.control.flow.d + scope: keyword.control.loop.d push: optional-block-statement - match: '\bfor\b' - scope: keyword.control.flow.d + scope: keyword.control.loop.d push: [optional-block-statement, for-arguments] - match: '\b(foreach|foreach_reverse)\b' - scope: keyword.control.flow.d + scope: keyword.control.loop.d push: [optional-block-statement, foreach-arguments] flow-statement-in: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index ce1a89ad87..e267dc8d61 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -768,12 +768,12 @@ extern(1) //^ punctuation.section.block.end.d static foreach (int foo, f; 12..3) { -//^^^^^^ keyword.control.flow.d -// ^^^^^^^ keyword.control.flow.d +//^^^^^^ keyword.control.loop.d +// ^^^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d static foreach (int a; 123) { - //^^^^^^ keyword.control.flow.d - // ^^^^^^^ keyword.control.flow.d + //^^^^^^ keyword.control.loop.d + // ^^^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^^^ storage.type.d // ^ variable.parameter.d @@ -1364,40 +1364,40 @@ extern(1) // ^ constant.numeric.integer.d while (2) 1; -//^^^^^ keyword.control.flow.d +//^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ constant.numeric.integer.d while (2) -//^^^^^ keyword.control.flow.d +//^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d { //^ punctuation.section.block.begin.d do 2; - //^^ keyword.control.flow.d + //^^ keyword.control.loop.d // ^ constant.numeric.integer.d while (3); - //^^^^^ keyword.control.flow.d + //^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d do - //^^ keyword.control.flow.d + //^^ keyword.control.loop.d { //^ punctuation.section.block.begin.d } while (1); //^ punctuation.section.block.end.d - // ^^^^^ keyword.control.flow.d + // ^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d } //^ punctuation.section.block.end.d for (1; 2; 3) { -//^^^ keyword.control.flow.d +//^^^ keyword.control.loop.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d @@ -1409,7 +1409,7 @@ extern(1) } //^ punctuation.section.block.end.d for(int a;;12) { -//^^^ keyword.control.flow.d +//^^^ keyword.control.loop.d // ^ punctuation.section.parens.begin.d // ^^^ storage.type.d // ^ variable.other.d @@ -1419,7 +1419,7 @@ extern(1) // ^ punctuation.section.block.begin.d } for (size_t i; !val.empty; val.popFront(), ++i) {} -//^^^ keyword.control.flow.d +//^^^ keyword.control.loop.d // ^ punctuation.section.parens.begin.d // ^^^^^^ storage.type.d // ^ variable.other.d @@ -1437,7 +1437,7 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d for (; a *b < cast(int)2;) {} -//^^^ keyword.control.flow.d +//^^^ keyword.control.loop.d // ^ punctuation.section.parens.begin.d // ^ punctuation.terminator.d // ^ variable.other.d @@ -1454,7 +1454,7 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d foreach (int a; 2) { -//^^^^^^^ keyword.control.flow.d +//^^^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^^^ storage.type.d // ^ variable.parameter.d @@ -1463,7 +1463,7 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^ punctuation.section.block.begin.d foreach_reverse (int a; 2) { - //^^^^^^^^^^^^^^^ keyword.control.flow.d + //^^^^^^^^^^^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^^^ storage.type.d // ^ variable.parameter.d @@ -1476,7 +1476,7 @@ extern(1) } //^ punctuation.section.block.end.d foreach (ref a; foo) {} -//^^^^^^^ keyword.control.flow.d +//^^^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^^^ storage.modifier.d // ^ variable.parameter.d @@ -1760,7 +1760,7 @@ extern(1) // ^ punctuation.terminator.d foreach (ref a; foo) {} -//^^^^^^^ keyword.control.flow.d +//^^^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^^^ storage.modifier.d // ^ variable.parameter.d @@ -2246,8 +2246,8 @@ extern(1) // ^ punctuation.section.block.end.d static foreach (Sint; AliasSeq!(S, const S, immutable S)) -//^^^^^^ keyword.control.flow.d -// ^^^^^^^ keyword.control.flow.d +//^^^^^^ keyword.control.loop.d +// ^^^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d @@ -2264,8 +2264,8 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.section.brackets.end.d static foreach (Uint; AliasSeq!(U, const U, immutable U)) {} -//^^^^^^ keyword.control.flow.d -// ^^^^^^^ keyword.control.flow.d +//^^^^^^ keyword.control.loop.d +// ^^^^^^^ keyword.control.loop.d // ^ punctuation.section.brackets.begin.d // ^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d From 7de31ea570de29b192db749491f4ececcc9a14c2 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 5 Feb 2019 11:47:56 +1100 Subject: [PATCH 072/108] Change try/catch/finally/throw keywords to use exception scope --- D/D.sublime-syntax | 8 ++++---- D/tests/syntax_test_d.d | 10 +++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 0167db32d8..274d62b6e8 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1856,13 +1856,13 @@ contexts: try-in: - match: '\btry\b' - scope: keyword.control.flow.d + scope: keyword.control.exception.d push: optional-block-statement - match: '\bcatch\b' - scope: keyword.control.flow.d + scope: keyword.control.exception.d push: [optional-block-statement, catch-arguments] - match: '\bfinally\b' - scope: keyword.control.flow.d + scope: keyword.control.exception.d push: optional-block-statement catch-arguments: - match: '\(' @@ -1884,7 +1884,7 @@ contexts: throw-in: - match: '\bthrow\b' - scope: keyword.control.flow.d + scope: keyword.control.flow.exception.d push: [expect-end-of-line, value] scope-in: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index e267dc8d61..a2276ef7dc 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1553,11 +1553,11 @@ extern(1) // ^ punctuation.section.parens.end.d try { -//^^^ keyword.control.flow.d +//^^^ keyword.control.exception.d // ^ punctuation.section.block.begin.d } catch (int a) { //^ punctuation.section.block.end.d -// ^^^^^ keyword.control.flow.d +// ^^^^^ keyword.control.exception.d // ^ punctuation.section.parens.begin.d // ^^^ storage.type.d // ^ variable.parameter.d @@ -1565,7 +1565,7 @@ extern(1) // ^ punctuation.section.block.begin.d } catch (Throwable; foo a) { //^ punctuation.section.block.end.d -// ^^^^^ keyword.control.flow.d +// ^^^^^ keyword.control.exception.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^^ storage.type.d // ^ invalid.illegal.d @@ -1576,12 +1576,12 @@ extern(1) } //^ punctuation.section.block.end.d finally { -//^^^^^^^ keyword.control.flow.d +//^^^^^^^ keyword.control.exception.d // ^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d throw 3; -//^^^^^ keyword.control.flow.d +//^^^^^ keyword.control.flow.exception.d // ^ constant.numeric.integer.d scope (exit) {} From d7b705be752ed7ff22c405da258a4a7fd95eb41b Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 5 Feb 2019 11:56:05 +1100 Subject: [PATCH 073/108] Fix brackets/parens confusion --- D/D.sublime-syntax | 16 +++---- D/tests/syntax_test_d.d | 104 ++++++++++++++++++++-------------------- 2 files changed, 60 insertions(+), 60 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 274d62b6e8..461f4a9e19 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -737,7 +737,7 @@ contexts: - include: not-whitespace-illegal-pop basic-type2-after-parens: - match: '\)' - scope: punctuation.section.brackets.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal-pop @@ -1596,7 +1596,7 @@ contexts: version-condition: - match: '\(' - scope: punctuation.section.brackets.begin.d + scope: punctuation.section.parens.begin.d set: - match: '\b(unittest|assert)\b' scope: keyword.d @@ -1610,13 +1610,13 @@ contexts: - include: not-whitespace-illegal version-condition-end: - match: '\)' - scope: punctuation.section.brackets.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal debug-condition: - match: '\(' - scope: punctuation.section.brackets.begin.d + scope: punctuation.section.parens.begin.d set: - match: '\b({{name}})\b' scope: constant.other.d @@ -1959,7 +1959,7 @@ contexts: foreach-arguments: - match: '\(' - scope: punctuation.section.brackets.begin.d + scope: punctuation.section.parens.begin.d set: [foreach-arguments-end, foreach-parameter-list] - include: not-whitespace-illegal foreach-parameter-list: @@ -1988,7 +1988,7 @@ contexts: - include: not-whitespace-illegal-pop foreach-arguments-after: - match: '\)' - scope: punctuation.section.brackets.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal-pop @@ -2005,12 +2005,12 @@ contexts: condition: - match: '\(' - scope: punctuation.section.brackets.begin.d + scope: punctuation.section.parens.begin.d set: [condition-after, value] - include: not-whitespace-illegal-pop condition-after: - match: '\)' - scope: punctuation.section.brackets.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal-pop diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index a2276ef7dc..ad26e7f46a 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -667,30 +667,30 @@ extern(1) version(unittest) {} //^^^^^^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^^^^^ keyword.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d version(assert) {} //^^^^^^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^^^ keyword.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d version(foo) {} //^^^^^^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^ constant.other.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d version(1): //^^^^^^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.separator.d debug: @@ -705,9 +705,9 @@ extern(1) // ^ punctuation.section.block.end.d debug(foo) {} else: //^^^^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^ constant.other.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d @@ -732,17 +732,17 @@ extern(1) static if (12 + 5): //^^^^^^ storage.modifier.d // ^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^ constant.numeric.integer.d // ^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.separator.d static if (true) {} else {} //^^^^^^ storage.modifier.d // ^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.begin.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d @@ -751,18 +751,18 @@ extern(1) static if (0) { //^^^^^^ storage.modifier.d // ^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d } else static if (1) { //^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d // ^^^^^^ storage.modifier.d // ^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d @@ -770,16 +770,16 @@ extern(1) static foreach (int foo, f; 12..3) { //^^^^^^ keyword.control.loop.d // ^^^^^^^ keyword.control.loop.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d static foreach (int a; 123) { //^^^^^^ keyword.control.loop.d // ^^^^^^^ keyword.control.loop.d - // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.parens.begin.d // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^ constant.numeric.integer.d - // ^ punctuation.section.brackets.end.d + // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ } @@ -1084,14 +1084,14 @@ extern(1) // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d // ^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^ storage.type.d // ^ keyword.operator.logical.d // ^ storage.type.d // ^ punctuation.section.parens.end.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d in {} //^^ keyword.control.conditional.d // ^ punctuation.section.block.begin.d @@ -1268,14 +1268,14 @@ extern(1) // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^ storage.type.d // ^ keyword.operator.logical.d // ^^^^^ storage.type.d // ^ punctuation.section.parens.end.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @property foo(T) = { @@ -1336,17 +1336,17 @@ extern(1) if (2) { //^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d if (1) {} else {} //^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d @@ -1355,9 +1355,9 @@ extern(1) if (1) 1; if (1) {} else 1; //^^ keyword.control.conditional.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^^^^ keyword.control.conditional.d @@ -1365,15 +1365,15 @@ extern(1) while (2) 1; //^^^^^ keyword.control.loop.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ constant.numeric.integer.d while (2) //^^^^^ keyword.control.loop.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d { //^ punctuation.section.block.begin.d do 2; @@ -1381,9 +1381,9 @@ extern(1) // ^ constant.numeric.integer.d while (3); //^^^^^ keyword.control.loop.d - // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d - // ^ punctuation.section.brackets.end.d + // ^ punctuation.section.parens.end.d do //^^ keyword.control.loop.d { @@ -1391,9 +1391,9 @@ extern(1) } while (1); //^ punctuation.section.block.end.d // ^^^^^ keyword.control.loop.d - // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d - // ^ punctuation.section.brackets.end.d + // ^ punctuation.section.parens.end.d } //^ punctuation.section.block.end.d for (1; 2; 3) { @@ -1455,21 +1455,21 @@ extern(1) // ^ punctuation.section.block.end.d foreach (int a; 2) { //^^^^^^^ keyword.control.loop.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ constant.numeric.integer.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d foreach_reverse (int a; 2) { //^^^^^^^^^^^^^^^ keyword.control.loop.d - // ^ punctuation.section.brackets.begin.d + // ^ punctuation.section.parens.begin.d // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ constant.numeric.integer.d - // ^ punctuation.section.brackets.end.d + // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d @@ -1477,12 +1477,12 @@ extern(1) //^ punctuation.section.block.end.d foreach (ref a; foo) {} //^^^^^^^ keyword.control.loop.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^ storage.modifier.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^ variable.other.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -1761,12 +1761,12 @@ extern(1) foreach (ref a; foo) {} //^^^^^^^ keyword.control.loop.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^ storage.modifier.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^ variable.other.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -1899,7 +1899,7 @@ extern(1) // ^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^^^ string.quoted.single.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ punctuation.terminator.d @@ -2248,7 +2248,7 @@ extern(1) static foreach (Sint; AliasSeq!(S, const S, immutable S)) //^^^^^^ keyword.control.loop.d // ^^^^^^^ keyword.control.loop.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^^^^^^ variable.other.d @@ -2262,11 +2262,11 @@ extern(1) // ^^^^^^^^^ storage.modifier.d // ^ storage.type.d // ^ punctuation.section.parens.end.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d static foreach (Uint; AliasSeq!(U, const U, immutable U)) {} //^^^^^^ keyword.control.loop.d // ^^^^^^^ keyword.control.loop.d -// ^ punctuation.section.brackets.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^^^^^^ variable.other.d @@ -2280,6 +2280,6 @@ extern(1) // ^^^^^^^^^ storage.modifier.d // ^ storage.type.d // ^ punctuation.section.parens.end.d -// ^ punctuation.section.brackets.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d From 24167072d85b47275f8781e3958a73c6d1088e07 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 11 Feb 2019 14:59:11 +1100 Subject: [PATCH 074/108] Replace shebang single regex with a simple context --- D/D.sublime-syntax | 13 +++++++------ D/tests/syntax_test_shebang.d | 2 +- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 461f4a9e19..4419250afd 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -61,12 +61,13 @@ contexts: main: - meta_include_prototype: false - - match: '^(#)!(.*)$' - scope: comment.line.number-sign.d - captures: - 1: punctuation.definition.comment.number-sign - 2: source.shell - set: main-after-shebang-in + - match: '^#!' + scope: punctuation.definition.comment.number-sign + set: + - meta_include_prototype: false + - meta_scope: source.shell comment.line.number-sign.d + - match: '$\n?' + set: main-after-shebang-in - match: '' set: main-after-shebang-in main-after-shebang-in: diff --git a/D/tests/syntax_test_shebang.d b/D/tests/syntax_test_shebang.d index 84d105aec8..c443265eeb 100644 --- a/D/tests/syntax_test_shebang.d +++ b/D/tests/syntax_test_shebang.d @@ -1,6 +1,6 @@ #! SYNTAX TEST "Packages/D/D.sublime-syntax" #! <- comment.line.number-sign.d punctuation.definition.comment.number-sign - #! <- comment.line.number-sign.d + #! <- comment.line.number-sign.d punctuation.definition.comment.number-sign #!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.number-sign.d // foo From 90d9fa0abd9afa3b5862b25737fbce2abd66773c Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 18 Feb 2019 12:33:27 +1100 Subject: [PATCH 075/108] Improve buile files and DMD output highlighting --- D/D Single File.sublime-build | 13 ------------- D/D.sublime-build | 14 ++++++++++++++ D/DMD Output.sublime-syntax | 16 ++++++++++------ 3 files changed, 24 insertions(+), 19 deletions(-) delete mode 100644 D/D Single File.sublime-build create mode 100644 D/D.sublime-build diff --git a/D/D Single File.sublime-build b/D/D Single File.sublime-build deleted file mode 100644 index e2fd1d6d14..0000000000 --- a/D/D Single File.sublime-build +++ /dev/null @@ -1,13 +0,0 @@ -{ - "shell_cmd": "dmd $file", - "file_regex": "^(.*?)\\(([0-9]+)(,[0-9]+)?\\)", - "selector": "source.d", - - "variants": - [ - { - "name": "Run", - "shell_cmd": "rdmd $file", - } - ] -} diff --git a/D/D.sublime-build b/D/D.sublime-build new file mode 100644 index 0000000000..1d92b89173 --- /dev/null +++ b/D/D.sublime-build @@ -0,0 +1,14 @@ +{ + "shell_cmd": "dmd \"$file\"", + "file_regex": "^(.*?)\\(([0-9]+)(,[0-9]+)?\\)", + "selector": "source.d", + "syntax": "Packages/D/DMD Output.sublime-syntax", + + "variants": + [ + { + "name": "Run", + "shell_cmd": "rdmd \"$file\"", + } + ] +} diff --git a/D/DMD Output.sublime-syntax b/D/DMD Output.sublime-syntax index 84016fd6d0..9b3334328e 100644 --- a/D/DMD Output.sublime-syntax +++ b/D/DMD Output.sublime-syntax @@ -2,11 +2,15 @@ --- name: DMD Output hidden: true -scope: source.build_output +scope: source.build_output.dmd contexts: main: - - match: '^(..[^:\n]*):([0-9]+):?([0-9]+)?:? ' - - match: '^(.*?)\([0-9]+(,[0-9]+)?\): ' - scope: entity.name.filename - - match: '\b(Warning|Error): ' - scope: message.error + - match: '^(.*?)\(([0-9]+)(?:,\s*([0-9]+))?\): ' + captures: + 1: entity.name.filename.dmd + 2: constant.numeric.line-number.dmd + 3: constant.numeric.line-number.dmd + - match: '\b(Warning|Error)(:) ' + captures: + 1: message.error.dmd + 2: punctuation.separator.dmd From 421ea67ed1baa91f1d3d2737aac57abdb7ae519b Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 18 Feb 2019 14:14:57 +1100 Subject: [PATCH 076/108] Clean up tmPreferences --- D/Indentation Rules.tmPreferences | 2 +- D/Symbol List.tmPreferences | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/D/Indentation Rules.tmPreferences b/D/Indentation Rules.tmPreferences index daaea0656f..7212904bab 100644 --- a/D/Indentation Rules.tmPreferences +++ b/D/Indentation Rules.tmPreferences @@ -9,7 +9,7 @@ decreaseIndentPattern (?x) - ^ (.*\*/)? \s* \} .* $ + ^ (.*\*/)? \s* \} | ^ \s* (public|private|protected|package): \s* $ increaseIndentPattern diff --git a/D/Symbol List.tmPreferences b/D/Symbol List.tmPreferences index c832d733de..d8d31de90d 100644 --- a/D/Symbol List.tmPreferences +++ b/D/Symbol List.tmPreferences @@ -4,7 +4,7 @@ name Symbol List scope - + source.d entity.name settings showInSymbolList From 1d9382d4c756892d64596f13385b84ec60e5b04e Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 18 Feb 2019 14:48:16 +1100 Subject: [PATCH 077/108] Rework start of file parsing, including modules and shebangs. Also fix D names not supporting non-ascii numbers in identifiers --- D/D.sublime-syntax | 41 ++++++++++++++++++----------------- D/tests/syntax_test_d.d | 23 ++++++++++++++------ D/tests/syntax_test_old.d | 1 + D/tests/syntax_test_shebang.d | 8 +++---- 4 files changed, 42 insertions(+), 31 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 4419250afd..f82f63c80f 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -9,7 +9,7 @@ file_extensions: first_line_match: ^#!.*\bg?dmd\b. scope: source.d variables: - name: '[[:alpha:]_][[:alnum:]_]*' + name: '[[:alpha:]_][[:alpha:]0-9_]*' identifier: '{{name}}(?:\.{{name}})*' std_identifier: '(?:std|core)\.{{identifier}}' identifier_ref: '(\b|\.){{identifier}}\b' @@ -60,28 +60,29 @@ contexts: - include: comment-in main: - - meta_include_prototype: false - match: '^#!' - scope: punctuation.definition.comment.number-sign - set: + scope: punctuation.definition.comment.number-sign.d + push: - meta_include_prototype: false - - meta_scope: source.shell comment.line.number-sign.d + - meta_scope: comment.line.number-sign.d - match: '$\n?' - set: main-after-shebang-in - - match: '' - set: main-after-shebang-in - main-after-shebang-in: - - include: attribute-specifier-in - - match: '\b(module)\s+({{identifier}})(;)' - captures: - 1: keyword.declaration.module.d - 2: entity.name.namespace.d - 3: punctuation.terminator.d - set: - - meta_scope: meta.namespace.d - - include: statement-list-in - - match: (?=\S) - set: statement-list-in + pop: true + - include: module-in + - include: statement-list-in + module-in: + - match: \bmodule\b + scope: keyword.declaration.module.d + push: + - match: '{{name}}(?=\s*(;|$))' + scope: entity.name.namespace.d + - match: '{{name}}' + scope: variable.other.d + push: + - match: \. + scope: punctuation.accessor.dot.d + pop: true + - include: not-whitespace-illegal + - include: expect-end-of-line statement-list-in: - include: import-in diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index ad26e7f46a..2dc26d606e 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1,14 +1,23 @@ // SYNTAX TEST "Packages/D/D.sublime-syntax" module foo.a.b1_3; -// <- meta.namespace.d keyword.declaration.module.d - // <- meta.namespace.d keyword.declaration.module.d -//^^^^ meta.namespace.d keyword.declaration.module.d -// ^^^^^^^^^^ meta.namespace.d entity.name.namespace.d -// ^ meta.namespace.d punctuation.terminator.d +// <- keyword.declaration.module.d + // <- keyword.declaration.module.d +//^^^^ keyword.declaration.module.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^^ entity.name.namespace.d +// ^ punctuation.terminator.d module foo.a.b1_3; -//^^^^^^ - keyword.control.module -// ^^^^^^^^^^ - entity.name.namespace +//^^^^^^ keyword.declaration.module.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^^ entity.name.namespace.d +// ^ punctuation.terminator.d /+ //^^ comment.block.nested.d punctuation.definition.comment.d diff --git a/D/tests/syntax_test_old.d b/D/tests/syntax_test_old.d index 4017ab5284..141edcafaf 100644 --- a/D/tests/syntax_test_old.d +++ b/D/tests/syntax_test_old.d @@ -21,6 +21,7 @@ shared int b = 5000; // ^ constant.numeric int c = 0x0; +// ^^ punctuation.definition.numeric.hex // ^ constant.numeric int d = 0x0_00; // ^ constant.numeric diff --git a/D/tests/syntax_test_shebang.d b/D/tests/syntax_test_shebang.d index c443265eeb..977129eb08 100644 --- a/D/tests/syntax_test_shebang.d +++ b/D/tests/syntax_test_shebang.d @@ -1,10 +1,10 @@ #! SYNTAX TEST "Packages/D/D.sublime-syntax" -#! <- comment.line.number-sign.d punctuation.definition.comment.number-sign - #! <- comment.line.number-sign.d punctuation.definition.comment.number-sign +#! <- comment.line.number-sign.d punctuation.definition.comment.number-sign.d + #! <- comment.line.number-sign.d punctuation.definition.comment.number-sign.d #!^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ comment.line.number-sign.d - +; // foo #! ^^^ comment.line.double-slash.d #! foo -#! ^^^ - comment.line.number-sign.d +#! ^^^ comment.line.number-sign.d From 3767a0497b45a682167ba4e0878ab10dbd512555 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 18 Feb 2019 15:17:11 +1100 Subject: [PATCH 078/108] Rename keyword.declaration.module to keyword.declaration.namespace --- D/D.sublime-syntax | 2 +- D/tests/syntax_test_d.d | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index f82f63c80f..cc2b85e3ac 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -71,7 +71,7 @@ contexts: - include: statement-list-in module-in: - match: \bmodule\b - scope: keyword.declaration.module.d + scope: keyword.declaration.namespace.d push: - match: '{{name}}(?=\s*(;|$))' scope: entity.name.namespace.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 2dc26d606e..18e80aa281 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1,9 +1,9 @@ // SYNTAX TEST "Packages/D/D.sublime-syntax" module foo.a.b1_3; -// <- keyword.declaration.module.d - // <- keyword.declaration.module.d -//^^^^ keyword.declaration.module.d +// <- keyword.declaration.namespace.d + // <- keyword.declaration.namespace.d +//^^^^ keyword.declaration.namespace.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^ variable.other.d @@ -11,7 +11,7 @@ module foo.a.b1_3; // ^^^^ entity.name.namespace.d // ^ punctuation.terminator.d module foo.a.b1_3; -//^^^^^^ keyword.declaration.module.d +//^^^^^^ keyword.declaration.namespace.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^ variable.other.d From 8f3565ef6f511309c68c2fd23de6a78eabf8180f Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Mon, 18 Feb 2019 15:23:06 +1100 Subject: [PATCH 079/108] Fix number literal scopes --- D/D.sublime-syntax | 18 +++++++++--------- D/tests/syntax_test_d.d | 32 ++++++++++++++++---------------- D/tests/syntax_test_old.d | 2 +- 3 files changed, 26 insertions(+), 26 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index cc2b85e3ac..ec2f2ede66 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -187,13 +187,13 @@ contexts: - match: '\b(0[bB])([01][01_]*)({{integer_suffix}})?\b' captures: 1: punctuation.definition.numeric.binary.d - 2: constant.numeric.binary.d + 2: constant.numeric.integer.binary.d 3: storage.type.integer.d pop: true - match: '\b(0[xX])({{hex_char}}(?:_|{{hex_char}})*)({{integer_suffix}})?\b' captures: - 1: punctuation.definition.numeric.hex.d - 2: constant.numeric.hex.d + 1: punctuation.definition.numeric.hexadecimal.d + 2: constant.numeric.integer.hexadecimal.d 3: storage.type.integer.d pop: true @@ -203,9 +203,9 @@ contexts: floating-point-opt: - match: '\b(0[xX])({{hex_or_under}}*\.?{{hex_or_under}}+)([pP][+\-]?[0-9]+)({{float_suffix}})?\b' captures: - 1: punctuation.definition.numeric.hex.d - 2: constant.numeric.float.d - 3: constant.numeric.float.d + 1: punctuation.definition.numeric.hexadecimal.d + 2: constant.numeric.float.hexadecimal.d + 3: constant.numeric.float.hexadecimal.d 4: storage.type.float.d pop: true - match: '\b(0|[1-9][0-9_]*)({{integer_float_suffix}})\b' @@ -216,13 +216,13 @@ contexts: - match: '\b(0[bB])([01][01_]*)({{integer_float_suffix}})\b' captures: 1: punctuation.definition.numeric.binary.d - 2: constant.numeric.float.d + 2: constant.numeric.float.binary.d 3: storage.type.float.d pop: true - match: '\b(0[xX])({{hex_char}}{{hex_or_under}}*)({{integer_float_suffix}})\b' captures: - 1: punctuation.definition.numeric.hex.d - 2: constant.numeric.float.d + 1: punctuation.definition.numeric.hexadecimal.d + 2: constant.numeric.float.hexadecimal.d 3: storage.type.float.d pop: true - match: '\b([0-9][0-9_]*\.[0-9][0-9_]*)({{float_exponent}})?({{float_suffix}})?\b' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 18e80aa281..3c7be72040 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -144,22 +144,22 @@ dec = 1UL; // ^^ storage.type.integer.d auto bin = 0b1; // ^^ punctuation.definition.numeric.binary.d -// ^ constant.numeric.binary.d +// ^ constant.numeric.integer.binary.d bin = 0b10__1; // ^^ punctuation.definition.numeric.binary.d -// ^^^^^ constant.numeric.binary.d +// ^^^^^ constant.numeric.integer.binary.d bin = 0B1; // ^^ punctuation.definition.numeric.binary.d -// ^ constant.numeric.binary.d +// ^ constant.numeric.integer.binary.d auto hex = 0xF; -// ^^ punctuation.definition.numeric.hex.d -// ^ constant.numeric.hex.d +// ^^ punctuation.definition.numeric.hexadecimal.d +// ^ constant.numeric.integer.hexadecimal.d hex = 0x012_3; -// ^^ punctuation.definition.numeric.hex.d -// ^^^^^ constant.numeric.hex.d +// ^^ punctuation.definition.numeric.hexadecimal.d +// ^^^^^ constant.numeric.integer.hexadecimal.d hex = 0X1; -// ^^ punctuation.definition.numeric.hex.d -// ^ constant.numeric.hex.d +// ^^ punctuation.definition.numeric.hexadecimal.d +// ^ constant.numeric.integer.hexadecimal.d auto f = 0_.0_; // ^^^ constant.numeric.float.d @@ -179,19 +179,19 @@ f = 1f; // ^ constant.numeric.float.d // ^ storage.type.float.d f = 0x123f; -// ^^ punctuation.definition.numeric.hex.d -// ^^^ constant.numeric.float.d +// ^^ punctuation.definition.numeric.hexadecimal.d +// ^^^ constant.numeric.float.hexadecimal.d // ^ storage.type.float.d f = 0b10101101f; // ^^ punctuation.definition.numeric.binary.d -// ^^^^^^^^ constant.numeric.float.d +// ^^^^^^^^ constant.numeric.float.binary.d // ^ storage.type.float.d f = 0x.1aFp2; -// ^^ punctuation.definition.numeric.hex.d -// ^^^^^^ constant.numeric.float.d +// ^^ punctuation.definition.numeric.hexadecimal.d +// ^^^^^^ constant.numeric.float.hexadecimal.d f = 0xF.AP-2f; -// ^^ punctuation.definition.numeric.hex.d -// ^^^^^^ constant.numeric.float.d +// ^^ punctuation.definition.numeric.hexadecimal.d +// ^^^^^^ constant.numeric.float.hexadecimal.d // ^ storage.type.float.d @foo: diff --git a/D/tests/syntax_test_old.d b/D/tests/syntax_test_old.d index 141edcafaf..6e7b8c3732 100644 --- a/D/tests/syntax_test_old.d +++ b/D/tests/syntax_test_old.d @@ -21,7 +21,7 @@ shared int b = 5000; // ^ constant.numeric int c = 0x0; -// ^^ punctuation.definition.numeric.hex +// ^^ punctuation.definition.numeric.hexadecimal // ^ constant.numeric int d = 0x0_00; // ^ constant.numeric From a75da797333c588c32e1c6201f7d266654855de5 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 11:52:22 +1100 Subject: [PATCH 080/108] Add proper identifier parsing and fix assert not being handled as a keyword everywhere --- D/D.sublime-syntax | 256 +++++++++++++++++++++------------------- D/tests/syntax_test_d.d | 86 +++++++++----- 2 files changed, 192 insertions(+), 150 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index ec2f2ede66..c3924158cd 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -10,16 +10,12 @@ first_line_match: ^#!.*\bg?dmd\b. scope: source.d variables: name: '[[:alpha:]_][[:alpha:]0-9_]*' - identifier: '{{name}}(?:\.{{name}})*' - std_identifier: '(?:std|core)\.{{identifier}}' - identifier_ref: '(\b|\.){{identifier}}\b' + name_lookahead: '(?=\b{{name}}\b)' string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' hex_or_under: '(?:{{hex_char}}|_)' - type_look_ahead: '(?={{identifier_ref}})' - number_lookahead: '(?=(\b|\.)[0-9])' integer_lookahead: '(?=\b[0-9])' integer_suffix: 'L[uU]|[uU]L|[LuU]' @@ -418,7 +414,7 @@ contexts: - match: ';' scope: punctuation.terminator.d - match: '\.' - scope: keyword.operator.d + scope: punctuation.accessor.dot.d - match: '\(' scope: punctuation.section.parens.begin.d push: @@ -529,20 +525,14 @@ contexts: - match: '\b(private|protected|public|export)\b' scope: storage.modifier.access-control.d pop: true - - match: '\b(package)\s*(\()' - captures: - 1: storage.modifier.access-control.d - 2: punctuation.definition.annotation.begin.d - set: - - match: '{{identifier}}' - scope: variable.other.constant.d - - match: '\)' - scope: punctuation.definition.annotation.end.d - pop: true - - include: not-whitespace-illegal - match: '\b(package)\b' scope: storage.modifier.access-control.d - pop: true + set: + - match: '\(' + scope: punctuation.definition.annotation.begin.d + set: [attribute-parens-after, identifier] + - match: (?=\S) + pop: true - match: '\b(pragma)\b' scope: keyword.other.pragma.d set: @@ -551,6 +541,11 @@ contexts: set: pragma-attribute - include: not-whitespace-illegal - include: not-whitespace-illegal-pop + attribute-parens-after: + - match: '\)' + scope: punctuation.definition.annotation.end.d + pop: true + - include: not-whitespace-illegal-pop at-attribute: - match: '({{at_attributes}})\b' scope: storage.attribute.d @@ -574,10 +569,13 @@ contexts: extern-attribute: - match: '(C\+\+|C|D|Windows|System|Objective-C)' scope: string.other.d - - match: '{{identifier}}' - scope: string.other.d + set: extern-attribute-after + - match: (?=\S) + set: [extern-attribute-after, identifier] + extern-attribute-after: - match: ',' scope: punctuation.separator.sequence.d + set: extern-attribute - match: '\)' scope: punctuation.definition.annotation.end.d pop: true @@ -608,71 +606,40 @@ contexts: pop: true - include: not-whitespace-illegal-pop + # TODO: Maybe make imports non-indexed entities (as opposed to variables) import-in: - match: '\b(import)(?!\s*\()\b' scope: keyword.control.import.d - push: import-list + push: [import-list, identifier] import-list: - - match: '\b(?:({{std_identifier}})|({{identifier}}))\b' - captures: - 1: support.module.d - 2: variable.other.constant.d - set: - - match: ':' - scope: punctuation.separator.import-binding.d - set: import-binding-list - - match: ';' - scope: punctuation.terminator.d - pop: true - - match: ',' - scope: punctuation.separator.sequence.d - set: import-list - - match: '=' - scope: keyword.operator.assignment.d - set: - - match: '\b(?:({{std_identifier}})|({{identifier}}))\b' - captures: - 1: support.module.d - 2: variable.other.constant.d - set: - - match: ';' - scope: punctuation.terminator.d - pop: true - - match: ',' - scope: punctuation.separator.sequence.d - set: import-list - - - include: not-whitespace-illegal - - include: not-whitespace-illegal - - include: not-whitespace-illegal - - include: not-whitespace-illegal + - match: ':' + scope: punctuation.separator.import-binding.d + set: [import-binding-list, identifier] + - match: ',' + scope: punctuation.separator.sequence.d + set: [import-list, identifier] + - match: '=' + scope: keyword.operator.assignment.d + set: [import-list-after-assignment, identifier] + - include: expect-end-of-line + import-list-after-assignment: + - match: ',' + scope: punctuation.separator.sequence.d + set: [import-list, identifier] + - include: expect-end-of-line import-binding-list: - - match: '\b({{identifier}})\b' - scope: variable.other.constant.d - set: - - match: ';' - scope: punctuation.terminator.d - pop: true - - match: ',' - scope: punctuation.separator.sequence.d - set: import-binding-list - - match: '=' - scope: keyword.operator.assignment.d - set: - - match: '\b({{identifier}})\b' - scope: variable.other.constant.d - set: - - match: ';' - scope: punctuation.terminator.d - pop: true - - match: ',' - scope: punctuation.separator.sequence.d - set: import-binding-list - - - include: not-whitespace-illegal - - include: not-whitespace-illegal - - include: not-whitespace-illegal - - include: not-whitespace-illegal + - match: ',' + scope: punctuation.separator.sequence.d + set: [import-binding-list, identifier] + - match: '=' + scope: keyword.operator.assignment.d + set: [import-binding-list-after-assignment, identifier] + - include: expect-end-of-line + import-binding-list-after-assignment: + - match: ',' + scope: punctuation.separator.sequence.d + set: [import-binding-list, identifier] + - include: expect-end-of-line type: - match: '\b({{type_qualifier}})\b' @@ -701,9 +668,8 @@ contexts: - match: '\bauto\b' scope: keyword.other.d pop: true - - match: '{{identifier_ref}}' - scope: storage.type.d - set: basic-type2 + - match: '{{name_lookahead}}' + set: [basic-type2, type-identifier-ref] - match: '(?=\S)' pop: true @@ -975,21 +941,19 @@ contexts: - match: '\b({{basic_type}})\b' scope: storage.type.d set: first-value-after - # Check for simple function call to highlight the identifier correctly - - match: '(?={{identifier_ref}}\s*\()' - set: [value-list-after, value] - - match: '{{identifier_ref}}' + # Match a regular function call so we properly highlight the name as a + # function + - match: '(?=[[:alpha:]0-9_\.]+\s*\()' + set: value-list + - match: '{{name_lookahead}}' scope: variable.other.d - set: first-value-after + set: [first-value-after, identifier-ref] - match: '(?=\S)' - set: value + set: value-list first-value-after: - match: '\.' scope: punctuation.accessor.dot.d - set: - - match: '{{identifier}}' - scope: variable.other.d - set: first-value-after + push: identifier - match: '!(?!=)' scope: keyword.operator.d set: @@ -1070,6 +1034,9 @@ contexts: scope: punctuation.section.parens.begin.d set: [value-parens-after, value-list] - include: not-whitespace-illegal + - match: \bassert\b + scope: keyword.other.assert.d + set: [value-after, assert-arguments] - match: '\bis\b' scope: keyword.other.d set: @@ -1151,12 +1118,11 @@ contexts: 1: variable.parameter.d 2: keyword.operator.lambda.d set: value - - match: '{{identifier_ref}}(?=\s*\()' - scope: variable.function.d - set: value-after - - match: '{{identifier_ref}}' - scope: variable.other.d - set: value-after + - match: \. + scope: punctuation.accessor.dot.d + set: [value-after, value-identifier] + - match: '{{name_lookahead}}' + set: [value-after, value-identifier] - include: not-whitespace-illegal cast-after: - match: '\)' @@ -1251,16 +1217,26 @@ contexts: set: value - match: (?=\S) set: value-after + value-identifier: + - match: '\b{{name}}\b(?=\s*\()' + scope: variable.function.d + pop: true + - match: '\b{{name}}\b' + scope: variable.other.d + set: + - match: \.(?!\.) + scope: punctuation.accessor.dot.d + set: value-identifier + - match: (?=\S) + pop: true + - include: not-whitespace-illegal-pop value-after: - match: '\.\.(?!\.)' scope: keyword.operator.d set: value - match: '\.(?!\.\.)' scope: punctuation.accessor.dot.d - set: - - match: '{{identifier}}' - scope: variable.other.d - set: value-after + set: [value-after, identifier] - match: '\(' scope: punctuation.section.parens.begin.d set: [value-parens-after, value-list] @@ -1359,12 +1335,9 @@ contexts: - include: not-whitespace-illegal alias-in: - - match: '\b(alias)\s+({{identifier}})\s+(this)(;)' - captures: - 1: keyword.control.alias.d - 2: variable.d - 3: keyword.control.alias.d - 4: punctuation.terminator.d + - match: '\b(alias)\b(?=[^;]*\bthis\s*;)' + scope: keyword.control.alias.d + push: [alias-this-after, identifier] - match: '\b(alias)\b' scope: keyword.control.alias.d push: @@ -1374,9 +1347,13 @@ contexts: captures: 1: entity.name.type.d set: alias-new - - match: '{{type_look_ahead}}' + - match: (?=\S) set: [alias-old, type] - - include: not-whitespace-illegal + alias-this-after: + - match: \b(this)\b + scope: keyword.control.alias.d + set: expect-end-of-line + - include: not-whitespace-illegal-pop alias-old: - match: '\b({{name}})\b' scope: entity.name.type.d @@ -1430,9 +1407,8 @@ contexts: set: optional-template-body-block base-class-list: - - match: '{{type_look_ahead}}' + - match: '' set: [base-class-list-after, basic-type] - - include: not-whitespace-illegal base-class-list-after: - match: ',' scope: punctuation.separator.sequence.d @@ -1532,6 +1508,7 @@ contexts: pop: true - match: '(?=\b({{name}})\b)' push: enum-member + - include: not-whitespace-illegal - include: not-whitespace-illegal enum-assignment: @@ -1562,7 +1539,7 @@ contexts: - include: attribute-in - match: '(?=\b({{name}})\s*(=|,|}|$))' push: enum-member - - match: '{{type_look_ahead}}' + - match: '(?=\S)' push: [enum-member, type] - include: not-whitespace-illegal @@ -1589,10 +1566,10 @@ contexts: - include: not-whitespace-illegal-pop conditional-declaration-in: - - match: '\b(version)\b' + - match: '\bversion\b' scope: keyword.control.conditional.d push: [optional-block-statement-or-label, version-condition] - - match: '\b(debug)\b' + - match: '\bdebug\b' scope: keyword.control.conditional.d push: [optional-block-statement-or-label, debug-condition] @@ -1600,8 +1577,11 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: - - match: '\b(unittest|assert)\b' - scope: keyword.d + - match: \bunittest\b + scope: keyword.control.conditional.d + set: version-condition-end + - match: \bassert\b + scope: keyword.other.assert.d set: version-condition-end - match: '\b({{name}})\b' scope: constant.other.d @@ -1639,8 +1619,8 @@ contexts: static-assert-in: - match: '\b(static)\s+(assert)\b' captures: - 1: keyword.control.conditional.d - 2: keyword.control.conditional.d + 1: keyword.other.assert.d + 2: keyword.other.assert.d push: [expect-end-of-line, assert-arguments] constructions-in: @@ -1998,7 +1978,7 @@ contexts: - match: '\(' scope: punctuation.section.parens.begin.d set: [assert-arguments-after, value-list] - - include: not-whitespace-illegal + - include: not-whitespace-illegal-pop assert-arguments-after: - match: '\)' scope: punctuation.section.parens.end.d @@ -2016,6 +1996,40 @@ contexts: pop: true - include: not-whitespace-illegal-pop + identifier: + - match: '\b{{name}}\b' + scope: variable.other.d + set: + - match: \. + scope: punctuation.accessor.dot.d + set: identifier + - match: '(?=\S)' + pop: true + - include: not-whitespace-illegal-pop + identifier-ref: + - match: \. + scope: punctuation.accessor.dot.d + set: identifier + - match: '(?=\S)' + set: identifier + + type-identifier: + - match: '\b{{name}}\b' + scope: storage.type.d + set: + - match: \. + scope: punctuation.accessor.dot.d + set: type-identifier + - match: '(?=\S)' + pop: true + - include: not-whitespace-illegal-pop + type-identifier-ref: + - match: \. + scope: punctuation.accessor.dot.d + set: type-identifier + - match: '(?=\S)' + set: type-identifier + not-whitespace-illegal: - match: '\S' scope: invalid.illegal.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 3c7be72040..a60a61ecbf 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -230,7 +230,9 @@ f = 0xF.AP-2f; // ^ punctuation.definition.annotation.begin.d // ^^^ string.other.d // ^ punctuation.separator.sequence.d -// ^^^^^ string.other.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^ variable.other.d // ^ punctuation.definition.annotation.end.d extern(1) // ^ invalid.illegal.d @@ -263,12 +265,14 @@ extern(1) // ^^^^^^ storage.modifier.access-control.d // ^^^^^^ storage.modifier.access-control.d // ^^^^^^^ storage.modifier.access-control.d - package(foo.bar. ) + package(foo.bar.2) //^^^^^^^ storage.modifier.access-control.d // ^ punctuation.definition.annotation.begin.d -// ^^^^^^^ variable.other.constant.d -// ^ invalid.illegal.d -// ^ - invalid.illegal.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^ invalid.illegal.d // ^ punctuation.definition.annotation.end.d pragma(f) pragma(test, void): //^^^^^^ keyword.other.pragma.d @@ -286,34 +290,38 @@ extern(1) import foo; //^^^^^^ keyword.control.import.d -// ^^^ variable.other.constant.d +// ^^^ variable.other.d // ^ punctuation.terminator.d import std.foo; import core.thread; //^^^^^^ keyword.control.import.d -// ^^^^^^^ support.module.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^ variable.other.d // ^ punctuation.terminator.d // ^^^^^^ keyword.control.import.d -// ^^^^^^^^^^^ support.module.d +// ^^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^^^^ variable.other.d // ^ punctuation.terminator.d import foo'; // ^ invalid.illegal.d import foo, a = bar, std : foo, bar, c = d; //^^^^^^ keyword.control.import.d -// ^^^ variable.other.constant.d +// ^^^ variable.other.d // ^ punctuation.separator.sequence.d -// ^ variable.other.constant.d +// ^ variable.other.d // ^ keyword.operator.assignment.d -// ^^^ variable.other.constant.d +// ^^^ variable.other.d // ^ punctuation.separator.sequence.d -// ^^^ variable.other.constant.d +// ^^^ variable.other.d // ^ punctuation.separator.import-binding.d -// ^^^ variable.other.constant.d +// ^^^ variable.other.d // ^ punctuation.separator.sequence.d -// ^^^ variable.other.constant.d +// ^^^ variable.other.d // ^ punctuation.separator.sequence.d -// ^ variable.other.constant.d +// ^ variable.other.d // ^ keyword.operator.assignment.d -// ^ variable.other.constant.d +// ^ variable.other.d // ^ punctuation.terminator.d alias foo = int; @@ -358,12 +366,16 @@ extern(1) // ^ punctuation.terminator.d alias foo this; //^^^^^ keyword.control.alias.d -// ^^^ variable.d +// ^^^ variable.other.d // ^^^^ keyword.control.alias.d // ^ punctuation.terminator.d alias foo.bar.baz this; //^^^^^ keyword.control.alias.d -// ^^^^^^^^^^^ variable.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^ variable.other.d // ^^^^ keyword.control.alias.d // ^ punctuation.terminator.d alias F(x) = foo*; @@ -547,6 +559,8 @@ extern(1) // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d + 1 + //^ invalid.illegal.d } //^ punctuation.section.block.end.d enum Foo : int { a = 12 } @@ -579,6 +593,8 @@ extern(1) // ^ punctuation.separator.sequence.d Foo //^^^ entity.name.constant.d + 2 + //^ invalid.illegal.d } //^ punctuation.section.block.end.d enum f = 12; @@ -677,14 +693,14 @@ extern(1) version(unittest) {} //^^^^^^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d -// ^^^^^^^^ keyword.d +// ^^^^^^^^ keyword.control.conditional.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d version(assert) {} //^^^^^^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d -// ^^^^^^ keyword.d +// ^^^^^^ keyword.other.assert.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -797,15 +813,15 @@ extern(1) //^ punctuation.section.block.end.d static assert(12); -//^^^^^^ keyword.control.conditional.d -// ^^^^^^ keyword.control.conditional.d +//^^^^^^ keyword.other.assert.d +// ^^^^^^ keyword.other.assert.d // ^ punctuation.section.parens.begin.d // ^^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d static assert(12, "foobar"); -//^^^^^^ keyword.control.conditional.d -// ^^^^^^ keyword.control.conditional.d +//^^^^^^ keyword.other.assert.d +// ^^^^^^ keyword.other.assert.d // ^ punctuation.section.parens.begin.d // ^^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d @@ -1112,11 +1128,17 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d assert(true); - //^^^^^^ variable.function.d + //^^^^^^ keyword.other.assert.d // ^ punctuation.section.parens.begin.d // ^^^^ constant.language.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d + foo(4); + //^^^ variable.function.d + // ^ punctuation.section.parens.begin.d + // ^ constant.numeric.integer.d + // ^ punctuation.section.parens.end.d + // ^ punctuation.terminator.d } //^ punctuation.section.block.end.d body { @@ -1434,9 +1456,13 @@ extern(1) // ^ variable.other.d // ^ punctuation.terminator.d // ^ keyword.operator.logical.d -// ^^^^^^^^^ variable.other.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^^^ variable.other.d // ^ punctuation.terminator.d -// ^^^^^^^^^^^^ variable.function.d +// ^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^^^^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d // ^ punctuation.separator.sequence.d @@ -2168,7 +2194,8 @@ extern(1) // ^ punctuation.terminator.d .AliasSeq!(immutable char, int); -//^^^^^^^^^ variable.other.d +//^ punctuation.accessor.dot.d +// ^^^^^^^^ variable.other.d // ^ keyword.operator.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^^ storage.modifier.d @@ -2186,7 +2213,8 @@ extern(1) // ^ variable.other.d // ^ keyword.operator.arithmetic.d // ^ punctuation.section.parens.end.d -// ^^^^ variable.other.d +// ^ punctuation.accessor.dot.d +// ^^^ variable.other.d // ^ punctuation.terminator.d void toString(Writer)(ref Writer w, const ref FormatSpec!char fmt) {} From f7d82f3b929d7c3194c1203ca0fadf11a74218dd Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 13:29:28 +1100 Subject: [PATCH 081/108] Fix variadic and slice scopes --- D/D.sublime-syntax | 12 ++++++------ D/tests/syntax_test_d.d | 28 +++++++++++++++------------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index c3924158cd..8e89352408 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -740,7 +740,7 @@ contexts: function-type-argument-type: - include: parameter-attribute-in - match: '\.\.\.' - scope: keyword.operator.d + scope: keyword.operator.variadic.d pop: true - include: type function-type-argument: @@ -748,7 +748,7 @@ contexts: scope: variable.parameter.d set: - match: '\.\.\.' - scope: keyword.operator.d + scope: keyword.operator.variadic.d - match: ',' scope: punctuation.separator.sequence.d set: [function-type-argument, function-type-argument-type] @@ -856,7 +856,7 @@ contexts: function-argument-or-type: - include: parameter-attribute-in - match: '\.\.\.' - scope: keyword.operator.d + scope: keyword.operator.variadic.d pop: true - match: '(?={{name}}\s*([,=:\)]|\.\.\.))' pop: true @@ -866,7 +866,7 @@ contexts: scope: variable.parameter.d set: - match: '\.\.\.' - scope: keyword.operator.d + scope: keyword.operator.variadic.d - match: ',' scope: punctuation.separator.sequence.d set: [function-argument, function-argument-or-type] @@ -1206,7 +1206,7 @@ contexts: scope: punctuation.separator.sequence.d set: [value-group-after-parens, function-argument, function-argument-or-type] - match: '\.\.\.' - scope: keyword.operator.d + scope: keyword.operator.variadic.d - include: not-whitespace-illegal value-group-after-parens: - include: function-attribute-in @@ -1232,7 +1232,7 @@ contexts: - include: not-whitespace-illegal-pop value-after: - match: '\.\.(?!\.)' - scope: keyword.operator.d + scope: keyword.operator.slice.d set: value - match: '\.(?!\.\.)' scope: punctuation.accessor.dot.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index a60a61ecbf..26e4ccb84f 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -921,13 +921,13 @@ extern(1) // ^ entity.name.function.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d -// ^^^ keyword.operator.d +// ^^^ keyword.operator.variadic.d // ^ punctuation.separator.sequence.d // ^^^^^^ storage.type.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ variable.parameter.d -// ^^^ keyword.operator.d +// ^^^ keyword.operator.variadic.d // ^ punctuation.section.group.end.d // ^ punctuation.section.group.begin.d // ^^^ storage.modifier.d @@ -935,7 +935,7 @@ extern(1) // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ variable.parameter.d -// ^^^ keyword.operator.d +// ^^^ keyword.operator.variadic.d // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -1165,7 +1165,7 @@ extern(1) //^^^^ storage.type.d // ^ entity.name.function.d // ^ punctuation.section.group.begin.d -// ^^^ keyword.operator.d +// ^^^ keyword.operator.variadic.d // ^ punctuation.section.group.end.d // ^ punctuation.terminator.d @@ -1242,7 +1242,7 @@ extern(1) // ^ punctuation.section.block.end.d invariant(0, "test") { -//^^^^^^^^^ keyword.control.flow.d +//^^^^^^^^^ keyword.other.invariant.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d @@ -1250,11 +1250,11 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d invariant(); - //^^^^^^^^^ keyword.control.flow.d + //^^^^^^^^^ keyword.other.invariant.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d invariant {} - //^^^^^^^^^ keyword.control.flow.d + //^^^^^^^^^ keyword.other.invariant.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d } @@ -1488,15 +1488,17 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d - foreach (int a; 2) { + foreach (int a; 2..5) { //^^^^^^^ keyword.control.loop.d // ^ punctuation.section.parens.begin.d // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ constant.numeric.integer.d -// ^ punctuation.section.parens.end.d -// ^ punctuation.section.block.begin.d +// ^^ keyword.operator.slice.d +// ^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.section.block.begin.d foreach_reverse (int a; 2) { //^^^^^^^^^^^^^^^ keyword.control.loop.d // ^ punctuation.section.parens.begin.d @@ -1976,7 +1978,7 @@ extern(1) (foo..., bar) @safe {}; //^ punctuation.section.group.begin.d // ^^^ variable.other.d -// ^^^ keyword.operator.d +// ^^^ keyword.operator.variadic.d // ^ punctuation.separator.sequence.d // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d @@ -2027,7 +2029,7 @@ extern(1) // ^ punctuation.section.group.begin.d // ^^^ storage.type.d // ^ variable.parameter.d -// ^^^ keyword.operator.d +// ^^^ keyword.operator.variadic.d // ^ punctuation.separator.sequence.d // ^^^ storage.type.d // ^ punctuation.section.group.end.d @@ -2126,7 +2128,7 @@ extern(1) //^^^^ storage.type.d // ^^^^^^^^ keyword.other.d // ^ punctuation.section.group.begin.d -// ^^^ keyword.operator.d +// ^^^ keyword.operator.variadic.d // ^ punctuation.section.group.end.d // ^ variable.other.d // ^ punctuation.terminator.d From e071f6e32d40bdffc65cfc2bd9cf5442c42f5856 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 13:36:30 +1100 Subject: [PATCH 082/108] Add keyword.declaration scopes to storage type declarations --- D/D.sublime-syntax | 74 ++++++++++++++++++++--------------------- D/tests/syntax_test_d.d | 70 ++++++++++++++++++++------------------ 2 files changed, 74 insertions(+), 70 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 8e89352408..b7d4230fb4 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1136,7 +1136,7 @@ contexts: - include: not-whitespace-illegal new-after: - match: '\bclass\b' - scope: storage.type.class.d + scope: storage.type.class.d keyword.declaration.class.d set: - match: '\(' scope: punctuation.section.parens.begin.d @@ -1388,7 +1388,7 @@ contexts: class-in: - match: '\b(class)\b' - scope: storage.type.class.d + scope: storage.type.class.d keyword.declaration.class.d push: - match: '\b({{name}})\b' scope: entity.name.class.d @@ -1419,7 +1419,7 @@ contexts: interface-in: - match: '\b(interface)\b' - scope: storage.type.interface.d + scope: storage.type.interface.d keyword.declaration.interface.d push: - match: '\b({{name}})\b' scope: entity.name.interface.d @@ -1440,7 +1440,7 @@ contexts: struct-in: - match: '\b(struct)\b' - scope: storage.type.struct.d + scope: storage.type.struct.d keyword.declaration.struct.d push: - match: '\b({{name}})\b' scope: entity.name.struct.d @@ -1455,7 +1455,7 @@ contexts: union-in: - match: '\b(union)\b' - scope: storage.type.union.d + scope: storage.type.union.d keyword.declaration.union.d push: - match: '\b({{name}})\b' scope: entity.name.union.d @@ -1470,7 +1470,7 @@ contexts: enum-in: - match: '\b(enum)\b' - scope: storage.type.enum.d + scope: storage.type.enum.d keyword.declaration.enum.d push: - match: '(?=\b({{basic_type}})\b)' push: type @@ -1568,46 +1568,57 @@ contexts: conditional-declaration-in: - match: '\bversion\b' scope: keyword.control.conditional.d - push: [optional-block-statement-or-label, version-condition] + push: version-condition - match: '\bdebug\b' scope: keyword.control.conditional.d - push: [optional-block-statement-or-label, debug-condition] - + push: debug-condition + conditional-declaration-after-parens: + - match: '\)' + scope: punctuation.section.parens.end.d + set: optional-block-statement-or-label + - include: not-whitespace-illegal + conditional-declaration-assignment: + - match: '\b{{name}}\b' + scope: entity.name.constant.d + set: expect-end-of-line + - match: '{{integer_lookahead}}' + set: [expect-end-of-line, integer] + - include: not-whitespace-illegal version-condition: - match: '\(' scope: punctuation.section.parens.begin.d set: - match: \bunittest\b scope: keyword.control.conditional.d - set: version-condition-end + set: conditional-declaration-after-parens - match: \bassert\b scope: keyword.other.assert.d - set: version-condition-end + set: conditional-declaration-after-parens - match: '\b({{name}})\b' scope: constant.other.d - set: version-condition-end + set: conditional-declaration-after-parens - match: '{{integer_lookahead}}' - set: [version-condition-end, integer] + set: [conditional-declaration-after-parens, integer] - include: not-whitespace-illegal + - match: '=' + scope: keyword.operator.assignment.d + set: conditional-declaration-assignment - include: not-whitespace-illegal - version-condition-end: - - match: '\)' - scope: punctuation.section.parens.end.d - pop: true - - include: not-whitespace-illegal - debug-condition: - match: '\(' scope: punctuation.section.parens.begin.d set: - match: '\b({{name}})\b' scope: constant.other.d - set: version-condition-end + set: conditional-declaration-after-parens - match: '{{integer_lookahead}}' - set: [version-condition-end, integer] + set: [conditional-declaration-after-parens, integer] - include: not-whitespace-illegal + - match: '=' + scope: keyword.operator.assignment.d + set: conditional-declaration-assignment - match: '(?=\S)' - pop: true + set: optional-block-statement-or-label static-foreach-in: - match: '\b(static)\s+(foreach|foreach_reverse)\b' @@ -1673,7 +1684,7 @@ contexts: invariant-in: - match: '\b(invariant)\b' - scope: keyword.control.flow.d + scope: keyword.other.invariant.d push: - match: '(?=\()' set: [invariant-block, assert-arguments] @@ -1706,22 +1717,9 @@ contexts: - include: statement-list-in - include: not-whitespace-illegal - specification-in: - - match: '\b(version|debug)\s*(=)' - captures: - 1: keyword.control.conditional.d - 2: keyword.operator.assignment.d - push: - - match: '\b{{name}}\b' - scope: entity.name.constant.d - set: expect-end-of-line - - match: '{{integer_lookahead}}' - set: [expect-end-of-line, integer] - - include: not-whitespace-illegal - template-in: - match: '\b(template)\b' - scope: storage.type.d + scope: storage.type.d keyword.declaration.template.d push: template template: - match: '\b({{name}})\b' @@ -1737,7 +1735,7 @@ contexts: - match: '\b(mixin)\s+(template)\b' captures: 1: keyword.control.d - 2: storage.type.d + 2: storage.type.d keyword.declaration.template.d push: template - match: '\b(mixin)(?!\s*\()' scope: keyword.control.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 26e4ccb84f..5cf7a20a27 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -438,12 +438,12 @@ extern(1) // ^ punctuation.terminator.d class Foo; -//^^^^^ storage.type.class.d +//^^^^^ storage.type.class.d keyword.declaration.class.d // ^^^ entity.name.class.d // ^ punctuation.terminator.d class Bar : Foo, b { -//^^^^^ storage.type.class.d +//^^^^^ storage.type.class.d keyword.declaration.class.d // ^^^ entity.name.class.d // ^ punctuation.separator.mapping.d // ^^^ storage.type.d @@ -451,14 +451,14 @@ extern(1) // ^ storage.type.d // ^ punctuation.section.block.begin.d class b {} - //^^^^^ storage.type.class.d + //^^^^^ storage.type.class.d keyword.declaration.class.d // ^ entity.name.class.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d class b(T, int s) { -//^^^^^ storage.type.class.d +//^^^^^ storage.type.class.d keyword.declaration.class.d // ^ entity.name.class.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d @@ -471,11 +471,11 @@ extern(1) //^ punctuation.section.block.end.d interface S; -//^^^^^^^^^ storage.type.interface.d +//^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d // ^ entity.name.interface.d // ^ punctuation.terminator.d interface Foo: Bar, Baz { -//^^^^^^^^^ storage.type.interface.d +//^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d // ^^^ entity.name.interface.d // ^ punctuation.separator.mapping.d // ^^^ storage.type.d @@ -483,14 +483,14 @@ extern(1) // ^^^ storage.type.d // ^ punctuation.section.block.begin.d interface c{} - //^^^^^^^^^ storage.type.interface.d + //^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d // ^ entity.name.interface.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d } //^ punctuation.section.block.end.d interface A(T, float f) { -//^^^^^^^^^ storage.type.interface.d +//^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d // ^ entity.name.interface.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d @@ -503,14 +503,14 @@ extern(1) //^ punctuation.section.block.end.d struct Foo { -//^^^^^^ storage.type.struct.d +//^^^^^^ storage.type.struct.d keyword.declaration.struct.d // ^^^ entity.name.struct.d // ^ punctuation.section.block.begin.d struct { - //^^^^^^ storage.type.struct.d + //^^^^^^ storage.type.struct.d keyword.declaration.struct.d // ^ punctuation.section.block.begin.d union {} - //^^^^^ storage.type.union.d + //^^^^^ storage.type.union.d keyword.declaration.union.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d } @@ -518,7 +518,7 @@ extern(1) } //^ punctuation.section.block.end.d struct F(int a, T) { -//^^^^^^ storage.type.struct.d +//^^^^^^ storage.type.struct.d keyword.declaration.struct.d // ^ entity.name.struct.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d @@ -531,12 +531,12 @@ extern(1) //^ punctuation.section.block.end.d union Foo {} -//^^^^^ storage.type.union.d +//^^^^^ storage.type.union.d keyword.declaration.union.d // ^^^ entity.name.union.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d union Test(string s, F) {} -//^^^^^ storage.type.union.d +//^^^^^ storage.type.union.d keyword.declaration.union.d // ^^^^ entity.name.union.d // ^ punctuation.section.group.begin.d // ^^^^^^ storage.type.d @@ -548,7 +548,7 @@ extern(1) // ^ punctuation.section.block.end.d enum Foo { -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^ entity.name.enum.d // ^ punctuation.section.block.begin.d foo, @@ -564,7 +564,7 @@ extern(1) } //^ punctuation.section.block.end.d enum Foo : int { a = 12 } -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^ entity.name.enum.d // ^ punctuation.separator.mapping.d // ^^^ storage.type.d @@ -574,7 +574,7 @@ extern(1) // ^^ constant.numeric.integer.d // ^ punctuation.section.block.end.d enum : foo[string] { TEST } -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^ punctuation.separator.mapping.d // ^^^ storage.type.d // ^ punctuation.section.brackets.begin.d @@ -584,7 +584,7 @@ extern(1) // ^^^^ entity.name.constant.d // ^ punctuation.section.block.end.d enum { int a = 12, -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^ punctuation.section.block.begin.d // ^^^ storage.type.d // ^ entity.name.constant.d @@ -598,13 +598,13 @@ extern(1) } //^ punctuation.section.block.end.d enum f = 12; -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^ entity.name.enum.d // ^ keyword.operator.assignment.d // ^^ constant.numeric.integer.d // ^ punctuation.terminator.d enum f(x, int t) = cast(x)t; -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^ entity.name.enum.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d @@ -620,7 +620,7 @@ extern(1) // ^ variable.other.d // ^ punctuation.terminator.d enum bool[] foo = 12; -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^ storage.type.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d @@ -629,14 +629,14 @@ extern(1) // ^^ constant.numeric.integer.d // ^ punctuation.terminator.d enum fool -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^ entity.name.enum.d { //^ punctuation.section.block.begin.d } //^ punctuation.section.block.end.d enum uint a = 1, b = 2, exponentBits = 3; -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^ storage.type.d // ^ entity.name.enum.d // ^ keyword.operator.assignment.d @@ -651,7 +651,7 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.terminator.d enum immutable(Char)[] seqBefore = "["; -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^^^^^^ storage.modifier.d // ^ punctuation.section.group.begin.d // ^^^^ storage.type.d @@ -663,7 +663,7 @@ extern(1) // ^^^ string.quoted.double.d // ^ punctuation.terminator.d enum ulong -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^^ storage.type.d a = 1 << 2, //^ entity.name.enum.d @@ -680,7 +680,7 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.terminator.d enum foo -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^ entity.name.enum.d bar = 2; //^^^ entity.name.enum.d @@ -688,7 +688,7 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.terminator.d enum Attr; -//^^^^ storage.type.enum.d +//^^^^ storage.type.enum.d keyword.declaration.enum.d version(unittest) {} //^^^^^^^ keyword.control.conditional.d @@ -753,6 +753,12 @@ extern(1) // ^ keyword.operator.assignment.d // ^^^ entity.name.constant.d // ^ punctuation.terminator.d + version +//^^^^^^^ keyword.control.conditional.d + = 5; +// ^ keyword.operator.assignment.d +// ^ constant.numeric.integer.d +// ^ punctuation.terminator.d int foo = true; static if (12 + 5): //^^^^^^ storage.modifier.d @@ -1272,7 +1278,7 @@ extern(1) //^ punctuation.section.block.end.d template foo(T, A) { -//^^^^^^^^ storage.type.d +//^^^^^^^^ storage.type.d keyword.declaration.template.d // ^^^ entity.name.template.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d @@ -1281,7 +1287,7 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d template a(size_t f) { - //^^^^^^^^ storage.type.d + //^^^^^^^^ storage.type.d keyword.declaration.template.d // ^ entity.name.template.d // ^ punctuation.section.group.begin.d // ^^^^^^ storage.type.d @@ -1293,7 +1299,7 @@ extern(1) } //^ punctuation.section.block.end.d template foo(T) if (is(T : class)) {} -//^^^^^^^^ storage.type.d +//^^^^^^^^ storage.type.d keyword.declaration.template.d // ^^^ entity.name.template.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d @@ -1330,7 +1336,7 @@ extern(1) mixin template f(int a) { //^^^^^ keyword.control.d -// ^^^^^^^^ storage.type.d +// ^^^^^^^^ storage.type.d keyword.declaration.template.d // ^ entity.name.template.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d @@ -1710,7 +1716,7 @@ extern(1) // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ keyword.operator.word.d -// ^^^^^ storage.type.class.d +// ^^^^^ storage.type.class.d keyword.declaration.class.d // ^ punctuation.section.parens.begin.d // ^^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d From d24d1334c8a469e23c1752be60ce108d2467c92a Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 13:41:56 +1100 Subject: [PATCH 083/108] Fix switch ':' scope --- D/D.sublime-syntax | 4 ++-- D/tests/syntax_test_d.d | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index b7d4230fb4..1ae7fc35f1 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1904,7 +1904,7 @@ contexts: scope: keyword.control.flow.d push: - match: ':' - scope: punctuation.section.block.begin.d + scope: punctuation.separator.case-statement.d pop: true - include: not-whitespace-illegal-pop switch-after: @@ -1914,7 +1914,7 @@ contexts: - include: not-whitespace-illegal-pop case-after: - match: ':' - scope: punctuation.section.block.begin.d + scope: punctuation.separator.case-statement.d set: - match: '\.\.(?!\.)' scope: keyword.operator.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 5cf7a20a27..4019881295 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1869,18 +1869,18 @@ extern(1) // ^ constant.numeric.integer.d // ^^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d - // ^ punctuation.section.block.begin.d + // ^ punctuation.separator.case-statement.d case 2: .. case 4: //^^^^ keyword.control.flow.d // ^ constant.numeric.integer.d - // ^ punctuation.section.block.begin.d + // ^ punctuation.separator.case-statement.d // ^^ keyword.operator.d // ^^^^ keyword.control.flow.d // ^ constant.numeric.integer.d - // ^ punctuation.section.block.begin.d + // ^ punctuation.separator.case-statement.d default: //^^^^^^^ keyword.control.flow.d - // ^ punctuation.section.block.begin.d + // ^ punctuation.separator.case-statement.d } //^ punctuation.section.block.end.d From ba37b44ed5dae5d696f209824e4836871be255fa Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 14:09:54 +1100 Subject: [PATCH 084/108] Improve tests --- D/tests/syntax_test_d.d | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 4019881295..b46c8037bd 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -31,10 +31,12 @@ module foo.a.b1_3; auto wysiwyg = r"f// \n\"; // ^^ punctuation.definition.string.begin.d // ^^^^^^^^^^ string.quoted.double.raw.d +// ^^ - constant.character.escape.d // ^ punctuation.definition.string.end.d auto wysiwygAlt = `f//\n\`; // ^ punctuation.definition.string.begin.d // ^^^^^^^^ string.quoted.double.raw.backtick.d +// ^^ - constant.character.escape.d // ^ punctuation.definition.string.end.d auto doubleQuoted = "c://\'\"\?\\\0\a\b\f\n\r\t\v\x0B\2\12\762\u0feb\Uabcdef98\""; // ^ punctuation.definition.string.begin.d @@ -43,6 +45,16 @@ auto doubleQuoted = "c://\'\"\?\\\0\a\b\f\n\r\t\v\x0B\2\12\762\u0feb\Uabcdef98\& // ^ punctuation.definition.string.end.d auto invalidEscape = "\p"; // ^^ string.quoted.double.d invalid.illegal.unknown-escape.d +auto invalidEscape2 = "\u0fe"; +// ^^^^^^^ string.quoted.double.d +// ^^ invalid.illegal.unknown-escape.d +auto invalidEscape3 = "\&;"; +// ^^^^^ string.quoted.double.d +// ^^ invalid.illegal.unknown-escape.d +auto invalidEscape4 = "\u12398"; +// ^^^^^^^^^ string.quoted.double.d +// ^^^^^^ constant.character.escape.d +// ^ - constant.character.escape.d auto hexString = x"00 ba // ^^ punctuation.definition.string.begin.d // ^^^^^^^^ string.quoted.double.raw.d From 06f7d69cc4365a23369416747273e71168b951d0 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 14:22:15 +1100 Subject: [PATCH 085/108] Fix annotation parens scopes --- D/D.sublime-syntax | 28 +++++++++++++------------- D/tests/syntax_test_d.d | 44 +++++++++++++++++++++-------------------- 2 files changed, 37 insertions(+), 35 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 1ae7fc35f1..19110f2459 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -504,13 +504,13 @@ contexts: - match: '\b(extern)\s*(\()' captures: 1: keyword.other.external.d - 2: punctuation.definition.annotation.begin.d + 2: punctuation.section.parens.begin.d set: extern-attribute - match: '\b(align)\b' scope: keyword.other.alignment.d set: - match: '\(' - scope: punctuation.definition.annotation.begin.d + scope: punctuation.section.parens.begin.d set: [align-attribute-after, value] - match: '(?=\S)' pop: true @@ -518,7 +518,7 @@ contexts: scope: keyword.other.deprecated.d set: - match: '\(' - scope: punctuation.definition.annotation.begin.d + scope: punctuation.section.parens.begin.d set: [deprecated-attribute-after, value] - match: '(?=\S)' pop: true @@ -529,7 +529,7 @@ contexts: scope: storage.modifier.access-control.d set: - match: '\(' - scope: punctuation.definition.annotation.begin.d + scope: punctuation.section.parens.begin.d set: [attribute-parens-after, identifier] - match: (?=\S) pop: true @@ -537,13 +537,13 @@ contexts: scope: keyword.other.pragma.d set: - match: '\(' - scope: punctuation.definition.annotation.begin.d + scope: punctuation.section.parens.begin.d set: pragma-attribute - include: not-whitespace-illegal - include: not-whitespace-illegal-pop attribute-parens-after: - match: '\)' - scope: punctuation.definition.annotation.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal-pop at-attribute: @@ -551,19 +551,19 @@ contexts: scope: storage.attribute.d pop: true - match: '\(' - scope: punctuation.definition.annotation.begin.d + scope: punctuation.section.parens.begin.d set: [uda-after, value-list] - match: '({{name}})\s*(\()' captures: 1: storage.type.d - 2: punctuation.definition.annotation.begin.d + 2: punctuation.section.parens.begin.d set: [uda-after, value-list] - match: '({{name}})\b' scope: storage.type.d pop: true uda-after: - match: '\)' - scope: punctuation.definition.annotation.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal extern-attribute: @@ -577,23 +577,23 @@ contexts: scope: punctuation.separator.sequence.d set: extern-attribute - match: '\)' - scope: punctuation.definition.annotation.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal align-attribute-after: - match: '\)' - scope: punctuation.definition.annotation.end.d + scope: punctuation.section.parens.end.d pop: true deprecated-attribute-after: - match: '\)' - scope: punctuation.definition.annotation.end.d + scope: punctuation.section.parens.end.d pop: true pragma-attribute: - match: '\b({{name}})\b' scope: variable.function.d set: - match: '\)' - scope: punctuation.definition.annotation.end.d + scope: punctuation.section.parens.end.d pop: true - match: ',' scope: punctuation.separator.sequence.d @@ -602,7 +602,7 @@ contexts: - include: not-whitespace-illegal-pop pragma-attribute-after: - match: '\)' - scope: punctuation.definition.annotation.end.d + scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal-pop diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index b46c8037bd..f77e48ef44 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -211,16 +211,18 @@ f = 0xF.AP-2f; // ^^^ storage.type.d // ^ punctuation.separator.d @("oo")@safer@Foo(2, 4)@property -//^^ punctuation.definition.annotation.begin.d +//^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d // ^ punctuation.definition.annotation.begin.d // ^^^^^ storage.type.d // ^ punctuation.definition.annotation.begin.d // ^^^ storage.type.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ constant.numeric.integer.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^^ storage.attribute.d static shared const immutable final __gshared nothrow pure ref @@ -235,42 +237,42 @@ f = 0xF.AP-2f; // ^^^ storage.modifier.d extern(C) extern (C++, foo.a) //^^^^^^ keyword.other.external.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^ string.other.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d // ^^^^^^ keyword.other.external.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^^^ string.other.d // ^ punctuation.separator.sequence.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^ variable.other.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d extern(1) // ^ invalid.illegal.d align align(1) align(foo * 2) //^^^^^ keyword.other.alignment.d // ^^^^^ keyword.other.alignment.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d // ^^^^^ keyword.other.alignment.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^^^ variable.other.d // ^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d deprecated //^^^^^^^^^^ keyword.other.deprecated.d deprecated( "message") deprecated(q{void}) //^^^^^^^^^^ keyword.other.deprecated.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^^^^^^ string.quoted.double.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d // ^^^^^^^^^^ keyword.other.deprecated.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^ source.d storage.type.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d private protected public export package //^^^^^^^ storage.modifier.access-control.d // ^^^^^^^^^ storage.modifier.access-control.d @@ -279,23 +281,23 @@ extern(1) // ^^^^^^^ storage.modifier.access-control.d package(foo.bar.2) //^^^^^^^ storage.modifier.access-control.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^ invalid.illegal.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d pragma(f) pragma(test, void): //^^^^^^ keyword.other.pragma.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^ variable.function.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d // ^^^^^^ keyword.other.pragma.d -// ^ punctuation.definition.annotation.begin.d +// ^ punctuation.section.parens.begin.d // ^^^^ variable.function.d // ^^^^ storage.type.d -// ^ punctuation.definition.annotation.end.d +// ^ punctuation.section.parens.end.d private: //^^^^^^^ storage.modifier.access-control.d // ^ punctuation.separator.d From 3bae0ff95863e144e79e58000f16b0738c66aa8e Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 14:35:05 +1100 Subject: [PATCH 086/108] Fix import expression scope --- D/D.sublime-syntax | 2 +- D/tests/syntax_test_d.d | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 19110f2459..56d399a626 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1021,7 +1021,7 @@ contexts: - match: '(?=\S)' set: new-after - match: '\bimport\b' - scope: keyword.declaration.d + scope: keyword.control.import.d set: - match: '\(' scope: punctuation.section.parens.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index f77e48ef44..5428aafc03 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -337,6 +337,25 @@ extern(1) // ^ keyword.operator.assignment.d // ^ variable.other.d // ^ punctuation.terminator.d + string foo = import("foo.txt"); +//^^^^^^ storage.type.d +// ^^^ variable.other.d +// ^ keyword.operator.assignment.d +// ^^^^^^ keyword.control.import.d +// ^ punctuation.section.parens.begin.d +// ^^^^^^^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + import("foo").each!writeln; +//^^^^^^ keyword.control.import.d +// ^ punctuation.section.parens.begin.d +// ^^^^^ string.quoted.double.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.accessor.dot.d +// ^^^^ variable.other.d +// ^ keyword.operator.d +// ^^^^^^^ variable.other.d +// ^ punctuation.terminator.d alias foo = int; //^^^^^ keyword.control.alias.d From 0354835053196b3fb03e7b92bef329233e5c1b53 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 14:51:42 +1100 Subject: [PATCH 087/108] Improve type specialization scopes --- D/D.sublime-syntax | 27 ++++++++++++++++++++------- D/tests/syntax_test_d.d | 24 ++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 7 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 56d399a626..4f0c79cc0a 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -46,9 +46,6 @@ variables: 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' - type_specialization_keyword: '__vector|function|delegate|super|return|__parameters' - type_specialization_storage: 'struct|union|class|interface|enum' - block_statement_loohahead: '(?={)' contexts: @@ -1181,10 +1178,26 @@ contexts: pop: true - include: not-whitespace-illegal type-specialization: - - match: '\b(?:({{type_specialization_storage}})|({{type_specialization_keyword}}))\b' - captures: - 1: storage.type.d - 2: keyword.d + - match: '\b(?:__vector|function|delegate|__parameters)\b' + scope: keyword.other.d + set: + - match: '(?=\))' + pop: true + - include: type-specialization + - match: '\breturn\b' + scope: keyword.control.flow.d + set: + - match: '(?=\))' + pop: true + - include: type-specialization + - match: '\bsuper\b' + scope: variable.language.d + set: + - match: '(?=\))' + pop: true + - include: type-specialization + - match: '\b(?:struct|union|class|interface|enum)\b' + scope: storage.type.d keyword.declaration.d set: - match: '(?=\))' pop: true diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 5428aafc03..3adf4ef28d 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1964,6 +1964,30 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d + is(foo : super); +//^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ storage.type.d +// ^ keyword.operator.logical.d +// ^^^^^ variable.language.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + is(foo : return); +//^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ storage.type.d +// ^ keyword.operator.logical.d +// ^^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d + is(foo : class); +//^^ keyword.other.d +// ^ punctuation.section.parens.begin.d +// ^^^ storage.type.d +// ^ keyword.operator.logical.d +// ^^^^^ storage.type.d keyword.declaration.d +// ^ punctuation.section.parens.end.d +// ^ punctuation.terminator.d typeof(2) a(typeof('f') b); //^^^^^^ keyword.other.d From d776db5f0a36a5af2cbbf78557895ceaef31dacf Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 19 Feb 2019 15:00:13 +1100 Subject: [PATCH 088/108] Remove dead code --- D/D.sublime-syntax | 1 - 1 file changed, 1 deletion(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 4f0c79cc0a..57f8087c4b 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -85,7 +85,6 @@ contexts: - include: struct-in - include: union-in - include: enum-in - - include: specification-in - include: conditional-declaration-in - include: static-foreach-in - include: static-assert-in From 69a591ba64d5126e30efe05ba9cad248c0fe9b32 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 10:43:13 +1100 Subject: [PATCH 089/108] Add meta.namespace to the module declaration --- D/D.sublime-syntax | 1 + D/tests/syntax_test_d.d | 6 ++++-- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 57f8087c4b..887741fa33 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -66,6 +66,7 @@ contexts: - match: \bmodule\b scope: keyword.declaration.namespace.d push: + - meta_scope: meta.namespace.d - match: '{{name}}(?=\s*(;|$))' scope: entity.name.namespace.d - match: '{{name}}' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 3adf4ef28d..a46caa4d7e 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1,9 +1,10 @@ // SYNTAX TEST "Packages/D/D.sublime-syntax" module foo.a.b1_3; -// <- keyword.declaration.namespace.d - // <- keyword.declaration.namespace.d +// <- meta.namespace.d keyword.declaration.namespace.d + // <- meta.namespace.d keyword.declaration.namespace.d //^^^^ keyword.declaration.namespace.d +//^^^^^^^^^^^^^^^^ meta.namespace.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^ variable.other.d @@ -11,6 +12,7 @@ module foo.a.b1_3; // ^^^^ entity.name.namespace.d // ^ punctuation.terminator.d module foo.a.b1_3; +//^^^^^^^^^^^^^^^^^^ meta.namespace.d //^^^^^^ keyword.declaration.namespace.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d From dbb212f9dd5829794d5e00b28ad3d2acf8a5a730 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 11:37:06 +1100 Subject: [PATCH 090/108] Add meta.string.d scope to strings and highlight string prefixes specially --- D/D.sublime-syntax | 102 ++++++++++++++++++++++++---------------- D/tests/syntax_test_d.d | 91 +++++++++++++++++++++-------------- 2 files changed, 117 insertions(+), 76 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 887741fa33..d4d1b47061 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -247,7 +247,7 @@ contexts: push: character character: - match: \'(?:({{escape_sequence}})|[^\\'])\' - scope: string.quoted.single.d + scope: meta.string.d string.quoted.single.d captures: 1: constant.character.escape.d pop: true @@ -268,7 +268,7 @@ contexts: scope: punctuation.definition.string.begin.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.d + - meta_scope: meta.string.d string.quoted.double.d - match: '(")({{string_postfix}})' captures: 1: punctuation.definition.string.end.d @@ -279,11 +279,13 @@ contexts: - match: \\. scope: invalid.illegal.unknown-escape.d # Wysiwyg string - - match: r" - scope: punctuation.definition.string.begin.d + - match: (r)(") + captures: + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.d + - meta_scope: meta.string.d string.quoted.double.raw.d - match: '(")({{string_postfix}})' captures: 1: punctuation.definition.string.end.d @@ -294,18 +296,20 @@ contexts: scope: punctuation.definition.string.begin.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.backtick.d + - meta_scope: meta.string.d string.quoted.double.raw.backtick.d - match: '(`)({{string_postfix}})' captures: 1: punctuation.definition.string.end.d 2: storage.type.string.d pop: true # Deprecated Hex string - - match: x" - scope: punctuation.definition.string.begin.d + - match: (x)(") + captures: + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.d + - meta_scope: meta.string.d string.quoted.double.raw.d - match: '(")({{string_postfix}})' captures: 1: punctuation.definition.string.end.d @@ -316,75 +320,94 @@ contexts: - match: '\S' scope: invalid.illegal.unknown-escape.d # Deliminated string with custom identifier - - match: 'q"({{name}})(.*)$' - scope: punctuation.definition.string.begin.d + - match: '(q)(")({{name}})(.*)$' captures: - 2: invalid.illegal.d + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d + 3: constant.other.delimeter.d + 4: invalid.illegal.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.d - - match: '(^\1")({{string_postfix}})' + - meta_scope: meta.string.d string.quoted.double.raw.d + - match: '(^\3)(")({{string_postfix}})' captures: - 1: punctuation.definition.string.end.d - 2: storage.type.string.d + 1: constant.other.delimeter.d + 2: punctuation.definition.string.end.d + 3: storage.type.string.d pop: true # Nested Deliminated string - - match: 'q"\[' - scope: punctuation.definition.string.begin.d + - match: (q)("\[) + captures: + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.d + - meta_scope: meta.string.d string.quoted.double.raw.d - match: '(\]")({{string_postfix}})' captures: 1: punctuation.definition.string.end.d 2: storage.type.string.d pop: true - - match: 'q"\(' - scope: punctuation.definition.string.begin.d + - match: (q)("\() + captures: + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.d + - meta_scope: meta.string.d string.quoted.double.raw.d - match: '(\)")({{string_postfix}})' captures: 1: punctuation.definition.string.end.d 2: storage.type.string.d pop: true - - match: 'q"<' - scope: punctuation.definition.string.begin.d + - match: (q)("<) + captures: + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.d + - meta_scope: meta.string.d string.quoted.double.raw.d - match: '(>")({{string_postfix}})' captures: 1: punctuation.definition.string.end.d 2: storage.type.string.d pop: true - - match: 'q"{' - scope: punctuation.definition.string.begin.d + - match: (q)("{) + captures: + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.d + - meta_scope: meta.string.d string.quoted.double.raw.d - match: '(}")({{string_postfix}})' captures: 1: punctuation.definition.string.end.d 2: storage.type.string.d pop: true # Other deliminated string - - match: 'q"(.)' - scope: punctuation.definition.string.begin.d + - match: '(q)(")(.)' + captures: + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d + 3: constant.other.delimeter.d set: - meta_include_prototype: false - - meta_scope: string.quoted.double.raw.d - - match: '(\1"|\1(.))({{string_postfix}})' + - meta_scope: meta.string.d string.quoted.double.raw.d + - match: '(\3)(?:(")|(.))({{string_postfix}})' captures: - 1: punctuation.definition.string.end.d - 2: invalid.illegal.d - 3: storage.type.string.d + 1: constant.other.delimeter.d + 2: punctuation.definition.string.end.d + 3: invalid.illegal.d + 4: storage.type.string.d pop: true # Token string - - match: 'q{' - scope: string.unquoted.embedded.d punctuation.definition.string.begin.d + - match: '(q)({)' + captures: + 1: storage.modifier.string.d + 2: punctuation.definition.string.begin.d + scope: string.unquoted.embedded.d set: + - meta_scope: meta.string.d - match: '}' scope: string.unquoted.embedded.d punctuation.definition.string.end.d pop: true @@ -1712,10 +1735,7 @@ contexts: scope: punctuation.section.block.end.d pop: true - include: statement-list-in - - match: ';' - scope: punctuation.terminator.d - pop: true - - include: not-whitespace-illegal + - include: expect-end-of-line unittest-in: - match: '\b(unittest)\b' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index a46caa4d7e..b746852b79 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -31,96 +31,117 @@ module foo.a.b1_3; //^^ comment.block.nested.d punctuation.definition.comment.d auto wysiwyg = r"f// \n\"; -// ^^ punctuation.definition.string.begin.d -// ^^^^^^^^^^ string.quoted.double.raw.d +// ^^^^^^^^^^ meta.string.d string.quoted.double.raw.d +// ^ storage.modifier.string.d +// ^ punctuation.definition.string.begin.d // ^^ - constant.character.escape.d // ^ punctuation.definition.string.end.d auto wysiwygAlt = `f//\n\`; +// ^^^^^^^^ meta.string.d string.quoted.double.raw.backtick.d // ^ punctuation.definition.string.begin.d -// ^^^^^^^^ string.quoted.double.raw.backtick.d // ^^ - constant.character.escape.d // ^ punctuation.definition.string.end.d auto doubleQuoted = "c://\'\"\?\\\0\a\b\f\n\r\t\v\x0B\2\12\762\u0feb\Uabcdef98\""; +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.d string.quoted.double.d // ^ punctuation.definition.string.begin.d -// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ string.quoted.double.d // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ constant.character.escape.d // ^ punctuation.definition.string.end.d auto invalidEscape = "\p"; // ^^ string.quoted.double.d invalid.illegal.unknown-escape.d auto invalidEscape2 = "\u0fe"; -// ^^^^^^^ string.quoted.double.d +// ^^^^^^^ meta.string.d string.quoted.double.d // ^^ invalid.illegal.unknown-escape.d auto invalidEscape3 = "\&;"; -// ^^^^^ string.quoted.double.d +// ^^^^^ meta.string.d string.quoted.double.d // ^^ invalid.illegal.unknown-escape.d auto invalidEscape4 = "\u12398"; -// ^^^^^^^^^ string.quoted.double.d +// ^^^^^^^^^ meta.string.d string.quoted.double.d // ^^^^^^ constant.character.escape.d // ^ - constant.character.escape.d auto hexString = x"00 ba -// ^^ punctuation.definition.string.begin.d -// ^^^^^^^^ string.quoted.double.raw.d +// ^^^^^^^^ meta.string.d string.quoted.double.raw.d +// ^ storage.modifier.string.d +// ^ punctuation.definition.string.begin.d 5 5 b"; -// ^^^^^^^ string.quoted.double.raw.d +// ^^^^^^^ meta.string.d string.quoted.double.raw.d // ^^^ string.quoted.double.raw.d constant.character.escape.d // ^ string.quoted.double.raw.d invalid.illegal.unknown-escape.d // ^ string.quoted.double.raw.d punctuation.definition.string.end.d auto deliminated = q"SQL_1 -// ^^^^^^^ string.quoted.double.raw.d punctuation.definition.string.begin.d +// ^^^^^^^^ meta.string.d string.quoted.double.raw.d +// ^ storage.modifier.string.d +// ^ punctuation.definition.string.begin.d +// ^^^^^ constant.other.delimeter.d select foo \n -// ^^^^^^^^^^^^^^ string.quoted.double.raw.d +// ^^^^^^^^^^^^^^ meta.string.d string.quoted.double.raw.d SQL_1"; -// <- string.quoted.double.raw.d punctuation.definition.string.end.d -// ^^^ string.quoted.double.raw.d punctuation.definition.string.end.d +// <- meta.string.d string.quoted.double.raw.d constant.other.delimeter.d +//^^^^ meta.string.d string.quoted.double.raw.d +// ^^ constant.other.delimeter.d +// ^ punctuation.definition.string.end.d +// ^ punctuation.terminator.d +// - meta.string.d auto deliminatedBad = q"SQL\ -// ^ string.quoted.double.raw.d punctuation.definition.string.begin.d invalid.illegal.d +// ^ meta.string.d string.quoted.double.raw.d invalid.illegal.d SQL"; auto deliminatedNested = q"(f("))" + q"{f{"}}" + q"[f["]]" + q">"; -// ^^^ punctuation.definition.string.begin.d -// ^^^^^^^^^ string.quoted.double.raw.d +// ^^^^^^^^^ meta.string.d string.quoted.double.raw.d +// ^ storage.modifier.string.d +// ^^ punctuation.definition.string.begin.d // ^^ punctuation.definition.string.end.d -// ^^^ punctuation.definition.string.begin.d -// ^^^^^^^^^ string.quoted.double.raw.d +// ^^^^^^^^^ meta.string.d string.quoted.double.raw.d +// ^ storage.modifier.string.d +// ^^ punctuation.definition.string.begin.d // ^^ punctuation.definition.string.end.d -// ^^^ punctuation.definition.string.begin.d -// ^^^^^^^^^ string.quoted.double.raw.d +// ^^^^^^^^^ meta.string.d string.quoted.double.raw.d +// ^ storage.modifier.string.d +// ^^ punctuation.definition.string.begin.d // ^^ punctuation.definition.string.end.d -// ^^^ punctuation.definition.string.begin.d -// ^^^^^^^^^ string.quoted.double.raw.d +// ^^^^^^^^^ meta.string.d string.quoted.double.raw.d +// ^ storage.modifier.string.d +// ^^ punctuation.definition.string.begin.d // ^^ punctuation.definition.string.end.d auto deliminatedAny = q"/foo(xxx)/"; -// ^^^ punctuation.definition.string.begin.d -// ^^^^^^^^^^^^^ string.quoted.double.raw.d -// ^^ punctuation.definition.string.end.d +// ^^^^^^^^^^^^^ meta.string.d string.quoted.double.raw.d +// ^ storage.modifier.string.d +// ^ punctuation.definition.string.begin.d +// ^ constant.other.delimeter.d +// ^ constant.other.delimeter.d +// ^ punctuation.definition.string.end.d auto stringPostfix = ``c + ""w + q"//"d; -// ^ string.quoted.double.raw.backtick.d storage.type.string.d -// ^ string.quoted.double.d storage.type.string.d -// ^ string.quoted.double.raw.d storage.type.string.d +// ^ meta.string.d string.quoted.double.raw.backtick.d storage.type.string.d +// ^ meta.string.d string.quoted.double.d storage.type.string.d +// ^ meta.string.d string.quoted.double.raw.d storage.type.string.d auto tokenString = q{ -// ^^ string.unquoted.embedded.d punctuation.definition.string.begin.d +// ^^ meta.string.d string.unquoted.embedded.d +// ^ storage.modifier.string.d +// ^ punctuation.definition.string.begin.d this is not real code 12 +// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.string.d // ^^^^ variable.language.d // ^^ keyword.d // ^^^^ storage.type.d // ^^ constant.numeric.integer.d /*}*/ +// ^^^^^^ meta.string.d // ^^ punctuation.definition.comment.d // ^^ punctuation.definition.comment.d // ^^^^^ comment.block.d '' 'a' +// ^^^^^^^^ meta.string.d // ^^ invalid.illegal.d // ^^^ string.quoted.single.d __TIME__ -// ^^^^^^^^ constant.language.d +// ^^^^^^^^ meta.string.d constant.language.d }; -// <- string.unquoted.embedded.d punctuation.definition.string.end.d +// <- meta.string.d string.unquoted.embedded.d punctuation.definition.string.end.d auto c = 'a'; -// ^^^ string.quoted.single.d +// ^^^ meta.string.d string.quoted.single.d c = 'Ó'; -// ^^^ string.quoted.single.d +// ^^^ meta.string.d string.quoted.single.d c = '\n'; -// ^^^^ string.quoted.single.d +// ^^^^ meta.string.d string.quoted.single.d // ^^ constant.character.escape.d c = '\x'; // ^^^^ invalid.illegal.d From c6891c01ed3edbb00d49d03dcfeab6a2fb8ad706 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 14:51:11 +1100 Subject: [PATCH 091/108] Add meta.function scopes for functions --- D/D.sublime-syntax | 72 +++++++++++----- D/tests/syntax_test_d.d | 186 ++++++++++++++++++++++++++++------------ 2 files changed, 180 insertions(+), 78 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index d4d1b47061..609ae2714f 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -776,7 +776,7 @@ contexts: scope: keyword.operator.assignment.d push: value - match: ':' - scope: keyword.operator.assignment.d + scope: punctuation.separator.mapping.d push: value - match: '\)' scope: punctuation.section.group.end.d @@ -792,10 +792,12 @@ contexts: function-or-variable-after-type: - match: '\b({{operator_overloads}})\s*(?=\(|$)' + scope: meta.function.d captures: 1: keyword.operator.overload.d set: function-definition-begin - match: '\b({{name}})\s*(?=\(|$)' + scope: meta.function.d captures: 1: entity.name.function.d set: function-definition-begin @@ -806,19 +808,24 @@ contexts: set: [function-definition-after-first-argument-list, function-argument-definition-list] - include: not-whitespace-illegal function-definition-after-first-argument-list: - - match: '=' - scope: keyword.operator.assignment.d - set: [expect-end-of-line, value] - match: '(?=\()' - set: [function-definition-after-arguments, function-argument-definition-list] - - include: function-definition-after-arguments + set: [function-definition-before-after-arguments, function-argument-definition-list] + - match: '(?=\S)' + set: function-definition-after-arguments + function-definition-before-after-arguments: + - match: '' + set: function-definition-after-arguments function-definition-after-arguments: + - meta_scope: meta.function.d - include: function-attribute-in + - match: '=' + scope: keyword.operator.assignment.d + set: [meta-function, expect-end-of-line, value] - match: '\bif\b' scope: keyword.control.conditional.d - set: [function-definition-after-condition, condition] + set: [meta-function, function-definition-after-condition, condition] - match: '(?=\S)' - set: function-definition-after-condition + set: [meta-function, function-definition-after-condition] function-definition-after-condition: - match: '\bin\b' scope: keyword.control.conditional.d @@ -863,16 +870,18 @@ contexts: pop: true - include: not-whitespace-illegal-pop function-argument-definition-list: + - meta_scope: meta.function.parameters.d - match: '\(' scope: punctuation.section.group.begin.d set: function-argument-definition-list-content - include: not-whitespace-illegal function-argument-definition-list-content: + - meta_scope: meta.function.parameters.d - match: '\)' scope: punctuation.section.group.end.d pop: true - match: '(?=\S)' - set: [function-argument, function-argument-or-type] + set: [meta-function-parameters, function-argument, function-argument-or-type] function-argument-or-type: - include: parameter-attribute-in - match: '\.\.\.' @@ -1677,38 +1686,38 @@ contexts: # Post-blit constructor - match: '\b(this)\s*(\()\s*(this)\s*(\))' captures: - 1: entity.name.function.post-blit.d - 2: punctuation.section.group.begin.d - 3: variable.language.d - 4: punctuation.section.group.end.d + 1: meta.function.d entity.name.function.post-blit.d + 2: meta.function.parameters.d punctuation.section.group.begin.d + 3: meta.function.parameters.d variable.language.d + 4: meta.function.parameters.d punctuation.section.group.end.d set: function-definition-after-arguments - match: '\b(this)\s*(?=\(|$)' captures: - 1: entity.name.function.constructor.d + 1: meta.function.d entity.name.function.constructor.d 2: punctuation.section.group.begin.d set: constructor-argument-list - - match: '(~\s*this)\s*(\()\s*(\))' - captures: - 1: entity.name.function.destructor.d - 2: punctuation.section.group.begin.d - 3: punctuation.section.group.end.d - set: function-definition-after-arguments + - match: '~\s*this' + scope: meta.function.d entity.name.function.destructor.d + set: destructor-arguments - include: not-whitespace-illegal-pop # This could either be function/template parameters or arguments. Assume # arguments and switch to parameters when possible constructor-argument-list: + - meta_scope: meta.function.parameters.d - match: '\(' scope: punctuation.section.group.begin.d set: + - meta_scope: meta.function.parameters.d - match: '\)' scope: punctuation.section.group.end.d set: function-definition-after-first-argument-list - match: '{{parameter_attribute_lookahead}}' - set: [function-definition-after-first-argument-list, function-argument-definition-list-content] + set: [function-definition-after-first-argument-list, meta-function-parameters, function-argument-definition-list-content] - match: '(?=\S)' set: [constructor-argument-list-after-value, value] - include: not-whitespace-illegal-pop constructor-argument-list-after-value: + - meta_scope: meta.function.parameters.d - match: ',' scope: punctuation.separator.sequence.d set: [constructor-argument-list-after-value, value] @@ -1716,7 +1725,17 @@ contexts: scope: punctuation.section.group.end.d set: function-definition-after-first-argument-list - match: '(?=\S)' - set: [function-definition-after-first-argument-list, function-argument] + set: [function-definition-after-first-argument-list, meta-function-parameters, function-argument] + destructor-arguments: + - match: '\(' + scope: meta.function.parameters.d punctuation.section.group.begin.d + set: + - meta_scope: meta.function.parameters.d + - match: '\)' + scope: punctuation.section.group.end.d + set: function-definition-after-arguments + - include: not-whitespace-illegal-pop + - include: not-whitespace-illegal-pop invariant-in: - match: '\b(invariant)\b' @@ -2083,3 +2102,12 @@ contexts: - include: end-of-line - match: '(?=\S)' pop: true + + meta-function: + - meta_scope: meta.function.d + - match: '' + pop: true + meta-function-parameters: + - meta_scope: meta.function.parameters.d + - match: '' + pop: true diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index b746852b79..cc0f80eaf8 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -891,26 +891,31 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d - int[string] foo() { + int[string] foo() {} //^^^ storage.type.d // ^ punctuation.section.brackets.begin.d // ^^^^^^ storage.type.d // ^ punctuation.section.brackets.end.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d void bar(); //^^^^ storage.type.d - // ^^^ entity.name.function.d + // ^^^ meta.function.d entity.name.function.d + // ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d - // ^ punctuation.terminator.d + // ^ meta.function.d punctuation.terminator.d int[] map(int[] array, ) { //^^^ storage.type.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d - // ^^^ entity.name.function.d + // ^^^ meta.function.d entity.name.function.d + // ^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d // ^ punctuation.section.brackets.begin.d @@ -918,14 +923,18 @@ extern(1) // ^^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^ - // ^ punctuation.section.block.begin.d + // ^ meta.function.d meta.block.d punctuation.section.block.begin.d + foo(); + //^^^^^^^ meta.function.d meta.block.d + //^^^ variable.function.d } - //^ punctuation.section.block.end.d + //^ meta.function.d meta.block.d punctuation.section.block.end.d T[] map(T, void fn)(T[] array) { //^ variable.other.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d - // ^^^ entity.name.function.d + // ^^^ meta.function.d entity.name.function.d + // ^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d @@ -938,34 +947,35 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^^^^^ variable.parameter.d // ^ punctuation.section.group.end.d - // ^ punctuation.section.block.begin.d + // ^ meta.function.d meta.block.d punctuation.section.block.begin.d } - //^ punctuation.section.block.end.d - } -//^ punctuation.section.block.end.d + //^ meta.function.d meta.block.d punctuation.section.block.end.d VeryLongTypeNameThatWillForceALineWrapWith80WidthLines //^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ variable.other.d veryLongFunctionNameToHelpWithTheLineWrappingThing -//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ entity.name.function.d +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.d entity.name.function.d ( -//^ punctuation.section.group.begin.d +//^ meta.function.parameters.d punctuation.section.group.begin.d int aVeryLongArgumentName, + //^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d //^^^ storage.type.d // ^^^^^^^^^^^^^^^^^^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d ) -//^ punctuation.section.group.end.d +//^ meta.function.parameters.d punctuation.section.group.end.d { -//^ punctuation.section.block.begin.d +//^ meta.function.d meta.block.d punctuation.section.block.begin.d int a; + //^^^^^^^ meta.function.d meta.block.d //^^^ storage.type.d // ^ variable.other.d // ^ punctuation.terminator.d } -//^ punctuation.section.block.end.d +//^ meta.function.d meta.block.d punctuation.section.block.end.d void foo(T)(ref T[] a) {} //^^^^ storage.type.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d @@ -976,11 +986,13 @@ extern(1) // ^ punctuation.section.brackets.end.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void f(T..., string[] B...)(ref T[] a...) {} //^^^^ storage.type.d -// ^ entity.name.function.d +// ^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d // ^^^ keyword.operator.variadic.d @@ -999,11 +1011,13 @@ extern(1) // ^ variable.parameter.d // ^^^ keyword.operator.variadic.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void f(T = int)(T[] a = [1, 2, 3]) {} //^^^^ storage.type.d -// ^ entity.name.function.d +// ^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d // ^ keyword.operator.assignment.d @@ -1023,11 +1037,13 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void foo(in int a, out int f) {} //^^^^ storage.type.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^ storage.modifier.d // ^^^ storage.type.d @@ -1037,51 +1053,64 @@ extern(1) // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void opEquals(int a) {} //^^^^ storage.type.d -// ^^^^^^^^ keyword.operator.overload.d +// ^^^^^^^^ meta.function.d keyword.operator.overload.d +// ^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d caster foo() {} //^^^^^^ storage.type.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d auto foo() {} //^^^^ storage.modifier.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d static foo() {} //^^^^^^ storage.modifier.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @property foo() {} //^ punctuation.definition.annotation.begin.d // ^^^^^^^^ storage.attribute.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d pure foo() {} //^^^^ storage.modifier.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d const(string) foo(T)(ref const(int) a, auto ref T b) {} @@ -1089,7 +1118,8 @@ extern(1) // ^ punctuation.section.group.begin.d // ^^^^^^ storage.type.d // ^ punctuation.section.group.end.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d @@ -1106,11 +1136,13 @@ extern(1) // ^ storage.type.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void foo(A : int, string a : "s") {} //^^^^ storage.type.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d // ^ keyword.operator.assignment.d @@ -1121,13 +1153,16 @@ extern(1) // ^ keyword.operator.assignment.d // ^^^ string.quoted.double.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void foo() const inout @property {} //^^^^ storage.type.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.d // ^^^^^ storage.modifier.d // ^^^^^ storage.modifier.d // ^ punctuation.definition.annotation.begin.d @@ -1136,15 +1171,18 @@ extern(1) // ^ punctuation.section.block.end.d void f() //^^^^ storage.type.d -// ^ entity.name.function.d +// ^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d in(true) +//^^^^^^^^^ meta.function.d //^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d // ^^^^ constant.language.d // ^ punctuation.section.parens.end.d in(true || false) +//^^^^^^^^^^^^^^^^^^ meta.function.d //^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d // ^^^^ constant.language.d @@ -1152,6 +1190,7 @@ extern(1) // ^^^^^ constant.language.d // ^ punctuation.section.parens.end.d out(; false || true) +//^^^^^^^^^^^^^^^^^^^^^ meta.function.d //^^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d // ^ punctuation.separator.sequence.d @@ -1160,16 +1199,19 @@ extern(1) // ^^^^ constant.language.d // ^ punctuation.section.parens.end.d {} +//^^ meta.function.d //^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void f(A)() if (is(A : B)) //^^^^ storage.type.d -// ^ entity.name.function.d +// ^ meta.function.d entity.name.function.d +// ^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d // ^ // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^^^^^^^^^^^^^^ meta.function.d // ^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d // ^^ keyword.other.d @@ -1180,39 +1222,45 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.section.parens.end.d in {} +//^^^^^^ meta.function.d //^^ keyword.control.conditional.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d out (foo) { +//^^^^^^^^^^^^ meta.function.d //^^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d // ^^^ variable.parameter.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d assert(true); + //^^^^^^^^^^^^^^ meta.function.d meta.block.d //^^^^^^ keyword.other.assert.d // ^ punctuation.section.parens.begin.d // ^^^^ constant.language.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d foo(4); + //^^^^^^^^ meta.function.d meta.block.d //^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d } -//^ punctuation.section.block.end.d +//^ meta.function.d meta.block.d punctuation.section.block.end.d body { //^^^^ keyword.other.d // ^ punctuation.section.block.begin.d } void f() //^^^^ storage.type.d -// ^ entity.name.function.d +// ^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d out (foo; foo == true) {} +//^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.d //^^^ keyword.control.conditional.d // ^ punctuation.section.parens.begin.d // ^^^ variable.parameter.d @@ -1221,6 +1269,7 @@ extern(1) // ^^ keyword.operator.comparison.d // ^^^^ constant.language.d // ^ punctuation.section.parens.end.d +// ^^ meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void f(...); @@ -1232,25 +1281,36 @@ extern(1) // ^ punctuation.terminator.d this(int foo) { -//^^^^ entity.name.function.constructor.d +//^^^^ meta.function.d entity.name.function.constructor.d +// ^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d -// ^ punctuation.section.block.begin.d +// ^ meta.function.d meta.block.d punctuation.section.block.begin.d } -//^ punctuation.section.block.end.d +//^ meta.function.d meta.block.d punctuation.section.block.end.d ~this() @disable; -//^^^^^ entity.name.function.destructor.d +//^^^^^ meta.function.d entity.name.function.destructor.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^^^^^^^^ meta.function.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ storage.attribute.d // ^ punctuation.terminator.d this(this) {} -//^^^^ entity.name.function.post-blit.d +//^^^^ meta.function.d entity.name.function.post-blit.d +// ^^^^^^ meta.function.d meta.function.parameters.d +// ^ punctuation.section.group.begin.d +// ^^^^ variable.language.d +// ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d this(1, 2, 3); -//^^^^ entity.name.function.constructor.d +//^^^^ meta.function.d entity.name.function.constructor.d +// ^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d @@ -1258,9 +1318,10 @@ extern(1) // ^ punctuation.separator.sequence.d // ^ constant.numeric.integer.d // ^ punctuation.section.group.end.d -// ^ punctuation.terminator.d +// ^ meta.function.d punctuation.terminator.d this(T)(T foo); -//^^^^ entity.name.function.constructor.d +//^^^^ meta.function.d entity.name.function.constructor.d +// ^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.other.d // ^ punctuation.section.group.end.d @@ -1268,25 +1329,29 @@ extern(1) // ^ storage.type.d // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d -// ^ punctuation.terminator.d +// ^ meta.function.d punctuation.terminator.d this(in ref foo t) {} -//^^^^ entity.name.function.constructor.d +//^^^^ meta.function.d entity.name.function.constructor.d +// ^^^^^^^^^^^^^^ meta.function.parameters.d meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^ storage.modifier.d // ^^^ storage.modifier.d // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d static this(int foo) { int b; } //^^^^^^ storage.modifier.d -// ^^^^ entity.name.function.constructor.d +// ^^^^ meta.function.d entity.name.function.constructor.d +// ^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^^^^^^^^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^^^ storage.type.d // ^ variable.other.d @@ -1294,9 +1359,11 @@ extern(1) // ^ punctuation.section.block.end.d static ~this() { int a; } //^^^^^^ storage.modifier.d -// ^^^^^ entity.name.function.destructor.d +// ^^^^^ meta.function.d entity.name.function.destructor.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^^^^^^^^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^^^ storage.type.d // ^ variable.other.d @@ -1806,18 +1873,20 @@ extern(1) override int foo() { //^^^^^^^^ storage.modifier.d // ^^^ storage.type.d - // ^^^ entity.name.function.d + // ^^^ meta.function.d entity.name.function.d + // ^^ meta.block.d meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d - // ^ punctuation.section.block.begin.d + // ^ meta.function.d meta.block.d punctuation.section.block.begin.d return num * 3; + //^^^^^^^^^^^^^^^^ meta.block.d meta.function.d meta.block.d //^^^^^^ keyword.control.flow.d // ^^^ variable.other.d // ^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d } - //^ punctuation.section.block.end.d + //^ meta.function.d meta.block.d punctuation.section.block.end.d }; //^ punctuation.section.block.end.d // ^ punctuation.terminator.d @@ -2017,7 +2086,8 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d -// ^ entity.name.function.d +// ^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d @@ -2025,8 +2095,7 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d -// ^ punctuation.terminator.d -// ^ +// ^ meta.function.d punctuation.terminator.d typeof(return); //^^^^^^ keyword.other.d // ^ punctuation.section.parens.begin.d @@ -2146,7 +2215,8 @@ extern(1) // ^ punctuation.terminator.d void fn(int delegate(ref Foo, scope float function(int a)) f); //^^^^ storage.type.d -// ^^ entity.name.function.d +// ^^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d // ^^^^^^^^ keyword.other.d @@ -2163,7 +2233,7 @@ extern(1) // ^^ punctuation.section.group.end.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d -// ^ punctuation.terminator.d +// ^ meta.function.d punctuation.terminator.d return () @trusted inout {}; //^^^^^^ keyword.control.flow.d // ^ punctuation.section.parens.begin.d @@ -2307,7 +2377,8 @@ extern(1) void toString(Writer)(ref Writer w, const ref FormatSpec!char fmt) {} //^^^^ storage.type.d -// ^^^^^^^^ entity.name.function.d +// ^^^^^^^^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^^^^ variable.parameter.d // ^ punctuation.section.group.end.d @@ -2323,6 +2394,7 @@ extern(1) // ^^^^ storage.type.d // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -2355,7 +2427,8 @@ extern(1) auto staticArray(size_t n, T)(scope T a) {} //^^^^ storage.modifier.d -// ^^^^^^^^^^^ entity.name.function.d +// ^^^^^^^^^^^ meta.function.d entity.name.function.d +// ^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^^^^ storage.type.d // ^ variable.parameter.d @@ -2367,6 +2440,7 @@ extern(1) // ^ storage.type.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d From 7c3c1300a69ab99367a6fdc43acd2384e511d7da Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 15:08:21 +1100 Subject: [PATCH 092/108] Add meta.function scopes for lambdas --- D/D.sublime-syntax | 37 +++++++++++++++++++++---------------- D/tests/syntax_test_d.d | 12 +++++++++++- 2 files changed, 32 insertions(+), 17 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 609ae2714f..a31647e57c 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -33,6 +33,7 @@ variables: attribute_lookahead: '(?=@|\b({{attributes}}|extern|align|deprecated|pragma|private|protected|public|export|package)\b)' attributes: 'static|abstract|final|override|synchronized|scope|__gshared|nothrow|pure|ref|return|auto' at_attributes: 'disable|nogc|property|safe|system|trusted' + function_attribute_lookahead: '{{attribute_lookahead}}|{{type_qualifier_lookahead}}' parameter_attribute_lookahead: '(?=\b({{parameter_attribute}})\b)' parameter_attribute: 'in|lazy|out|alias' @@ -870,7 +871,6 @@ contexts: pop: true - include: not-whitespace-illegal-pop function-argument-definition-list: - - meta_scope: meta.function.parameters.d - match: '\(' scope: punctuation.section.group.begin.d set: function-argument-definition-list-content @@ -1092,24 +1092,19 @@ contexts: scope: punctuation.separator.sequence.d set: [value-parens-after, value-list] - match: '\b(function|delegate)\b' - scope: keyword.other.d + scope: meta.function.d keyword.other.d set: + - meta_scope: meta.function.d - match: '(?=\()' set: [value-after, function-definition-begin] - match: '(?=\S)' - set: [value-after, function-definition-begin, type] + set: [value-after, function-definition-begin, meta-function, type] - match: '(\()\s*(\))' + scope: meta.function.parameters.d captures: 1: punctuation.section.parens.begin.d 2: punctuation.section.parens.end.d - set: - - include: function-attribute-in - - match: '=>' - scope: keyword.operator.lambda.d - set: value - - match: '(?={)' - set: [value-after, block-statement] - - include: not-whitespace-illegal-pop + set: [value-after, value-group-after-parens] - match: '\(' scope: punctuation.section.group.begin.d set: @@ -1146,7 +1141,7 @@ contexts: captures: 1: variable.parameter.d 2: keyword.operator.lambda.d - set: value + set: [meta-function, value] - match: \. scope: punctuation.accessor.dot.d set: [value-after, value-identifier] @@ -1254,14 +1249,24 @@ contexts: scope: keyword.operator.variadic.d - include: not-whitespace-illegal value-group-after-parens: - - include: function-attribute-in + - match: '{{function_attribute_lookahead}}' + set: value-group-after-lambda - match: (?={) - set: [value-after, block-statement] + set: [value-after, meta-function, block-statement] - match: '=>' - scope: keyword.operator.lambda.d - set: value + scope: meta.function.d keyword.operator.lambda.d + set: [meta-function, value] - match: (?=\S) set: value-after + value-group-after-lambda: + - meta_scope: meta.function.d + - include: function-attribute-in + - match: (?={) + set: [value-after, meta-function, block-statement] + - match: '=>' + scope: meta.function.d keyword.operator.lambda.d + set: [meta-function, value] + - include: not-whitespace-illegal-pop value-identifier: - match: '\b{{name}}\b(?=\s*\()' scope: variable.function.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index cc0f80eaf8..2a65e2f616 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -448,6 +448,7 @@ extern(1) //^^^^^ keyword.control.alias.d // ^^^^^ entity.name.type.d // ^ keyword.operator.assignment.d +// ^^^^^^ meta.function.d // ^ variable.parameter.d // ^^ keyword.operator.lambda.d // ^ variable.other.d @@ -2236,14 +2237,18 @@ extern(1) // ^ meta.function.d punctuation.terminator.d return () @trusted inout {}; //^^^^^^ keyword.control.flow.d +// ^^ meta.function.parameters.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d +// ^^^^^^^^^^^^^^^^^ meta.function.d +// ^^ meta.block.d (in ref a) {}; //^ punctuation.section.group.begin.d // ^^ storage.modifier.d // ^^^ storage.modifier.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d @@ -2257,7 +2262,8 @@ extern(1) // ^^^ variable.other.d // ^ punctuation.terminator.d function(int a, string b) @trusted {}; -//^^^^^^^^ keyword.other.d +//^^^^^^^^ meta.function.d keyword.other.d +// ^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d // ^ variable.parameter.d @@ -2265,18 +2271,22 @@ extern(1) // ^^^^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^^^^^^^^^^ meta.function.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ storage.attribute.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d function size_t(foo a) {}; +//^^^^^^^^^^^^^^^ meta.function.d //^^^^^^^^ keyword.other.d // ^^^^^^ storage.type.d +// ^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d From 00a3967b0de137f583fc0cabf56393936bbd885d Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 15:12:20 +1100 Subject: [PATCH 093/108] Fix lambda operator scope --- D/D.sublime-syntax | 6 +++--- D/tests/syntax_test_d.d | 18 ++++++++++++++---- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index a31647e57c..6a6eb7840b 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1140,7 +1140,7 @@ contexts: - match: '\b({{name}})\s*(=>)' captures: 1: variable.parameter.d - 2: keyword.operator.lambda.d + 2: storage.type.function.d keyword.declaration.function.lambda.d set: [meta-function, value] - match: \. scope: punctuation.accessor.dot.d @@ -1254,7 +1254,7 @@ contexts: - match: (?={) set: [value-after, meta-function, block-statement] - match: '=>' - scope: meta.function.d keyword.operator.lambda.d + scope: meta.function.d storage.type.function.d keyword.declaration.function.lambda.d set: [meta-function, value] - match: (?=\S) set: value-after @@ -1264,7 +1264,7 @@ contexts: - match: (?={) set: [value-after, meta-function, block-statement] - match: '=>' - scope: meta.function.d keyword.operator.lambda.d + scope: meta.function.d storage.type.function.d keyword.declaration.function.lambda.d set: [meta-function, value] - include: not-whitespace-illegal-pop value-identifier: diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 2a65e2f616..33c3d2797f 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -450,7 +450,7 @@ extern(1) // ^ keyword.operator.assignment.d // ^^^^^^ meta.function.d // ^ variable.parameter.d -// ^^ keyword.operator.lambda.d +// ^^ storage.type.function.d keyword.declaration.function.lambda.d // ^ variable.other.d // ^ punctuation.terminator.d @@ -2105,17 +2105,20 @@ extern(1) // ^ punctuation.terminator.d () @trusted => 2; +//^^ meta.function.parameters.d //^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d +// ^^^^^^^^^^^^^ meta.function.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ storage.attribute.d -// ^^ keyword.operator.lambda.d +// ^^ storage.type.function.d keyword.declaration.function.lambda.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d (a => 2); //^ punctuation.section.group.begin.d +// ^^^^^^ meta.function.d // ^ variable.parameter.d -// ^^ keyword.operator.lambda.d +// ^^ storage.type.function.d keyword.declaration.function.lambda.d // ^ constant.numeric.integer.d // ^ punctuation.section.group.end.d // ^ punctuation.terminator.d @@ -2123,9 +2126,10 @@ extern(1) //^ punctuation.section.group.begin.d // ^^^ variable.other.d // ^ punctuation.section.group.end.d +// ^^^^^^^^^^^^^^^^^^ meta.function.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ storage.attribute.d -// ^^ keyword.operator.lambda.d +// ^^ storage.type.function.d keyword.declaration.function.lambda.d // ^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d @@ -2138,8 +2142,10 @@ extern(1) // ^ punctuation.separator.sequence.d // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^^^^^^^ meta.function.d // ^ punctuation.definition.annotation.begin.d // ^^^^ storage.attribute.d +// ^^ meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d @@ -2147,6 +2153,7 @@ extern(1) //^ punctuation.section.group.begin.d // ^^^ variable.other.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.section.parens.begin.d @@ -2157,9 +2164,11 @@ extern(1) // ^^^ storage.type.d // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^^^^^^^^^^^^ meta.function.d // ^^^^ storage.modifier.d // ^ punctuation.definition.annotation.begin.d // ^^^^ storage.attribute.d +// ^^ meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d @@ -2175,6 +2184,7 @@ extern(1) // ^^^ storage.type.d // ^ variable.parameter.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d From ea7f25c4aed21be462ae1435f7cea9f2e30d2e91 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 16:46:39 +1100 Subject: [PATCH 094/108] Add function call meta scopes --- D/D.sublime-syntax | 71 +++++++++++++++++++++++++++++++---------- D/tests/syntax_test_d.d | 32 ++++++++++++++----- 2 files changed, 79 insertions(+), 24 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 6a6eb7840b..9490ad1ed9 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -575,10 +575,11 @@ contexts: scope: punctuation.section.parens.begin.d set: [uda-after, value-list] - match: '({{name}})\s*(\()' + scope: meta.function-call.d captures: 1: storage.type.d 2: punctuation.section.parens.begin.d - set: [uda-after, value-list] + set: [meta-function-call, uda-after, value-list] - match: '({{name}})\b' scope: storage.type.d pop: true @@ -703,14 +704,14 @@ contexts: - match: '\b(delegate|function)\b' scope: keyword.other.d set: [basic-type2, function-type] - - match: '!' - scope: keyword.operator.d + - match: '!(?!=)' + scope: meta.function-call.d keyword.operator.d set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [basic-type2, basic-type2-after-parens, value-list] + set: [basic-type2, basic-type2-after-call, value-list] - match: '(?=\S)' - set: value + set: [value-after, meta-function-call, value-template-single] - match: '\.(?!\.\.)' scope: storage.type.d set: @@ -729,6 +730,9 @@ contexts: scope: punctuation.section.parens.end.d pop: true - include: not-whitespace-illegal-pop + basic-type2-after-call: + - meta_scope: meta.function-call.d + - include: basic-type2-after-parens typeof-value: - match: '\breturn\b' @@ -976,7 +980,7 @@ contexts: set: value-list - match: '{{name_lookahead}}' scope: variable.other.d - set: [first-value-after, identifier-ref] + set: [first-value-after, value-identifier] - match: '(?=\S)' set: value-list first-value-after: @@ -984,11 +988,11 @@ contexts: scope: punctuation.accessor.dot.d push: identifier - match: '!(?!=)' - scope: keyword.operator.d + scope: meta.function-call.d keyword.operator.d set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [first-value-parens-after, value-list] + set: [first-value-call-after, value-list] - match: '(?=\S)' set: first-value - match: '\[' @@ -1016,6 +1020,9 @@ contexts: scope: punctuation.section.parens.end.d set: first-value-after - include: not-whitespace-illegal + first-value-call-after: + - meta_scope: meta.function-call.d + - include: first-value-parens-after value: - include: attribute-in @@ -1173,9 +1180,10 @@ contexts: set: [new-after-named, type] - include: not-whitespace-illegal new-after-named: + - meta_scope: meta.function-call.d - match: '\(' scope: punctuation.section.parens.begin.d - set: [value-parens-after, value-list] + set: [value-call-parens-after, value-list] - match: (?=\S) set: value-after new-anonymous-after-args: @@ -1268,8 +1276,8 @@ contexts: set: [meta-function, value] - include: not-whitespace-illegal-pop value-identifier: - - match: '\b{{name}}\b(?=\s*\()' - scope: variable.function.d + - match: '\b{{name}}\b(?=\s*(\(|!(?!=)))' + scope: meta.function-call.d variable.function.d pop: true - match: '\b{{name}}\b' scope: variable.other.d @@ -1286,10 +1294,10 @@ contexts: set: value - match: '\.(?!\.\.)' scope: punctuation.accessor.dot.d - set: [value-after, identifier] + set: [value-after, value-identifier] - match: '\(' scope: punctuation.section.parens.begin.d - set: [value-parens-after, value-list] + set: [value-call-parens-after, value-list] - match: '\[' scope: punctuation.section.brackets.begin.d set: [value-bracket-after, value-list] @@ -1315,13 +1323,13 @@ contexts: scope: keyword.operator.assignment.d set: value - match: '!' - scope: keyword.operator.d + scope: meta.function-call.d keyword.operator.d set: - match: '\(' scope: punctuation.section.parens.begin.d - set: [value-parens-after, value-list] + set: [value-call-parens-after, value-list] - match: '(?=\S)' - set: value + set: [value-after, meta-function-call, value-template-single] # This can also be a pointer in some situations - match: \* scope: keyword.operator.arithmetic.d @@ -1337,6 +1345,25 @@ contexts: set: [value-after, basic-type2] - match: '(?=\S)' pop: true + value-template-single: + - match: '\b({{basic_type}})\b' + scope: storage.type.d + set: value-after + - match: '{{number_lookahead}}' + set: [value-after, number] + - match: '{{character_lookahead}}' + set: [value-after, character] + - match: '{{string_lookahead}}' + set: [value-after, string] + - match: '\b({{language_constant}})\b' + scope: constant.language.d + set: value-after + - match: '\b({{language_variable}})\b' + scope: variable.language.d + set: value-after + - match: '{{name_lookahead}}|\.' + set: [value-after, identifier-ref] + - include: not-whitespace-illegal-pop value-condition-after: - match: ':' scope: keyword.operator.logical.d @@ -1347,6 +1374,9 @@ contexts: scope: punctuation.section.parens.end.d set: value-after - include: not-whitespace-illegal + value-call-parens-after: + - meta_scope: meta.function-call.d + - include: value-parens-after value-bracket-after: - match: '\]' scope: punctuation.section.brackets.end.d @@ -2069,6 +2099,9 @@ contexts: set: identifier type-identifier: + - match: '\b{{name}}\b(?=\s*!)' + scope: meta.function-call.d variable.function.d + pop: true - match: '\b{{name}}\b' scope: storage.type.d set: @@ -2112,7 +2145,13 @@ contexts: - meta_scope: meta.function.d - match: '' pop: true + meta-function-parameters: - meta_scope: meta.function.parameters.d - match: '' pop: true + + meta-function-call: + - meta_scope: meta.function-call.d + - match: '' + pop: true diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 33c3d2797f..26eac3465a 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -241,6 +241,7 @@ f = 0xF.AP-2f; // ^ punctuation.definition.annotation.begin.d // ^^^^^ storage.type.d // ^ punctuation.definition.annotation.begin.d +// ^^^^^^^^^ meta.function-call.d // ^^^ storage.type.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d @@ -375,7 +376,8 @@ extern(1) // ^^^^^ string.quoted.double.d // ^ punctuation.section.parens.end.d // ^ punctuation.accessor.dot.d -// ^^^^ variable.other.d +// ^^^^^^^^^^^^ meta.function-call.d +// ^^^^ variable.function.d // ^ keyword.operator.d // ^^^^^^^ variable.other.d // ^ punctuation.terminator.d @@ -1243,6 +1245,7 @@ extern(1) // ^ punctuation.terminator.d foo(4); //^^^^^^^^ meta.function.d meta.block.d + //^^^^^^ meta.function-call.d //^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d @@ -1471,7 +1474,8 @@ extern(1) //^ punctuation.section.block.end.d mixin Foo!("foo"); //^^^^^ keyword.control.d -// ^^^ variable.other.d +// ^^^^^^^^^^^ meta.function-call.d +// ^^^ variable.function.d // ^ keyword.operator.d // ^ punctuation.section.parens.begin.d // ^^^^^ string.quoted.double.d @@ -1592,6 +1596,7 @@ extern(1) // ^ punctuation.terminator.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d +// ^^^^^^^^^^ meta.function-call.d // ^^^^^^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d @@ -1817,6 +1822,7 @@ extern(1) //^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ keyword.operator.word.d +// ^^^^^ meta.function-call.d // ^^^ storage.type.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d @@ -2130,6 +2136,7 @@ extern(1) // ^ punctuation.definition.annotation.begin.d // ^^^^^^^ storage.attribute.d // ^^ storage.type.function.d keyword.declaration.function.lambda.d +// ^^^^^^ meta.function-call.d // ^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d @@ -2208,9 +2215,11 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d -// ^^^ entity.name.function.d +// ^^^ meta.function.d entity.name.function.d +// ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d +// ^^ meta.function.d meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d (void function(int foo)).sizeof; @@ -2320,6 +2329,7 @@ extern(1) values ~= toValue(__traits(getMember, this, primaryKey)); //^^^^^^ variable.other.d // ^^ keyword.operator.assignment.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d // ^^^^^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^ keyword.other.d @@ -2361,6 +2371,7 @@ extern(1) // ^^^^^ constant.numeric.integer.d // ^ punctuation.terminator.d foo(); +//^^^^^ meta.function-call.d //^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d @@ -2373,7 +2384,8 @@ extern(1) .AliasSeq!(immutable char, int); //^ punctuation.accessor.dot.d -// ^^^^^^^^ variable.other.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d +// ^^^^^^^^ variable.function.d // ^ keyword.operator.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^^ storage.modifier.d @@ -2386,7 +2398,8 @@ extern(1) cast(Unqual!T*).foo; //^^^^ keyword.operator.word.d // ^ punctuation.section.parens.begin.d -// ^^^^^^ storage.type.d +// ^^^^^^^^ meta.function-call.d +// ^^^^^^ variable.function.d // ^ keyword.operator.d // ^ variable.other.d // ^ keyword.operator.arithmetic.d @@ -2409,7 +2422,8 @@ extern(1) // ^ punctuation.separator.sequence.d // ^^^^^ storage.modifier.d // ^^^ storage.modifier.d -// ^^^^^^^^^^ storage.type.d +// ^^^^^^^^^^^^^^^ meta.function-call.d +// ^^^^^^^^^^ variable.function.d // ^ keyword.operator.d // ^^^^ storage.type.d // ^^^ variable.parameter.d @@ -2470,7 +2484,8 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d -// ^^^^^^^^ variable.other.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d +// ^^^^^^^^ variable.function.d // ^ keyword.operator.d // ^ punctuation.section.parens.begin.d // ^ variable.other.d @@ -2488,7 +2503,8 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d -// ^^^^^^^^ variable.other.d +// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d +// ^^^^^^^^ variable.function.d // ^ keyword.operator.d // ^ punctuation.section.parens.begin.d // ^ variable.other.d From 76534e37529baccd00d7de4b8ab7d253939691ae Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 16:56:54 +1100 Subject: [PATCH 095/108] Fix line comment not including newlines --- D/D.sublime-syntax | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 9490ad1ed9..8554a672e3 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -144,7 +144,7 @@ contexts: - match: \*/ scope: punctuation.definition.comment.d pop: true - - match: (///?).*$ + - match: (///?).*$\n? scope: comment.line.double-slash.d captures: 1: punctuation.definition.comment.d From fe30031be1e865f2806fcc31792642e459ec4af9 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 17:20:41 +1100 Subject: [PATCH 096/108] Add class meta scope --- D/D.sublime-syntax | 43 ++++++++++++++++++++++++----------------- D/tests/syntax_test_d.d | 37 +++++++++++++++++++++-------------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 8554a672e3..50af3f5925 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1167,18 +1167,19 @@ contexts: - include: not-whitespace-illegal new-after: - match: '\bclass\b' - scope: storage.type.class.d keyword.declaration.class.d - set: - - match: '\(' - scope: punctuation.section.parens.begin.d - set: [new-anonymous-after-args, value-list] - - match: '(?={)' - set: optional-template-body-block - - match: '(?=\S)' - set: [optional-template-body-block, base-class-list] + scope: meta.class.d storage.type.class.d keyword.declaration.class.d + set: [meta-class, new-class] - match: (?=\S) set: [new-after-named, type] - include: not-whitespace-illegal + new-class: + - match: '\(' + scope: punctuation.section.parens.begin.d + set: [new-anonymous-after-args, value-list] + - match: '(?={)' + set: optional-template-body-block + - match: '(?=\S)' + set: [optional-template-body-block, base-class-list] new-after-named: - meta_scope: meta.function-call.d - match: '\(' @@ -1469,15 +1470,16 @@ contexts: class-in: - match: '\b(class)\b' scope: storage.type.class.d keyword.declaration.class.d - push: - - match: '\b({{name}})\b' - scope: entity.name.class.d - set: - - match: '(?=\()' - set: [class-after, function-argument-definition-list] - - match: '(?=\S)' - set: class-after - - include: not-whitespace-illegal + push: [meta-class, class-name] + class-name: + - match: '\b({{name}})\b' + scope: entity.name.class.d + set: + - match: '(?=\()' + set: [class-after, function-argument-definition-list] + - match: '(?=\S)' + set: class-after + - include: not-whitespace-illegal class-after: - include: end-of-line - match: ':' @@ -2155,3 +2157,8 @@ contexts: - meta_scope: meta.function-call.d - match: '' pop: true + + meta-class: + - meta_scope: meta.class.d + - match: '' + pop: true diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 26eac3465a..5e00d1cef7 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -497,11 +497,13 @@ extern(1) // ^ punctuation.terminator.d class Foo; +//^^^^^^^^^ meta.class.d //^^^^^ storage.type.class.d keyword.declaration.class.d // ^^^ entity.name.class.d // ^ punctuation.terminator.d class Bar : Foo, b { +//^^^^^^^^^^^^^^^^^^^^^ meta.class.d //^^^^^ storage.type.class.d keyword.declaration.class.d // ^^^ entity.name.class.d // ^ punctuation.separator.mapping.d @@ -510,13 +512,15 @@ extern(1) // ^ storage.type.d // ^ punctuation.section.block.begin.d class b {} + //^^^^^^^^^^ meta.class.d meta.block.d meta.class.d //^^^^^ storage.type.class.d keyword.declaration.class.d // ^ entity.name.class.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d } -//^ punctuation.section.block.end.d +//^ meta.class.d punctuation.section.block.end.d class b(T, int s) { +//^^^^^^^^^^^^^^^^^^^^ meta.class.d //^^^^^ storage.type.class.d keyword.declaration.class.d // ^ entity.name.class.d // ^ punctuation.section.group.begin.d @@ -527,7 +531,7 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d } -//^ punctuation.section.block.end.d +//^ meta.class.d punctuation.section.block.end.d interface S; //^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d @@ -1841,26 +1845,29 @@ extern(1) // ^^ constant.numeric.integer.d // ^ punctuation.section.brackets.end.d // ^ punctuation.terminator.d - auto c = new class(12) T, Bar { + auto c = new class (12) T, Bar { //^^^^ storage.modifier.d // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ keyword.operator.word.d +// ^^^^^^^^^^^^^^^^^^^^ meta.class.d // ^^^^^ storage.type.class.d keyword.declaration.class.d -// ^ punctuation.section.parens.begin.d -// ^^ constant.numeric.integer.d -// ^ punctuation.section.parens.end.d -// ^ storage.type.d -// ^ punctuation.separator.sequence.d -// ^^^ storage.type.d -// ^ punctuation.section.block.begin.d +// ^ punctuation.section.parens.begin.d +// ^^ constant.numeric.integer.d +// ^ punctuation.section.parens.end.d +// ^ storage.type.d +// ^ punctuation.separator.sequence.d +// ^^^ storage.type.d +// ^ meta.block.d punctuation.section.block.begin.d private int foo; + //^^^^^^^^^^^^^^^^^ meta.class.d meta.block.d //^^^^^^^ storage.modifier.access-control.d // ^^^ storage.type.d // ^^^ variable.other.d // ^ punctuation.terminator.d this(int num) { + //^^^^^^^^^^^^^^^^ meta.class.d meta.block.d //^^^^ entity.name.function.constructor.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d @@ -1868,6 +1875,7 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d this.foo = num; + //^^^^^^^^^^^^^^^^ meta.class.d meta.block.d meta.function.d meta.block.d //^^^^ variable.language.d // ^ punctuation.accessor.dot.d // ^^^ variable.other.d @@ -1875,9 +1883,10 @@ extern(1) // ^^^ variable.other.d // ^ punctuation.terminator.d } - //^ punctuation.section.block.end.d + //^ meta.class.d meta.block.d meta.function.d meta.block.d punctuation.section.block.end.d override int foo() { + //^^^^^^^^^^^^^^^^^^^^^ meta.class.d meta.block.d //^^^^^^^^ storage.modifier.d // ^^^ storage.type.d // ^^^ meta.function.d entity.name.function.d @@ -1886,16 +1895,16 @@ extern(1) // ^ punctuation.section.group.end.d // ^ meta.function.d meta.block.d punctuation.section.block.begin.d return num * 3; - //^^^^^^^^^^^^^^^^ meta.block.d meta.function.d meta.block.d + //^^^^^^^^^^^^^^^^ meta.class.d meta.block.d meta.function.d meta.block.d //^^^^^^ keyword.control.flow.d // ^^^ variable.other.d // ^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d } - //^ meta.function.d meta.block.d punctuation.section.block.end.d + //^ meta.class.d meta.block.d meta.function.d meta.block.d punctuation.section.block.end.d }; -//^ punctuation.section.block.end.d +//^ meta.class.d meta.block.d punctuation.section.block.end.d // ^ punctuation.terminator.d mixin("a") = (12 ^^ 4) % 5 / (3++ + --4) ~ "foo"; From bb450a105158985ad001770d85dbb8b03684c715 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 17:31:44 +1100 Subject: [PATCH 097/108] Add interface, struct, union and enum meta scopes --- D/D.sublime-syntax | 112 ++++++++++++++++++++++++---------------- D/tests/syntax_test_d.d | 51 ++++++++++++++---- 2 files changed, 108 insertions(+), 55 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 50af3f5925..3fc92318a7 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1502,15 +1502,16 @@ contexts: interface-in: - match: '\b(interface)\b' scope: storage.type.interface.d keyword.declaration.interface.d - push: - - match: '\b({{name}})\b' - scope: entity.name.interface.d - set: - - match: '(?=\()' - set: [interface-after, function-argument-definition-list] - - match: '(?=\S)' - set: interface-after - - include: not-whitespace-illegal + push: [meta-interface, interface-name] + interface-name: + - match: '\b({{name}})\b' + scope: entity.name.interface.d + set: + - match: '(?=\()' + set: [interface-after, function-argument-definition-list] + - match: '(?=\S)' + set: interface-after + - include: not-whitespace-illegal interface-after: - include: end-of-line - match: ':' @@ -1523,51 +1524,54 @@ contexts: struct-in: - match: '\b(struct)\b' scope: storage.type.struct.d keyword.declaration.struct.d - push: - - match: '\b({{name}})\b' - scope: entity.name.struct.d - set: - - match: '(?=\()' - set: [optional-template-body-block, function-argument-definition-list] - - match: '(?=\S)' - set: optional-template-body-block - - match: '(?={)' + push: [meta-struct, struct-name] + struct-name: + - match: '\b({{name}})\b' + scope: entity.name.struct.d + set: + - match: '(?=\()' + set: [optional-template-body-block, function-argument-definition-list] + - match: '(?=\S)' set: optional-template-body-block - - include: not-whitespace-illegal + - match: '(?={)' + set: optional-template-body-block + - include: not-whitespace-illegal union-in: - match: '\b(union)\b' scope: storage.type.union.d keyword.declaration.union.d - push: - - match: '\b({{name}})\b' - scope: entity.name.union.d - set: - - match: '(?=\()' - set: [optional-template-body-block, function-argument-definition-list] - - match: '(?=\S)' - set: optional-template-body-block - - match: '(?={)' + push: [meta-union, union-name] + union-name: + - match: '\b({{name}})\b' + scope: entity.name.union.d + set: + - match: '(?=\()' + set: [optional-template-body-block, function-argument-definition-list] + - match: '(?=\S)' set: optional-template-body-block - - include: not-whitespace-illegal + - match: '(?={)' + set: optional-template-body-block + - include: not-whitespace-illegal enum-in: - match: '\b(enum)\b' scope: storage.type.enum.d keyword.declaration.enum.d - push: - - match: '(?=\b({{basic_type}})\b)' - push: type - - match: '{{type_qualifier_lookahead}}' - push: type - - match: '\b({{name}})(?=\s*({|:|=|\(|;|$))\b' - scope: entity.name.enum.d - set: enum-after - - match: ':' - scope: punctuation.separator.mapping.d - set: [enum-body, type] - - match: '(?={)' - set: anonymous-enum-body - - match: '(?=\S)' - push: type + push: [meta-enum, enum-after-kw] + enum-after-kw: + - match: '(?=\b({{basic_type}})\b)' + push: type + - match: '{{type_qualifier_lookahead}}' + push: type + - match: '\b({{name}})(?=\s*({|:|=|\(|;|$))\b' + scope: entity.name.enum.d + set: enum-after + - match: ':' + scope: punctuation.separator.mapping.d + set: [enum-body, type] + - match: '(?={)' + set: anonymous-enum-body + - match: '(?=\S)' + push: type enum-after: - include: end-of-line - match: '(?={)' @@ -2162,3 +2166,23 @@ contexts: - meta_scope: meta.class.d - match: '' pop: true + + meta-interface: + - meta_scope: meta.interface.d + - match: '' + pop: true + + meta-struct: + - meta_scope: meta.struct.d + - match: '' + pop: true + + meta-union: + - meta_scope: meta.union.d + - match: '' + pop: true + + meta-enum: + - meta_scope: meta.enum.d + - match: '' + pop: true diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 5e00d1cef7..481c478b4b 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -534,10 +534,12 @@ extern(1) //^ meta.class.d punctuation.section.block.end.d interface S; +//^^^^^^^^^^^^ meta.interface.d //^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d // ^ entity.name.interface.d // ^ punctuation.terminator.d interface Foo: Bar, Baz { +//^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interface.d //^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d // ^^^ entity.name.interface.d // ^ punctuation.separator.mapping.d @@ -546,13 +548,15 @@ extern(1) // ^^^ storage.type.d // ^ punctuation.section.block.begin.d interface c{} + //^^^^^^^^^^^^^ meta.interface.d meta.block.d meta.interface.d //^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d // ^ entity.name.interface.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d } -//^ punctuation.section.block.end.d +//^ meta.interface.d meta.block.d punctuation.section.block.end.d interface A(T, float f) { +//^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.interface.d //^^^^^^^^^ storage.type.interface.d keyword.declaration.interface.d // ^ entity.name.interface.d // ^ punctuation.section.group.begin.d @@ -563,24 +567,28 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d } -//^ punctuation.section.block.end.d +//^ meta.interface.d meta.block.d punctuation.section.block.end.d struct Foo { +//^^^^^^^^^^^^^ meta.struct.d //^^^^^^ storage.type.struct.d keyword.declaration.struct.d // ^^^ entity.name.struct.d // ^ punctuation.section.block.begin.d struct { + //^^^^^^^^^ meta.struct.d meta.block.d meta.struct.d //^^^^^^ storage.type.struct.d keyword.declaration.struct.d // ^ punctuation.section.block.begin.d union {} + //^^^^^^^^ meta.struct.d meta.block.d meta.struct.d meta.block.d meta.union.d //^^^^^ storage.type.union.d keyword.declaration.union.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d } - //^ punctuation.section.block.end.d + //^ meta.struct.d meta.block.d meta.struct.d meta.block.d punctuation.section.block.end.d } -//^ punctuation.section.block.end.d +//^ meta.struct.d meta.block.d punctuation.section.block.end.d struct F(int a, T) { +//^^^^^^^^^^^^^^^^^^^^^ meta.struct.d //^^^^^^ storage.type.struct.d keyword.declaration.struct.d // ^ entity.name.struct.d // ^ punctuation.section.group.begin.d @@ -591,14 +599,16 @@ extern(1) // ^ punctuation.section.group.end.d // ^ punctuation.section.block.begin.d } -//^ punctuation.section.block.end.d +//^ meta.struct.d meta.block.d punctuation.section.block.end.d union Foo {} +//^^^^^^^^^^^^ meta.union.d //^^^^^ storage.type.union.d keyword.declaration.union.d // ^^^ entity.name.union.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d union Test(string s, F) {} +//^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.union.d //^^^^^ storage.type.union.d keyword.declaration.union.d // ^^^^ entity.name.union.d // ^ punctuation.section.group.begin.d @@ -611,22 +621,26 @@ extern(1) // ^ punctuation.section.block.end.d enum Foo { +//^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^ entity.name.enum.d // ^ punctuation.section.block.begin.d foo, + //^^^^^ meta.enum.d //^^^ entity.name.constant.d // ^ punctuation.separator.sequence.d bar = 2, + //^^^^^^^^^ meta.enum.d //^^^ entity.name.constant.d // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d 1 - //^ invalid.illegal.d + //^ meta.enum.d invalid.illegal.d } -//^ punctuation.section.block.end.d +//^ meta.enum.d punctuation.section.block.end.d enum Foo : int { a = 12 } +//^^^^^^^^^^^^^^^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^ entity.name.enum.d // ^ punctuation.separator.mapping.d @@ -637,6 +651,7 @@ extern(1) // ^^ constant.numeric.integer.d // ^ punctuation.section.block.end.d enum : foo[string] { TEST } +//^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^ punctuation.separator.mapping.d // ^^^ storage.type.d @@ -647,6 +662,7 @@ extern(1) // ^^^^ entity.name.constant.d // ^ punctuation.section.block.end.d enum { int a = 12, +//^^^^^^^^^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^ punctuation.section.block.begin.d // ^^^ storage.type.d @@ -655,18 +671,21 @@ extern(1) // ^^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d Foo + //^^^^ meta.enum.d //^^^ entity.name.constant.d 2 - //^ invalid.illegal.d + //^ meta.enum.d invalid.illegal.d } -//^ punctuation.section.block.end.d +//^ meta.enum.d punctuation.section.block.end.d enum f = 12; +//^^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^ entity.name.enum.d // ^ keyword.operator.assignment.d // ^^ constant.numeric.integer.d // ^ punctuation.terminator.d enum f(x, int t) = cast(x)t; +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^ entity.name.enum.d // ^ punctuation.section.group.begin.d @@ -683,6 +702,7 @@ extern(1) // ^ variable.other.d // ^ punctuation.terminator.d enum bool[] foo = 12; +//^^^^^^^^^^^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^ storage.type.d // ^ punctuation.section.brackets.begin.d @@ -692,13 +712,15 @@ extern(1) // ^^ constant.numeric.integer.d // ^ punctuation.terminator.d enum fool +//^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^ entity.name.enum.d { -//^ punctuation.section.block.begin.d +//^ meta.enum.d punctuation.section.block.begin.d } -//^ punctuation.section.block.end.d +//^ meta.enum.d punctuation.section.block.end.d enum uint a = 1, b = 2, exponentBits = 3; +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^ storage.type.d // ^ entity.name.enum.d @@ -714,6 +736,7 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.terminator.d enum immutable(Char)[] seqBefore = "["; +//^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^^^^^^ storage.modifier.d // ^ punctuation.section.group.begin.d @@ -726,9 +749,11 @@ extern(1) // ^^^ string.quoted.double.d // ^ punctuation.terminator.d enum ulong +//^^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^^^ storage.type.d a = 1 << 2, + //^^^^^^^^^^^^ meta.enum.d //^ entity.name.enum.d // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d @@ -736,6 +761,7 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.separator.sequence.d b = 1 << 3; + //^^^^^^^^^^^ meta.enum.d //^ entity.name.enum.d // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d @@ -743,14 +769,17 @@ extern(1) // ^ constant.numeric.integer.d // ^ punctuation.terminator.d enum foo +//^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d // ^^^ entity.name.enum.d bar = 2; + //^^^^^^^^ meta.enum.d //^^^ entity.name.enum.d // ^ keyword.operator.assignment.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d enum Attr; +//^^^^^^^^^^ meta.enum.d //^^^^ storage.type.enum.d keyword.declaration.enum.d version(unittest) {} From c7a4857e9db6d73e5fde057acaef5fc9ff6504ef Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Tue, 26 Feb 2019 17:54:00 +1100 Subject: [PATCH 098/108] Add meta.path to identifiers --- D/D.sublime-syntax | 38 ++++++++--------- D/tests/syntax_test_d.d | 95 ++++++++++++++++++++++------------------- 2 files changed, 71 insertions(+), 62 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 3fc92318a7..e8930ee79e 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -69,12 +69,12 @@ contexts: push: - meta_scope: meta.namespace.d - match: '{{name}}(?=\s*(;|$))' - scope: entity.name.namespace.d + scope: meta.path.d entity.name.namespace.d - match: '{{name}}' - scope: variable.other.d + scope: meta.path.d variable.other.d push: - match: \. - scope: punctuation.accessor.dot.d + scope: meta.path.d punctuation.accessor.dot.d pop: true - include: not-whitespace-illegal - include: expect-end-of-line @@ -577,11 +577,11 @@ contexts: - match: '({{name}})\s*(\()' scope: meta.function-call.d captures: - 1: storage.type.d + 1: meta.path.d storage.type.d 2: punctuation.section.parens.begin.d set: [meta-function-call, uda-after, value-list] - match: '({{name}})\b' - scope: storage.type.d + scope: meta.path.d storage.type.d pop: true uda-after: - match: '\)' @@ -985,8 +985,8 @@ contexts: set: value-list first-value-after: - match: '\.' - scope: punctuation.accessor.dot.d - push: identifier + scope: meta.path.d punctuation.accessor.dot.d + push: value-identifier - match: '!(?!=)' scope: meta.function-call.d keyword.operator.d set: @@ -1150,7 +1150,7 @@ contexts: 2: storage.type.function.d keyword.declaration.function.lambda.d set: [meta-function, value] - match: \. - scope: punctuation.accessor.dot.d + scope: meta.path.d punctuation.accessor.dot.d set: [value-after, value-identifier] - match: '{{name_lookahead}}' set: [value-after, value-identifier] @@ -1278,13 +1278,13 @@ contexts: - include: not-whitespace-illegal-pop value-identifier: - match: '\b{{name}}\b(?=\s*(\(|!(?!=)))' - scope: meta.function-call.d variable.function.d + scope: meta.function-call.d meta.path.d variable.function.d pop: true - match: '\b{{name}}\b' - scope: variable.other.d + scope: meta.path.d variable.other.d set: - match: \.(?!\.) - scope: punctuation.accessor.dot.d + scope: meta.path.d punctuation.accessor.dot.d set: value-identifier - match: (?=\S) pop: true @@ -1294,7 +1294,7 @@ contexts: scope: keyword.operator.slice.d set: value - match: '\.(?!\.\.)' - scope: punctuation.accessor.dot.d + scope: meta.path.d punctuation.accessor.dot.d set: [value-after, value-identifier] - match: '\(' scope: punctuation.section.parens.begin.d @@ -2089,37 +2089,37 @@ contexts: identifier: - match: '\b{{name}}\b' - scope: variable.other.d + scope: meta.path.d variable.other.d set: - match: \. - scope: punctuation.accessor.dot.d + scope: meta.path.d punctuation.accessor.dot.d set: identifier - match: '(?=\S)' pop: true - include: not-whitespace-illegal-pop identifier-ref: - match: \. - scope: punctuation.accessor.dot.d + scope: meta.path.d punctuation.accessor.dot.d set: identifier - match: '(?=\S)' set: identifier type-identifier: - match: '\b{{name}}\b(?=\s*!)' - scope: meta.function-call.d variable.function.d + scope: meta.function-call.d meta.path.d variable.function.d pop: true - match: '\b{{name}}\b' - scope: storage.type.d + scope: meta.path.d storage.type.d set: - match: \. - scope: punctuation.accessor.dot.d + scope: meta.path.d punctuation.accessor.dot.d set: type-identifier - match: '(?=\S)' pop: true - include: not-whitespace-illegal-pop type-identifier-ref: - match: \. - scope: punctuation.accessor.dot.d + scope: meta.path.d punctuation.accessor.dot.d set: type-identifier - match: '(?=\S)' set: type-identifier diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 481c478b4b..f3ba1975e4 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -5,6 +5,7 @@ module foo.a.b1_3; // <- meta.namespace.d keyword.declaration.namespace.d //^^^^ keyword.declaration.namespace.d //^^^^^^^^^^^^^^^^ meta.namespace.d +// ^^^^^^^^^^ meta.path.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^ variable.other.d @@ -14,6 +15,7 @@ module foo.a.b1_3; module foo.a.b1_3; //^^^^^^^^^^^^^^^^^^ meta.namespace.d //^^^^^^ keyword.declaration.namespace.d +// ^^^^^^^^^^ meta.path.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^ variable.other.d @@ -231,7 +233,7 @@ f = 0xF.AP-2f; @foo: //^ punctuation.definition.annotation.begin.d -// ^^^ storage.type.d +// ^^^ meta.path.d storage.type.d // ^ punctuation.separator.d @("oo")@safer@Foo(2, 4)@property //^ punctuation.definition.annotation.begin.d @@ -239,10 +241,10 @@ f = 0xF.AP-2f; // ^^^^ string.quoted.double.d // ^ punctuation.section.parens.end.d // ^ punctuation.definition.annotation.begin.d -// ^^^^^ storage.type.d +// ^^^^^ meta.path.d storage.type.d // ^ punctuation.definition.annotation.begin.d // ^^^^^^^^^ meta.function-call.d -// ^^^ storage.type.d +// ^^^ meta.path.d storage.type.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ constant.numeric.integer.d @@ -306,6 +308,7 @@ extern(1) package(foo.bar.2) //^^^^^^^ storage.modifier.access-control.d // ^ punctuation.section.parens.begin.d +// ^^^^^^^^ meta.path.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^^^ variable.other.d @@ -328,15 +331,17 @@ extern(1) import foo; //^^^^^^ keyword.control.import.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ punctuation.terminator.d import std.foo; import core.thread; //^^^^^^ keyword.control.import.d +// ^^^^^^^ meta.path.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^^^ variable.other.d // ^ punctuation.terminator.d // ^^^^^^ keyword.control.import.d +// ^^^^^^^^^^^ meta.path.d // ^^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^^^^^^ variable.other.d @@ -345,21 +350,21 @@ extern(1) // ^ invalid.illegal.d import foo, a = bar, std : foo, bar, c = d; //^^^^^^ keyword.control.import.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ punctuation.separator.sequence.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ keyword.operator.assignment.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ punctuation.separator.sequence.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ punctuation.separator.import-binding.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ punctuation.separator.sequence.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ punctuation.separator.sequence.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ keyword.operator.assignment.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ punctuation.terminator.d string foo = import("foo.txt"); //^^^^^^ storage.type.d @@ -377,9 +382,9 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.accessor.dot.d // ^^^^^^^^^^^^ meta.function-call.d -// ^^^^ variable.function.d +// ^^^^ meta.path.d variable.function.d // ^ keyword.operator.d -// ^^^^^^^ variable.other.d +// ^^^^^^^ meta.path.d variable.other.d // ^ punctuation.terminator.d alias foo = int; @@ -424,11 +429,12 @@ extern(1) // ^ punctuation.terminator.d alias foo this; //^^^^^ keyword.control.alias.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^^^^ keyword.control.alias.d // ^ punctuation.terminator.d alias foo.bar.baz this; //^^^^^ keyword.control.alias.d +// ^^^^^^^^^^^ meta.path.d // ^^^ variable.other.d // ^ punctuation.accessor.dot.d // ^^^ variable.other.d @@ -443,7 +449,7 @@ extern(1) // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^ keyword.operator.assignment.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ keyword.operator.arithmetic.d // ^ punctuation.terminator.d alias rSave = a => a; @@ -453,7 +459,7 @@ extern(1) // ^^^^^^ meta.function.d // ^ variable.parameter.d // ^^ storage.type.function.d keyword.declaration.function.lambda.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ punctuation.terminator.d int a; @@ -1279,7 +1285,7 @@ extern(1) foo(4); //^^^^^^^^ meta.function.d meta.block.d //^^^^^^ meta.function-call.d - //^^^ variable.function.d + //^^^ meta.path.d variable.function.d // ^ punctuation.section.parens.begin.d // ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d @@ -1906,6 +1912,7 @@ extern(1) this.foo = num; //^^^^^^^^^^^^^^^^ meta.class.d meta.block.d meta.function.d meta.block.d //^^^^ variable.language.d + // ^^^^ meta.path.d // ^ punctuation.accessor.dot.d // ^^^ variable.other.d // ^ keyword.operator.assignment.d @@ -1926,7 +1933,7 @@ extern(1) return num * 3; //^^^^^^^^^^^^^^^^ meta.class.d meta.block.d meta.function.d meta.block.d //^^^^^^ keyword.control.flow.d - // ^^^ variable.other.d + // ^^^ meta.path.d variable.other.d // ^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d @@ -1965,7 +1972,7 @@ extern(1) //^^^^ storage.modifier.d // ^ variable.other.d // ^ keyword.operator.assignment.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ keyword.operator.logical.d // ^^ constant.numeric.integer.d // ^ keyword.operator.logical.d @@ -1978,7 +1985,7 @@ extern(1) // ^^^ storage.modifier.d // ^ variable.parameter.d // ^ punctuation.separator.sequence.d -// ^^^ variable.other.d +// ^^^ meta.path.d variable.other.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -1995,11 +2002,11 @@ extern(1) // ^ punctuation.terminator.d a = "foo", b = "bar"; -//^ variable.other.d +//^ meta.path.d variable.other.d // ^ keyword.operator.assignment.d // ^^^^^ string.quoted.double.d // ^ punctuation.separator.sequence.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ keyword.operator.assignment.d // ^^^^^ string.quoted.double.d // ^ punctuation.terminator.d @@ -2079,12 +2086,12 @@ extern(1) is(T); //^^ keyword.other.d // ^ punctuation.section.parens.begin.d -// ^ storage.type.d +// ^ meta.path.d storage.type.d // ^ punctuation.section.parens.end.d is(T : immutable); //^^ keyword.other.d // ^ punctuation.section.parens.begin.d -// ^ storage.type.d +// ^ meta.path.d storage.type.d // ^ keyword.operator.logical.d // ^^^^^^^^^ storage.modifier.d // ^ punctuation.section.parens.end.d @@ -2093,10 +2100,10 @@ extern(1) //^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^^ storage.modifier.d -// ^^^^^ storage.type.d +// ^^^^^ meta.path.d storage.type.d // ^^ keyword.operator.logical.d // ^^^^^^^^^ storage.modifier.d -// ^ storage.type.d +// ^ meta.path.d storage.type.d // ^ punctuation.section.brackets.begin.d // ^ punctuation.section.brackets.end.d // ^ punctuation.section.parens.end.d @@ -2104,7 +2111,7 @@ extern(1) is(foo : super); //^^ keyword.other.d // ^ punctuation.section.parens.begin.d -// ^^^ storage.type.d +// ^^^ meta.path.d storage.type.d // ^ keyword.operator.logical.d // ^^^^^ variable.language.d // ^ punctuation.section.parens.end.d @@ -2112,7 +2119,7 @@ extern(1) is(foo : return); //^^ keyword.other.d // ^ punctuation.section.parens.begin.d -// ^^^ storage.type.d +// ^^^ meta.path.d storage.type.d // ^ keyword.operator.logical.d // ^^^^^^ keyword.control.flow.d // ^ punctuation.section.parens.end.d @@ -2120,7 +2127,7 @@ extern(1) is(foo : class); //^^ keyword.other.d // ^ punctuation.section.parens.begin.d -// ^^^ storage.type.d +// ^^^ meta.path.d storage.type.d // ^ keyword.operator.logical.d // ^^^^^ storage.type.d keyword.declaration.d // ^ punctuation.section.parens.end.d @@ -2268,6 +2275,7 @@ extern(1) // ^^^ storage.type.d // ^^^ variable.parameter.d // ^^ punctuation.section.group.end.d +// ^^^^^^^ meta.path.d // ^ punctuation.accessor.dot.d // ^^^^^^ variable.other.d // ^ punctuation.terminator.d @@ -2361,11 +2369,11 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^^^ variable.function.d // ^ punctuation.separator.sequence.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d values ~= toValue(__traits(getMember, this, primaryKey)); -//^^^^^^ variable.other.d +//^^^^^^ meta.path.d variable.other.d // ^^ keyword.operator.assignment.d // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d // ^^^^^^^ variable.function.d @@ -2376,7 +2384,7 @@ extern(1) // ^ punctuation.separator.sequence.d // ^^^^ variable.language.d // ^ punctuation.separator.sequence.d -// ^^^^^^^^^^ variable.other.d +// ^^^^^^^^^^ meta.path.d variable.other.d // ^^ punctuation.section.parens.end.d // ^ punctuation.terminator.d @@ -2437,11 +2445,12 @@ extern(1) //^^^^ keyword.operator.word.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^ meta.function-call.d -// ^^^^^^ variable.function.d +// ^^^^^^ meta.path.d variable.function.d // ^ keyword.operator.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ keyword.operator.arithmetic.d // ^ punctuation.section.parens.end.d +// ^^^^ meta.path.d // ^ punctuation.accessor.dot.d // ^^^ variable.other.d // ^ punctuation.terminator.d @@ -2523,16 +2532,16 @@ extern(1) // ^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d -// ^^^^^^^^ variable.function.d +// ^^^^^^^^ meta.path.d variable.function.d // ^ keyword.operator.d // ^ punctuation.section.parens.begin.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ punctuation.separator.sequence.d // ^^^^^ storage.modifier.d -// ^ storage.type.d +// ^ meta.path.d storage.type.d // ^ punctuation.separator.sequence.d // ^^^^^^^^^ storage.modifier.d -// ^ storage.type.d +// ^ meta.path.d storage.type.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.parens.end.d static foreach (Uint; AliasSeq!(U, const U, immutable U)) {} @@ -2542,16 +2551,16 @@ extern(1) // ^^^^ variable.parameter.d // ^ punctuation.separator.sequence.d // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d -// ^^^^^^^^ variable.function.d +// ^^^^^^^^ meta.path.d variable.function.d // ^ keyword.operator.d // ^ punctuation.section.parens.begin.d -// ^ variable.other.d +// ^ meta.path.d variable.other.d // ^ punctuation.separator.sequence.d // ^^^^^ storage.modifier.d -// ^ storage.type.d +// ^ meta.path.d storage.type.d // ^ punctuation.separator.sequence.d // ^^^^^^^^^ storage.modifier.d -// ^ storage.type.d +// ^ meta.path.d storage.type.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d From 43f8ebec0b0c3fccf49d94906a802bfc09173bca Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 11:53:58 +1100 Subject: [PATCH 099/108] Fix ternary scope --- D/D.sublime-syntax | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index e8930ee79e..8e1616aea9 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1340,7 +1340,7 @@ contexts: - match: '(?=\S)' set: value - match: '\?' - scope: keyword.operator.logical.d + scope: keyword.operator.ternary.d set: [value-condition-after, value] - match: '(?=function|delegate)' set: [value-after, basic-type2] @@ -1367,7 +1367,7 @@ contexts: - include: not-whitespace-illegal-pop value-condition-after: - match: ':' - scope: keyword.operator.logical.d + scope: keyword.operator.ternary.d set: value - include: not-whitespace-illegal value-parens-after: From 2819f1d456e902c7eafd06b967ba83f3e63a6ad7 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 11:57:36 +1100 Subject: [PATCH 100/108] Fix scope of `:` when used for comparison --- D/D.sublime-syntax | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 8e1616aea9..5052ad0535 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -781,7 +781,7 @@ contexts: scope: keyword.operator.assignment.d push: value - match: ':' - scope: punctuation.separator.mapping.d + scope: keyword.operator.comparison.d push: value - match: '\)' scope: punctuation.section.group.end.d @@ -907,7 +907,7 @@ contexts: scope: keyword.operator.assignment.d push: value - match: ':' - scope: keyword.operator.assignment.d + scope: keyword.operator.comparison.d push: value - match: '\)' scope: punctuation.section.group.end.d @@ -1203,7 +1203,7 @@ contexts: scope: punctuation.section.parens.end.d pop: true - match: '\=\=|:' - scope: keyword.operator.logical.d + scope: keyword.operator.comparison.d set: [is-after, type-specialization] is-after: - match: ',' From 4d168e853dec149d059257dd4d8002f731bd92f9 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 12:00:54 +1100 Subject: [PATCH 101/108] Fix tests --- D/tests/syntax_test_d.d | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index f3ba1975e4..ea01676209 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1187,12 +1187,12 @@ extern(1) // ^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d -// ^ keyword.operator.assignment.d +// ^ keyword.operator.comparison.d // ^^^ storage.type.d // ^ punctuation.separator.sequence.d // ^^^^^^ storage.type.d // ^ variable.parameter.d -// ^ keyword.operator.assignment.d +// ^ keyword.operator.comparison.d // ^^^ string.quoted.double.d // ^ punctuation.section.group.end.d // ^^ meta.function.d meta.block.d @@ -1259,7 +1259,7 @@ extern(1) // ^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^ storage.type.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.comparison.d // ^ storage.type.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.parens.end.d @@ -1475,7 +1475,7 @@ extern(1) // ^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^ storage.type.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.comparison.d // ^^^^^ storage.type.d // ^ punctuation.section.parens.end.d // ^ punctuation.section.parens.end.d @@ -1973,9 +1973,9 @@ extern(1) // ^ variable.other.d // ^ keyword.operator.assignment.d // ^^^ meta.path.d variable.other.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.ternary.d // ^^ constant.numeric.integer.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.ternary.d // ^^ constant.numeric.integer.d // ^ punctuation.terminator.d @@ -2066,7 +2066,7 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^^^ storage.type.d // ^ variable.parameter.d -// ^^ keyword.operator.logical.d +// ^^ keyword.operator.comparison.d // ^^^^^ storage.type.d // ^ punctuation.separator.sequence.d // ^ variable.parameter.d @@ -2079,7 +2079,7 @@ extern(1) //^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^^^ storage.type.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.comparison.d // ^^^ storage.type.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d @@ -2092,7 +2092,7 @@ extern(1) //^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^ meta.path.d storage.type.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.comparison.d // ^^^^^^^^^ storage.modifier.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d @@ -2101,7 +2101,7 @@ extern(1) // ^ punctuation.section.parens.begin.d // ^^^^^^^^^ storage.modifier.d // ^^^^^ meta.path.d storage.type.d -// ^^ keyword.operator.logical.d +// ^^ keyword.operator.comparison.d // ^^^^^^^^^ storage.modifier.d // ^ meta.path.d storage.type.d // ^ punctuation.section.brackets.begin.d @@ -2112,7 +2112,7 @@ extern(1) //^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^^^ meta.path.d storage.type.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.comparison.d // ^^^^^ variable.language.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d @@ -2120,7 +2120,7 @@ extern(1) //^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^^^ meta.path.d storage.type.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.comparison.d // ^^^^^^ keyword.control.flow.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d @@ -2128,7 +2128,7 @@ extern(1) //^^ keyword.other.d // ^ punctuation.section.parens.begin.d // ^^^ meta.path.d storage.type.d -// ^ keyword.operator.logical.d +// ^ keyword.operator.comparison.d // ^^^^^ storage.type.d keyword.declaration.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d From 141373dfdbe14bac1ac7451e542ff8affe9b881d Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 12:12:58 +1100 Subject: [PATCH 102/108] Fix operator overloads being highlighted as keywords instead of entities --- D/D.sublime-syntax | 2 +- ...rences => Symbol Index Hide Special Functions.tmPreferences} | 2 +- D/tests/syntax_test_d.d | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) rename D/{Symbol Index Hide Ctors.tmPreferences => Symbol Index Hide Special Functions.tmPreferences} (87%) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 5052ad0535..a98b9f9ccc 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -799,7 +799,7 @@ contexts: - match: '\b({{operator_overloads}})\s*(?=\(|$)' scope: meta.function.d captures: - 1: keyword.operator.overload.d + 1: entity.name.function.operator.d set: function-definition-begin - match: '\b({{name}})\s*(?=\(|$)' scope: meta.function.d diff --git a/D/Symbol Index Hide Ctors.tmPreferences b/D/Symbol Index Hide Special Functions.tmPreferences similarity index 87% rename from D/Symbol Index Hide Ctors.tmPreferences rename to D/Symbol Index Hide Special Functions.tmPreferences index 30ad118d09..3adce7f135 100644 --- a/D/Symbol Index Hide Ctors.tmPreferences +++ b/D/Symbol Index Hide Special Functions.tmPreferences @@ -2,7 +2,7 @@ scope - + settings showInIndexedSymbolList diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index ea01676209..06c54b57ba 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1100,7 +1100,7 @@ extern(1) // ^ punctuation.section.block.end.d void opEquals(int a) {} //^^^^ storage.type.d -// ^^^^^^^^ meta.function.d keyword.operator.overload.d +// ^^^^^^^^ meta.function.d entity.name.function.operator.d // ^^^^^^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d // ^^^ storage.type.d From 012b2e2cad42a4d211bc1c38ffaa89d621efe91b Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 14:14:42 +1100 Subject: [PATCH 103/108] Fix scope for builtin at-attributes --- D/D.sublime-syntax | 7 +++++-- D/tests/syntax_test_d.d | 33 +++++++++++---------------------- D/tests/syntax_test_old.d | 4 ++-- 3 files changed, 18 insertions(+), 26 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index a98b9f9ccc..43ff7f1ec2 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -519,7 +519,10 @@ contexts: - match: '\b({{attributes}})\b' scope: storage.modifier.d pop: true - - match: '(@)' + - match: '@(?=\s*({{at_attributes}})\b)' + scope: storage.modifier.d + set: at-attribute + - match: '@' scope: punctuation.definition.annotation.begin.d set: at-attribute - match: '\b(extern)\s*(\()' @@ -569,7 +572,7 @@ contexts: - include: not-whitespace-illegal-pop at-attribute: - match: '({{at_attributes}})\b' - scope: storage.attribute.d + scope: storage.modifier.d pop: true - match: '\(' scope: punctuation.section.parens.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 06c54b57ba..cf4b87b8b9 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -249,8 +249,7 @@ f = 0xF.AP-2f; // ^ constant.numeric.integer.d // ^ constant.numeric.integer.d // ^ punctuation.section.parens.end.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^^^^^ storage.attribute.d +// ^^^^^^^^^ storage.modifier.d static shared const immutable final __gshared nothrow pure ref //^^^^^^ storage.modifier.d // ^^^^^^ storage.modifier.d @@ -1137,8 +1136,7 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @property foo() {} -//^ punctuation.definition.annotation.begin.d -// ^^^^^^^^ storage.attribute.d +//^^^^^^^^^ storage.modifier.d // ^^^ meta.function.d entity.name.function.d // ^^ meta.function.parameters.d // ^ punctuation.section.group.begin.d @@ -1207,8 +1205,7 @@ extern(1) // ^^^^^^^^^^^^^^^^^^^^^^^^ meta.function.d // ^^^^^ storage.modifier.d // ^^^^^ storage.modifier.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^^^^^ storage.attribute.d +// ^^^^^^^^^ storage.modifier.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d void f() @@ -1339,8 +1336,7 @@ extern(1) // ^ punctuation.section.group.begin.d // ^ punctuation.section.group.end.d // ^^^^^^^^^ meta.function.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^^^^ storage.attribute.d +// ^^^^^^^^ storage.modifier.d // ^ punctuation.terminator.d this(this) {} //^^^^ meta.function.d entity.name.function.post-blit.d @@ -1482,8 +1478,7 @@ extern(1) // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @property foo(T) = { -//^ punctuation.definition.annotation.begin.d -// ^^^^^^^^ storage.attribute.d +//^^^^^^^^^ storage.modifier.d // ^^^ entity.name.function.d // ^ punctuation.section.group.begin.d // ^ variable.parameter.d @@ -1829,8 +1824,7 @@ extern(1) asm nothrow @safe {} //^^^ keyword.declaration.asm.d // ^^^^^^^ storage.modifier.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^ storage.attribute.d +// ^^^^^ storage.modifier.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -2160,8 +2154,7 @@ extern(1) //^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d // ^^^^^^^^^^^^^ meta.function.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^^^^ storage.attribute.d +// ^^^^^^^^ storage.modifier.d // ^^ storage.type.function.d keyword.declaration.function.lambda.d // ^ constant.numeric.integer.d // ^ punctuation.terminator.d @@ -2178,8 +2171,7 @@ extern(1) // ^^^ variable.other.d // ^ punctuation.section.group.end.d // ^^^^^^^^^^^^^^^^^^ meta.function.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^^^^ storage.attribute.d +// ^^^^^^^^ storage.modifier.d // ^^ storage.type.function.d keyword.declaration.function.lambda.d // ^^^^^^ meta.function-call.d // ^^^ variable.function.d @@ -2195,8 +2187,7 @@ extern(1) // ^^^ variable.parameter.d // ^ punctuation.section.group.end.d // ^^^^^^^^ meta.function.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^ storage.attribute.d +// ^^^^^ storage.modifier.d // ^^ meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -2218,8 +2209,7 @@ extern(1) // ^ punctuation.section.group.end.d // ^^^^^^^^^^^^^ meta.function.d // ^^^^ storage.modifier.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^ storage.attribute.d +// ^^^^^ storage.modifier.d // ^^ meta.block.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d @@ -2337,8 +2327,7 @@ extern(1) // ^ variable.parameter.d // ^ punctuation.section.group.end.d // ^^^^^^^^^^^ meta.function.d -// ^ punctuation.definition.annotation.begin.d -// ^^^^^^^ storage.attribute.d +// ^^^^^^^^ storage.modifier.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d // ^ punctuation.terminator.d diff --git a/D/tests/syntax_test_old.d b/D/tests/syntax_test_old.d index 6e7b8c3732..32c66b8416 100644 --- a/D/tests/syntax_test_old.d +++ b/D/tests/syntax_test_old.d @@ -53,10 +53,10 @@ template testTemplate(X) } @safe pure nothrow @nogc unittest {} -// ^ storage.attribute +// ^ storage.modifier // ^ storage.modifier // ^ storage.modifier -// ^ storage.attribute +// ^ storage.modifier auto takeByRef(ref int h) // ^ storage.modifier From 06d1a44233ddde0d6f079c3d6231448164a7f7f2 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 14:22:00 +1100 Subject: [PATCH 104/108] Fix single value template arguments not popping --- D/D.sublime-syntax | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 43ff7f1ec2..c4b52a630f 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1352,21 +1352,21 @@ contexts: value-template-single: - match: '\b({{basic_type}})\b' scope: storage.type.d - set: value-after + pop: true - match: '{{number_lookahead}}' - set: [value-after, number] + set: number - match: '{{character_lookahead}}' - set: [value-after, character] + set: character - match: '{{string_lookahead}}' - set: [value-after, string] + set: string - match: '\b({{language_constant}})\b' scope: constant.language.d - set: value-after + pop: true - match: '\b({{language_variable}})\b' scope: variable.language.d - set: value-after + pop: true - match: '{{name_lookahead}}|\.' - set: [value-after, identifier-ref] + set: identifier-ref - include: not-whitespace-illegal-pop value-condition-after: - match: ':' From 8b09acf4ae050c2e89a095889de0d6b2368fcac1 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 14:27:43 +1100 Subject: [PATCH 105/108] Fix switch with not working --- D/D.sublime-syntax | 2 +- D/tests/syntax_test_d.d | 13 +++++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index c4b52a630f..34895c24e2 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -2006,7 +2006,7 @@ contexts: switch-after: - match: '\)' scope: punctuation.section.parens.end.d - set: block-statement + set: optional-block-statement - include: not-whitespace-illegal-pop case-after: - match: ':' diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index cf4b87b8b9..fd04c78c6b 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -2554,3 +2554,16 @@ extern(1) // ^ punctuation.section.parens.end.d // ^ punctuation.section.block.begin.d // ^ punctuation.section.block.end.d + + switch (foo) with (bar) {} +//^^^^^^ keyword.control.flow.d +// ^ punctuation.section.parens.begin.d +// ^^^ meta.path.d variable.other.d +// ^ punctuation.section.parens.end.d +// ^^^^ keyword.other.with.d +// ^ punctuation.section.parens.begin.d +// ^^^ meta.path.d variable.other.d +// ^ punctuation.section.parens.end.d +// ^^ meta.block.d +// ^ punctuation.section.block.begin.d +// ^ punctuation.section.block.end.d From 8d632906fe6adb19589c2f9f05b177b67c862fbd Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 14:51:03 +1100 Subject: [PATCH 106/108] Add special case for `new` instances of classes using variable.function --- D/D.sublime-syntax | 23 +++++++++++++++++++++++ D/tests/syntax_test_d.d | 2 +- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 34895c24e2..f545155f7a 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -11,6 +11,7 @@ scope: source.d variables: name: '[[:alpha:]_][[:alpha:]0-9_]*' name_lookahead: '(?=\b{{name}}\b)' + identifier_ref: '\.?\s*{{name}}(\s*\.\s*{{name}})*' string_postfix: '[cwd]?' escape_sequence: '\\([''"?\\0abfnrtv]|x{{hex_char}}{2}|[0-7]{1,3}|u{{hex_char}}{4}|U{{hex_char}}{8}|&\w+;)' hex_char: '[0-9a-fA-F]' @@ -1172,6 +1173,8 @@ contexts: - match: '\bclass\b' scope: meta.class.d storage.type.class.d keyword.declaration.class.d set: [meta-class, new-class] + - match: (?={{identifier_ref}}\s*\() + set: [new-after-named, new-type-identifier-ref] - match: (?=\S) set: [new-after-named, type] - include: not-whitespace-illegal @@ -2127,6 +2130,26 @@ contexts: - match: '(?=\S)' set: type-identifier + new-type-identifier: + - match: '\b{{name}}(?=\s*\()' + scope: meta.function-call.d meta.path.d variable.function.d + pop: true + - match: '\b{{name}}\b' + scope: meta.path.d storage.type.d + set: + - match: \. + scope: meta.path.d punctuation.accessor.dot.d + set: new-type-identifier + - match: '(?=\S)' + pop: true + - include: not-whitespace-illegal-pop + new-type-identifier-ref: + - match: \. + scope: meta.path.d punctuation.accessor.dot.d + set: new-type-identifier + - match: '(?=\S)' + set: new-type-identifier + not-whitespace-illegal: - match: '\S' scope: invalid.illegal.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index fd04c78c6b..c3baf68e44 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1856,7 +1856,7 @@ extern(1) // ^ keyword.operator.assignment.d // ^^^ keyword.operator.word.d // ^^^^^ meta.function-call.d -// ^^^ storage.type.d +// ^^^ variable.function.d // ^ punctuation.section.parens.begin.d // ^ punctuation.section.parens.end.d // ^ punctuation.terminator.d From 8b359df10dd5fc15c24257679a9fc3c1ab3af827 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 15:07:33 +1100 Subject: [PATCH 107/108] Fix concatenation operator scope --- D/D.sublime-syntax | 5 ++++- D/tests/syntax_test_d.d | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index f545155f7a..23cc24b1cd 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1317,9 +1317,12 @@ contexts: - match: '(\+|-|/|%|\*|&|\||\^\^|\^|~|<<|>>>|>>)=' scope: keyword.operator.assignment.d set: value - - match: '(\+|\-|~|/|%|\^\^)' + - match: '(\+|\-|/|%|\^\^)' scope: keyword.operator.arithmetic.d set: value + - match: '~' + scope: keyword.operator.concatenation.d + set: value - match: '(<<|>>>|>>|\||\^|&)' scope: keyword.operator.bitwise.d set: value diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index c3baf68e44..00c914ce80 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -1958,7 +1958,7 @@ extern(1) // ^^ keyword.operator.arithmetic.d // ^ constant.numeric.integer.d // ^ punctuation.section.group.end.d -// ^ keyword.operator.arithmetic.d +// ^ keyword.operator.concatenation.d // ^^^^^ string.quoted.double.d // ^ punctuation.terminator.d From 95c77fec01eeab7cf2a553a2fe9d9aea19139345 Mon Sep 17 00:00:00 2001 From: Benjamin Schaaf Date: Wed, 27 Feb 2019 15:21:35 +1100 Subject: [PATCH 108/108] Fix template call operator scope --- D/D.sublime-syntax | 2 +- D/tests/syntax_test_d.d | 12 ++++++------ 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/D/D.sublime-syntax b/D/D.sublime-syntax index 23cc24b1cd..ed98483430 100644 --- a/D/D.sublime-syntax +++ b/D/D.sublime-syntax @@ -1333,7 +1333,7 @@ contexts: scope: keyword.operator.assignment.d set: value - match: '!' - scope: meta.function-call.d keyword.operator.d + scope: meta.function-call.d punctuation.section.generic.begin.d set: - match: '\(' scope: punctuation.section.parens.begin.d diff --git a/D/tests/syntax_test_d.d b/D/tests/syntax_test_d.d index 00c914ce80..10c1d824c8 100644 --- a/D/tests/syntax_test_d.d +++ b/D/tests/syntax_test_d.d @@ -382,7 +382,7 @@ extern(1) // ^ punctuation.accessor.dot.d // ^^^^^^^^^^^^ meta.function-call.d // ^^^^ meta.path.d variable.function.d -// ^ keyword.operator.d +// ^ punctuation.section.generic.begin.d // ^^^^^^^ meta.path.d variable.other.d // ^ punctuation.terminator.d @@ -405,7 +405,7 @@ extern(1) // ^^^ entity.name.type.d // ^ keyword.operator.assignment.d // ^^^^ storage.type.d -// ^ keyword.operator.d +// ^ punctuation.section.generic.begin.d // ^^^ storage.type.d // ^ punctuation.terminator.d alias int a; @@ -1510,7 +1510,7 @@ extern(1) //^^^^^ keyword.control.d // ^^^^^^^^^^^ meta.function-call.d // ^^^ variable.function.d -// ^ keyword.operator.d +// ^ punctuation.section.generic.begin.d // ^ punctuation.section.parens.begin.d // ^^^^^ string.quoted.double.d // ^ punctuation.section.parens.end.d @@ -2421,7 +2421,7 @@ extern(1) //^ punctuation.accessor.dot.d // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d // ^^^^^^^^ variable.function.d -// ^ keyword.operator.d +// ^ punctuation.section.generic.begin.d // ^ punctuation.section.parens.begin.d // ^^^^^^^^^ storage.modifier.d // ^^^^ storage.type.d @@ -2522,7 +2522,7 @@ extern(1) // ^ punctuation.separator.sequence.d // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d // ^^^^^^^^ meta.path.d variable.function.d -// ^ keyword.operator.d +// ^ punctuation.section.generic.begin.d // ^ punctuation.section.parens.begin.d // ^ meta.path.d variable.other.d // ^ punctuation.separator.sequence.d @@ -2541,7 +2541,7 @@ extern(1) // ^ punctuation.separator.sequence.d // ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ meta.function-call.d // ^^^^^^^^ meta.path.d variable.function.d -// ^ keyword.operator.d +// ^ punctuation.section.generic.begin.d // ^ punctuation.section.parens.begin.d // ^ meta.path.d variable.other.d // ^ punctuation.separator.sequence.d