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

Unified Diff: pkg/compiler/lib/src/parser/node_listener.dart

Issue 2567133002: Add support for the new function-type syntax. (Closed)
Patch Set: Fixes after rebase. Created 3 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 side-by-side diff with in-line comments
Download patch
Index: pkg/compiler/lib/src/parser/node_listener.dart
diff --git a/pkg/compiler/lib/src/parser/node_listener.dart b/pkg/compiler/lib/src/parser/node_listener.dart
index b5cbad61da0b334b0f4874726239afca58218d09..f533629100912f6ebaac2d97afc7e48bbf40482d 100644
--- a/pkg/compiler/lib/src/parser/node_listener.dart
+++ b/pkg/compiler/lib/src/parser/node_listener.dart
@@ -126,13 +126,60 @@ class NodeListener extends ElementListener {
}
@override
- void endFunctionTypeAlias(Token typedefKeyword, Token endToken) {
+ void endFunctionTypeAlias(
+ Token typedefKeyword, Token equals, Token endToken) {
+ bool isGeneralizedTypeAlias;
+ NodeList templateParameters;
+ TypeAnnotation returnType;
+ Identifier name;
+ NodeList typeParameters;
+ NodeList formals;
+ if (equals == null) {
+ isGeneralizedTypeAlias = false;
+ formals = popNode();
+ templateParameters = popNode();
+ name = popNode();
+ returnType = popNode();
+ } else {
+ // TODO(floitsch): keep using the `FunctionTypeAnnotation' node.
+ isGeneralizedTypeAlias = true;
+ Node type = popNode();
+ if (type.asFunctionTypeAnnotation() == null) {
+ // TODO(floitsch): The parser should diagnose this problem, not
+ // this listener.
+ // However, this problem goes away, when we allow aliases for
+ // non-function types too.
+ reportFatalError(type, 'Expected a function type.');
+ }
+ FunctionTypeAnnotation functionType = type;
+ templateParameters = popNode();
+ name = popNode();
+ returnType = functionType.returnType;
+ typeParameters = functionType.typeParameters;
+ formals = functionType.formals;
+ }
+ pushNode(new Typedef(
+ isGeneralizedTypeAlias,
+ templateParameters,
+ returnType,
+ name,
+ typeParameters,
+ formals,
+ typedefKeyword,
+ endToken));
+ }
+
+ void handleNoName(Token token) {
+ pushNode(null);
+ }
+
+ @override
+ void handleFunctionType(Token functionToken, Token endToken) {
NodeList formals = popNode();
NodeList typeParameters = popNode();
- Identifier name = popNode();
TypeAnnotation returnType = popNode();
- pushNode(new Typedef(
- returnType, name, typeParameters, formals, typedefKeyword, endToken));
+ pushNode(new FunctionTypeAnnotation(
+ returnType, functionToken, typeParameters, formals));
}
@override
@@ -229,7 +276,7 @@ class NodeListener extends ElementListener {
NodeList typeArguments = popNode();
Node classReference = popNode();
if (typeArguments != null) {
- classReference = new TypeAnnotation(classReference, typeArguments);
+ classReference = new NominalTypeAnnotation(classReference, typeArguments);
} else {
Identifier identifier = classReference.asIdentifier();
Send send = classReference.asSend();
@@ -867,7 +914,7 @@ class NodeListener extends ElementListener {
NodeList typeArguments = popNode();
Node receiver = popNode();
if (typeArguments != null) {
- receiver = new TypeAnnotation(receiver, typeArguments);
+ receiver = new NominalTypeAnnotation(receiver, typeArguments);
recoverableError(typeArguments, 'Type arguments are not allowed here.');
} else {
Identifier identifier = receiver.asIdentifier();

Powered by Google App Engine
This is Rietveld 408576698