Class: Rsec::Seq_
- Inherits:
-
Struct
- Object
- Struct
- Rsec::Seq_
- Includes:
- Parser
- Defined in:
- lib/rsec/parsers/seq.rb,
lib/rsec/helpers.rb
Overview
skips skipper between tokens
Instance Attribute Summary collapse
-
#first ⇒ Object
Returns the value of attribute first.
-
#rest ⇒ Object
Returns the value of attribute rest.
-
#skipper ⇒ Object
Returns the value of attribute skipper.
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
#first ⇒ Object
Returns the value of attribute first
32 33 34 |
# File 'lib/rsec/parsers/seq.rb', line 32 def first @first end |
#rest ⇒ Object
Returns the value of attribute rest
32 33 34 |
# File 'lib/rsec/parsers/seq.rb', line 32 def rest @rest end |
#skipper ⇒ Object
Returns the value of attribute skipper
32 33 34 |
# File 'lib/rsec/parsers/seq.rb', line 32 def skipper @skipper end |
Instance Method Details
#[](idx, &p) ⇒ Object
340 341 342 343 344 345 346 347 348 349 |
# File 'lib/rsec/helpers.rb', line 340 def [] idx, &p raise 'index out of range' if idx > rest.size or idx < 0 # optimize parsers, use skip if possible new_first = (0 == idx ? first : Rsec.try_skip_pattern(first)) new_rest = rest().map.with_index do |p, i| # NOTE rest start with 1 (i+1) == idx ? p : Rsec.try_skip_pattern(p) end SeqOne_[new_first, new_rest, skipper, idx].map p end |
#_parse(ctx) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/rsec/parsers/seq.rb', line 35 def _parse ctx res = first._parse ctx return INVALID if INVALID[res] ret = [res] rest.each do |e| return INVALID if INVALID[skipper._parse ctx] res = e._parse ctx return INVALID if INVALID[res] ret << res end ret end |
#inner(&p) ⇒ Object
355 356 357 |
# File 'lib/rsec/helpers.rb', line 355 def inner &p Inner[self].map p end |
#unbox(&p) ⇒ Object
351 352 353 |
# File 'lib/rsec/helpers.rb', line 351 def unbox &p Unbox[self].map p end |