Skip to content

Commit

Permalink
fix: add Dart required keyword
Browse files Browse the repository at this point in the history
  • Loading branch information
triallax authored and alecthomas committed Mar 4, 2022
1 parent 647b7a6 commit 7bfe2f4
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion lexers/embedded/dart.xml
Expand Up @@ -97,7 +97,7 @@
<rule pattern="\b(assert|break|case|catch|continue|default|do|else|finally|for|if|in|is|new|return|super|switch|this|throw|try|while)\b">
<token type="Keyword"/>
</rule>
<rule pattern="\b(abstract|async|await|const|extends|factory|final|get|implements|native|operator|set|static|sync|typedef|var|with|yield)\b">
<rule pattern="\b(abstract|async|await|const|extends|factory|final|get|implements|native|operator|required|set|static|sync|typedef|var|with|yield)\b">
<token type="KeywordDeclaration"/>
</rule>
<rule pattern="\b(bool|double|dynamic|int|num|Object|String|void)\b">
Expand Down
8 changes: 4 additions & 4 deletions lexers/testdata/dart.actual
Expand Up @@ -3,8 +3,8 @@ import 'dart:html';
import 'dart:math' show Random;

// We changed 5 lines of code to make this sample nicer on
// the web (so that the execution waits for animation frame,
// the number gets updated in the DOM, and the program ends
// the web (so that the execution waits for animation frame,
// the number gets updated in the DOM, and the program ends
// after 500 iterations).

main() async {
Expand Down Expand Up @@ -39,12 +39,12 @@ Stream<double> computePi({int batch: 100000}) async* {
Iterable<Point> generateRandom([int seed]) sync* {
final random = new Random(seed);
while (true) {
yield new Point(random.nextDouble(), random.nextDouble());
yield new Point(x: random.nextDouble(), y: random.nextDouble());
}
}

class Point {
final double x, y;
const Point(this.x, this.y);
const Point({required this.x, required this.y});
bool get isInsideUnitCircle => x * x + y * y <= 1;
}
14 changes: 11 additions & 3 deletions lexers/testdata/dart.expected
Expand Up @@ -18,7 +18,7 @@
{"type":"Name","value":"Random"},
{"type":"Punctuation","value":";"},
{"type":"Text","value":"\n\n"},
{"type":"CommentSingle","value":"// We changed 5 lines of code to make this sample nicer on\n// the web (so that the execution waits for animation frame, \n// the number gets updated in the DOM, and the program ends \n// after 500 iterations).\n"},
{"type":"CommentSingle","value":"// We changed 5 lines of code to make this sample nicer on\n// the web (so that the execution waits for animation frame,\n// the number gets updated in the DOM, and the program ends\n// after 500 iterations).\n"},
{"type":"Text","value":"\n"},
{"type":"Name","value":"main"},
{"type":"Punctuation","value":"()"},
Expand Down Expand Up @@ -270,11 +270,15 @@
{"type":"Text","value":" "},
{"type":"Name","value":"Point"},
{"type":"Punctuation","value":"("},
{"type":"NameLabel","value":"x:"},
{"type":"Text","value":" "},
{"type":"Name","value":"random"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"nextDouble"},
{"type":"Punctuation","value":"(),"},
{"type":"Text","value":" "},
{"type":"NameLabel","value":"y:"},
{"type":"Text","value":" "},
{"type":"Name","value":"random"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"nextDouble"},
Expand Down Expand Up @@ -303,16 +307,20 @@
{"type":"KeywordDeclaration","value":"const"},
{"type":"Text","value":" "},
{"type":"Name","value":"Point"},
{"type":"Punctuation","value":"("},
{"type":"Punctuation","value":"({"},
{"type":"KeywordDeclaration","value":"required"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"this"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"x"},
{"type":"Punctuation","value":","},
{"type":"Text","value":" "},
{"type":"KeywordDeclaration","value":"required"},
{"type":"Text","value":" "},
{"type":"Keyword","value":"this"},
{"type":"Punctuation","value":"."},
{"type":"Name","value":"y"},
{"type":"Punctuation","value":");"},
{"type":"Punctuation","value":"});"},
{"type":"Text","value":"\n "},
{"type":"KeywordType","value":"bool"},
{"type":"Text","value":" "},
Expand Down

0 comments on commit 7bfe2f4

Please sign in to comment.