OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 part of dart._internal; | 5 part of dart._internal; |
6 | 6 |
7 /** | 7 /** |
8 * Implementation of [core.Symbol]. This class uses the same name as | 8 * Implementation of [core.Symbol]. This class uses the same name as |
9 * a core class so a user can't tell the difference. | 9 * a core class so a user can't tell the difference. |
10 * | 10 * |
11 * The purpose of this class is to hide [_name] from user code, but | 11 * The purpose of this class is to hide [_name] from user code, but |
12 * make it accessible to Dart platform code via the static method | 12 * make it accessible to Dart platform code via the static method |
13 * [getName]. | 13 * [getName]. |
14 */ | 14 */ |
15 class Symbol implements core.Symbol { | 15 class Symbol implements core.Symbol { |
16 final String _name; | 16 final String _name; |
17 | 17 |
| 18 // Reserved words are not allowed as identifiers. |
| 19 static const String reservedWord = |
| 20 r'assert|break|c(?:a(?:se|tch)|lass|on(?:st|tinue))|d(?:efault|o)|' |
| 21 r'e(?:lse|num|xtends)|f(?:alse|inal(?:ly)?|or)|i[fns]|n(?:ew|ull)|' |
| 22 r'ret(?:hrow|urn)|s(?:uper|witch)|t(?:h(?:is|row)|r(?:ue|y))|' |
| 23 r'v(?:ar|oid)|w(?:hile|ith)'; |
| 24 |
18 static final RegExp validationPattern = | 25 static final RegExp validationPattern = |
19 new RegExp(r'^(?:[a-zA-Z$][a-zA-Z$0-9_]*\.)*(?:[a-zA-Z$][a-zA-Z$0-9_]*=?|' | 26 new RegExp(r'^(?:' |
20 r'-|' | 27 r'[\-+*/%&|^]|' |
| 28 r'\[\]=?|' |
| 29 r'==|' |
| 30 r'~/?|' |
| 31 r'<[<=]?|' |
| 32 r'>[>=]?|' |
21 r'unary-|' | 33 r'unary-|' |
22 r'\[\]=|' | 34 r'(?!(?:''$reservedWord'r')\b)[a-zA-Z$][\w$]*' |
23 r'~|' | 35 r'(?:=?|(?:\.(?!(?:''$reservedWord'r')\b)[a-zA-Z$][\w$]*)*)' |
24 r'==|' | |
25 r'\[\]|' | |
26 r'\*|' | |
27 r'/|' | |
28 r'%|' | |
29 r'~/|' | |
30 r'\+|' | |
31 r'<<|' | |
32 r'>>|' | |
33 r'>=|' | |
34 r'>|' | |
35 r'<=|' | |
36 r'<|' | |
37 r'&|' | |
38 r'\^|' | |
39 r'\|' | |
40 r')$'); | 36 r')$'); |
41 | 37 |
42 external const Symbol(String name); | 38 external const Symbol(String name); |
43 | 39 |
44 /** | 40 /** |
45 * Platform-private method used by the mirror system to create | 41 * Platform-private method used by the mirror system to create |
46 * otherwise invalid names. | 42 * otherwise invalid names. |
47 */ | 43 */ |
48 const Symbol.unvalidated(this._name); | 44 const Symbol.unvalidated(this._name); |
49 | 45 |
(...skipping 18 matching lines...) Expand all Loading... |
68 if (name.startsWith('_')) { | 64 if (name.startsWith('_')) { |
69 throw new ArgumentError('"$name" is a private identifier'); | 65 throw new ArgumentError('"$name" is a private identifier'); |
70 } | 66 } |
71 if (!validationPattern.hasMatch(name)) { | 67 if (!validationPattern.hasMatch(name)) { |
72 throw new ArgumentError( | 68 throw new ArgumentError( |
73 '"$name" is not an identifier or an empty String'); | 69 '"$name" is not an identifier or an empty String'); |
74 } | 70 } |
75 return name; | 71 return name; |
76 } | 72 } |
77 } | 73 } |
OLD | NEW |