Chromium Code Reviews| Index: sdk/lib/internal/symbol.dart |
| diff --git a/sdk/lib/internal/symbol.dart b/sdk/lib/internal/symbol.dart |
| index 338b06b0b7e5930cc7f2f756134afbb6f2d11b8b..08fb6b302fa7916b7445ef0297fd101282f58b8c 100644 |
| --- a/sdk/lib/internal/symbol.dart |
| +++ b/sdk/lib/internal/symbol.dart |
| @@ -21,9 +21,12 @@ class Symbol implements core.Symbol { |
| r'e(?:lse|num|xtends)|f(?:alse|inal(?:ly)?|or)|i[fns]|n(?:ew|ull)|' |
| r'ret(?:hrow|urn)|s(?:uper|witch)|t(?:h(?:is|row)|r(?:ue|y))|' |
| r'v(?:ar|oid)|w(?:hile|ith))'; |
| - // Mathces a public identifier (identifier not starting with '_'). |
| + // Matches a public identifier (identifier not starting with '_'). |
| static const String publicIdentifierRE = |
| r'(?!' '$reservedWordRE' r'\b(?!\$))[a-zA-Z$][\w$]*'; |
| + // Matches a public or private identifier. |
|
ahe
2014/02/24 10:43:23
I suggest:
/// Matches an identifier (public or p
Lasse Reichstein Nielsen
2014/03/03 12:58:44
rewritten.
|
| + static const String identifierRE = |
| + r'(?!' '$reservedWordRE' r'\b(?!\$))[a-zA-Z$_][\w$]*'; |
| // Matches the names of declarable operators. |
| static const String operatorRE = |
| r'(?:[\-+*/%&|^]|\[\]=?|==|~/?|<[<=]?|>[>=]?|unary-)'; |
| @@ -54,6 +57,9 @@ class Symbol implements core.Symbol { |
| static final RegExp validationPattern = new RegExp( |
| '^(?:$operatorRE\$|$publicIdentifierRE(?:=?\$|[.](?!\$)))+?\$'); |
| + static final RegExp privateValidationPattern = new RegExp( |
|
ahe
2014/02/24 10:43:23
This name is slightly confusing: this doesn't vali
Lasse Reichstein Nielsen
2014/03/03 12:58:44
Changed to publicSymbolPattern and symbolPattern.
|
| + '^(?:$operatorRE\$|$identifierRE(?:=?\$|[.](?!\$)))+?\$'); |
| + |
| external const Symbol(String name); |
| /** |
| @@ -89,4 +95,16 @@ class Symbol implements core.Symbol { |
| throw new ArgumentError( |
| '"$name" is not a valid (qualified) symbol name'); |
| } |
| + |
| + static String validatePrivate(String name) { |
| + if (name.isEmpty || privateValidationPattern.hasMatch(name)) return name; |
| + if (name.startsWith('_')) { |
| + // There may be other private parts in a qualified name than the first |
| + // one, but this is a common case that deserves a specific error |
| + // message. |
| + throw new ArgumentError('"$name" is a private identifier'); |
| + } |
| + throw new ArgumentError( |
| + '"$name" is not a valid (qualified) symbol name'); |
| + } |
| } |