Class: Rsec::RepeatAtLeastN

Inherits:
Struct
  • Object
show all
Includes:
Parser
Defined in:
lib/rsec/parsers/repeat.rb

Overview

repeat at least n.abs times <- [n, inf) <br/>

Instance Attribute Summary collapse

Attributes included from Parser

#name

Instance Method Summary collapse

Methods included from Parser

#&, #*, #<<, #>>, #^, #cached, #eof, #fail, #inspect, #join, #map, #maybe, #parse, #parse!, #star, #|

Instance Attribute Details

#baseObject

Returns the value of attribute base

Returns:

  • (Object)

    the current value of base



66
67
68
# File 'lib/rsec/parsers/repeat.rb', line 66

def base
  @base
end

#nObject

Returns the value of attribute n

Returns:

  • (Object)

    the current value of 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