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

Side by Side Diff: editor/tools/plugins/com.google.dart.engine/src/com/google/dart/engine/parser/Parser.java

Issue 48623010: Issue 12694. Fix for parsing 'buildIn() {}' top-level functions. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 1 month 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 | editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/parser/SimpleParserTest.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 /* 1 /*
2 * Copyright (c) 2012, the Dart project authors. 2 * Copyright (c) 2012, the Dart project authors.
3 * 3 *
4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except 4 * Licensed under the Eclipse Public License v1.0 (the "License"); you may not u se this file except
5 * in compliance with the License. You may obtain a copy of the License at 5 * in compliance with the License. You may obtain a copy of the License at
6 * 6 *
7 * http://www.eclipse.org/legal/epl-v10.html 7 * http://www.eclipse.org/legal/epl-v10.html
8 * 8 *
9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License 9 * Unless required by applicable law or agreed to in writing, software distribut ed under the License
10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express 10 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY K IND, either express
(...skipping 583 matching lines...) Expand 10 before | Expand all | Expand 10 after
594 boolean libraryDirectiveFound = false; 594 boolean libraryDirectiveFound = false;
595 boolean partOfDirectiveFound = false; 595 boolean partOfDirectiveFound = false;
596 boolean partDirectiveFound = false; 596 boolean partDirectiveFound = false;
597 boolean directiveFoundAfterDeclaration = false; 597 boolean directiveFoundAfterDeclaration = false;
598 List<Directive> directives = new ArrayList<Directive>(); 598 List<Directive> directives = new ArrayList<Directive>();
599 List<CompilationUnitMember> declarations = new ArrayList<CompilationUnitMemb er>(); 599 List<CompilationUnitMember> declarations = new ArrayList<CompilationUnitMemb er>();
600 Token memberStart = currentToken; 600 Token memberStart = currentToken;
601 while (!matches(TokenType.EOF)) { 601 while (!matches(TokenType.EOF)) {
602 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata(); 602 CommentAndMetadata commentAndMetadata = parseCommentAndMetadata();
603 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword .LIBRARY) || matches(Keyword.PART)) 603 if ((matches(Keyword.IMPORT) || matches(Keyword.EXPORT) || matches(Keyword .LIBRARY) || matches(Keyword.PART))
604 && !matches(peek(), TokenType.PERIOD) && !matches(peek(), TokenType.LT )) { 604 && !matches(peek(), TokenType.PERIOD)
605 && !matches(peek(), TokenType.LT)
606 && !matches(peek(), TokenType.OPEN_PAREN)) {
605 Directive directive = parseDirective(commentAndMetadata); 607 Directive directive = parseDirective(commentAndMetadata);
606 if (declarations.size() > 0 && !directiveFoundAfterDeclaration) { 608 if (declarations.size() > 0 && !directiveFoundAfterDeclaration) {
607 reportError(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION); 609 reportError(ParserErrorCode.DIRECTIVE_AFTER_DECLARATION);
608 directiveFoundAfterDeclaration = true; 610 directiveFoundAfterDeclaration = true;
609 } 611 }
610 if (directive instanceof LibraryDirective) { 612 if (directive instanceof LibraryDirective) {
611 if (libraryDirectiveFound) { 613 if (libraryDirectiveFound) {
612 reportError(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES); 614 reportError(ParserErrorCode.MULTIPLE_LIBRARY_DIRECTIVES);
613 } else { 615 } else {
614 if (directives.size() > 0) { 616 if (directives.size() > 0) {
(...skipping 2285 matching lines...) Expand 10 before | Expand all | Expand 10 after
2900 * 2902 *
2901 * @param commentAndMetadata the metadata to be associated with the member 2903 * @param commentAndMetadata the metadata to be associated with the member
2902 * @return the compilation unit member that was parsed, or {@code null} if wha t was parsed could 2904 * @return the compilation unit member that was parsed, or {@code null} if wha t was parsed could
2903 * not be represented as a compilation unit member 2905 * not be represented as a compilation unit member
2904 */ 2906 */
2905 private CompilationUnitMember parseCompilationUnitMember(CommentAndMetadata co mmentAndMetadata) { 2907 private CompilationUnitMember parseCompilationUnitMember(CommentAndMetadata co mmentAndMetadata) {
2906 Modifiers modifiers = parseModifiers(); 2908 Modifiers modifiers = parseModifiers();
2907 if (matches(Keyword.CLASS)) { 2909 if (matches(Keyword.CLASS)) {
2908 return parseClassDeclaration(commentAndMetadata, validateModifiersForClass (modifiers)); 2910 return parseClassDeclaration(commentAndMetadata, validateModifiersForClass (modifiers));
2909 } else if (matches(Keyword.TYPEDEF) && !matches(peek(), TokenType.PERIOD) 2911 } else if (matches(Keyword.TYPEDEF) && !matches(peek(), TokenType.PERIOD)
2910 && !matches(peek(), TokenType.LT)) { 2912 && !matches(peek(), TokenType.LT) && !matches(peek(), TokenType.OPEN_PAR EN)) {
2911 validateModifiersForTypedef(modifiers); 2913 validateModifiersForTypedef(modifiers);
2912 return parseTypeAlias(commentAndMetadata); 2914 return parseTypeAlias(commentAndMetadata);
2913 } 2915 }
2914 if (matches(Keyword.VOID)) { 2916 if (matches(Keyword.VOID)) {
2915 TypeName returnType = parseReturnType(); 2917 TypeName returnType = parseReturnType();
2916 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier(pe ek())) { 2918 if ((matches(Keyword.GET) || matches(Keyword.SET)) && matchesIdentifier(pe ek())) {
2917 validateModifiersForTopLevelFunction(modifiers); 2919 validateModifiersForTopLevelFunction(modifiers);
2918 return parseFunctionDeclaration(commentAndMetadata, modifiers.getExterna lKeyword(), null); 2920 return parseFunctionDeclaration(commentAndMetadata, modifiers.getExterna lKeyword(), null);
2919 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) { 2921 } else if (matches(Keyword.OPERATOR) && isOperator(peek())) {
2920 reportError(ParserErrorCode.TOP_LEVEL_OPERATOR, currentToken); 2922 reportError(ParserErrorCode.TOP_LEVEL_OPERATOR, currentToken);
(...skipping 1357 matching lines...) Expand 10 before | Expand all | Expand 10 after
4278 * modifiers ::= 4280 * modifiers ::=
4279 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | ' var')* 4281 * ('abstract' | 'const' | 'external' | 'factory' | 'final' | 'static' | ' var')*
4280 * </pre> 4282 * </pre>
4281 * 4283 *
4282 * @return the modifiers that were parsed 4284 * @return the modifiers that were parsed
4283 */ 4285 */
4284 private Modifiers parseModifiers() { 4286 private Modifiers parseModifiers() {
4285 Modifiers modifiers = new Modifiers(); 4287 Modifiers modifiers = new Modifiers();
4286 boolean progress = true; 4288 boolean progress = true;
4287 while (progress) { 4289 while (progress) {
4288 if (matches(Keyword.ABSTRACT) && !matches(peek(), TokenType.PERIOD) 4290 if (matches(peek(), TokenType.PERIOD) || matches(peek(), TokenType.LT)
4289 && !matches(peek(), TokenType.LT)) { 4291 || matches(peek(), TokenType.OPEN_PAREN)) {
4292 return modifiers;
4293 }
4294 if (matches(Keyword.ABSTRACT)) {
4290 if (modifiers.getAbstractKeyword() != null) { 4295 if (modifiers.getAbstractKeyword() != null) {
4291 reportError(ParserErrorCode.DUPLICATED_MODIFIER, currentToken.getLexem e()); 4296 reportError(ParserErrorCode.DUPLICATED_MODIFIER, currentToken.getLexem e());
4292 advance(); 4297 advance();
4293 } else { 4298 } else {
4294 modifiers.setAbstractKeyword(getAndAdvance()); 4299 modifiers.setAbstractKeyword(getAndAdvance());
4295 } 4300 }
4296 } else if (matches(Keyword.CONST)) { 4301 } else if (matches(Keyword.CONST)) {
4297 if (modifiers.getConstKeyword() != null) { 4302 if (modifiers.getConstKeyword() != null) {
4298 reportError(ParserErrorCode.DUPLICATED_MODIFIER, currentToken.getLexem e()); 4303 reportError(ParserErrorCode.DUPLICATED_MODIFIER, currentToken.getLexem e());
4299 advance(); 4304 advance();
(...skipping 2229 matching lines...) Expand 10 before | Expand all | Expand 10 after
6529 reportError(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.getExternalKeyword ()); 6534 reportError(ParserErrorCode.EXTERNAL_TYPEDEF, modifiers.getExternalKeyword ());
6530 } 6535 }
6531 if (modifiers.getFinalKeyword() != null) { 6536 if (modifiers.getFinalKeyword() != null) {
6532 reportError(ParserErrorCode.FINAL_TYPEDEF, modifiers.getFinalKeyword()); 6537 reportError(ParserErrorCode.FINAL_TYPEDEF, modifiers.getFinalKeyword());
6533 } 6538 }
6534 if (modifiers.getVarKeyword() != null) { 6539 if (modifiers.getVarKeyword() != null) {
6535 reportError(ParserErrorCode.VAR_TYPEDEF, modifiers.getVarKeyword()); 6540 reportError(ParserErrorCode.VAR_TYPEDEF, modifiers.getVarKeyword());
6536 } 6541 }
6537 } 6542 }
6538 } 6543 }
OLDNEW
« no previous file with comments | « no previous file | editor/tools/plugins/com.google.dart.engine_test/src/com/google/dart/engine/parser/SimpleParserTest.java » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698