Class: RegexpExamples::Parser
- Inherits:
-
Object
- Object
- RegexpExamples::Parser
- Includes:
- CharsetNegationHelper, ParseAfterBackslashGroupHelper, ParseGroupHelper, ParseMultiGroupHelper, ParseRepeaterHelper
- Defined in:
- lib/regexp-examples/parser.rb
Overview
A Regexp parser, used to build a structured collection of objects that represents the regular expression. This object can then be used to generate strings that match the regular expression.
Instance Attribute Summary collapse
-
#regexp_string ⇒ Object
readonly
Returns the value of attribute regexp_string.
Instance Method Summary collapse
-
#initialize(regexp_string, regexp_options) ⇒ Parser
constructor
A new instance of Parser.
- #parse ⇒ Object
Methods included from CharsetNegationHelper
Constructor Details
#initialize(regexp_string, regexp_options) ⇒ Parser
Returns a new instance of Parser.
22 23 24 25 26 27 28 29 |
# File 'lib/regexp-examples/parser.rb', line 22 def initialize(regexp_string, ) @regexp_string = regexp_string @ignorecase = !( & Regexp::IGNORECASE).zero? @multiline = !( & Regexp::MULTILINE).zero? @extended = !( & Regexp::EXTENDED).zero? @num_groups = 0 @current_position = 0 end |
Instance Attribute Details
#regexp_string ⇒ Object (readonly)
Returns the value of attribute regexp_string.
20 21 22 |
# File 'lib/regexp-examples/parser.rb', line 20 def regexp_string @regexp_string end |
Instance Method Details
#parse ⇒ Object
31 32 33 34 35 36 37 38 39 40 |
# File 'lib/regexp-examples/parser.rb', line 31 def parse repeaters = [PlaceHolderGroup.new] until end_of_regexp group = parse_group(repeaters) return [group] if group.is_a? OrGroup @current_position += 1 repeaters << parse_repeater(group) end repeaters end |