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

Side by Side Diff: sdk/lib/_internal/compiler/implementation/scanner/partial_parser.dart

Issue 694353007: Move dart2js from sdk/lib/_internal/compiler to pkg/compiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 1 month 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
(Empty)
1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file
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.
4
5 part of scanner;
6
7 class PartialParser extends Parser {
8 PartialParser(Listener listener) : super(listener);
9
10 Token parseClassBody(Token token) => skipClassBody(token);
11
12 Token fullParseClassBody(Token token) => super.parseClassBody(token);
13
14 Token parseExpression(Token token) => skipExpression(token);
15
16 Token parseArgumentsOpt(Token token) {
17 // This method is overridden for two reasons:
18 // 1. Avoid generating events for arguments.
19 // 2. Avoid calling skip expression for each argument (which doesn't work).
20 if (optional('(', token)) {
21 BeginGroupToken begin = token;
22 return begin.endGroup.next;
23 } else {
24 return token;
25 }
26 }
27
28 Token skipExpression(Token token) {
29 while (true) {
30 final kind = token.kind;
31 final value = token.stringValue;
32 if ((identical(kind, EOF_TOKEN)) ||
33 (identical(value, ';')) ||
34 (identical(value, ',')) ||
35 (identical(value, '}')) ||
36 (identical(value, ')')) ||
37 (identical(value, ']'))) {
38 break;
39 }
40 if (identical(value, '=') ||
41 identical(value, '?') ||
42 identical(value, ':')) {
43 var nextValue = token.next.stringValue;
44 if (identical(nextValue, 'const')) {
45 token = token.next;
46 nextValue = token.next.stringValue;
47 }
48 if (identical(nextValue, '{')) {
49 // Handle cases like this:
50 // class Foo {
51 // var map;
52 // Foo() : map = {};
53 // Foo.x() : map = true ? {} : {};
54 // }
55 BeginGroupToken begin = token.next;
56 token = (begin.endGroup != null) ? begin.endGroup : token;
57 token = token.next;
58 continue;
59 }
60 if (identical(nextValue, '<')) {
61 // Handle cases like this:
62 // class Foo {
63 // var map;
64 // Foo() : map = <String, Foo>{};
65 // Foo.x() : map = true ? <String, Foo>{} : <String, Foo>{};
66 // }
67 BeginGroupToken begin = token.next;
68 token = (begin.endGroup != null) ? begin.endGroup : token;
69 token = token.next;
70 if (identical(token.stringValue, '{')) {
71 begin = token;
72 token = (begin.endGroup != null) ? begin.endGroup : token;
73 token = token.next;
74 }
75 continue;
76 }
77 }
78 if (!mayParseFunctionExpressions && identical(value, '{')) {
79 break;
80 }
81 if (token is BeginGroupToken) {
82 BeginGroupToken begin = token;
83 token = (begin.endGroup != null) ? begin.endGroup : token;
84 } else if (token is ErrorToken) {
85 listener.reportErrorToken(token);
86 }
87 token = token.next;
88 }
89 return token;
90 }
91
92 Token skipClassBody(Token token) {
93 if (!optional('{', token)) {
94 return listener.expectedClassBodyToSkip(token);
95 }
96 BeginGroupToken beginGroupToken = token;
97 Token endGroup = beginGroupToken.endGroup;
98 if (endGroup == null) {
99 return listener.unmatched(beginGroupToken);
100 } else if (!identical(endGroup.kind, $CLOSE_CURLY_BRACKET)) {
101 return listener.unmatched(beginGroupToken);
102 }
103 return endGroup;
104 }
105
106 Token skipAsyncModifier(Token token) {
107 String value = token.stringValue;
108 if (identical(value, 'async')) {
109 token = token.next;
110 value = token.stringValue;
111
112 if (identical(value, '*')) {
113 token = token.next;
114 }
115 } else if (identical(value, 'sync')) {
116 token = token.next;
117 value = token.stringValue;
118
119 if (identical(value, '*')) {
120 token = token.next;
121 }
122 }
123 return token;
124 }
125
126 Token parseFunctionBody(Token token, bool isExpression, bool allowAbstract) {
127 assert(!isExpression);
128 token = skipAsyncModifier(token);
129 String value = token.stringValue;
130 if (identical(value, ';')) {
131 if (!allowAbstract) {
132 listener.reportError(token, MessageKind.BODY_EXPECTED);
133 }
134 listener.handleNoFunctionBody(token);
135 } else {
136 if (identical(value, '=>')) {
137 token = parseExpression(token.next);
138 expectSemicolon(token);
139 } else if (value == '=') {
140 token = parseRedirectingFactoryBody(token);
141 expectSemicolon(token);
142 } else {
143 token = skipBlock(token);
144 }
145 listener.skippedFunctionBody(token);
146 }
147 return token;
148 }
149
150 Token parseFormalParameters(Token token) => skipFormals(token);
151
152 Token skipFormals(Token token) {
153 listener.beginOptionalFormalParameters(token);
154 if (!optional('(', token)) {
155 if (optional(';', token)) {
156 listener.recoverableError(token, "expected '('");
157 return token;
158 }
159 return listener.unexpected(token);
160 }
161 BeginGroupToken beginGroupToken = token;
162 Token endToken = beginGroupToken.endGroup;
163 listener.endFormalParameters(0, token, endToken);
164 return endToken.next;
165 }
166 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698