capture.rb

Path: lib/parslet/atoms/capture.rb
Last Update: Fri Jul 15 14:35:39 -0400 2016

Stores the result of matching an atom against input in the captures in parse context. Doing so will allow you to pull parts of the ongoing parse out later and use them to match other pieces of input.

Example:

  # After this, context.captures[:an_a] returns 'a'
  str('a').capture(:an_a)

  # Capture and use of the capture: (matches either 'aa' or 'bb')
  match['ab'].capture(:first) >>
    dynamic { |src, ctx| str(ctx.captures[:first]) }

[Validate]