Class: Rsec::RepeatAtLeastN
- Inherits:
-
Struct
- Object
- Struct
- Rsec::RepeatAtLeastN
- Includes:
- Parser
- Defined in:
- lib/rsec/parsers/repeat.rb
Overview
repeat at least n.abs times <- [n, inf) <br/>
Instance Attribute Summary collapse
-
#base ⇒ Object
Returns the value of attribute base.
-
#n ⇒ Object
Returns the value of attribute n.
Attributes included from Parser
Instance Method Summary collapse
Methods included from Parser
#&, #*, #<<, #>>, #^, #cached, #eof, #fail, #inspect, #join, #map, #maybe, #parse, #parse!, #star, #|
Instance Attribute Details
#base ⇒ Object
Returns the value of attribute base
66 67 68 |
# File 'lib/rsec/parsers/repeat.rb', line 66 def base @base end |
#n ⇒ Object
Returns the value of attribute n
66 67 68 |
# File 'lib/rsec/parsers/repeat.rb', line 66 def n @n end |
Instance Method Details
#_parse(ctx) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rsec/parsers/repeat.rb', line 68 def _parse ctx rp_node = [] n.times do res = base._parse(ctx) return INVALID if INVALID[res] rp_node.push res end # note this may be an infinite action # returns if the pos didn't change loop do save = ctx.pos res = base._parse ctx if (INVALID[res] or ctx.pos == save) ctx.pos = save break end rp_node.push res end rp_node end |