From 29711c178aac35e8a6a7eaf24d10be8e6dd008f4 Mon Sep 17 00:00:00 2001 From: Ersikan Date: Mon, 6 Dec 2021 08:40:43 +0100 Subject: [PATCH] Better syntax highlighting for Dart (#1959) Remove unmaintained Dart syntax submodule. Add elMuso/Dartlight as submodule. Update Dart syntax highlighting. Add changes to changelog. --- .gitmodules | 6 +- CHANGELOG.md | 1 + assets/syntaxes/02_Extra/Dart | 2 +- assets/syntaxes/02_Extra/Dart.sublime-syntax | 328 +++++------------- .../highlighted/Dart/inner_comment.dart | 5 + tests/syntax-tests/highlighted/Dart/test.dart | 104 +++--- .../source/Dart/inner_comment.dart | 5 + 7 files changed, 152 insertions(+), 299 deletions(-) create mode 100644 tests/syntax-tests/highlighted/Dart/inner_comment.dart create mode 100644 tests/syntax-tests/source/Dart/inner_comment.dart diff --git a/.gitmodules b/.gitmodules index e97868e045..fda68b551b 100644 --- a/.gitmodules +++ b/.gitmodules @@ -67,9 +67,6 @@ [submodule "assets/syntaxes/JavaScript (Babel)"] path = assets/syntaxes/02_Extra/JavaScript (Babel) url = https://github.com/babel/babel-sublime -[submodule "assets/syntaxes/Dart"] - path = assets/syntaxes/02_Extra/Dart - url = https://github.com/guillermooo/dart-sublime-bundle [submodule "assets/syntaxes/FSharp"] path = assets/syntaxes/02_Extra/FSharp url = https://github.com/hoest/sublimetext-fsharp @@ -236,3 +233,6 @@ [submodule "assets/syntaxes/02_Extra/MediaWiki"] path = assets/syntaxes/02_Extra/MediaWiki url = https://github.com/tosher/Mediawiker.git +[submodule "assets/syntaxes/02_Extra/Dart"] + path = assets/syntaxes/02_Extra/Dart + url = https://github.com/elMuso/Dartlight.git diff --git a/CHANGELOG.md b/CHANGELOG.md index c91be47285..439cb11231 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -36,6 +36,7 @@ - LiveScript, see #1915 (@Enselic) - MediaWiki, see #1925 (@sorairolake) - The `requirements.txt` syntax has been removed due to incompatible license requirements. +- Dart, new highlighter, see #1959 (@Ersikan) ## New themes diff --git a/assets/syntaxes/02_Extra/Dart b/assets/syntaxes/02_Extra/Dart index d891fb36c9..2734901b01 160000 --- a/assets/syntaxes/02_Extra/Dart +++ b/assets/syntaxes/02_Extra/Dart @@ -1 +1 @@ -Subproject commit d891fb36c98ca0b111a35cba109b05a16b6c4b83 +Subproject commit 2734901b014191f5a7f71c3f48678adf31239098 diff --git a/assets/syntaxes/02_Extra/Dart.sublime-syntax b/assets/syntaxes/02_Extra/Dart.sublime-syntax index 34ed01e930..1b0fb2db51 100644 --- a/assets/syntaxes/02_Extra/Dart.sublime-syntax +++ b/assets/syntaxes/02_Extra/Dart.sublime-syntax @@ -1,6 +1,6 @@ %YAML 1.2 --- -# http://www.sublimetext.com/docs/3/syntax.html +# http://www.sublimetext.com/docs/syntax.html name: Dart file_extensions: - dart @@ -9,7 +9,7 @@ contexts: main: - match: ^(#!.*)$ scope: meta.preprocessor.script.dart - - match: ^\s*\b(library|import|export|part of|part)\b + - match: ^\w*\b(library|import|part of|part|export)\b captures: 0: keyword.other.import.dart push: @@ -19,242 +19,114 @@ contexts: 0: punctuation.terminator.dart pop: true - include: strings - - match: \b(as|show|hide|deferred)\b + - include: comments + - match: \b(as|show|hide)\b scope: keyword.other.import.dart - include: comments - - include: constants-and-special-vars + - include: punctuation - include: annotations - - include: decl-typedef - - include: decl-class - - include: decl-enum - - include: decl-function - include: keywords + - include: constants-and-special-vars - include: strings annotations: - - match: '^(?:\s*)((@)([a-zA-Z0-9_]+))' - captures: - 1: annotation.dart - 2: entity.name.function.annotation.dart - 3: support.type.dart + - match: '@[a-zA-Z]+' + scope: storage.type.annotation.dart comments: - match: /\*\*/ scope: comment.block.empty.dart captures: 0: punctuation.definition.comment.dart + - include: comments-doc-oldschool + - include: comments-doc - include: comments-inline - comments-inline: + comments-block: - match: /\* push: - meta_scope: comment.block.dart - match: \*/ pop: true - - include: scope:text.dart-doccomments - - match: (///) - captures: - 1: marker.dart + - include: comments-block + comments-doc: + - match: /// push: - - meta_scope: comment.line.triple-slash.dart - - match: $ + - meta_scope: comment.block.documentation.dart + - match: .* pop: true - - include: scope:text.dart-doccomments - - match: (//) - captures: - 1: marker.dart + - include: dartdoc + comments-doc-oldschool: + - match: /\*\* push: - - meta_scope: comment.line.double-slash.dart - - match: $ + - meta_scope: comment.block.documentation.dart + - match: \*/ pop: true - - include: scope:text.dart-doccomments + - include: comments-doc-oldschool + - include: comments-block + - include: dartdoc + comments-inline: + - include: comments-block + - match: ((//).*)$ + captures: + 1: comment.line.double-slash.dart constants-and-special-vars: - - match: \b(true|false|null)\b + - match: (?)' captures: - 0: keyword.control.new.dart - push: - - meta_scope: meta.declaration.class.dart - - match: "(?={)" - pop: true - - include: keywords - - match: "[A-Za-z_][A-Za-z0-9_]*" - scope: class.name.dart - decl-enum: - - match: \benum\b - captures: - 0: keyword.declaration.dart - push: - - meta_scope: meta.declaration.enum.dart - - match: "(?={)" - pop: true - - include: keywords - - match: "[A-Za-z_][A-Za-z0-9_]*" - scope: enum.name.dart - decl-function: - - match: ^\s*(?:\b(void|bool|num|int|double|dynamic|var|String|List|Map)\b)\s+(get)\s+(\w+)\s+(?==>) - comment: A getter with a primitive return type. - scope: meta.declaration.function.dart + 1: entity.name.function.dart + dartdoc: + - match: '(\[.*?\])' captures: - 1: storage.type.primitive.dart - 2: keyword.declaration.dart - 3: function.name.dart - - match: ^\s*(?:\b(\w+)\b\s+)?(get)\s+(\w+)\s+(?==>) - comment: A getter with a user-defined return type or no return type. - scope: meta.declaration.function.dart - captures: - 1: type.user-defined.dart - 2: keyword.declaration.dart - 3: function.name.dart - - match: ^\s*(set)\s+(\w+)(?=\() - comment: A setter. - captures: - 1: keyword.declaration.dart - 2: function.name.dart - push: - - meta_scope: meta.declaration.function.dart - - match: \) - pop: true - - include: comments-inline - - include: decl-function-parameter - - include: strings - - include: keywords - - match: ^\s*(?:\b(void|bool|num|int|double|dynamic|var|String|List|Map)\b)\s+(\w+)(?=\() - comment: A function with a primitive return type. - captures: - 1: storage.type.primitive.dart - 2: function.name.dart - push: - - meta_scope: meta.declaration.function.dart - - match: \) - pop: true - - include: comments-inline - - include: decl-function-parameter - - include: strings - - include: keywords - - match: ^\s*(?:\b(return)\b)\s+(\w+)(?=\() - comment: A function invocation after 'return' - captures: - 1: keyword.control.dart - 2: function.name.dart - push: - - meta_scope: meta.invocation.function.dart - - match: \) - pop: true - - include: comments-inline - - include: decl-function-parameter - - include: strings - - include: keywords - - match: ^\s*\b(new)\b\s+(\w+)(?=\() - comment: A class instantiation after 'new' - captures: - 1: keyword.declaration.dart - 2: function.name.dart - push: - - meta_scope: meta.invocation.function.dart - - match: \) - pop: true - - include: comments-inline - - include: decl-function-parameter - - include: strings - - include: keywords - decl-function-parameter: - - include: constants-and-special-vars - - match: (?:\b(void|bool|num|int|double|dynamic|var|String|List|Map)\b)\s+(\w+)(?=\() - comment: A function with a primitive return type. - captures: - 1: storage.type.primitive.dart - 2: function.name.dart - push: - - meta_scope: meta.parameter.function.dart - - match: \) - pop: true - - include: decl-function-parameter - - include: strings - - include: keywords - - match: \b(new)\b\s+(\w+)(?=\() - comment: A class instantiation after 'new' + 0: variable.name.source.dart + - match: '^ {4,}(?![ \*]).*' captures: - 1: keyword.declaration.dart - 2: function.name.dart + 0: variable.name.source.dart + - match: '```.*?$' push: - - meta_scope: meta.invocation.function.dart - - match: \) + - meta_content_scope: variable.other.source.dart + - match: '```' pop: true - - include: decl-function-parameter - - include: strings - - include: keywords - - match: (?:\b(\w+)\b)\s+(\w+)(?=\() - comment: A function with a user-defined return type. + - match: (`.*?`) captures: - 1: type.user-defined.dart - 2: function.name.dart - push: - - meta_scope: meta.parameter.function.dart - - match: \) - pop: true - - include: decl-function-parameter - - include: strings - - include: keywords - - match: (\w+)(?=\() - comment: A function with no return type. + 0: variable.other.source.dart + - match: (`.*?`) captures: - 1: function.name.dart - push: - - meta_scope: meta.parameter.function.dart - - match: \) - pop: true - - include: decl-function-parameter - - include: strings - - include: keywords - decl-typedef: - - match: typedef + 0: variable.other.source.dart + - match: (\* (( ).*))$ captures: - 0: keyword.control.new.dart - push: - - meta_scope: meta.declaration.typedef.dart - - match: ; - captures: - 0: punctuation.terminator.dart - pop: true - - match: '(?:\b(void|bool|num|int|double|dynamic|var|String|List|Map)\b|([a-zA-Z_][a-zA-Z0-9_]*))\s+([a-zA-Z_][a-zA-Z0-9_]+)' - captures: - 1: storage.type.primitive.dart - 2: typedef.return.dart - 3: typedef.name.dart - - match: \( - push: - - meta_scope: typedef.params.dart - - match: \) - pop: true - - include: keywords + 2: variable.other.source.dart + - match: (\* .*)$ keywords: - - match: \bassert\b - scope: keyword.control.assert.dart - - match: \bas\b + - match: (?>>?|~|\^|\||&) scope: keyword.operator.bitwise.dart - match: ((&|\^|\||<<|>>>?)=) scope: keyword.operator.assignment.bitwise.dart - - match: (===?|!==?|<=?|>=?) + - match: (=>) + scope: keyword.operator.closure.dart + - match: (==|!=|<=?|>=?) scope: keyword.operator.comparison.dart - match: '(([+*/%-]|\~)=)' scope: keyword.operator.assignment.arithmetic.dart @@ -266,56 +138,22 @@ contexts: scope: keyword.operator.arithmetic.dart - match: (!|&&|\|\|) scope: keyword.operator.logical.dart - - match: ; - scope: punctuation.terminator.dart - - match: \b(static|final|const)\b + - match: (? launchDate?.year; + int get launchYear => launchDate?.year; - void describe() { - print('Spacecraft: $name'); + void describe() { + print('Spacecraft: $name');  if (launchDate != null) { - int years = DateTime.now().difference(launchDate).inDays ~/ 365; - print('Launched: $launchYear ($years years ago)'); + int years = DateTime.now().difference(launchDate).inDays ~/ 365; + print('Launched: $launchYear ($years years ago)');  } else { - print('Unlaunched'); + print('Unlaunched');  }  } } /* Mixins */ -class PilotedCraft extends Spacecraft with Piloted { - // ยทยทยท +class PilotedCraft extends Spacecraft with Piloted { + // ยทยทยท } /* Interfaces and abstract classes */ -class MockSpaceship implements Spacecraft { - // ยทยทยท +class MockSpaceship implements Spacecraft { + // ยทยทยท } /* async */ -Future<void> printWithDelay(String message) { - return Future.delayed(const Duration(seconds: 2)).then((_) { - print(message); +Future<void> printWithDelay(String message) { + return Future.delayed(const Duration(seconds: 2)).then((_) { + print(message);  }); } -Stream<String> report(Spacecraft craft, Iterable<String> objects) async* { +Stream<String> report(Spacecraft craft, Iterable<String> objects) async* {  for (var object in objects) { - await Future.delayed(const Duration(seconds: 2)); - yield '${craft.name} flies by $object'; + await Future.delayed(const Duration(seconds: 2)); + yield '${craft.name} flies by $object';  } } diff --git a/tests/syntax-tests/source/Dart/inner_comment.dart b/tests/syntax-tests/source/Dart/inner_comment.dart new file mode 100644 index 0000000000..b7aa348194 --- /dev/null +++ b/tests/syntax-tests/source/Dart/inner_comment.dart @@ -0,0 +1,5 @@ +return Object( + Object( + // Not highlighted as a comment + ) +)