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

Unified 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, 11 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 side-by-side diff with in-line comments
Download patch
Index: sdk/lib/internal/symbol.dart
diff --git a/sdk/lib/internal/symbol.dart b/sdk/lib/internal/symbol.dart
index 7a0369a9a5686a9b4fb926e632cd3eced29a11cf..5683c2ceb3ae66bba6976984f746cc8e03a6bb36 100644
--- a/sdk/lib/internal/symbol.dart
+++ b/sdk/lib/internal/symbol.dart
@@ -15,28 +15,24 @@ part of dart._internal;
class Symbol implements core.Symbol {
final String _name;
+ // Reserved words are not allowed as identifiers.
+ static const String reservedWord =
+ 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
+ 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)';
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
+
static final RegExp validationPattern =
- new RegExp(r'^(?:[a-zA-Z$][a-zA-Z$0-9_]*\.)*(?:[a-zA-Z$][a-zA-Z$0-9_]*=?|'
- r'-|'
- r'unary-|'
- r'\[\]=|'
- r'~|'
+ new RegExp(r'^(?:'
+ r'[\-+*/%&|^]|'
+ r'\[\]=?|'
r'==|'
- r'\[\]|'
- r'\*|'
- r'/|'
- r'%|'
- r'~/|'
- r'\+|'
- r'<<|'
- r'>>|'
- r'>=|'
- r'>|'
- r'<=|'
- r'<|'
- r'&|'
- r'\^|'
- r'\|'
+ r'~/?|'
+ r'<[<=]?|'
+ r'>[>=]?|'
+ r'unary-|'
+ 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.
+ r'(?:=?|(?:\.(?!(?:''$reservedWord'r')\b)[a-zA-Z_$][\w$]*)*)'
r')$');
external const Symbol(String name);

Powered by Google App Engine
This is Rietveld 408576698