OLD | NEW |
| (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 class PartialParser extends Parser { | |
6 PartialParser(Listener listener) : super(listener); | |
7 | |
8 Token parseClassBody(Token token) => skipClassBody(token); | |
9 | |
10 Token fullParseClassBody(Token token) => super.parseClassBody(token); | |
11 | |
12 Token parseExpression(Token token) => skipExpression(token); | |
13 | |
14 Token skipExpression(Token token) { | |
15 while (true) { | |
16 final kind = token.kind; | |
17 final value = token.stringValue; | |
18 if ((kind === EOF_TOKEN) || | |
19 (value === ';') || | |
20 (value === ',') || | |
21 (value === ']')) | |
22 return token; | |
23 if (value === '=') { | |
24 var nextValue = token.next.stringValue; | |
25 if (nextValue === 'const') { | |
26 token = token.next; | |
27 nextValue = token.next.stringValue; | |
28 } | |
29 if (nextValue === '{') { | |
30 // Handle cases like this: | |
31 // class Foo { | |
32 // var map; | |
33 // Foo() : map = {}; | |
34 // } | |
35 BeginGroupToken begin = token.next; | |
36 token = (begin.endGroup !== null) ? begin.endGroup : token; | |
37 token = token.next; | |
38 continue; | |
39 } | |
40 if (nextValue === '<') { | |
41 // Handle cases like this: | |
42 // class Foo { | |
43 // var map; | |
44 // Foo() : map = <Foo>{}; | |
45 // } | |
46 BeginGroupToken begin = token.next; | |
47 token = (begin.endGroup !== null) ? begin.endGroup : token; | |
48 token = token.next; | |
49 if (token.stringValue === '{') { | |
50 begin = token; | |
51 token = (begin.endGroup !== null) ? begin.endGroup : token; | |
52 token = token.next; | |
53 } | |
54 continue; | |
55 } | |
56 } | |
57 if (!mayParseFunctionExpressions && value === '{') | |
58 return token; | |
59 if ((value !== '<') && (token is BeginGroupToken)) { | |
60 BeginGroupToken begin = token; | |
61 token = (begin.endGroup !== null) ? begin.endGroup : token; | |
62 } | |
63 token = token.next; | |
64 } | |
65 } | |
66 | |
67 Token skipClassBody(Token token) { | |
68 if (!optional('{', token)) { | |
69 return listener.expectedClassBodyToSkip(token); | |
70 } | |
71 BeginGroupToken beginGroupToken = token; | |
72 assert(beginGroupToken.endGroup === null || | |
73 beginGroupToken.endGroup.kind === $CLOSE_CURLY_BRACKET); | |
74 return beginGroupToken.endGroup; | |
75 } | |
76 | |
77 Token parseFunctionBody(Token token, bool isExpression) { | |
78 assert(!isExpression); | |
79 String value = token.stringValue; | |
80 if (value === ';') { | |
81 // No body. | |
82 } else if (value === '=>') { | |
83 token = parseExpression(token.next); | |
84 expectSemicolon(token); | |
85 } else { | |
86 token = skipBlock(token); | |
87 } | |
88 // There is no "skipped function body event", so we use | |
89 // handleNoFunctionBody instead. | |
90 listener.handleNoFunctionBody(token); | |
91 return token; | |
92 } | |
93 | |
94 Token parseFormalParameters(Token token) => skipFormals(token); | |
95 | |
96 Token skipFormals(Token token) { | |
97 listener.beginOptionalFormalParameters(token); | |
98 if (!optional('(', token)) { | |
99 if (optional(';', token)) { | |
100 listener.recoverableError("expected '('", token: token); | |
101 return token; | |
102 } | |
103 return listener.unexpected(token); | |
104 } | |
105 BeginGroupToken beginGroupToken = token; | |
106 Token endToken = beginGroupToken.endGroup; | |
107 listener.endFormalParameters(0, token, endToken); | |
108 return endToken.next; | |
109 } | |
110 } | |
OLD | NEW |