scanner-tool: add explicit command-line arguments to enable printing tokens
This will be used instead of -DprintTokens=true.
Context: we use this tool in bazel where we use a modular pipeline. That
pipeline will no longer support dart environment variables due to
https://github.com/dart-lang/sdk/issues/36513.
In this specific file the intent was anyways to pass an option when
launching the program, so a command-line option is appropriate IMO.
Change-Id: I5187190a01afe59aef57ec6a7311b1e380313a81
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/99102
Reviewed-by: Ari Aye <ariaye@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Sigmund Cherem <sigmund@google.com>
diff --git a/pkg/front_end/lib/src/fasta/scanner/scanner_main.dart b/pkg/front_end/lib/src/fasta/scanner/scanner_main.dart
index 848b65d..fd3c030 100644
--- a/pkg/front_end/lib/src/fasta/scanner/scanner_main.dart
+++ b/pkg/front_end/lib/src/fasta/scanner/scanner_main.dart
@@ -8,22 +8,18 @@
import '../scanner.dart' show ErrorToken, Token, scan;
-scanAll(Map<Uri, List<int>> files) {
+scanAll(Map<Uri, List<int>> files, {bool verbose: false, bool verify: false}) {
Stopwatch sw = new Stopwatch()..start();
int byteCount = 0;
files.forEach((Uri uri, List<int> bytes) {
var token = scan(bytes).tokens;
- if (const bool.fromEnvironment("printTokens")) {
- printTokens(token);
- }
- if (const bool.fromEnvironment('verifyErrorTokens')) {
- verifyErrorTokens(token, uri);
- }
+ if (verbose) printTokens(token);
+ if (verify) verifyErrorTokens(token, uri);
byteCount += bytes.length - 1;
});
sw.stop();
print("Scanning files took: ${sw.elapsed}");
- print("Bytes/ms: ${byteCount/sw.elapsedMilliseconds}");
+ print("Bytes/ms: ${byteCount / sw.elapsedMilliseconds}");
}
void printTokens(Token token) {
@@ -78,12 +74,25 @@
mainEntryPoint(List<String> arguments) {
Map<Uri, List<int>> files = <Uri, List<int>>{};
Stopwatch sw = new Stopwatch()..start();
- for (String name in arguments) {
- Uri uri = Uri.base.resolve(name);
+ bool verbose = const bool.fromEnvironment("printTokens");
+ bool verify = const bool.fromEnvironment('verifyErrorTokens');
+ for (String arg in arguments) {
+ if (arg.startsWith('--')) {
+ if (arg == '--print-tokens') {
+ verbose = true;
+ } else if (arg == '--verify-error-tokens') {
+ verify = true;
+ } else {
+ print('Unrecognized option: $arg');
+ }
+ continue;
+ }
+
+ Uri uri = Uri.base.resolve(arg);
List<int> bytes = readBytesFromFileSync(uri);
files[uri] = bytes;
}
sw.stop();
print("Reading files took: ${sw.elapsed}");
- scanAll(files);
+ scanAll(files, verbose: verbose, verify: verify);
}