Class: Rsec::JoinOdd

Inherits:
Binary
  • Object
show all
Defined in:
lib/rsec/parsers/join.rb,
lib/rsec/helpers.rb

Overview

keep only inters NOTE if only 1 token matches, return empty array

Instance Attribute Summary

Attributes inherited from Binary

#left, #right

Attributes included from Parser

#name

Instance Method Summary collapse

Methods included from Parser

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

Instance Method Details

#_parse(ctx) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/rsec/parsers/join.rb', line 61

def _parse ctx
  e = left._parse ctx
  return INVALID if INVALID[e]
  ret = []
  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
  end # loop
  ret
end

#unbox(&p) ⇒ Object



385
386
387
# File 'lib/rsec/helpers.rb', line 385

def unbox &p
  Unbox[self].map p
end