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

Side by Side Diff: frog/leg/scanner/parser.dart

Issue 9502002: Add FunctionDeclaration node. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 8 years, 9 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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. 7 * all tokens in a linked list.
8 */ 8 */
9 class Parser { 9 class Parser {
10 final Listener listener; 10 final Listener listener;
(...skipping 706 matching lines...) Expand 10 before | Expand all | Expand 10 after
717 717
718 Token parseUnamedFunction(Token token) { 718 Token parseUnamedFunction(Token token) {
719 listener.beginUnamedFunction(token); 719 listener.beginUnamedFunction(token);
720 token = parseFormalParameters(token); 720 token = parseFormalParameters(token);
721 bool isBlock = optional('{', token); 721 bool isBlock = optional('{', token);
722 token = parseFunctionBody(token, true); 722 token = parseFunctionBody(token, true);
723 listener.endUnamedFunction(token); 723 listener.endUnamedFunction(token);
724 return isBlock ? token.next : token; 724 return isBlock ? token.next : token;
725 } 725 }
726 726
727 Token parseFunctionDeclaration(Token token) {
728 listener.beginFunctionDeclaration(token);
729 token = parseFunction(token, null);
730 listener.endFunctionDeclaration(token);
731 return token;
732 }
733
727 Token parseFunctionExpression(Token token) { 734 Token parseFunctionExpression(Token token) {
728 listener.beginFunction(token); 735 listener.beginFunction(token);
729 listener.handleModifiers(0); 736 listener.handleModifiers(0);
730 token = parseReturnTypeOpt(token); 737 token = parseReturnTypeOpt(token);
731 listener.beginFunctionName(token); 738 listener.beginFunctionName(token);
732 token = parseIdentifier(token); 739 token = parseIdentifier(token);
733 listener.endFunctionName(token); 740 listener.endFunctionName(token);
734 token = parseFormalParameters(token); 741 token = parseFormalParameters(token);
735 listener.handleNoInitializers(); 742 listener.handleNoInitializers();
736 bool isBlock = optional('{', token); 743 bool isBlock = optional('{', token);
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
845 // We are looking at "type identifier" followed by '=', ';', ','. 852 // We are looking at "type identifier" followed by '=', ';', ','.
846 return parseVariablesDeclaration(token); 853 return parseVariablesDeclaration(token);
847 } else if (afterIdKind === OPEN_PAREN_TOKEN) { 854 } else if (afterIdKind === OPEN_PAREN_TOKEN) {
848 // We are looking at "type identifier '('". 855 // We are looking at "type identifier '('".
849 BeginGroupToken beginParen = afterId; 856 BeginGroupToken beginParen = afterId;
850 Token endParen = beginParen.endGroup; 857 Token endParen = beginParen.endGroup;
851 Token afterParens = endParen.next; 858 Token afterParens = endParen.next;
852 if (optional('{', afterParens) || optional('=>', afterParens)) { 859 if (optional('{', afterParens) || optional('=>', afterParens)) {
853 // We are looking at "type identifier '(' ... ')'" followed 860 // We are looking at "type identifier '(' ... ')'" followed
854 // by '=>' or '{'. 861 // by '=>' or '{'.
855 return parseFunction(token, null); 862 return parseFunctionDeclaration(token);
856 } 863 }
857 } 864 }
858 // Fall-through to expression statement. 865 // Fall-through to expression statement.
859 } else { 866 } else {
860 if (optional(':', token.next)) { 867 if (optional(':', token.next)) {
861 return parseLabelledStatement(token); 868 return parseLabelledStatement(token);
862 } else if (optional('(', token.next)) { 869 } else if (optional('(', token.next)) {
863 BeginGroupToken begin = token.next; 870 BeginGroupToken begin = token.next;
864 String afterParens = begin.endGroup.next.stringValue; 871 String afterParens = begin.endGroup.next.stringValue;
865 if (afterParens === '{' || afterParens === '=>') { 872 if (afterParens === '{' || afterParens === '=>') {
866 return parseFunction(token, null); 873 return parseFunctionDeclaration(token);
867 } 874 }
868 } 875 }
869 } 876 }
870 return parseExpressionStatement(token); 877 return parseExpressionStatement(token);
871 } 878 }
872 879
873 Token parseLabelledStatement(Token token) { 880 Token parseLabelledStatement(Token token) {
874 listener.beginLabelledStatement(token); 881 listener.beginLabelledStatement(token);
875 token = parseIdentifier(token); 882 token = parseIdentifier(token);
876 Token colon = token; 883 Token colon = token;
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after
1631 } 1638 }
1632 listener.handleContinueStatement(hasTarget, continueKeyword, token); 1639 listener.handleContinueStatement(hasTarget, continueKeyword, token);
1633 return expectSemicolon(token); 1640 return expectSemicolon(token);
1634 } 1641 }
1635 1642
1636 Token parseEmptyStatement(Token token) { 1643 Token parseEmptyStatement(Token token) {
1637 listener.handleEmptyStatement(token); 1644 listener.handleEmptyStatement(token);
1638 return expectSemicolon(token); 1645 return expectSemicolon(token);
1639 } 1646 }
1640 } 1647 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698