Class: JsRegex::Converter::Context
- Inherits:
-
Object
- Object
- JsRegex::Converter::Context
- Defined in:
- lib/js_regex/converter/context.rb
Overview
Passed among Converters to globalize basic status data.
The Converters themselves are stateless.
Instance Attribute Summary collapse
-
#buffered_set_extractions ⇒ Object
readonly
Returns the value of attribute buffered_set_extractions.
-
#buffered_set_members ⇒ Object
readonly
Returns the value of attribute buffered_set_members.
-
#in_atomic_group ⇒ Object
readonly
Returns the value of attribute in_atomic_group.
-
#named_group_positions ⇒ Object
readonly
Returns the value of attribute named_group_positions.
-
#negative_base_set ⇒ Object
readonly
Returns the value of attribute negative_base_set.
-
#root_options ⇒ Object
readonly
Returns the value of attribute root_options.
-
#warnings ⇒ Object
readonly
Returns the value of attribute warnings.
Instance Method Summary collapse
-
#capture_group ⇒ Object
group context.
- #end_atomic_group ⇒ Object
-
#initialize(ruby_regex) ⇒ Context
constructor
A new instance of Context.
-
#multiline? ⇒ Boolean
option context.
-
#negate_base_set ⇒ Object
set context.
-
#new_capturing_group_position(old_position) ⇒ Object
takes and returns 1-indexed group positions.
- #original_capturing_group_count ⇒ Object
- #reset_set_context ⇒ Object
- #start_atomic_group ⇒ Object
- #store_named_group_position(name) ⇒ Object
- #total_added_capturing_groups ⇒ Object
- #wrap_in_backrefed_lookahead(content) ⇒ Object
Constructor Details
#initialize(ruby_regex) ⇒ Context
Returns a new instance of Context.
19 20 21 22 23 24 25 26 27 |
# File 'lib/js_regex/converter/context.rb', line 19 def initialize(ruby_regex) self.added_capturing_groups_after_group = Hash.new(0) self.capturing_group_count = 0 self.named_group_positions = {} self.warnings = [] self. = {} [:m] = !(ruby_regex. & Regexp::MULTILINE).equal?(0) end |
Instance Attribute Details
#buffered_set_extractions ⇒ Object
Returns the value of attribute buffered_set_extractions.
11 12 13 |
# File 'lib/js_regex/converter/context.rb', line 11 def buffered_set_extractions @buffered_set_extractions end |
#buffered_set_members ⇒ Object
Returns the value of attribute buffered_set_members.
11 12 13 |
# File 'lib/js_regex/converter/context.rb', line 11 def buffered_set_members @buffered_set_members end |
#in_atomic_group ⇒ Object
Returns the value of attribute in_atomic_group.
11 12 13 |
# File 'lib/js_regex/converter/context.rb', line 11 def in_atomic_group @in_atomic_group end |
#named_group_positions ⇒ Object
Returns the value of attribute named_group_positions.
11 12 13 |
# File 'lib/js_regex/converter/context.rb', line 11 def named_group_positions @named_group_positions end |
#negative_base_set ⇒ Object
Returns the value of attribute negative_base_set.
11 12 13 |
# File 'lib/js_regex/converter/context.rb', line 11 def negative_base_set @negative_base_set end |
#root_options ⇒ Object
Returns the value of attribute root_options.
11 12 13 |
# File 'lib/js_regex/converter/context.rb', line 11 def end |
#warnings ⇒ Object
Returns the value of attribute warnings.
11 12 13 |
# File 'lib/js_regex/converter/context.rb', line 11 def warnings @warnings end |
Instance Method Details
#capture_group ⇒ Object
group context
49 50 51 |
# File 'lib/js_regex/converter/context.rb', line 49 def capture_group self.capturing_group_count = capturing_group_count + 1 end |
#end_atomic_group ⇒ Object
57 58 59 |
# File 'lib/js_regex/converter/context.rb', line 57 def end_atomic_group self.in_atomic_group = false end |
#multiline? ⇒ Boolean
option context
31 32 33 |
# File 'lib/js_regex/converter/context.rb', line 31 def multiline? .fetch(:m) end |
#negate_base_set ⇒ Object
set context
37 38 39 |
# File 'lib/js_regex/converter/context.rb', line 37 def negate_base_set self.negative_base_set = true end |
#new_capturing_group_position(old_position) ⇒ Object
takes and returns 1-indexed group positions. new is different from old if capturing groups were added in between.
72 73 74 75 76 77 78 |
# File 'lib/js_regex/converter/context.rb', line 72 def new_capturing_group_position(old_position) increment = 0 added_capturing_groups_after_group.each do |after_n_groups, count| increment += count if after_n_groups < old_position end old_position + increment end |
#original_capturing_group_count ⇒ Object
80 81 82 |
# File 'lib/js_regex/converter/context.rb', line 80 def original_capturing_group_count capturing_group_count - total_added_capturing_groups end |
#reset_set_context ⇒ Object
41 42 43 44 45 |
# File 'lib/js_regex/converter/context.rb', line 41 def reset_set_context self.buffered_set_extractions = [] self.buffered_set_members = [] self.negative_base_set = false end |
#start_atomic_group ⇒ Object
53 54 55 |
# File 'lib/js_regex/converter/context.rb', line 53 def start_atomic_group self.in_atomic_group = true end |
#store_named_group_position(name) ⇒ Object
88 89 90 |
# File 'lib/js_regex/converter/context.rb', line 88 def store_named_group_position(name) named_group_positions[name] = capturing_group_count + 1 end |
#total_added_capturing_groups ⇒ Object
84 85 86 |
# File 'lib/js_regex/converter/context.rb', line 84 def total_added_capturing_groups added_capturing_groups_after_group.values.inject(0, &:+) end |
#wrap_in_backrefed_lookahead(content) ⇒ Object
61 62 63 64 65 66 67 68 |
# File 'lib/js_regex/converter/context.rb', line 61 def wrap_in_backrefed_lookahead(content) new_backref_num = capturing_group_count + 1 # an empty passive group (?:) is appended as literal digits may follow result = "(?=(#{content}))\\#{new_backref_num}(?:)" added_capturing_groups_after_group[original_capturing_group_count] += 1 capture_group result end |