Class: OneOrMoreOfPattern

Inherits:
RepeatablePattern show all
Defined in:
lib/ruby_grammar_builder/pattern_extensions/one_or_more_of.rb

Overview

An optional repeated pattern for some pattern ‘p` this is equivalent to (?:p+)

Instance Attribute Summary

Attributes inherited from RepeatablePattern

#at_least, #at_most

Attributes inherited from PatternBase

#arguments, #match, #next_pattern, #original_arguments

Instance Method Summary collapse

Methods inherited from RepeatablePattern

#add_quantifier_options_to, #do_add_attributes, #do_evaluate_self, #process_quantifiers_from_arguments, #self_capture_group_rematch, #simple_quantifier

Methods inherited from PatternBase

#==, #__deep_clone__, #__deep_clone_self__, #collect_group_attributes, #convert_group_attributes_to_captures, #convert_includes_to_patterns, #do_add_attributes, #do_collect_self_groups, #do_evaluate_self, #each, #eql?, #evaluate, #evaluate_operator, #fixup_regex_references, #groupless, #groupless?, #hash, #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, #single_entity?, #start_pattern, #then, #to_r, #to_s, #to_tag, #transform_includes, #transform_tag_as, #zeroOrMoreOf

Constructor Details

#initialize(*args) ⇒ OneOrMoreOfPattern

Returns a new instance of OneOrMoreOfPattern.



6
7
8
9
10
11
12
# File 'lib/ruby_grammar_builder/pattern_extensions/one_or_more_of.rb', line 6

def initialize(*args)
    # run the normal pattern
    super(*args)
    # add quantifying options
    @at_least = 1
    @at_most = nil
end

Instance Method Details

#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

Parameters:

  • top_level (Boolean)

    is this top_level or chained

Returns:

  • (String)

    the name of the method



21
22
23
# File 'lib/ruby_grammar_builder/pattern_extensions/one_or_more_of.rb', line 21

def do_get_to_s_name(top_level)
    top_level ? "oneOrMoreOf(" : ".oneOrMoreOf("
end

#quantifying_allowed?Boolean, false

Note:

override when inheriting. Return false unless the subclass allow quantifying

Note:

the default implementation returns True

controls weather @arguments et. al. set @at_most et. al.

Returns:

  • (Boolean)

    if quantifying is allowed

  • (false)


16
17
18
# File 'lib/ruby_grammar_builder/pattern_extensions/one_or_more_of.rb', line 16

def quantifying_allowed?
    false
end