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

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: General string interpolation also uses kind test 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 var tokenKind = token.kind;
ahe 2012/06/25 08:12:37 In other places I have used: var kind = token.kin
Johnni Winther 2012/06/25 10:40:00 Done.
1287 token = token.next; 1290 while (tokenKind != EOF_TOKEN) {
1288 token = parseExpression(token); 1291 if (tokenKind === STRING_INTERPOLATION_TOKEN) {
1289 token = expect('}', token); 1292 // Parsing ${expression}.
1290 token = parseStringPart(token); 1293 token = token.next;
1291 ++interpolationCount; 1294 token = parseExpression(token);
1295 token = expect('}', token);
1296 token = parseStringPart(token);
ahe 2012/06/25 08:12:37 The last two lines can be shared.
Johnni Winther 2012/06/25 10:40:00 Done.
1297 ++interpolationCount;
1298 } else if (tokenKind === STRING_INTERPOLATION_IDENTIFIER_TOKEN) {
1299 // Parsing $identifier.
1300 token = token.next;
1301 token = parseExpression(token);
1302 token = parseStringPart(token);
1303 ++interpolationCount;
1304 } else {
1305 break;
1306 }
1307 tokenKind = token.kind;
1292 } 1308 }
1293 listener.endLiteralString(interpolationCount); 1309 listener.endLiteralString(interpolationCount);
1294 return token; 1310 return token;
1295 } 1311 }
1296 1312
1297 Token parseLiteralBool(Token token) { 1313 Token parseLiteralBool(Token token) {
1298 listener.handleLiteralBool(token); 1314 listener.handleLiteralBool(token);
1299 return token.next; 1315 return token.next;
1300 } 1316 }
1301 1317
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
1672 } 1688 }
1673 listener.handleContinueStatement(hasTarget, continueKeyword, token); 1689 listener.handleContinueStatement(hasTarget, continueKeyword, token);
1674 return expectSemicolon(token); 1690 return expectSemicolon(token);
1675 } 1691 }
1676 1692
1677 Token parseEmptyStatement(Token token) { 1693 Token parseEmptyStatement(Token token) {
1678 listener.handleEmptyStatement(token); 1694 listener.handleEmptyStatement(token);
1679 return expectSemicolon(token); 1695 return expectSemicolon(token);
1680 } 1696 }
1681 } 1697 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698