| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef VM_REGEXP_PARSER_H_ | 5 #ifndef VM_REGEXP_PARSER_H_ |
| 6 #define VM_REGEXP_PARSER_H_ | 6 #define VM_REGEXP_PARSER_H_ |
| 7 | 7 |
| 8 #include "vm/allocation.h" | 8 #include "vm/allocation.h" |
| 9 #include "vm/growable_array.h" | 9 #include "vm/growable_array.h" |
| 10 #include "vm/regexp_ast.h" | 10 #include "vm/regexp_ast.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 void NewAlternative(); // '|' | 25 void NewAlternative(); // '|' |
| 26 void AddQuantifierToAtom( | 26 void AddQuantifierToAtom( |
| 27 intptr_t min, intptr_t max, RegExpQuantifier::QuantifierType type); | 27 intptr_t min, intptr_t max, RegExpQuantifier::QuantifierType type); |
| 28 RegExpTree* ToRegExp(); | 28 RegExpTree* ToRegExp(); |
| 29 | 29 |
| 30 private: | 30 private: |
| 31 void FlushCharacters(); | 31 void FlushCharacters(); |
| 32 void FlushText(); | 32 void FlushText(); |
| 33 void FlushTerms(); | 33 void FlushTerms(); |
| 34 | 34 |
| 35 Isolate* isolate() const { return isolate_; } | 35 Zone* zone() const { return zone_; } |
| 36 | 36 |
| 37 Isolate* isolate_; | 37 Zone* zone_; |
| 38 bool pending_empty_; | 38 bool pending_empty_; |
| 39 ZoneGrowableArray<uint16_t>* characters_; | 39 ZoneGrowableArray<uint16_t>* characters_; |
| 40 GrowableArray<RegExpTree*> terms_; | 40 GrowableArray<RegExpTree*> terms_; |
| 41 GrowableArray<RegExpTree*> text_; | 41 GrowableArray<RegExpTree*> text_; |
| 42 GrowableArray<RegExpTree*> alternatives_; | 42 GrowableArray<RegExpTree*> alternatives_; |
| 43 #ifdef DEBUG | 43 #ifdef DEBUG |
| 44 enum {ADD_NONE, ADD_CHAR, ADD_TERM, ADD_ASSERT, ADD_ATOM} last_added_; | 44 enum {ADD_NONE, ADD_CHAR, ADD_TERM, ADD_ASSERT, ADD_ATOM} last_added_; |
| 45 #define LAST(x) last_added_ = x; | 45 #define LAST(x) last_added_ = x; |
| 46 #else | 46 #else |
| 47 #define LAST(x) | 47 #define LAST(x) |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 111 POSITIVE_LOOKAHEAD, | 111 POSITIVE_LOOKAHEAD, |
| 112 NEGATIVE_LOOKAHEAD, | 112 NEGATIVE_LOOKAHEAD, |
| 113 GROUPING | 113 GROUPING |
| 114 }; | 114 }; |
| 115 | 115 |
| 116 class RegExpParserState : public ZoneAllocated { | 116 class RegExpParserState : public ZoneAllocated { |
| 117 public: | 117 public: |
| 118 RegExpParserState(RegExpParserState* previous_state, | 118 RegExpParserState(RegExpParserState* previous_state, |
| 119 SubexpressionType group_type, | 119 SubexpressionType group_type, |
| 120 intptr_t disjunction_capture_index, | 120 intptr_t disjunction_capture_index, |
| 121 Isolate *isolate) | 121 Zone *zone) |
| 122 : previous_state_(previous_state), | 122 : previous_state_(previous_state), |
| 123 builder_(new(isolate) RegExpBuilder()), | 123 builder_(new(zone) RegExpBuilder()), |
| 124 group_type_(group_type), | 124 group_type_(group_type), |
| 125 disjunction_capture_index_(disjunction_capture_index) {} | 125 disjunction_capture_index_(disjunction_capture_index) {} |
| 126 // Parser state of containing expression, if any. | 126 // Parser state of containing expression, if any. |
| 127 RegExpParserState* previous_state() { return previous_state_; } | 127 RegExpParserState* previous_state() { return previous_state_; } |
| 128 bool IsSubexpression() { return previous_state_ != NULL; } | 128 bool IsSubexpression() { return previous_state_ != NULL; } |
| 129 // RegExpBuilder building this regexp's AST. | 129 // RegExpBuilder building this regexp's AST. |
| 130 RegExpBuilder* builder() { return builder_; } | 130 RegExpBuilder* builder() { return builder_; } |
| 131 // Type of regexp being parsed (parenthesized group or entire regexp). | 131 // Type of regexp being parsed (parenthesized group or entire regexp). |
| 132 SubexpressionType group_type() { return group_type_; } | 132 SubexpressionType group_type() { return group_type_; } |
| 133 // Index in captures array of first capture in this sub-expression, if any. | 133 // Index in captures array of first capture in this sub-expression, if any. |
| 134 // Also the capture index of this sub-expression itself, if group_type | 134 // Also the capture index of this sub-expression itself, if group_type |
| 135 // is CAPTURE. | 135 // is CAPTURE. |
| 136 intptr_t capture_index() { return disjunction_capture_index_; } | 136 intptr_t capture_index() { return disjunction_capture_index_; } |
| 137 | 137 |
| 138 private: | 138 private: |
| 139 // Linked list implementation of stack of states. | 139 // Linked list implementation of stack of states. |
| 140 RegExpParserState* previous_state_; | 140 RegExpParserState* previous_state_; |
| 141 // Builder for the stored disjunction. | 141 // Builder for the stored disjunction. |
| 142 RegExpBuilder* builder_; | 142 RegExpBuilder* builder_; |
| 143 // Stored disjunction type (capture, look-ahead or grouping), if any. | 143 // Stored disjunction type (capture, look-ahead or grouping), if any. |
| 144 SubexpressionType group_type_; | 144 SubexpressionType group_type_; |
| 145 // Stored disjunction's capture index (if any). | 145 // Stored disjunction's capture index (if any). |
| 146 intptr_t disjunction_capture_index_; | 146 intptr_t disjunction_capture_index_; |
| 147 }; | 147 }; |
| 148 | 148 |
| 149 Isolate* isolate() { return isolate_; } | 149 Zone* zone() { return zone_; } |
| 150 | 150 |
| 151 uint32_t current() { return current_; } | 151 uint32_t current() { return current_; } |
| 152 bool has_more() { return has_more_; } | 152 bool has_more() { return has_more_; } |
| 153 bool has_next() { return next_pos_ < in().Length(); } | 153 bool has_next() { return next_pos_ < in().Length(); } |
| 154 uint32_t Next(); | 154 uint32_t Next(); |
| 155 const String& in() { return in_; } | 155 const String& in() { return in_; } |
| 156 void ScanForCaptures(); | 156 void ScanForCaptures(); |
| 157 | 157 |
| 158 Isolate* isolate_; | 158 Zone* zone_; |
| 159 String* error_; | 159 String* error_; |
| 160 ZoneGrowableArray<RegExpCapture*>* captures_; | 160 ZoneGrowableArray<RegExpCapture*>* captures_; |
| 161 const String& in_; | 161 const String& in_; |
| 162 uint32_t current_; | 162 uint32_t current_; |
| 163 intptr_t next_pos_; | 163 intptr_t next_pos_; |
| 164 // The capture count is only valid after we have scanned for captures. | 164 // The capture count is only valid after we have scanned for captures. |
| 165 intptr_t capture_count_; | 165 intptr_t capture_count_; |
| 166 bool has_more_; | 166 bool has_more_; |
| 167 bool multiline_; | 167 bool multiline_; |
| 168 bool simple_; | 168 bool simple_; |
| 169 bool contains_anchor_; | 169 bool contains_anchor_; |
| 170 bool is_scanned_for_captures_; | 170 bool is_scanned_for_captures_; |
| 171 bool failed_; | 171 bool failed_; |
| 172 }; | 172 }; |
| 173 | 173 |
| 174 } // namespace dart | 174 } // namespace dart |
| 175 | 175 |
| 176 #endif // VM_REGEXP_PARSER_H_ | 176 #endif // VM_REGEXP_PARSER_H_ |
| OLD | NEW |