| 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_PARSER_H_ | 5 #ifndef V8_PARSER_H_ |
| 6 #define V8_PARSER_H_ | 6 #define V8_PARSER_H_ |
| 7 | 7 |
| 8 #include "src/allocation.h" | 8 #include "src/allocation.h" |
| 9 #include "src/ast.h" | 9 #include "src/ast.h" |
| 10 #include "src/compiler.h" // For CachedDataMode | 10 #include "src/compiler.h" // For CachedDataMode |
| (...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 215 enum {ADD_NONE, ADD_CHAR, ADD_TERM, ADD_ASSERT, ADD_ATOM} last_added_; | 215 enum {ADD_NONE, ADD_CHAR, ADD_TERM, ADD_ASSERT, ADD_ATOM} last_added_; |
| 216 #define LAST(x) last_added_ = x; | 216 #define LAST(x) last_added_ = x; |
| 217 #else | 217 #else |
| 218 #define LAST(x) | 218 #define LAST(x) |
| 219 #endif | 219 #endif |
| 220 }; | 220 }; |
| 221 | 221 |
| 222 | 222 |
| 223 class RegExpParser BASE_EMBEDDED { | 223 class RegExpParser BASE_EMBEDDED { |
| 224 public: | 224 public: |
| 225 RegExpParser(FlatStringReader* in, | 225 RegExpParser(FlatStringReader* in, Handle<String>* error, bool multiline_mode, |
| 226 Handle<String>* error, | 226 bool unicode, Zone* zone); |
| 227 bool multiline_mode, | |
| 228 Zone* zone); | |
| 229 | 227 |
| 230 static bool ParseRegExp(FlatStringReader* input, | 228 static bool ParseRegExp(FlatStringReader* input, bool multiline, bool unicode, |
| 231 bool multiline, | 229 RegExpCompileData* result, Zone* zone); |
| 232 RegExpCompileData* result, | |
| 233 Zone* zone); | |
| 234 | 230 |
| 235 RegExpTree* ParsePattern(); | 231 RegExpTree* ParsePattern(); |
| 236 RegExpTree* ParseDisjunction(); | 232 RegExpTree* ParseDisjunction(); |
| 237 RegExpTree* ParseGroup(); | 233 RegExpTree* ParseGroup(); |
| 238 RegExpTree* ParseCharacterClass(); | 234 RegExpTree* ParseCharacterClass(); |
| 239 | 235 |
| 240 // Parses a {...,...} quantifier and stores the range in the given | 236 // Parses a {...,...} quantifier and stores the range in the given |
| 241 // out parameters. | 237 // out parameters. |
| 242 bool ParseIntervalQuantifier(int* min_out, int* max_out); | 238 bool ParseIntervalQuantifier(int* min_out, int* max_out); |
| 243 | 239 |
| 244 // Parses and returns a single escaped character. The character | 240 // Parses and returns a single escaped character. The character |
| 245 // must not be 'b' or 'B' since they are usually handle specially. | 241 // must not be 'b' or 'B' since they are usually handle specially. |
| 246 uc32 ParseClassCharacterEscape(); | 242 uc32 ParseClassCharacterEscape(); |
| 247 | 243 |
| 248 // Checks whether the following is a length-digit hexadecimal number, | 244 // Checks whether the following is a length-digit hexadecimal number, |
| 249 // and sets the value if it is. | 245 // and sets the value if it is. |
| 250 bool ParseHexEscape(int length, uc32* value); | 246 bool ParseHexEscape(int length, uc32* value); |
| 247 bool ParseUnicodeEscape(uc32* value); |
| 248 bool ParseUnlimitedLengthHexNumber(int max_value, uc32* value); |
| 251 | 249 |
| 252 uc32 ParseOctalLiteral(); | 250 uc32 ParseOctalLiteral(); |
| 253 | 251 |
| 254 // Tries to parse the input as a back reference. If successful it | 252 // Tries to parse the input as a back reference. If successful it |
| 255 // stores the result in the output parameter and returns true. If | 253 // stores the result in the output parameter and returns true. If |
| 256 // it fails it will push back the characters read so the same characters | 254 // it fails it will push back the characters read so the same characters |
| 257 // can be reparsed. | 255 // can be reparsed. |
| 258 bool ParseBackReferenceIndex(int* index_out); | 256 bool ParseBackReferenceIndex(int* index_out); |
| 259 | 257 |
| 260 CharacterRange ParseClassAtom(uc16* char_class); | 258 CharacterRange ParseClassAtom(uc16* char_class); |
| 261 RegExpTree* ReportError(Vector<const char> message); | 259 RegExpTree* ReportError(Vector<const char> message); |
| 262 void Advance(); | 260 void Advance(); |
| 263 void Advance(int dist); | 261 void Advance(int dist); |
| 264 void Reset(int pos); | 262 void Reset(int pos); |
| 265 | 263 |
| 266 // Reports whether the pattern might be used as a literal search string. | 264 // Reports whether the pattern might be used as a literal search string. |
| 267 // Only use if the result of the parse is a single atom node. | 265 // Only use if the result of the parse is a single atom node. |
| 268 bool simple(); | 266 bool simple(); |
| 269 bool contains_anchor() { return contains_anchor_; } | 267 bool contains_anchor() { return contains_anchor_; } |
| 270 void set_contains_anchor() { contains_anchor_ = true; } | 268 void set_contains_anchor() { contains_anchor_ = true; } |
| 271 int captures_started() { return captures_ == NULL ? 0 : captures_->length(); } | 269 int captures_started() { return captures_ == NULL ? 0 : captures_->length(); } |
| 272 int position() { return next_pos_ - 1; } | 270 int position() { return next_pos_ - 1; } |
| 273 bool failed() { return failed_; } | 271 bool failed() { return failed_; } |
| 274 | 272 |
| 273 static bool IsSyntaxCharacter(uc32 c); |
| 274 |
| 275 static const int kMaxCaptures = 1 << 16; | 275 static const int kMaxCaptures = 1 << 16; |
| 276 static const uc32 kEndMarker = (1 << 21); | 276 static const uc32 kEndMarker = (1 << 21); |
| 277 | 277 |
| 278 private: | 278 private: |
| 279 enum SubexpressionType { | 279 enum SubexpressionType { |
| 280 INITIAL, | 280 INITIAL, |
| 281 CAPTURE, // All positive values represent captures. | 281 CAPTURE, // All positive values represent captures. |
| 282 POSITIVE_LOOKAHEAD, | 282 POSITIVE_LOOKAHEAD, |
| 283 NEGATIVE_LOOKAHEAD, | 283 NEGATIVE_LOOKAHEAD, |
| 284 GROUPING | 284 GROUPING |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 Zone* zone_; | 331 Zone* zone_; |
| 332 Handle<String>* error_; | 332 Handle<String>* error_; |
| 333 ZoneList<RegExpCapture*>* captures_; | 333 ZoneList<RegExpCapture*>* captures_; |
| 334 FlatStringReader* in_; | 334 FlatStringReader* in_; |
| 335 uc32 current_; | 335 uc32 current_; |
| 336 int next_pos_; | 336 int next_pos_; |
| 337 // The capture count is only valid after we have scanned for captures. | 337 // The capture count is only valid after we have scanned for captures. |
| 338 int capture_count_; | 338 int capture_count_; |
| 339 bool has_more_; | 339 bool has_more_; |
| 340 bool multiline_; | 340 bool multiline_; |
| 341 bool unicode_; |
| 341 bool simple_; | 342 bool simple_; |
| 342 bool contains_anchor_; | 343 bool contains_anchor_; |
| 343 bool is_scanned_for_captures_; | 344 bool is_scanned_for_captures_; |
| 344 bool failed_; | 345 bool failed_; |
| 345 }; | 346 }; |
| 346 | 347 |
| 347 // ---------------------------------------------------------------------------- | 348 // ---------------------------------------------------------------------------- |
| 348 // JAVASCRIPT PARSING | 349 // JAVASCRIPT PARSING |
| 349 | 350 |
| 350 class Parser; | 351 class Parser; |
| (...skipping 651 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1002 } | 1003 } |
| 1003 | 1004 |
| 1004 | 1005 |
| 1005 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, | 1006 Expression* ParserTraits::CloseTemplateLiteral(TemplateLiteralState* state, |
| 1006 int start, Expression* tag) { | 1007 int start, Expression* tag) { |
| 1007 return parser_->CloseTemplateLiteral(state, start, tag); | 1008 return parser_->CloseTemplateLiteral(state, start, tag); |
| 1008 } | 1009 } |
| 1009 } } // namespace v8::internal | 1010 } } // namespace v8::internal |
| 1010 | 1011 |
| 1011 #endif // V8_PARSER_H_ | 1012 #endif // V8_PARSER_H_ |
| OLD | NEW |