Method: RPEG#R

Defined in:
lib/rpeg/rpeg.rb

#R(*ranges) ⇒ Object

Given a 2-char string xy, the ASCII range x..y. Each argument gives a range and we match on their union.

Always represent with a Set.



142
143
144
145
146
147
148
149
150
151
152
153
# File 'lib/rpeg/rpeg.rb', line 142

def R(*ranges)
  return P(false) if ranges.empty?

  check = lambda do |str|
    raise "Bad data #{str} for Pattern#R" unless str.is_a?(String) && str.size == 2

    Set.new ((str[0])..(str[1])).to_a
  end

  result = ranges.map{ check.call(_1) }.reduce(:|)
  S(result)
end