Method: RPEG#C

Defined in:
lib/rpeg/rpeg.rb

#C(pattern) ⇒ Object

LPEG: Creates a simple capture, which captures the substring of the subject that matches patt. The captured value is a string. If patt has other captures, their values are returned after this one.

Note: it appears that when a simple capture is over another simple capture - like C(C(patt)) - we squeeze out the duplication. See this test at l.216 of test.lua:

assert(#m.match(m.C(m.C(i)), string.rep('a', i)) == i)

(In lua the # operator gives the size of a string or table)



176
177
178
179
180
181
# File 'lib/rpeg/rpeg.rb', line 176

def C(pattern)
  pattern = P(pattern)
  return pattern if pattern.type == Pattern::CAPTURE && pattern.capture == Capture::SIMPLE

  Pattern.new(Pattern::CAPTURE, pattern, capture: Capture::SIMPLE)
end