Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(193)

Side by Side Diff: sdk/lib/internal/symbol.dart

Issue 140643006: Update documentation on Symbol. Make validation match. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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)|'
floitsch 2014/01/31 14:37:24 I would have just written them out. It would be al
Lasse Reichstein Nielsen 2014/01/31 18:19:26 This is being used as part of another regexp, so n
floitsch 2014/01/31 18:23:06 That's not necessarily the case. A good regexp eng
Lasse Reichstein Nielsen 2014/01/31 20:00:43 They could use, e.g., KMP or BMH for searching (an
floitsch 2014/01/31 20:07:48 Right. But that makes it even easier. A good regex
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)';
Lasse Reichstein Nielsen 2014/01/31 23:17:04 Did a benchmark. This version is ~14% faster than
floitsch 2014/01/31 23:41:44 I guess that means that we should file a bug. It c
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$]*'
floitsch 2014/01/31 14:37:24 this is hard to read (the ''...'r'). Maybe use "+"
floitsch 2014/01/31 14:37:24 You have to explain how negative lookahead works.
Lasse Reichstein Nielsen 2014/01/31 18:19:26 Spaces or newlines will do. String plus is not a c
Lasse Reichstein Nielsen 2014/01/31 18:19:26 Ok, will add more comments.
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
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698