Class: Rsec::RepeatRange
- Inherits:
-
Object
- Object
- Rsec::RepeatRange
- Includes:
- Parser
- Defined in:
- lib/rsec/parsers/repeat.rb
Overview
repeat from range.begin.abs to range.end.abs <br/> note: range’s max should always be > 0<br/>
see also helpers
Instance Attribute Summary
Attributes included from Parser
Class Method Summary collapse
Instance Method Summary collapse
- #_parse(ctx) ⇒ Object
-
#initialize(base, range) ⇒ RepeatRange
constructor
A new instance of RepeatRange.
Methods included from Parser
#&, #*, #<<, #>>, #^, #cached, #eof, #fail, #inspect, #join, #map, #maybe, #parse, #parse!, #star, #|
Constructor Details
#initialize(base, range) ⇒ RepeatRange
Returns a new instance of RepeatRange.
27 28 29 30 31 |
# File 'lib/rsec/parsers/repeat.rb', line 27 def initialize base, range @base = base @at_least = range.min.abs @optional = range.max - @at_least end |
Class Method Details
.[](base, range) ⇒ Object
23 24 25 |
# File 'lib/rsec/parsers/repeat.rb', line 23 def self.[] base, range self.new base, range end |
Instance Method Details
#_parse(ctx) ⇒ Object
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rsec/parsers/repeat.rb', line 33 def _parse ctx rp_node = [] @at_least.times do res = @base._parse ctx return INVALID if INVALID[res] rp_node.push res end @optional.times do save = ctx.pos res = @base._parse ctx if INVALID[res] ctx.pos = save break end rp_node.push res end rp_node end |