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

Unified Diff: src/preparser.h

Issue 198053002: Move ParseConditionalExpression to ParserBase. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: rebased Created 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/preparser.h
diff --git a/src/preparser.h b/src/preparser.h
index 8c0e06732055c3ef6d310a5cdcfa902f71c5fffa..7561d16df24017d63265792b00ff5ad011f6a627 100644
--- a/src/preparser.h
+++ b/src/preparser.h
@@ -385,6 +385,8 @@ class ParserBase : public Traits {
typename Traits::Type::Expression ParseAssignmentExpression(bool accept_IN,
bool* ok);
typename Traits::Type::Expression ParseYieldExpression(bool* ok);
+ typename Traits::Type::Expression ParseConditionalExpression(bool accept_IN,
+ bool* ok);
// Used to detect duplicates in object literals. Each of the values
// kGetterProperty, kSetterProperty and kValueProperty represents
@@ -715,6 +717,13 @@ class PreParserFactory {
int pos) {
return PreParserExpression::Default();
}
+
+ PreParserExpression NewConditional(PreParserExpression condition,
+ PreParserExpression then_expression,
+ PreParserExpression else_expression,
+ int pos) {
+ return PreParserExpression::Default();
+ }
};
@@ -887,7 +896,7 @@ class PreParserTraits {
int function_token_position,
FunctionLiteral::FunctionType type,
bool* ok);
- PreParserExpression ParseConditionalExpression(bool accept_IN, bool* ok);
+ PreParserExpression ParseBinaryExpression(int prec, bool accept_IN, bool* ok);
private:
PreParser* pre_parser_;
@@ -1689,6 +1698,32 @@ typename Traits::Type::Expression ParserBase<Traits>::ParseYieldExpression(
}
+// Precedence = 3
+template <class Traits>
+typename Traits::Type::Expression
+ParserBase<Traits>::ParseConditionalExpression(bool accept_IN, bool* ok) {
+ // ConditionalExpression ::
+ // LogicalOrExpression
+ // LogicalOrExpression '?' AssignmentExpression ':' AssignmentExpression
+
+ int pos = peek_position();
+ // We start using the binary expression parser for prec >= 4 only!
+ typename Traits::Type::Expression expression =
+ this->ParseBinaryExpression(4, accept_IN, CHECK_OK);
+ if (peek() != Token::CONDITIONAL) return expression;
+ Consume(Token::CONDITIONAL);
+ // In parsing the first assignment expression in conditional
+ // expressions we always accept the 'in' keyword; see ECMA-262,
+ // section 11.12, page 58.
+ typename Traits::Type::Expression left =
+ ParseAssignmentExpression(true, CHECK_OK);
+ Expect(Token::COLON, CHECK_OK);
+ typename Traits::Type::Expression right =
+ ParseAssignmentExpression(accept_IN, CHECK_OK);
+ return factory()->NewConditional(expression, left, right, pos);
+}
+
+
#undef CHECK_OK
#undef CHECK_OK_CUSTOM
« no previous file with comments | « src/parser.cc ('k') | src/preparser.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698