class Rattler::Parsers::Label

Label decorates a parser and associates a label with the decorated parser’s parse result if successful. The label only applies if nested in a Choice or Sequence decorated by an Action.

Public Class Methods

[](label, parser) click to toggle source

Create a new parser that decorates parser and associates label with parser‘s parse result on success.

# File lib/rattler/parsers/label.rb, line 18
def self.[](label, parser)
  self.new(parser, :label => label.to_sym)
end

Public Instance Methods

capturing_decidable?() click to toggle source

(see Parser#capturing_decidable?)

# File lib/rattler/parsers/label.rb, line 23
def capturing_decidable?
  child.capturing_decidable?
end
labeled?() click to toggle source

@return true

# File lib/rattler/parsers/label.rb, line 28
def labeled?
  true
end
parse(scanner, rules, scope = ParserScope.empty) { |bind(label => result)| ... } click to toggle source

Delegate to the decorated parser and associate label with the parse result if successful.

@param (see Match#parse)

@return the decorated parser’s parse result

# File lib/rattler/parsers/label.rb, line 38
def parse(scanner, rules, scope = ParserScope.empty)
  if result = child.parse(scanner, rules, scope) {|_| scope = _ }
    yield scope.bind(label => result) if block_given?
    result
  end
end