Better syntax highlighting for Dart (#1959)

Remove unmaintained Dart syntax submodule. Add elMuso/Dartlight as submodule. Update Dart syntax highlighting. Add changes to changelog.
This commit is contained in:
Ersikan 2021-12-06 08:40:43 +01:00 committed by GitHub
parent 8072d5a3e3
commit 29711c178a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 154 additions and 301 deletions

6
.gitmodules vendored
View File

@ -67,9 +67,6 @@
[submodule "assets/syntaxes/JavaScript (Babel)"] [submodule "assets/syntaxes/JavaScript (Babel)"]
path = assets/syntaxes/02_Extra/JavaScript (Babel) path = assets/syntaxes/02_Extra/JavaScript (Babel)
url = https://github.com/babel/babel-sublime 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"] [submodule "assets/syntaxes/FSharp"]
path = assets/syntaxes/02_Extra/FSharp path = assets/syntaxes/02_Extra/FSharp
url = https://github.com/hoest/sublimetext-fsharp url = https://github.com/hoest/sublimetext-fsharp
@ -236,3 +233,6 @@
[submodule "assets/syntaxes/02_Extra/MediaWiki"] [submodule "assets/syntaxes/02_Extra/MediaWiki"]
path = assets/syntaxes/02_Extra/MediaWiki path = assets/syntaxes/02_Extra/MediaWiki
url = https://github.com/tosher/Mediawiker.git 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

View File

@ -36,6 +36,7 @@
- LiveScript, see #1915 (@Enselic) - LiveScript, see #1915 (@Enselic)
- MediaWiki, see #1925 (@sorairolake) - MediaWiki, see #1925 (@sorairolake)
- The `requirements.txt` syntax has been removed due to incompatible license requirements. - The `requirements.txt` syntax has been removed due to incompatible license requirements.
- Dart, new highlighter, see #1959 (@Ersikan)
## New themes ## New themes

@ -1 +1 @@
Subproject commit d891fb36c98ca0b111a35cba109b05a16b6c4b83 Subproject commit 2734901b014191f5a7f71c3f48678adf31239098

View File

@ -1,6 +1,6 @@
%YAML 1.2 %YAML 1.2
--- ---
# http://www.sublimetext.com/docs/3/syntax.html # http://www.sublimetext.com/docs/syntax.html
name: Dart name: Dart
file_extensions: file_extensions:
- dart - dart
@ -9,7 +9,7 @@ contexts:
main: main:
- match: ^(#!.*)$ - match: ^(#!.*)$
scope: meta.preprocessor.script.dart 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: captures:
0: keyword.other.import.dart 0: keyword.other.import.dart
push: push:
@ -19,242 +19,114 @@ contexts:
0: punctuation.terminator.dart 0: punctuation.terminator.dart
pop: true pop: true
- include: strings - include: strings
- match: \b(as|show|hide|deferred)\b - include: comments
- match: \b(as|show|hide)\b
scope: keyword.other.import.dart scope: keyword.other.import.dart
- include: comments - include: comments
- include: constants-and-special-vars - include: punctuation
- include: annotations - include: annotations
- include: decl-typedef
- include: decl-class
- include: decl-enum
- include: decl-function
- include: keywords - include: keywords
- include: constants-and-special-vars
- include: strings - include: strings
annotations: annotations:
- match: '^(?:\s*)((@)([a-zA-Z0-9_]+))' - match: '@[a-zA-Z]+'
captures: scope: storage.type.annotation.dart
1: annotation.dart
2: entity.name.function.annotation.dart
3: support.type.dart
comments: comments:
- match: /\*\*/ - match: /\*\*/
scope: comment.block.empty.dart scope: comment.block.empty.dart
captures: captures:
0: punctuation.definition.comment.dart 0: punctuation.definition.comment.dart
- include: comments-doc-oldschool
- include: comments-doc
- include: comments-inline - include: comments-inline
comments-inline: comments-block:
- match: /\* - match: /\*
push: push:
- meta_scope: comment.block.dart - meta_scope: comment.block.dart
- match: \*/ - match: \*/
pop: true pop: true
- include: scope:text.dart-doccomments - include: comments-block
- match: (///) comments-doc:
captures: - match: ///
1: marker.dart
push: push:
- meta_scope: comment.line.triple-slash.dart - meta_scope: comment.block.documentation.dart
- match: $ - match: .*
pop: true pop: true
- include: scope:text.dart-doccomments - include: dartdoc
- match: (//) comments-doc-oldschool:
captures: - match: /\*\*
1: marker.dart
push: push:
- meta_scope: comment.line.double-slash.dart - meta_scope: comment.block.documentation.dart
- match: $ - match: \*/
pop: true 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: constants-and-special-vars:
- match: \b(true|false|null)\b - match: (?<!\$)\b(true|false|null)\b(?!\$)
scope: constant.language.dart scope: constant.language.dart
- match: \b(this|super)\b - match: (?<!\$)\b(this|super)\b(?!\$)
scope: variable.language.dart scope: variable.language.dart
- match: '\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b' - match: '(?<!\$)\b((0(x|X)[0-9a-fA-F]*)|(([0-9]+\.?[0-9]*)|(\.[0-9]+))((e|E)(\+|-)?[0-9]+)?)\b(?!\$)'
scope: constant.numeric.dart scope: constant.numeric.dart
decl-class: - match: '(?<![a-zA-Z0-9_$])([_$]*[A-Z][a-zA-Z0-9_$]*|bool\b|num\b|int\b|double\b|dynamic\b)'
- match: \bclass\b scope: support.class.dart
- match: '([_$]*[a-z][a-zA-Z0-9_$]*)(<|\(|\s+=>)'
captures: captures:
0: keyword.control.new.dart 1: entity.name.function.dart
dartdoc:
- match: '(\[.*?\])'
captures:
0: variable.name.source.dart
- match: '^ {4,}(?![ \*]).*'
captures:
0: variable.name.source.dart
- match: '```.*?$'
push: push:
- meta_scope: meta.declaration.class.dart - meta_content_scope: variable.other.source.dart
- match: "(?={)" - match: '```'
pop: true pop: true
- include: keywords - match: (`.*?`)
- match: "[A-Za-z_][A-Za-z0-9_]*"
scope: class.name.dart
decl-enum:
- match: \benum\b
captures: captures:
0: keyword.declaration.dart 0: variable.other.source.dart
push: - match: (`.*?`)
- 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
captures: captures:
1: storage.type.primitive.dart 0: variable.other.source.dart
2: keyword.declaration.dart - match: (\* (( ).*))$
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: captures:
1: type.user-defined.dart 2: variable.other.source.dart
2: keyword.declaration.dart - match: (\* .*)$
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'
captures:
1: keyword.declaration.dart
2: function.name.dart
push:
- meta_scope: meta.invocation.function.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.
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.
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
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
keywords: keywords:
- match: \bassert\b - match: (?<!\$)\bas\b(?!\$)
scope: keyword.control.assert.dart
- match: \bas\b
scope: keyword.cast.dart scope: keyword.cast.dart
- match: \b(try|catch|finally|throw|on|rethrow)\b - match: (?<!\$)\b(try|on|catch|finally|throw|rethrow)\b(?!\$)
scope: keyword.control.catch-exception.dart scope: keyword.control.catch-exception.dart
- match: \s+\?\s+|\s+:\s+ - match: (?<!\$)\b(break|case|continue|default|do|else|for|if|in|return|switch|while)\b(?!\$)
scope: keyword.control.ternary.dart
- match: \b(break|case|continue|default|do|else|for|if|in|return|switch|while)\b
scope: keyword.control.dart scope: keyword.control.dart
- match: \b(async\*|async|await\*|await|yield)\b - match: (?<!\$)\b(sync(\*)?|async(\*)?|await|yield(\*)?)\b(?!\$)
scope: keyword.control.async.dart scope: keyword.control.dart
- match: \b(new)\b - match: (?<!\$)\bassert\b(?!\$)
scope: keyword.control.dart
- match: (?<!\$)\b(new)\b(?!\$)
scope: keyword.control.new.dart scope: keyword.control.new.dart
- match: \b(abstract|extends|external|factory|implements|with|interface|get|native|operator|set|typedef)\b - match: (?<!\$)\b(abstract|class|enum|extends|external|factory|implements|get|mixin|native|operator|set|typedef|with|covariant)\b(?!\$)
scope: keyword.declaration.dart scope: keyword.declaration.dart
- match: \b(is\!?)\b - match: (?<!\$)\b(is\!?)\b(?!\$)
scope: keyword.operator.dart scope: keyword.operator.dart
- match: '\?|:'
scope: keyword.operator.ternary.dart
- match: (<<|>>>?|~|\^|\||&) - match: (<<|>>>?|~|\^|\||&)
scope: keyword.operator.bitwise.dart scope: keyword.operator.bitwise.dart
- match: ((&|\^|\||<<|>>>?)=) - match: ((&|\^|\||<<|>>>?)=)
scope: keyword.operator.assignment.bitwise.dart scope: keyword.operator.assignment.bitwise.dart
- match: (===?|!==?|<=?|>=?) - match: (=>)
scope: keyword.operator.closure.dart
- match: (==|!=|<=?|>=?)
scope: keyword.operator.comparison.dart scope: keyword.operator.comparison.dart
- match: '(([+*/%-]|\~)=)' - match: '(([+*/%-]|\~)=)'
scope: keyword.operator.assignment.arithmetic.dart scope: keyword.operator.assignment.arithmetic.dart
@ -266,56 +138,22 @@ contexts:
scope: keyword.operator.arithmetic.dart scope: keyword.operator.arithmetic.dart
- match: (!|&&|\|\|) - match: (!|&&|\|\|)
scope: keyword.operator.logical.dart scope: keyword.operator.logical.dart
- match: (?<!\$)\b(static|final|const)\b(?!\$)
scope: storage.modifier.dart
- match: (?<!\$)\b(?:void|var)\b(?!\$)
scope: storage.type.primitive.dart
punctuation:
- match: ','
scope: punctuation.comma.dart
- match: ; - match: ;
scope: punctuation.terminator.dart scope: punctuation.terminator.dart
- match: \b(static|final|const)\b
scope: storage.modifier.dart
- match: \b(?:void|bool|num|int|double|dynamic|var|String|List|Map)\b
scope: storage.type.primitive.dart
regexp:
- match: '\\[^''"]'
scope: constant.character.escaped.regex.dart
- match: \(
push:
- meta_content_scope: meta.capture.regex.dart
- match: \)
pop: true
- match: \?(:|=|!)
scope: ignore.capture.regex.dart
- match: \*|\+|\?|\.|\|
scope: keyword.other.regex.dart
- match: \^|\$
scope: keyword.other.regex.dart
- match: \. - match: \.
scope: constant.other.regex.dart scope: punctuation.dot.dart
- match: '\[(\^)?'
captures:
1: keyword.other.negation.regex.dart
push:
- meta_scope: constant.character.range.regex.dart
- match: '\]'
pop: true
- match: '\\[^"'']'
scope: constant.character.escaped.regex.dart
- match: '\{(?:\d+)?,(?:\d+)?\}'
scope: keyword.other.regex.dart
string-interp: string-interp:
- match: '(\$)(\{)' - match: '\$((\w+)|\{([^{}]+)\})'
captures: captures:
1: keyword.other.dart
2: keyword.other.dart
push:
- meta_scope: interpolation.dart
- meta_content_scope: source.dart
- match: '(\})'
captures:
1: keyword.other.dart
pop: true
- include: main
- match: (\$)(\w+)
captures:
1: keyword.other.dart
2: variable.parameter.dart 2: variable.parameter.dart
3: variable.parameter.dart
- match: \\. - match: \\.
scope: constant.character.escape.dart scope: constant.character.escape.dart
strings: strings:
@ -328,7 +166,7 @@ contexts:
- match: (?<!r)''' - match: (?<!r)'''
push: push:
- meta_scope: string.interpolated.triple.single.dart - meta_scope: string.interpolated.triple.single.dart
- match: "'''(?!')" - match: '''''''(?!'')'
pop: true pop: true
- include: string-interp - include: string-interp
- match: r""" - match: r"""
@ -339,9 +177,9 @@ contexts:
- match: r''' - match: r'''
push: push:
- meta_scope: string.quoted.triple.single.dart - meta_scope: string.quoted.triple.single.dart
- match: "'''(?!')" - match: '''''''(?!'')'
pop: true pop: true
- match: (?<!\\|r)" - match: (?<!\|r)"
push: push:
- meta_scope: string.interpolated.double.dart - meta_scope: string.interpolated.double.dart
- match: '"' - match: '"'
@ -354,16 +192,20 @@ contexts:
- meta_scope: string.quoted.double.dart - meta_scope: string.quoted.double.dart
- match: '"' - match: '"'
pop: true pop: true
- include: regexp - match: \n
scope: invalid.string.newline
- match: (?<!\|r)' - match: (?<!\|r)'
push: push:
- meta_scope: string.interpolated.single.dart - meta_scope: string.interpolated.single.dart
- match: "'" - match: "'"
pop: true pop: true
- match: \n
scope: invalid.string.newline
- include: string-interp - include: string-interp
- match: r' - match: r'
push: push:
- meta_scope: string.quoted.single.dart - meta_scope: string.quoted.single.dart
- match: "'" - match: "'"
pop: true pop: true
- include: regexp - match: \n
scope: invalid.string.newline

View File

@ -0,0 +1,5 @@
return Object(
 Object(
 // Not highlighted as a comment
 )
)

View File

@ -1,45 +1,45 @@
/* array sorting alogorithm */ /* array sorting alogorithm */
int partition(List list, int low, int high) { int partition(List list, int low, int high) {
 if (list == null || list.length == 0) return 0;  if (list == null || list.length == 0) return 0;
 int pivot = list[high];  int pivot = list[high];
 int i = low - 1;  int i = low - 1;
 void swap(List list, int i, int j) {  void swap(List list, int i, int j) {
 int temp = list[i];  int temp = list[i];
 list[i] = list[j];  list[i] = list[j];
 list[j] = temp;  list[j] = temp;
 }  }
 for (int j = low; j < high; j++) {  for (int j = low; j < high; j++) {
 if (list[j] <= pivot) {  if (list[j] <= pivot) {
 i++;  i++;
 swap(list, i, j);  swap(list, i, j);
 }  }
 swap(list, i + 1, high);  swap(list, i + 1, high);
 return i + 1;  return i + 1;
 }  }
} }
void quickSort(List list, int low, int high) { void quickSort(List list, int low, int high) {
 if (low < high) {  if (low < high) {
 int pi = partition(list, low, high);  int pi = partition(list, low, high);
 quickSort(list, low, pi - 1);  quickSort(list, low, pi - 1);
 quickSort(list, pi + 1, high);  quickSort(list, pi + 1, high);
 }  }
} }
void merge(List list, int leftIndex, int middleIndex, int rightIndex) { void merge(List list, int leftIndex, int middleIndex, int rightIndex) {
 int leftSize = middleIndex - leftIndex + 1;  int leftSize = middleIndex - leftIndex + 1;
 int rightSize = rightIndex - middleIndex;  int rightSize = rightIndex - middleIndex;
 List leftList = new List(leftSize);  List leftList = new List(leftSize);
 List rightList = new List(rightSize);  List rightList = new List(rightSize);
 for (int i = 0; i < leftSize; i++) leftList[i] = list[leftIndex + i];  for (int i = 0; i < leftSize; i++) leftList[i] = list[leftIndex + i];
 for (int j = 0; j < rightSize; j++) rightList[j] = list[middleIndex + j + 1];  for (int j = 0; j < rightSize; j++) rightList[j] = list[middleIndex + j + 1];
 int i = 0, j = 0;  int i = 0, j = 0;
 int k = leftIndex;  int k = leftIndex;
 while (i < leftSize && j < rightSize) {  while (i < leftSize && j < rightSize) {
 if (leftList[i] <= rightList[j]) {  if (leftList[i] <= rightList[j]) {
@ -65,14 +65,14 @@
 }  }
} }
void mergeSort(List list, int leftIndex, int rightIndex) { void mergeSort(List list, int leftIndex, int rightIndex) {
 if (leftIndex < rightIndex) {  if (leftIndex < rightIndex) {
 int middleIndex = (rightIndex + leftIndex) ~/ 2;  int middleIndex = (rightIndex + leftIndex) ~/ 2;
 mergeSort(list, leftIndex, middleIndex);  mergeSort(list, leftIndex, middleIndex);
 mergeSort(list, middleIndex + 1, rightIndex);  mergeSort(list, middleIndex + 1, rightIndex);
 merge(list, leftIndex, middleIndex, rightIndex);  merge(list, leftIndex, middleIndex, rightIndex);
 }  }
} }
@ -80,54 +80,54 @@
var name = 'Voyager I'; var name = 'Voyager I';
var year = 1977; var year = 1977;
var antennaDiameter = 3.7; var antennaDiameter = 3.7;
var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune']; var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
var image = { var image = {
 'tags': ['saturn'],  'tags': ['saturn'],
 'url': '//path/to/saturn.jpg'  'url': '//path/to/saturn.jpg'
}; };
/*classes */ /*classes */
class Spacecraft { class Spacecraft {
 String name;  String name;
 DateTime launchDate;  DateTime launchDate;
 Spacecraft(this.name, this.launchDate) {}  Spacecraft(this.name, this.launchDate) {}
 // Named constructor that forwards to the default one.  // Named constructor that forwards to the default one.
 Spacecraft.unlaunched(String name) : this(name, null);  Spacecraft.unlaunched(String name) : this(name, null);
 int get launchYear => launchDate?.year;  int get launchYear => launchDate?.year;
 void describe() {  void describe() {
 print('Spacecraft: $name');  print('Spacecraft: $name');
 if (launchDate != null) {  if (launchDate != null) {
 int years = DateTime.now().difference(launchDate).inDays ~/ 365;  int years = DateTime.now().difference(launchDate).inDays ~/ 365;
 print('Launched: $launchYear ($years years ago)');  print('Launched: $launchYear ($years years ago)');
 } else {  } else {
 print('Unlaunched');  print('Unlaunched');
 }  }
 }  }
} }
/* Mixins */ /* Mixins */
class PilotedCraft extends Spacecraft with Piloted { class PilotedCraft extends Spacecraft with Piloted {
 // ···  // ···
} }
/* Interfaces and abstract classes */ /* Interfaces and abstract classes */
class MockSpaceship implements Spacecraft { class MockSpaceship implements Spacecraft {
 // ···  // ···
} }
/* async */ /* async */
Future<void> printWithDelay(String message) { Future<void> printWithDelay(String message) {
 return Future.delayed(const Duration(seconds: 2)).then((_) {  return Future.delayed(const Duration(seconds: 2)).then((_) {
 print(message);  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) {  for (var object in objects) {
 await Future.delayed(const Duration(seconds: 2));  await Future.delayed(const Duration(seconds: 2));
 yield '${craft.name} flies by $object';  yield '${craft.name} flies by $object';
 }  }
} }

View File

@ -0,0 +1,5 @@
return Object(
Object(
// Not highlighted as a comment
)
)