class Rattler::Parsers::Rule

Rule is a binding for a parser that can be referenced by name from another rule.

Public Class Methods

[](name, parser, attrs={}) click to toggle source

Create a new Rule.

@param [Symbol, String] name the name of the new rule @param [Parser] parser the parser that defines the rule body

@return [Rule] a new parse rule

# File lib/rattler/parsers/rule.rb, line 15
def self.[](name, parser, attrs={})
  self.new(parser, attrs.merge(:name => name.to_sym))
end

Public Instance Methods

parse(scanner, rules, scope = ParserScope.empty) click to toggle source

Parse using the rule body and on success return the result, on failure return a false value.

@param (see Match#parse) @return (see Match#parse)

# File lib/rattler/parsers/rule.rb, line 26
def parse(scanner, rules, scope = ParserScope.empty)
  catch(:rule_failed) do
    return expr.parse(scanner, rules, scope)
  end
  false
end
with_ws(ws) click to toggle source

(see Parser#with_ws)

# File lib/rattler/parsers/rule.rb, line 36
def with_ws(ws)
  self.with_expr expr.with_ws(ws)
end