Class: PEG::OneOrMore

Inherits:
Sequence show all
Defined in:
lib/peg.rb

Direct Known Subclasses

Optional, ZeroOrMore

Class Attribute Summary collapse

Attributes inherited from Rule

#children

Instance Method Summary collapse

Methods inherited from Sequence

#_inspect

Methods inherited from Rule

#initialize, #inspect, #name, #parse, #result

Methods inherited from ValueObject

#==

Constructor Details

This class inherits a constructor from PEG::Rule

Class Attribute Details

.rangeObject

Returns the value of attribute range.



126
127
128
# File 'lib/peg.rb', line 126

def range
  @range
end

Instance Method Details

#match(text) ⇒ Object



129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
# File 'lib/peg.rb', line 129

def match(text)
  text_ = String.new(text)
  len = 0
  children = []
  loop do
    node = @children[0].match(text_)
    break if not node
    children << node
    break if node.text == ''
    text_ = text_.slice node.text.length..text_.length
    len += node.text.length
  end
  in_range = self.class.range.include?(children.length)
  in_range ? result(text.slice(0...len), children) : nil
end