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

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

Issue 10236005: Fix small problems with precedence of cascades. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: 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 | « frog/tests/leg_only/src/CascadePrecedenceTest.dart ('k') | lib/compiler/implementation/scanner/token.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 00ccaa2c81acea9ec55bbd237cfd4ee3a4da6b81..16f145a047a88d8db3a38a854822d587f7530139 100644
--- a/lib/compiler/implementation/scanner/parser.dart
+++ b/lib/compiler/implementation/scanner/parser.dart
@@ -9,6 +9,7 @@
class Parser {
final Listener listener;
bool mayParseFunctionExpressions = true;
+ bool mayParseCascades = true;
ahe 2012/04/26 14:33:30 Does this need to be a global flag?
Lasse Reichstein Nielsen 2012/04/27 07:08:31 Actually not. Passing it to just parsePrecedenceEx
Parser(Listener this.listener);
@@ -855,16 +856,28 @@ class Parser {
}
Token parseExpression(Token token) {
- return parsePrecedenceExpression(token, CASCADE_PRECEDENCE);
+ bool couldParseCascades = mayParseCascades;
+ mayParseCascades = true;
+ Token result = parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE);
+ mayParseCascades = couldParseCascades;
+ return result;
+ }
+
+ Token parseExpressionWithoutCascade(Token token) {
+ bool couldParseCascades = mayParseCascades;
+ mayParseCascades = false;
+ Token result = parsePrecedenceExpression(token, ASSIGNMENT_PRECEDENCE);
+ mayParseCascades = couldParseCascades;
+ return result;
}
Token parseConditionalExpressionRest(Token token) {
assert(optional('?', token));
Token question = token;
- token = parseExpression(token.next);
+ token = parseExpressionWithoutCascade(token.next);
Token colon = token;
token = expect(':', token);
- token = parseExpression(token);
+ token = parseExpressionWithoutCascade(token);
listener.handleConditionalExpression(question, colon);
return token;
}
@@ -879,6 +892,9 @@ class Parser {
while (tokenLevel === level) {
Token operator = token;
if (tokenLevel === CASCADE_PRECEDENCE) {
+ if (!mayParseCascades) {
Lasse Reichstein Nielsen 2012/04/27 07:08:31 Another alternative here is to start the outer for
+ return token;
+ }
token = parseCascadeExpression(token);
} else if (tokenLevel === ASSIGNMENT_PRECEDENCE) {
// Right associative, so we recurse at the same precedence
@@ -946,7 +962,7 @@ class Parser {
if (token.info.precedence === ASSIGNMENT_PRECEDENCE) {
Token assignment = token;
- token = parsePrecedenceExpression(token.next, CASCADE_PRECEDENCE + 1);
+ token = parseExpressionWithoutCascade(token.next);
listener.handleAssignmentExpression(assignment);
}
listener.endCascade();
« no previous file with comments | « frog/tests/leg_only/src/CascadePrecedenceTest.dart ('k') | lib/compiler/implementation/scanner/token.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698