Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef V8_PREPARSER_H | 5 #ifndef V8_PREPARSER_H |
| 6 #define V8_PREPARSER_H | 6 #define V8_PREPARSER_H |
| 7 | 7 |
| 8 #include "src/v8.h" | 8 #include "src/v8.h" |
| 9 | 9 |
| 10 #include "src/bailout-reason.h" | 10 #include "src/bailout-reason.h" |
| (...skipping 2924 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2935 Traits::AddTemplateSpan(&ts, false); | 2935 Traits::AddTemplateSpan(&ts, false); |
| 2936 Token::Value next; | 2936 Token::Value next; |
| 2937 | 2937 |
| 2938 // If we open with a TEMPLATE_SPAN, we must scan the subsequent expression, | 2938 // If we open with a TEMPLATE_SPAN, we must scan the subsequent expression, |
| 2939 // and repeat if the following token is a TEMPLATE_SPAN as well (in this | 2939 // and repeat if the following token is a TEMPLATE_SPAN as well (in this |
| 2940 // case, representing a TemplateMiddle). | 2940 // case, representing a TemplateMiddle). |
| 2941 | 2941 |
| 2942 do { | 2942 do { |
| 2943 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); | 2943 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); |
| 2944 next = peek(); | 2944 next = peek(); |
| 2945 if (!next) { | 2945 if (next == Token::EOS) { |
| 2946 ReportMessageAt(Scanner::Location(start, peek_position()), | 2946 ReportMessageAt(Scanner::Location(start, peek_position()), |
| 2947 "unterminated_template"); | 2947 "unterminated_template"); |
| 2948 *ok = false; | 2948 *ok = false; |
| 2949 return Traits::EmptyExpression(); | 2949 return Traits::EmptyExpression(); |
| 2950 } else if (next == Token::ILLEGAL) { | |
| 2951 Traits::ReportMessageAt( | |
| 2952 Scanner::Location(position() + 1, peek_position()), | |
| 2953 "unexpected_token", "ILLEGAL", false); | |
| 2954 *ok = false; | |
| 2955 return Traits::EmptyExpression(); | |
| 2950 } | 2956 } |
| 2951 | 2957 |
| 2952 int expr_pos = peek_position(); | 2958 int expr_pos = peek_position(); |
| 2953 ExpressionT expression = this->ParseExpression(true, CHECK_OK); | 2959 ExpressionT expression = this->ParseExpression(true, CHECK_OK); |
| 2954 Traits::AddTemplateExpression(&ts, expression); | 2960 Traits::AddTemplateExpression(&ts, expression); |
| 2955 | 2961 |
| 2956 if (peek() != Token::RBRACE) { | 2962 if (peek() != Token::RBRACE) { |
| 2957 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), | 2963 ReportMessageAt(Scanner::Location(expr_pos, peek_position()), |
| 2958 "unterminated_template_expr"); | 2964 "unterminated_template_expr"); |
| 2959 *ok = false; | 2965 *ok = false; |
| 2960 return Traits::EmptyExpression(); | 2966 return Traits::EmptyExpression(); |
| 2961 } | 2967 } |
| 2962 | 2968 |
| 2963 // If we didn't die parsing that expression, our next token should be a | 2969 // If we didn't die parsing that expression, our next token should be a |
| 2964 // TEMPLATE_SPAN or TEMPLATE_TAIL. | 2970 // TEMPLATE_SPAN or TEMPLATE_TAIL. |
| 2965 next = scanner()->ScanTemplateContinuation(); | 2971 next = scanner()->ScanTemplateContinuation(); |
| 2966 Next(); | 2972 Next(); |
| 2967 pos = position(); | 2973 pos = position(); |
| 2968 | 2974 |
| 2969 if (!next) { | 2975 if (next == Token::EOS) { |
| 2970 ReportMessageAt(Scanner::Location(start, pos), "unterminated_template"); | 2976 ReportMessageAt(Scanner::Location(start, pos), "unterminated_template"); |
| 2971 *ok = false; | 2977 *ok = false; |
| 2972 return Traits::EmptyExpression(); | 2978 return Traits::EmptyExpression(); |
| 2979 } else if (next == Token::ILLEGAL) { | |
|
arv (Not doing code reviews)
2015/01/19 17:24:32
Can this code duplication be prevented?
caitp (gmail)
2015/01/19 17:27:04
The first `else if (next == Token::ILLEGAL)` block
| |
| 2980 Traits::ReportMessageAt( | |
| 2981 Scanner::Location(position() + 1, peek_position()), | |
| 2982 "unexpected_token", "ILLEGAL", false); | |
| 2983 *ok = false; | |
| 2984 return Traits::EmptyExpression(); | |
| 2973 } | 2985 } |
| 2974 | 2986 |
| 2975 Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL); | 2987 Traits::AddTemplateSpan(&ts, next == Token::TEMPLATE_TAIL); |
| 2976 } while (next == Token::TEMPLATE_SPAN); | 2988 } while (next == Token::TEMPLATE_SPAN); |
| 2977 | 2989 |
| 2978 DCHECK_EQ(next, Token::TEMPLATE_TAIL); | 2990 DCHECK_EQ(next, Token::TEMPLATE_TAIL); |
| 2979 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); | 2991 CheckTemplateOctalLiteral(pos, peek_position(), CHECK_OK); |
| 2980 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. | 2992 // Once we've reached a TEMPLATE_TAIL, we can close the TemplateLiteral. |
| 2981 return Traits::CloseTemplateLiteral(&ts, start, tag); | 2993 return Traits::CloseTemplateLiteral(&ts, start, tag); |
| 2982 } | 2994 } |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3034 DCHECK(IsAccessorAccessorConflict(old_type, type)); | 3046 DCHECK(IsAccessorAccessorConflict(old_type, type)); |
| 3035 // Both accessors of the same type. | 3047 // Both accessors of the same type. |
| 3036 parser()->ReportMessage("accessor_get_set"); | 3048 parser()->ReportMessage("accessor_get_set"); |
| 3037 } | 3049 } |
| 3038 *ok = false; | 3050 *ok = false; |
| 3039 } | 3051 } |
| 3040 } | 3052 } |
| 3041 } } // v8::internal | 3053 } } // v8::internal |
| 3042 | 3054 |
| 3043 #endif // V8_PREPARSER_H | 3055 #endif // V8_PREPARSER_H |
| OLD | NEW |