Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2011, the Dart project authors. Please see the AUTHORS file | 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 | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 /** | 5 /** |
| 6 * An event generating parser of Dart programs. This parser expects | 6 * An event generating parser of Dart programs. This parser expects |
| 7 * all tokens in a linked list. | 7 * all tokens in a linked list. |
| 8 */ | 8 */ |
| 9 class Parser<L extends Listener> { | 9 class Parser<L extends Listener> { |
| 10 final L listener; | 10 final L listener; |
| (...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 298 case kind === EQ_TOKEN: | 298 case kind === EQ_TOKEN: |
| 299 break LOOP; | 299 break LOOP; |
| 300 default: | 300 default: |
| 301 previous = token; | 301 previous = token; |
| 302 token = next(token); | 302 token = next(token); |
| 303 break; | 303 break; |
| 304 } | 304 } |
| 305 } | 305 } |
| 306 token = parseIdentifier(previous); | 306 token = parseIdentifier(previous); |
| 307 bool isField; | 307 bool isField; |
| 308 if (optional('(', token)) { | 308 do { |
|
kasperl
2011/11/09 12:59:18
Why do you prefer do { } while (true) over while (
ahe
2011/11/09 13:07:55
No particular reason. I was thinking about writing
| |
| 309 isField = false; | 309 // Loop to allow the listener to rewrite the token stream to |
| 310 } else if (optional('=', token) || optional(';', token)) { | 310 // make the parser happy. |
| 311 isField = true; | 311 if (optional('(', token)) { |
| 312 } else { | 312 isField = false; |
| 313 token = listener.unexpected(token); | 313 break; |
| 314 } | 314 } else if (optional('=', token) || optional(';', token)) { |
| 315 isField = true; | |
| 316 break; | |
| 317 } else { | |
| 318 token = listener.unexpected(token); | |
| 319 } | |
| 320 } while (true); | |
| 315 while (token !== null && | 321 while (token !== null && |
| 316 token.kind !== LBRACE_TOKEN && | 322 token.kind !== LBRACE_TOKEN && |
| 317 token.kind !== SEMICOLON_TOKEN) { | 323 token.kind !== SEMICOLON_TOKEN) { |
| 318 token = next(token); | 324 token = next(token); |
| 319 } | 325 } |
| 320 if (!optional(';', token)) { | 326 if (!optional(';', token)) { |
| 321 token = skipBlock(token); | 327 token = skipBlock(token); |
| 322 } | 328 } |
| 323 if (isField) { | 329 if (isField) { |
| 324 listener.endTopLevelField(start, token); | 330 listener.endTopLevelField(start, token); |
| (...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 699 if (optional(';', token)) { | 705 if (optional(';', token)) { |
| 700 listener.endRethrowStatement(throwToken, token); | 706 listener.endRethrowStatement(throwToken, token); |
| 701 return token.next; | 707 return token.next; |
| 702 } else { | 708 } else { |
| 703 token = parseExpression(token); | 709 token = parseExpression(token); |
| 704 listener.endThrowStatement(throwToken, token); | 710 listener.endThrowStatement(throwToken, token); |
| 705 return expectSemicolon(token); | 711 return expectSemicolon(token); |
| 706 } | 712 } |
| 707 } | 713 } |
| 708 } | 714 } |
| OLD | NEW |