Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:io'; | 5 import 'dart:io'; |
| 6 | 6 |
| 7 import 'dart:isolate'; | 7 import 'dart:isolate'; |
| 8 | 8 |
| 9 import 'package:yaml/yaml.dart' show loadYaml; | 9 import 'package:yaml/yaml.dart' show loadYaml; |
| 10 | 10 |
| 11 import 'package:front_end/src/fasta/parser/error_kind.dart' show ErrorKind; | 11 import 'package:front_end/src/fasta/parser/error_kind.dart' show ErrorKind; |
| 12 | 12 |
| 13 import 'package:dart_style/dart_style.dart' show DartFormatter; | |
|
Siggi Cherem (dart-lang)
2017/07/12 20:06:51
note: this introduced a circular dependency on fas
ahe
2017/07/13 00:26:54
We could do that, but then we have to use the slig
| |
| 14 | |
| 13 main(List<String> arguments) async { | 15 main(List<String> arguments) async { |
| 14 var port = new ReceivePort(); | 16 var port = new ReceivePort(); |
| 15 Uri messagesFile = Platform.script.resolve("../../messages.yaml"); | 17 Uri messagesFile = Platform.script.resolve("../../messages.yaml"); |
| 16 Map yaml = loadYaml(await new File.fromUri(messagesFile).readAsStringSync()); | 18 Map yaml = loadYaml(await new File.fromUri(messagesFile).readAsStringSync()); |
| 17 Set<String> names = | 19 Set<String> names = |
| 18 new Set<String>.from(yaml.keys.map((String s) => "ErrorKind.$s")); | 20 new Set<String>.from(yaml.keys.map((String s) => "ErrorKind.$s")); |
| 19 Set<String> kinds = | 21 Set<String> kinds = |
| 20 new Set<String>.from(ErrorKind.values.map((kind) => "$kind")); | 22 new Set<String>.from(ErrorKind.values.map((kind) => "$kind")); |
| 21 Set<String> difference = kinds.difference(names); | 23 Set<String> difference = kinds.difference(names); |
| 22 if (difference.isNotEmpty) { | 24 if (difference.isNotEmpty) { |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 45 """); | 47 """); |
| 46 | 48 |
| 47 yaml.forEach((String name, description) { | 49 yaml.forEach((String name, description) { |
| 48 while (description is String) { | 50 while (description is String) { |
| 49 description = yaml[description]; | 51 description = yaml[description]; |
| 50 } | 52 } |
| 51 Map map = description; | 53 Map map = description; |
| 52 sb.writeln(compileTemplate(name, map['template'], map['tip'])); | 54 sb.writeln(compileTemplate(name, map['template'], map['tip'])); |
| 53 }); | 55 }); |
| 54 | 56 |
| 57 String dartfmtedText = new DartFormatter().format("$sb"); | |
| 58 | |
| 55 Uri problemsFile = await Isolate.resolvePackageUri( | 59 Uri problemsFile = await Isolate.resolvePackageUri( |
| 56 Uri.parse('package:front_end/src/fasta/problems.dart')); | 60 Uri.parse('package:front_end/src/fasta/problems.dart')); |
| 57 await new File.fromUri(problemsFile).writeAsString("$sb", flush: true); | 61 await new File.fromUri(problemsFile) |
| 62 .writeAsString(dartfmtedText, flush: true); | |
| 58 port.close(); | 63 port.close(); |
| 59 } | 64 } |
| 60 | 65 |
| 61 final RegExp placeholderPattern = new RegExp("#[a-zA-Z0-9_]+"); | 66 final RegExp placeholderPattern = new RegExp("#[a-zA-Z0-9_]+"); |
| 62 | 67 |
| 63 String compileTemplate(String name, String template, String tip) { | 68 String compileTemplate(String name, String template, String tip) { |
| 64 var parameters = new Set<String>(); | 69 var parameters = new Set<String>(); |
| 65 var conversions = new Set<String>(); | 70 var conversions = new Set<String>(); |
| 66 var arguments = new Set<String>(); | 71 var arguments = new Set<String>(); |
| 67 for (Match match in placeholderPattern.allMatches("$template${tip ?? ''}")) { | 72 for (Match match in placeholderPattern.allMatches("$template${tip ?? ''}")) { |
| (...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 113 ${interpolate('message', template)} | 118 ${interpolate('message', template)} |
| 114 ${interpolate('tip', tip)} | 119 ${interpolate('tip', tip)} |
| 115 'code': ErrorKind.$name, | 120 'code': ErrorKind.$name, |
| 116 'arguments': { | 121 'arguments': { |
| 117 ${arguments.join('\n ')} | 122 ${arguments.join('\n ')} |
| 118 }, | 123 }, |
| 119 }; | 124 }; |
| 120 } | 125 } |
| 121 """; | 126 """; |
| 122 } | 127 } |
| OLD | NEW |