Class: Rattler::Parsers::Rule
- Inherits:
-
Util::Node
- Object
- Util::Node
- Rattler::Parsers::Rule
- Defined in:
- lib/rattler/parsers/rule.rb
Overview
Rule
is a binding for a parser that can be referenced by name from another rule.
Class Method Summary collapse
-
.[](name, parser, attrs = {}) ⇒ Rule
Create a new
Rule
.
Instance Method Summary collapse
-
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
Parse using the rule body and on success return the result, on failure return a false value.
-
#with_ws(ws) ⇒ Parser
A new parser that uses
ws
to skip whitespace.
Methods inherited from Util::Node
#==, #[], #attrs, #can_equal?, #child, #children, #each, #empty?, #eql?, #initialize, #inspect, #method_missing, #name, #pretty_print, #pretty_print_cycle, #respond_to?, #same_contents?, #to_graphviz, #with_attrs, #with_attrs!, #with_children
Constructor Details
This class inherits a constructor from Rattler::Util::Node
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Rattler::Util::Node
Class Method Details
.[](name, parser, attrs = {}) ⇒ Rule
Create a new Rule
.
15 16 17 |
# File 'lib/rattler/parsers/rule.rb', line 15 def self.[](name, parser, attrs={}) self.new(parser, attrs.merge(:name => name.to_sym)) end |
Instance Method Details
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
Parse using the rule body and on success return the result, on failure return a false value.
26 27 28 29 30 31 |
# 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) ⇒ Parser
Returns a new parser that uses ws
to skip whitespace.
36 37 38 |
# File 'lib/rattler/parsers/rule.rb', line 36 def with_ws(ws) self.with_expr expr.with_ws(ws) end |