Class: LookAroundPattern
- Inherits:
-
PatternBase
- Object
- PatternBase
- LookAroundPattern
- Defined in:
- lib/ruby_grammar_builder/pattern_extensions/lookaround_pattern.rb
Overview
Implements lookarounds for some pattern p this is equivalent to one of /(?=p)/, /(?!p)/, /(?<p)/, /(?<!p)/ depending on the type
Instance Attribute Summary
Attributes inherited from PatternBase
#arguments, #match, #next_pattern, #original_arguments
Instance Method Summary collapse
-
#do_add_attributes(indent) ⇒ String
return a string of any additional attributes that need to be added to the #to_s output indent is a string with the amount of space the parent block is indented, attributes are indented 2 more spaces called by #to_s.
-
#do_evaluate_self(groups) ⇒ String
evaluates @match.
-
#do_get_to_s_name(top_level) ⇒ String
What is the name of the method that the user would call top_level is if a freestanding or chaining function is called called by #to_s.
- #single_entity? ⇒ true
Methods inherited from PatternBase
#==, #__deep_clone__, #__deep_clone_self__, #collect_group_attributes, #convert_group_attributes_to_captures, #convert_includes_to_patterns, #do_collect_self_groups, #each, #eql?, #evaluate, #evaluate_operator, #fixup_regex_references, #groupless, #groupless?, #hash, #initialize, #insert, #insert!, #inspect, #lookAheadFor, #lookAheadToAvoid, #lookAround, #lookBehindFor, #lookBehindToAvoid, #map, #map!, #map_includes!, #matchResultOf, #maybe, #name, #needs_to_capture?, #oneOf, #oneOrMoreOf, #optimize_outer_group?, #or, #placeholder, #raise_if_regex_has_capture_group, #reTag, #recursivelyMatch, #resolve, #run_self_tests, #run_tests, #self_scramble_references, #start_pattern, #then, #to_r, #to_s, #to_tag, #transform_includes, #transform_tag_as, #zeroOrMoreOf
Constructor Details
This class inherits a constructor from PatternBase
Instance Method Details
#do_add_attributes(indent) ⇒ String
return a string of any additional attributes that need to be added to the #to_s output indent is a string with the amount of space the parent block is indented, attributes are indented 2 more spaces called by #to_s
34 35 36 |
# File 'lib/ruby_grammar_builder/pattern_extensions/lookaround_pattern.rb', line 34 def do_add_attributes(indent) ",\n#{indent} type: :#{@arguments[:type]}" end |
#do_evaluate_self(groups) ⇒ String
optionally override when inheriting
by default this optionally adds a capture group
evaluates @match
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/ruby_grammar_builder/pattern_extensions/lookaround_pattern.rb', line 10 def do_evaluate_self(groups) self_regex = @match self_regex = @match.evaluate(groups) if @match.is_a? PatternBase case @arguments[:type] when :lookAheadFor then self_regex = "(?=#{self_regex})" when :lookAheadToAvoid then self_regex = "(?!#{self_regex})" when :lookBehindFor then self_regex = "(?<=#{self_regex})" when :lookBehindToAvoid then self_regex = "(?<!#{self_regex})" end if needs_to_capture? raise "You cannot capture a lookAround\nconsider capturing the pattern inside" end self_regex end |
#do_get_to_s_name(top_level) ⇒ String
What is the name of the method that the user would call top_level is if a freestanding or chaining function is called called by #to_s
29 30 31 |
# File 'lib/ruby_grammar_builder/pattern_extensions/lookaround_pattern.rb', line 29 def do_get_to_s_name(top_level) top_level ? "lookAround(" : ".lookAround(" end |
#single_entity? ⇒ true
40 41 42 |
# File 'lib/ruby_grammar_builder/pattern_extensions/lookaround_pattern.rb', line 40 def single_entity? true end |