OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 /// Generic utility functions. Stuff that should possibly be in core. | 5 /// Generic utility functions. Stuff that should possibly be in core. |
6 library pub.utils; | 6 library pub.utils; |
7 | 7 |
8 import 'dart:async'; | 8 import 'dart:async'; |
9 import "dart:convert"; | 9 import "dart:convert"; |
10 import 'dart:io'; | 10 import 'dart:io'; |
11 | 11 |
12 import "package:crypto/crypto.dart"; | 12 import "package:crypto/crypto.dart"; |
13 import 'package:path/path.dart' as path; | 13 import 'package:path/path.dart' as path; |
14 import "package:stack_trace/stack_trace.dart"; | 14 import "package:stack_trace/stack_trace.dart"; |
15 | 15 |
16 import 'exceptions.dart'; | 16 import 'exceptions.dart'; |
17 import 'io.dart'; | 17 import 'io.dart'; |
18 import 'log.dart' as log; | 18 import 'log.dart' as log; |
19 | 19 |
20 export 'asset/dart/utils.dart'; | 20 export 'asset/dart/utils.dart'; |
21 | 21 |
22 /// A regular expression matching a Dart identifier. | 22 /// A regular expression matching a Dart identifier. |
23 /// | 23 /// |
24 /// This also matches a package name, since they must be Dart identifiers. | 24 /// This also matches a package name, since they must be Dart identifiers. |
25 final identifierRegExp = new RegExp(r"[a-zA-Z_][a-zA-Z0-9_]+"); | 25 final identifierRegExp = new RegExp(r"[a-zA-Z_]\w*"); |
26 | 26 |
27 /// Like [identifierRegExp], but anchored so that it only matches strings that | 27 /// Like [identifierRegExp], but anchored so that it only matches strings that |
28 /// are *just* Dart identifiers. | 28 /// are *just* Dart identifiers. |
29 final onlyIdentifierRegExp = new RegExp("^${identifierRegExp.pattern}\$"); | 29 final onlyIdentifierRegExp = new RegExp("^${identifierRegExp.pattern}\$"); |
30 | 30 |
| 31 /// Dart reserved words, from the Dart spec. |
| 32 const reservedWords = const [ |
| 33 "assert", "break", "case", "catch", "class", "const", "continue", "default", |
| 34 "do", "else", "extends", "false", "final", "finally", "for", "if", "in", "is", |
| 35 "new", "null", "return", "super", "switch", "this", "throw", "true", "try", |
| 36 "var", "void", "while", "with" |
| 37 ]; |
| 38 |
31 /// A pair of values. | 39 /// A pair of values. |
32 class Pair<E, F> { | 40 class Pair<E, F> { |
33 E first; | 41 E first; |
34 F last; | 42 F last; |
35 | 43 |
36 Pair(this.first, this.last); | 44 Pair(this.first, this.last); |
37 | 45 |
38 String toString() => '($first, $last)'; | 46 String toString() => '($first, $last)'; |
39 | 47 |
40 bool operator==(other) { | 48 bool operator==(other) { |
(...skipping 893 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
934 } else { | 942 } else { |
935 throw new ApplicationException(message); | 943 throw new ApplicationException(message); |
936 } | 944 } |
937 } | 945 } |
938 | 946 |
939 /// Throw a [DataException] with [message] to indicate that the command has | 947 /// Throw a [DataException] with [message] to indicate that the command has |
940 /// failed because of invalid input data. | 948 /// failed because of invalid input data. |
941 /// | 949 /// |
942 /// This will report the error and cause pub to exit with [exit_codes.DATA]. | 950 /// This will report the error and cause pub to exit with [exit_codes.DATA]. |
943 void dataError(String message) => throw new DataException(message); | 951 void dataError(String message) => throw new DataException(message); |
OLD | NEW |