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

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

Issue 11783089: Fix VariableDefinitions.endToken for formal parameters. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Updated cf. comments. Created 7 years, 10 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 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 token = parseFormalParameters(token); 356 token = parseFormalParameters(token);
357 listener.handleFunctionTypedFormalParameter(token); 357 listener.handleFunctionTypedFormalParameter(token);
358 } 358 }
359 String value = token.stringValue; 359 String value = token.stringValue;
360 if ((identical('=', value)) || (identical(':', value))) { 360 if ((identical('=', value)) || (identical(':', value))) {
361 // TODO(ahe): Validate that these are only used for optional parameters. 361 // TODO(ahe): Validate that these are only used for optional parameters.
362 Token equal = token; 362 Token equal = token;
363 token = parseExpression(token.next); 363 token = parseExpression(token.next);
364 listener.handleValuedFormalParameter(equal, token); 364 listener.handleValuedFormalParameter(equal, token);
365 } 365 }
366 listener.endFormalParameter(token, thisKeyword); 366 listener.endFormalParameter(thisKeyword);
367 return token; 367 return token;
368 } 368 }
369 369
370 Token parseOptionalFormalParameters(Token token, bool isNamed) { 370 Token parseOptionalFormalParameters(Token token, bool isNamed) {
371 Token begin = token; 371 Token begin = token;
372 listener.beginOptionalFormalParameters(begin); 372 listener.beginOptionalFormalParameters(begin);
373 assert((isNamed && optional('{', token)) || optional('[', token)); 373 assert((isNamed && optional('{', token)) || optional('[', token));
374 int parameterCount = 0; 374 int parameterCount = 0;
375 do { 375 do {
376 token = token.next; 376 token = token.next;
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 } else { 547 } else {
548 listener.handleNoType(token); 548 listener.handleNoType(token);
549 } 549 }
550 listener.endTypeVariable(token); 550 listener.endTypeVariable(token);
551 return token; 551 return token;
552 } 552 }
553 553
554 /** 554 /**
555 * Returns true if the stringValue of the [token] is [value]. 555 * Returns true if the stringValue of the [token] is [value].
556 */ 556 */
557 bool optional(String value, Token token) => identical(value, token.stringValue ); 557 bool optional(String value, Token token) {
558 return identical(value, token.stringValue);
559 }
560
561 /**
562 * Returns true if the stringValue of the [token] is either [value1],
563 * [value2], [value3], or [value4].
564 */
565 bool isOneOf4(Token token,
566 String value1, String value2, String value3, String value4) {
567 String stringValue = token.stringValue;
568 return identical(value1, stringValue) ||
569 identical(value2, stringValue) ||
570 identical(value3, stringValue) ||
571 identical(value4, stringValue);
572 }
558 573
559 bool notEofOrValue(String value, Token token) { 574 bool notEofOrValue(String value, Token token) {
560 return !identical(token.kind, EOF_TOKEN) && !identical(value, token.stringVa lue); 575 return !identical(token.kind, EOF_TOKEN) &&
576 !identical(value, token.stringValue);
561 } 577 }
562 578
563 Token parseType(Token token) { 579 Token parseType(Token token) {
564 Token begin = token; 580 Token begin = token;
565 if (isValidTypeReference(token)) { 581 if (isValidTypeReference(token)) {
566 token = parseIdentifier(token); 582 token = parseIdentifier(token);
567 token = parseQualifiedRestOpt(token); 583 token = parseQualifiedRestOpt(token);
568 } else { 584 } else {
569 token = listener.expectedType(token); 585 token = listener.expectedType(token);
570 } 586 }
(...skipping 1290 matching lines...) Expand 10 before | Expand all | Expand 10 after
1861 listener.handleAsOperator(operator, token); 1877 listener.handleAsOperator(operator, token);
1862 String value = token.stringValue; 1878 String value = token.stringValue;
1863 if (identical(value, 'is') || identical(value, 'as')) { 1879 if (identical(value, 'is') || identical(value, 'as')) {
1864 // The is- and as-operators cannot be chained. 1880 // The is- and as-operators cannot be chained.
1865 listener.unexpected(token); 1881 listener.unexpected(token);
1866 } 1882 }
1867 return token; 1883 return token;
1868 } 1884 }
1869 1885
1870 Token parseVariablesDeclaration(Token token) { 1886 Token parseVariablesDeclaration(Token token) {
1871 token = parseVariablesDeclarationNoSemicolon(token); 1887 return parseVariablesDeclarationMaybeSemicolon(token, true);
1872 return expectSemicolon(token);
1873 } 1888 }
1874 1889
1875 Token parseVariablesDeclarationNoSemicolon(Token token) { 1890 Token parseVariablesDeclarationNoSemicolon(Token token) {
1891 return parseVariablesDeclarationMaybeSemicolon(token, false);
1892 }
1893
1894 Token parseVariablesDeclarationMaybeSemicolon(Token token,
1895 bool endWithSemicolon) {
1876 int count = 1; 1896 int count = 1;
1877 listener.beginVariablesDeclaration(token); 1897 listener.beginVariablesDeclaration(token);
1878 token = parseModifiers(token); 1898 token = parseModifiers(token);
1879 token = parseTypeOpt(token); 1899 token = parseTypeOpt(token);
1880 token = parseOptionallyInitializedIdentifier(token); 1900 token = parseOptionallyInitializedIdentifier(token);
1881 while (optional(',', token)) { 1901 while (optional(',', token)) {
1882 token = parseOptionallyInitializedIdentifier(token.next); 1902 token = parseOptionallyInitializedIdentifier(token.next);
1883 ++count; 1903 ++count;
1884 } 1904 }
1885 listener.endVariablesDeclaration(count, token); 1905 if (endWithSemicolon) {
1886 return token; 1906 Token semicolon = token;
1907 token = expectSemicolon(semicolon);
1908 listener.endVariablesDeclaration(count, semicolon);
1909 return token;
1910 } else {
1911 listener.endVariablesDeclaration(count, null);
1912 return token;
1913 }
1887 } 1914 }
1888 1915
1889 Token parseOptionallyInitializedIdentifier(Token token) { 1916 Token parseOptionallyInitializedIdentifier(Token token) {
1890 listener.beginInitializedIdentifier(token); 1917 listener.beginInitializedIdentifier(token);
1891 token = parseIdentifier(token); 1918 token = parseIdentifier(token);
1892 token = parseVariableInitializerOpt(token); 1919 token = parseVariableInitializerOpt(token);
1893 listener.endInitializedIdentifier(); 1920 listener.endInitializedIdentifier();
1894 return token; 1921 return token;
1895 } 1922 }
1896 1923
(...skipping 29 matching lines...) Expand all
1926 final String value = token.stringValue; 1953 final String value = token.stringValue;
1927 if (identical(value, ';')) { 1954 if (identical(value, ';')) {
1928 listener.handleNoExpression(token); 1955 listener.handleNoExpression(token);
1929 return token; 1956 return token;
1930 } else if ((identical(value, 'var')) || (identical(value, 'final'))) { 1957 } else if ((identical(value, 'var')) || (identical(value, 'final'))) {
1931 return parseVariablesDeclarationNoSemicolon(token); 1958 return parseVariablesDeclarationNoSemicolon(token);
1932 } 1959 }
1933 Token identifier = peekIdentifierAfterType(token); 1960 Token identifier = peekIdentifierAfterType(token);
1934 if (identifier != null) { 1961 if (identifier != null) {
1935 assert(identifier.isIdentifier()); 1962 assert(identifier.isIdentifier());
1936 Token afterId = identifier.next; 1963 if (isOneOf4(identifier.next, '=', ';', ',', 'in')) {
1937 int afterIdKind = afterId.kind;
1938 if (identical(afterIdKind, EQ_TOKEN) || identical(afterIdKind, SEMICOLON_T OKEN) ||
1939 identical(afterIdKind, COMMA_TOKEN) || optional('in', afterId)) {
1940 return parseVariablesDeclarationNoSemicolon(token); 1964 return parseVariablesDeclarationNoSemicolon(token);
1941 } 1965 }
1942 } 1966 }
1943 return parseExpression(token); 1967 return parseExpression(token);
1944 } 1968 }
1945 1969
1946 Token parseForRest(Token forToken, Token token) { 1970 Token parseForRest(Token forToken, Token token) {
1947 token = expectSemicolon(token); 1971 token = expectSemicolon(token);
1948 if (optional(';', token)) { 1972 if (optional(';', token)) {
1949 token = parseEmptyStatement(token); 1973 token = parseEmptyStatement(token);
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
2197 } 2221 }
2198 listener.handleContinueStatement(hasTarget, continueKeyword, token); 2222 listener.handleContinueStatement(hasTarget, continueKeyword, token);
2199 return expectSemicolon(token); 2223 return expectSemicolon(token);
2200 } 2224 }
2201 2225
2202 Token parseEmptyStatement(Token token) { 2226 Token parseEmptyStatement(Token token) {
2203 listener.handleEmptyStatement(token); 2227 listener.handleEmptyStatement(token);
2204 return expectSemicolon(token); 2228 return expectSemicolon(token);
2205 } 2229 }
2206 } 2230 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698