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

Side by Side Diff: compiler/java/com/google/dart/compiler/parser/DartParser.java

Issue 10836252: Finalize support for new getter syntax, per issue 3607 (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 years, 4 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
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 package com.google.dart.compiler.parser; 5 package com.google.dart.compiler.parser;
6 6
7 import com.google.common.annotations.VisibleForTesting; 7 import com.google.common.annotations.VisibleForTesting;
8 import com.google.common.collect.ImmutableSet; 8 import com.google.common.collect.ImmutableSet;
9 import com.google.common.io.CharStreams; 9 import com.google.common.io.CharStreams;
10 import com.google.dart.compiler.DartCompilationError; 10 import com.google.dart.compiler.DartCompilationError;
(...skipping 1354 matching lines...) Expand 10 before | Expand all | Expand 10 after
1365 // operator []= ( 1365 // operator []= (
1366 if (peek(2).equals(Token.ASSIGN) && peek(3).equals(Token.LPAREN)) { 1366 if (peek(2).equals(Token.ASSIGN) && peek(3).equals(Token.LPAREN)) {
1367 return true; 1367 return true;
1368 } 1368 }
1369 } 1369 }
1370 return false; 1370 return false;
1371 } 1371 }
1372 1372
1373 if (peekPseudoKeyword(0, GETTER_KEYWORD) 1373 if (peekPseudoKeyword(0, GETTER_KEYWORD)
1374 || peekPseudoKeyword(0, SETTER_KEYWORD)) { 1374 || peekPseudoKeyword(0, SETTER_KEYWORD)) {
1375 boolean isGetter = peekPseudoKeyword(0, GETTER_KEYWORD);
1375 next(); 1376 next();
1376 // Using 'get' or 'set' as a field name is valid 1377 // Using 'get' or 'set' as a field name is valid
1377 if (peek(0).equals(Token.SEMICOLON) || peek(0).equals(Token.ASSIGN)) { 1378 if (peek(0).equals(Token.SEMICOLON) || peek(0).equals(Token.ASSIGN)) {
1378 return false; 1379 return false;
1379 } 1380 }
1380 // Using 'get' or 'set' as a method name is valid (but discouraged) 1381 // Using 'get' or 'set' as a method name is valid (but discouraged)
1381 if (peek(0).equals(Token.LPAREN)) { 1382 if (peek(0).equals(Token.LPAREN)) {
1382 return true; 1383 return true;
1383 } 1384 }
1384 // normal case: get foo ( 1385 // normal case: get foo (
1385 if (peek(0).equals(Token.IDENTIFIER) && peek(1).equals(Token.LPAREN)) { 1386 if (peek(0).equals(Token.IDENTIFIER) && (isGetter || peek(1).equals(Toke n.LPAREN))) {
1386 return true; 1387 return true;
1387 } 1388 }
1388 return false; 1389 return false;
1389 } 1390 }
1390 1391
1391 consume(Token.IDENTIFIER); 1392 consume(Token.IDENTIFIER);
1392 1393
1393 if (peek(0).equals(Token.PERIOD) && peek(1).equals(Token.IDENTIFIER)) { 1394 if (peek(0).equals(Token.PERIOD) && peek(1).equals(Token.IDENTIFIER)) {
1394 consume(Token.PERIOD); 1395 consume(Token.PERIOD);
1395 consume(Token.IDENTIFIER); 1396 consume(Token.IDENTIFIER);
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
1550 done(null); 1551 done(null);
1551 } 1552 }
1552 1553
1553 // Parse the parameters definitions. 1554 // Parse the parameters definitions.
1554 List<DartParameter> parameters; 1555 List<DartParameter> parameters;
1555 if (modifiers.isGetter() && peek(0) != Token.LPAREN) { 1556 if (modifiers.isGetter() && peek(0) != Token.LPAREN) {
1556 // TODO: For now the parameters are optional so that both the old and new style will be 1557 // TODO: For now the parameters are optional so that both the old and new style will be
1557 // accepted, but eventually parameters should be disallowed. 1558 // accepted, but eventually parameters should be disallowed.
1558 parameters = new ArrayList<DartParameter>(); 1559 parameters = new ArrayList<DartParameter>();
1559 } else { 1560 } else {
1560 if (modifiers.isSetter()) {
1561 // TODO: For now we optionally allow an equal sign before the formal par ameter list, but
1562 // eventually it should be required.
1563 optional(Token.ASSIGN);
1564 }
1565 parameters = parseFormalParameterList(); 1561 parameters = parseFormalParameterList();
1566 } 1562 }
1567 1563
1568 if (arity != -1) { 1564 if (arity != -1) {
1569 if (parameters.size() != arity) { 1565 if (parameters.size() != arity) {
1570 reportError(position(), ParserErrorCode.ILLEGAL_NUMBER_OF_PARAMETERS); 1566 reportError(position(), ParserErrorCode.ILLEGAL_NUMBER_OF_PARAMETERS);
1571 } 1567 }
1572 // In methods with required arity each parameter is required. 1568 // In methods with required arity each parameter is required.
1573 for (DartParameter parameter : parameters) { 1569 for (DartParameter parameter : parameters) {
1574 if (parameter.getModifiers().isNamed()) { 1570 if (parameter.getModifiers().isNamed()) {
(...skipping 3289 matching lines...) Expand 10 before | Expand all | Expand 10 after
4864 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen ts) { 4860 private void reportError(DartNode node, ErrorCode errorCode, Object... argumen ts) {
4865 if (node != null) { 4861 if (node != null) {
4866 reportError(new DartCompilationError(node, errorCode, arguments)); 4862 reportError(new DartCompilationError(node, errorCode, arguments));
4867 } 4863 }
4868 } 4864 }
4869 4865
4870 private boolean currentlyParsingToplevel() { 4866 private boolean currentlyParsingToplevel() {
4871 return !(isParsingInterface || isTopLevelAbstract || isParsingClass); 4867 return !(isParsingInterface || isTopLevelAbstract || isParsingClass);
4872 } 4868 }
4873 } 4869 }
OLDNEW
« no previous file with comments | « no previous file | compiler/javatests/com/google/dart/compiler/parser/SyntaxTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698