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

Unified Diff: sdk/lib/_internal/compiler/implementation/scanner/parser.dart

Issue 11878043: Start adding support for mixin application syntax. We now parse the typedef variant of mixin applic… (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests and fix broken parsing. Created 7 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/compiler/implementation/scanner/parser.dart
diff --git a/sdk/lib/_internal/compiler/implementation/scanner/parser.dart b/sdk/lib/_internal/compiler/implementation/scanner/parser.dart
index 64f712f45eaa636998c1fbc7faabd5387c6d36ef..95b5a9ab5c2317f348f91175ae00cf02d7adf13b 100644
--- a/sdk/lib/_internal/compiler/implementation/scanner/parser.dart
+++ b/sdk/lib/_internal/compiler/implementation/scanner/parser.dart
@@ -52,7 +52,7 @@ class Parser {
} else if ((identical(value, 'abstract')) || (identical(value, 'class'))) {
return parseClass(token);
} else if (identical(value, 'typedef')) {
- return parseNamedFunctionAlias(token);
+ return parseTypedef(token);
} else if (identical(value, '#')) {
return parseScriptTags(token);
} else if (identical(value, 'library')) {
@@ -161,6 +161,19 @@ class Parser {
return token;
}
+ /// type (, type)*
+ Token parseTypeList(Token token) {
+ listener.beginTypeList(token);
+ token = parseType(token);
+ int count = 1;
+ while (optional(',', token)) {
+ token = parseType(token.next);
+ count++;
+ }
+ listener.endTypeList(count);
+ return token;
+ }
+
Token parsePartOrPartOf(Token token) {
assert(optional('part', token));
if (optional('of', token.next)) {
@@ -246,17 +259,54 @@ class Parser {
return parseClassBody(token);
}
- Token parseNamedFunctionAlias(Token token) {
+ Token parseTypedef(Token token) {
Token typedefKeyword = token;
- listener.beginFunctionTypeAlias(token);
- token = parseReturnTypeOpt(token.next);
- token = parseIdentifier(token);
- token = parseTypeVariablesOpt(token);
- token = parseFormalParameters(token);
- listener.endFunctionTypeAlias(typedefKeyword, token);
+ // Figure out if we're dealing with a function type alias by
+ // peeking ahead at the token following the name and optional type
+ // parameters. If that is an = token, we found something that
+ // isn't a function type alias.
+ bool isFunctionTypeAlias = true;
ahe 2013/01/16 09:37:57 Try using peekAfterType.
+ if (identical(token.next.kind, IDENTIFIER_TOKEN)) {
ahe 2013/01/16 09:37:57 token.next.isIdentifier() (it's complicated)
+ Token peek = token.next.next;
+ if (identical(peek.kind, LT_TOKEN)) {
ahe 2013/01/16 09:37:57 optional('<', peek)
+ BeginGroupToken beginGroupToken = peek;
+ Token endGroupToken = beginGroupToken.endGroup;
+ if (endGroupToken != null) peek = endGroupToken.next;
+ }
+ // Function type aliases do not use = so the name and type
+ // parameters we've peeked past are part of the return type
+ // specification instead.
+ isFunctionTypeAlias = !optional('=', peek);
+ }
+
+ if (isFunctionTypeAlias) {
+ listener.beginFunctionTypeAlias(token);
+ token = parseReturnTypeOpt(token.next);
+ token = parseIdentifier(token);
+ token = parseTypeVariablesOpt(token);
+ token = parseFormalParameters(token);
+ listener.endFunctionTypeAlias(typedefKeyword, token);
+ } else {
+ listener.beginNamedMixinApplication(token);
+ token = parseIdentifier(token.next);
+ token = parseTypeVariablesOpt(token);
+ token = expect('=', token);
+ token = parseMixinApplication(token);
+ listener.endNamedMixinApplication(typedefKeyword, token);
+ }
return expect(';', token);
}
+ Token parseMixinApplication(Token token) {
+ listener.beginMixinApplication(token);
+ token = parseModifiers(token);
+ token = parseType(token);
+ token = expect('with', token);
+ token = parseTypeList(token);
+ listener.endMixinApplication();
+ return token;
+ }
+
Token parseReturnTypeOpt(Token token) {
if (identical(token.stringValue, 'void')) {
listener.handleVoidKeyword(token);

Powered by Google App Engine
This is Rietveld 408576698