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

Side by Side Diff: lib/compiler/implementation/scanner/parser.dart

Issue 10539021: Scanner can include comments in the token stream. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: String interpolation identifier used new token Created 8 years, 6 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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
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 985 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
1282 Token parseSingleLiteralString(Token token) { 1285 Token parseSingleLiteralString(Token token) {
1283 listener.beginLiteralString(token); 1286 listener.beginLiteralString(token);
1284 token = token.next; 1287 token = token.next;
1285 int interpolationCount = 0; 1288 int interpolationCount = 0;
1286 while (optional('\${', token)) { 1289 while (token.kind != EOF_TOKEN) {
1287 token = token.next; 1290 if (optional('\${', token)) {
1288 token = parseExpression(token); 1291 // Parsing ${expression}.
1289 token = expect('}', token); 1292 token = token.next;
1290 token = parseStringPart(token); 1293 token = parseExpression(token);
1291 ++interpolationCount; 1294 token = expect('}', token);
1295 token = parseStringPart(token);
1296 ++interpolationCount;
1297 } else if (token.kind == STRING_INTERPOLATION_IDENTIFIER_TOKEN) {
1298 // Parsing $identifier.
1299 token = token.next;
1300 token = parseExpression(token);
1301 token = parseStringPart(token);
1302 ++interpolationCount;
1303 } else {
1304 break;
1305 }
1292 } 1306 }
1293 listener.endLiteralString(interpolationCount); 1307 listener.endLiteralString(interpolationCount);
1294 return token; 1308 return token;
1295 } 1309 }
1296 1310
1297 Token parseLiteralBool(Token token) { 1311 Token parseLiteralBool(Token token) {
1298 listener.handleLiteralBool(token); 1312 listener.handleLiteralBool(token);
1299 return token.next; 1313 return token.next;
1300 } 1314 }
1301 1315
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 } 1686 }
1673 listener.handleContinueStatement(hasTarget, continueKeyword, token); 1687 listener.handleContinueStatement(hasTarget, continueKeyword, token);
1674 return expectSemicolon(token); 1688 return expectSemicolon(token);
1675 } 1689 }
1676 1690
1677 Token parseEmptyStatement(Token token) { 1691 Token parseEmptyStatement(Token token) {
1678 listener.handleEmptyStatement(token); 1692 listener.handleEmptyStatement(token);
1679 return expectSemicolon(token); 1693 return expectSemicolon(token);
1680 } 1694 }
1681 } 1695 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698