Class: Rsec::Join
- Defined in:
- lib/rsec/parsers/join.rb,
lib/rsec/helpers.rb
Overview
Join base
Instance Attribute Summary
Attributes inherited from Binary
Attributes included from Parser
Instance Method Summary collapse
- #_parse(ctx) ⇒ Object
-
#even(&p) ⇒ Object
@ desc.join Only keep the even(left, token) parts.
-
#odd(&p) ⇒ Object
@ desc.join Only keep the odd(right, inter) parts.
- #unbox(&p) ⇒ Object
Methods included from Parser
#&, #*, #<<, #>>, #^, #cached, #eof, #fail, #inspect, #join, #map, #maybe, #parse, #parse!, #star, #|
Instance Method Details
#_parse(ctx) ⇒ Object
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rsec/parsers/join.rb', line 5 def _parse ctx e = left._parse ctx return INVALID if INVALID[e] ret = [e] loop do save_point = ctx.pos i = right._parse ctx if INVALID[i] ctx.pos = save_point break end t = left._parse ctx if INVALID[t] ctx.pos = save_point break end break if save_point == ctx.pos # stop if no advance, prevent infinite loop ret << i ret << t end # loop ret end |
#even(&p) ⇒ Object
@ desc.join
Only keep the even(left, token) parts
367 368 369 |
# File 'lib/rsec/helpers.rb', line 367 def even &p JoinEven[left, Rsec.try_skip_pattern(right)].map p end |
#odd(&p) ⇒ Object
@ desc.join
Only keep the odd(right, inter) parts
373 374 375 |
# File 'lib/rsec/helpers.rb', line 373 def odd &p JoinOdd[Rsec.try_skip_pattern(left), right].map p end |
#unbox(&p) ⇒ Object
361 362 363 |
# File 'lib/rsec/helpers.rb', line 361 def unbox &p Unbox[self].map p end |