Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 (aka a token stream). | 7 * all tokens in a linked list (aka a token stream). |
| 8 * | 8 * |
| 9 * The class [Scanner] is used to generate a token stream. See the | 9 * The class [Scanner] is used to generate a token stream. See the |
| 10 * file scanner.dart. | 10 * file scanner.dart. |
| (...skipping 260 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 271 token = parseIdentifier(token); | 271 token = parseIdentifier(token); |
| 272 if (optional('extends', token)) { | 272 if (optional('extends', token)) { |
| 273 token = parseType(token.next); | 273 token = parseType(token.next); |
| 274 } else { | 274 } else { |
| 275 listener.handleNoType(token); | 275 listener.handleNoType(token); |
| 276 } | 276 } |
| 277 listener.endTypeVariable(token); | 277 listener.endTypeVariable(token); |
| 278 return token; | 278 return token; |
| 279 } | 279 } |
| 280 | 280 |
| 281 /** | |
| 282 * Returns true if the stringValue of the [token] is [value]. | |
| 283 */ | |
| 281 bool optional(String value, Token token) => value === token.stringValue; | 284 bool optional(String value, Token token) => value === token.stringValue; |
| 282 | 285 |
| 283 bool notEofOrValue(String value, Token token) { | 286 bool notEofOrValue(String value, Token token) { |
| 284 return token.kind !== EOF_TOKEN && value !== token.stringValue; | 287 return token.kind !== EOF_TOKEN && value !== token.stringValue; |
| 285 } | 288 } |
| 286 | 289 |
| 287 Token parseType(Token token) { | 290 Token parseType(Token token) { |
| 288 Token begin = token; | 291 Token begin = token; |
| 289 if (isIdentifier(token)) { | 292 if (isIdentifier(token)) { |
| 290 token = parseIdentifier(token); | 293 token = parseIdentifier(token); |
| (...skipping 981 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1272 while (token.kind === STRING_TOKEN) { | 1275 while (token.kind === STRING_TOKEN) { |
| 1273 token = parseSingleLiteralString(token); | 1276 token = parseSingleLiteralString(token); |
| 1274 count++; | 1277 count++; |
| 1275 } | 1278 } |
| 1276 if (count > 1) { | 1279 if (count > 1) { |
| 1277 listener.handleStringJuxtaposition(count); | 1280 listener.handleStringJuxtaposition(count); |
| 1278 } | 1281 } |
| 1279 return token; | 1282 return token; |
| 1280 } | 1283 } |
| 1281 | 1284 |
| 1285 /** | |
| 1286 * Only called when [:token.kind === STRING_TOKEN:]. | |
| 1287 */ | |
| 1282 Token parseSingleLiteralString(Token token) { | 1288 Token parseSingleLiteralString(Token token) { |
| 1283 listener.beginLiteralString(token); | 1289 listener.beginLiteralString(token); |
| 1290 // Parsing the prefix, for instance 'x of 'x${id}y${id}z' | |
| 1284 token = token.next; | 1291 token = token.next; |
| 1285 int interpolationCount = 0; | 1292 int interpolationCount = 0; |
| 1286 while (optional('\${', token)) { | 1293 var kind = token.kind; |
| 1287 token = token.next; | 1294 while (kind != EOF_TOKEN) { |
| 1288 token = parseExpression(token); | 1295 if (kind === STRING_INTERPOLATION_TOKEN) { |
| 1289 token = expect('}', token); | 1296 // Parsing ${expression}. |
| 1297 token = token.next; | |
| 1298 token = parseExpression(token); | |
| 1299 token = expect('}', token); | |
| 1300 } else if (kind === STRING_INTERPOLATION_IDENTIFIER_TOKEN) { | |
| 1301 // Parsing $identifier. | |
| 1302 token = token.next; | |
| 1303 token = parseExpression(token); | |
| 1304 } else { | |
| 1305 break; | |
| 1306 } | |
| 1307 ++interpolationCount; | |
| 1308 // Parsing the infix/suffix, for instance y and z' of 'x${id}y${id}z' | |
|
ahe
2012/06/25 10:55:52
Very nice.
| |
| 1290 token = parseStringPart(token); | 1309 token = parseStringPart(token); |
| 1291 ++interpolationCount; | 1310 kind = token.kind; |
| 1292 } | 1311 } |
| 1293 listener.endLiteralString(interpolationCount); | 1312 listener.endLiteralString(interpolationCount); |
| 1294 return token; | 1313 return token; |
| 1295 } | 1314 } |
| 1296 | 1315 |
| 1297 Token parseLiteralBool(Token token) { | 1316 Token parseLiteralBool(Token token) { |
| 1298 listener.handleLiteralBool(token); | 1317 listener.handleLiteralBool(token); |
| 1299 return token.next; | 1318 return token.next; |
| 1300 } | 1319 } |
| 1301 | 1320 |
| (...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1672 } | 1691 } |
| 1673 listener.handleContinueStatement(hasTarget, continueKeyword, token); | 1692 listener.handleContinueStatement(hasTarget, continueKeyword, token); |
| 1674 return expectSemicolon(token); | 1693 return expectSemicolon(token); |
| 1675 } | 1694 } |
| 1676 | 1695 |
| 1677 Token parseEmptyStatement(Token token) { | 1696 Token parseEmptyStatement(Token token) { |
| 1678 listener.handleEmptyStatement(token); | 1697 listener.handleEmptyStatement(token); |
| 1679 return expectSemicolon(token); | 1698 return expectSemicolon(token); |
| 1680 } | 1699 } |
| 1681 } | 1700 } |
| OLD | NEW |