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)"]
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

View File

@ -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

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

View File

@ -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: (?<!\$)\b(true|false|null)\b(?!\$)
scope: constant.language.dart
- match: \b(this|super)\b
- match: (?<!\$)\b(this|super)\b(?!\$)
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
decl-class:
- match: \bclass\b
- match: '(?<![a-zA-Z0-9_$])([_$]*[A-Z][a-zA-Z0-9_$]*|bool\b|num\b|int\b|double\b|dynamic\b)'
scope: support.class.dart
- match: '([_$]*[a-z][a-zA-Z0-9_$]*)(<|\(|\s+=>)'
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:
- meta_scope: meta.declaration.class.dart
- match: "(?={)"
- meta_content_scope: variable.other.source.dart
- match: '```'
pop: true
- include: keywords
- match: "[A-Za-z_][A-Za-z0-9_]*"
scope: class.name.dart
decl-enum:
- match: \benum\b
- match: (`.*?`)
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
0: variable.other.source.dart
- 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
0: variable.other.source.dart
- match: (\* (( ).*))$
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'
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
2: variable.other.source.dart
- match: (\* .*)$
keywords:
- match: \bassert\b
scope: keyword.control.assert.dart
- match: \bas\b
- match: (?<!\$)\bas\b(?!\$)
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
- match: \s+\?\s+|\s+:\s+
scope: keyword.control.ternary.dart
- match: \b(break|case|continue|default|do|else|for|if|in|return|switch|while)\b
- match: (?<!\$)\b(break|case|continue|default|do|else|for|if|in|return|switch|while)\b(?!\$)
scope: keyword.control.dart
- match: \b(async\*|async|await\*|await|yield)\b
scope: keyword.control.async.dart
- match: \b(new)\b
- match: (?<!\$)\b(sync(\*)?|async(\*)?|await|yield(\*)?)\b(?!\$)
scope: keyword.control.dart
- match: (?<!\$)\bassert\b(?!\$)
scope: keyword.control.dart
- match: (?<!\$)\b(new)\b(?!\$)
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
- match: \b(is\!?)\b
- match: (?<!\$)\b(is\!?)\b(?!\$)
scope: keyword.operator.dart
- match: '\?|:'
scope: keyword.operator.ternary.dart
- 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: (?<!\$)\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: ;
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: \.
scope: constant.other.regex.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
scope: punctuation.dot.dart
string-interp:
- match: '(\$)(\{)'
- match: '\$((\w+)|\{([^{}]+)\})'
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
3: variable.parameter.dart
- match: \\.
scope: constant.character.escape.dart
strings:
@ -328,7 +166,7 @@ contexts:
- match: (?<!r)'''
push:
- meta_scope: string.interpolated.triple.single.dart
- match: "'''(?!')"
- match: '''''''(?!'')'
pop: true
- include: string-interp
- match: r"""
@ -339,9 +177,9 @@ contexts:
- match: r'''
push:
- meta_scope: string.quoted.triple.single.dart
- match: "'''(?!')"
- match: '''''''(?!'')'
pop: true
- match: (?<!\\|r)"
- match: (?<!\|r)"
push:
- meta_scope: string.interpolated.double.dart
- match: '"'
@ -354,16 +192,20 @@ contexts:
- meta_scope: string.quoted.double.dart
- match: '"'
pop: true
- include: regexp
- match: \n
scope: invalid.string.newline
- match: (?<!\|r)'
push:
- meta_scope: string.interpolated.single.dart
- match: "'"
pop: true
- match: \n
scope: invalid.string.newline
- include: string-interp
- match: r'
push:
- meta_scope: string.quoted.single.dart
- match: "'"
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 */
int partition(List list, int low, int high) {
 if (list == null || list.length == 0) return 0;
 int pivot = list[high];
 int i = low - 1;
int partition(List list, int low, int high) {
 if (list == null || list.length == 0) return 0;
 int pivot = list[high];
 int i = low - 1;
 void swap(List list, int i, int j) {
 int temp = list[i];
 void swap(List list, int i, int j) {
 int temp = list[i];
 list[i] = list[j];
 list[j] = temp;
 }
 for (int j = low; j < high; j++) {
 for (int j = low; j < high; j++) {
 if (list[j] <= pivot) {
 i++;
 swap(list, i, j);
 swap(list, i, j);
 }
 swap(list, i + 1, high);
 swap(list, i + 1, high);
 return i + 1;
 }
}
void quickSort(List list, int low, int high) {
void quickSort(List list, int low, int high) {
 if (low < high) {
 int pi = partition(list, low, high);
 quickSort(list, low, pi - 1);
 quickSort(list, pi + 1, high);
 int pi = partition(list, low, high);
 quickSort(list, low, pi - 1);
 quickSort(list, pi + 1, high);
 }
}
void merge(List list, int leftIndex, int middleIndex, int rightIndex) {
 int leftSize = middleIndex - leftIndex + 1;
 int rightSize = rightIndex - middleIndex;
void merge(List list, int leftIndex, int middleIndex, int rightIndex) {
 int leftSize = middleIndex - leftIndex + 1;
 int rightSize = rightIndex - middleIndex;
 List leftList = new List(leftSize);
 List rightList = new List(rightSize);
 List leftList = new List(leftSize);
 List rightList = new List(rightSize);
 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 i = 0; i < leftSize; i++) leftList[i] = list[leftIndex + i];
 for (int j = 0; j < rightSize; j++) rightList[j] = list[middleIndex + j + 1];
 int i = 0, j = 0;
 int k = leftIndex;
 int i = 0, j = 0;
 int k = leftIndex;
 while (i < leftSize && j < rightSize) {
 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) {
 int middleIndex = (rightIndex + leftIndex) ~/ 2;
 int middleIndex = (rightIndex + leftIndex) ~/ 2;
 mergeSort(list, leftIndex, middleIndex);
 mergeSort(list, middleIndex + 1, rightIndex);
 mergeSort(list, leftIndex, middleIndex);
 mergeSort(list, middleIndex + 1, rightIndex);
 merge(list, leftIndex, middleIndex, rightIndex);
 merge(list, leftIndex, middleIndex, rightIndex);
 }
}
@ -80,54 +80,54 @@
var name = 'Voyager I';
var year = 1977;
var antennaDiameter = 3.7;
var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
var flybyObjects = ['Jupiter', 'Saturn', 'Uranus', 'Neptune'];
var image = {
 'tags': ['saturn'],
 'url': '//path/to/saturn.jpg'
 'tags': ['saturn'],
 'url': '//path/to/saturn.jpg'
};
/*classes */
class Spacecraft {
 String name;
 DateTime launchDate;
 Spacecraft(this.name, this.launchDate) {}
class Spacecraft {
 String name;
 DateTime launchDate;
 Spacecraft(this.name, this.launchDate) {}
 // Named constructor that forwards to the default one.
 Spacecraft.unlaunched(String name) : this(name, null);
 // Named constructor that forwards to the default one.
 Spacecraft.unlaunched(String name) : this(name, null);
 int get launchYear => 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';
 }
}

View File

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