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

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

Issue 21511003: Support symbol literals. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 3 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 part of scanner; 5 part of scanner;
6 6
7 /** 7 /**
8 * An event generating parser of Dart programs. This parser expects 8 * An event generating parser of Dart programs. This parser expects
9 * all tokens in a linked list (aka a token stream). 9 * all tokens in a linked list (aka a token stream).
10 * 10 *
(...skipping 1654 matching lines...) Expand 10 before | Expand all | Expand 10 after
1665 final kind = token.kind; 1665 final kind = token.kind;
1666 if (identical(kind, IDENTIFIER_TOKEN)) { 1666 if (identical(kind, IDENTIFIER_TOKEN)) {
1667 return parseSendOrFunctionLiteral(token); 1667 return parseSendOrFunctionLiteral(token);
1668 } else if (identical(kind, INT_TOKEN) 1668 } else if (identical(kind, INT_TOKEN)
1669 || identical(kind, HEXADECIMAL_TOKEN)) { 1669 || identical(kind, HEXADECIMAL_TOKEN)) {
1670 return parseLiteralInt(token); 1670 return parseLiteralInt(token);
1671 } else if (identical(kind, DOUBLE_TOKEN)) { 1671 } else if (identical(kind, DOUBLE_TOKEN)) {
1672 return parseLiteralDouble(token); 1672 return parseLiteralDouble(token);
1673 } else if (identical(kind, STRING_TOKEN)) { 1673 } else if (identical(kind, STRING_TOKEN)) {
1674 return parseLiteralString(token); 1674 return parseLiteralString(token);
1675 } else if (identical(kind, HASH_TOKEN)) {
1676 return parseLiteralSymbol(token);
1675 } else if (identical(kind, KEYWORD_TOKEN)) { 1677 } else if (identical(kind, KEYWORD_TOKEN)) {
1676 final value = token.stringValue; 1678 final value = token.stringValue;
1677 if ((identical(value, 'true')) || (identical(value, 'false'))) { 1679 if ((identical(value, 'true')) || (identical(value, 'false'))) {
1678 return parseLiteralBool(token); 1680 return parseLiteralBool(token);
1679 } else if (identical(value, 'null')) { 1681 } else if (identical(value, 'null')) {
1680 return parseLiteralNull(token); 1682 return parseLiteralNull(token);
1681 } else if (identical(value, 'this')) { 1683 } else if (identical(value, 'this')) {
1682 return parseThisExpression(token); 1684 return parseThisExpression(token);
1683 } else if (identical(value, 'super')) { 1685 } else if (identical(value, 'super')) {
1684 return parseSuperExpression(token); 1686 return parseSuperExpression(token);
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
1885 while (identical(token.kind, STRING_TOKEN)) { 1887 while (identical(token.kind, STRING_TOKEN)) {
1886 token = parseSingleLiteralString(token); 1888 token = parseSingleLiteralString(token);
1887 count++; 1889 count++;
1888 } 1890 }
1889 if (count > 1) { 1891 if (count > 1) {
1890 listener.handleStringJuxtaposition(count); 1892 listener.handleStringJuxtaposition(count);
1891 } 1893 }
1892 return token; 1894 return token;
1893 } 1895 }
1894 1896
1897 Token parseLiteralSymbol(Token token) {
1898 Token hashToken = token;
1899 listener.beginLiteralSymbol(hashToken);
1900 token = token.next;
1901 if (isUserDefinableOperator(token.stringValue)) {
1902 listener.handleOperator(token);
1903 listener.endLiteralSymbol(hashToken, 1);
1904 return token.next;
1905 } else {
1906 int count = 1;
1907 token = parseIdentifier(token);
1908 while (identical(token.stringValue, '.')) {
1909 count++;
1910 token = parseIdentifier(token.next);
1911 }
1912 listener.endLiteralSymbol(hashToken, count);
1913 return token;
1914 }
1915 }
1916
1895 /** 1917 /**
1896 * Only called when [:token.kind === STRING_TOKEN:]. 1918 * Only called when [:token.kind === STRING_TOKEN:].
1897 */ 1919 */
1898 Token parseSingleLiteralString(Token token) { 1920 Token parseSingleLiteralString(Token token) {
1899 listener.beginLiteralString(token); 1921 listener.beginLiteralString(token);
1900 // Parsing the prefix, for instance 'x of 'x${id}y${id}z' 1922 // Parsing the prefix, for instance 'x of 'x${id}y${id}z'
1901 token = token.next; 1923 token = token.next;
1902 int interpolationCount = 0; 1924 int interpolationCount = 0;
1903 var kind = token.kind; 1925 var kind = token.kind;
1904 while (kind != EOF_TOKEN) { 1926 while (kind != EOF_TOKEN) {
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
2357 } 2379 }
2358 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2380 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2359 return expectSemicolon(token); 2381 return expectSemicolon(token);
2360 } 2382 }
2361 2383
2362 Token parseEmptyStatement(Token token) { 2384 Token parseEmptyStatement(Token token) {
2363 listener.handleEmptyStatement(token); 2385 listener.handleEmptyStatement(token);
2364 return expectSemicolon(token); 2386 return expectSemicolon(token);
2365 } 2387 }
2366 } 2388 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698