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

Unified Diff: lib/compiler/implementation/scanner/parser.dart

Issue 9958009: Implement cascaded calls. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Address review comments. Created 8 years, 8 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/compiler/implementation/scanner/listener.dart ('k') | lib/compiler/implementation/scanner/scanner.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/compiler/implementation/scanner/parser.dart
diff --git a/lib/compiler/implementation/scanner/parser.dart b/lib/compiler/implementation/scanner/parser.dart
index aad8ee44c54f71f6d39cf3940c7f7cb29830128a..e2760019dafe340652dd45b369d19d68c6bd0355 100644
--- a/lib/compiler/implementation/scanner/parser.dart
+++ b/lib/compiler/implementation/scanner/parser.dart
@@ -236,7 +236,6 @@ class Parser {
return token.next;
}
-
Token parseStringPart(Token token) {
if (token.kind === STRING_TOKEN) {
listener.handleStringPart(token);
@@ -856,7 +855,7 @@ class Parser {
}
Token parseExpression(Token token) {
- return parsePrecedenceExpression(token, 2);
+ return parsePrecedenceExpression(token, CASCADE_PRECEDENCE);
}
Token parseConditionalExpressionRest(Token token) {
@@ -871,7 +870,7 @@ class Parser {
}
Token parsePrecedenceExpression(Token token, int precedence) {
- assert(precedence >= 2);
+ assert(precedence >= 1);
assert(precedence <= POSTFIX_PRECEDENCE);
token = parseUnaryExpression(token);
PrecedenceInfo info = token.info;
@@ -879,7 +878,9 @@ class Parser {
for (int level = tokenLevel; level >= precedence; --level) {
while (tokenLevel === level) {
Token operator = token;
- if (tokenLevel === ASSIGNMENT_PRECEDENCE) {
+ if (tokenLevel === CASCADE_PRECEDENCE) {
+ token = parseCascadeExpression(token);
+ } else if (tokenLevel === ASSIGNMENT_PRECEDENCE) {
// Right associative, so we recurse at the same precedence
// level.
token = parsePrecedenceExpression(token.next, level);
@@ -919,6 +920,38 @@ class Parser {
return token;
}
+ Token parseCascadeExpression(Token token) {
+ listener.beginCascade(token);
+ assert(optional('..', token));
+ Token cascadeOperator = token;
+ if (optional('[', token)) {
+ token = parseArgumentOrIndexStar(token);
+ } else if (isIdentifier(token)) {
+ token = parseSend(token);
+ listener.handleBinaryExpression(cascadeOperator);
+ } else {
+ return listener.unexpected(token);
+ }
+ Token mark;
+ do {
+ mark = token;
+ if (optional('.', token)) {
+ Token period = token;
+ token = parseSend(period.token);
+ listener.handleBinaryExpression(period);
+ }
+ token = parseArgumentOrIndexStar(token);
+ } while (mark !== token);
+
+ if (token.info.precedence === ASSIGNMENT_PRECEDENCE) {
+ Token assignment = token;
+ token = parsePrecedenceExpression(token.token, CASCADE_PRECEDENCE + 1);
+ listener.handleAssignmentExpression(assignment);
+ }
+ listener.endCascade();
+ return token;
+ }
+
Token parseUnaryExpression(Token token) {
String value = token.stringValue;
// Prefix:
« no previous file with comments | « lib/compiler/implementation/scanner/listener.dart ('k') | lib/compiler/implementation/scanner/scanner.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698