Method: RPEG#Cc

Defined in:
lib/rpeg/rpeg.rb

#Cc(*values) ⇒ Object

LPEG: Creates a constant capture. This pattern matches the empty string and produces all given values as its captured values.

No value at all - Cc() - adds nothing to the result, which is different from a value of nil.

We capture several values with individual captures.



213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/rpeg/rpeg.rb', line 213

def Cc(*values)
  return P(true) if values.empty?

  patt = Pattern.new(Pattern::CAPTURE, P(true), data: values.first, capture: Capture::CONST)
  return patt if values.size == 1

  # Otherwise, follow LPEG and make an anonymous Group capture over a sequence of single-val const captures
  values[1...].each do |val|
    patt *= Cc(val)
  end
  Cg(patt)
end