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 = {}) ⇒ Object
Parse using
scanner
andrules
and on success return the result, on failure return a false value. - #with_expr(new_expr) ⇒ Object
-
#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, #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
.
25 26 27 |
# File 'lib/rattler/parsers/rule.rb', line 25 def self.[](name, parser, attrs={}) self.new(parser, attrs.merge(:name => name.to_sym)) end |
Instance Method Details
#parse(scanner, rules, scope = {}) ⇒ Object
Parse using scanner
and rules
and on success return the result, on failure return a false value.
38 39 40 41 42 43 |
# File 'lib/rattler/parsers/rule.rb', line 38 def parse(scanner, rules, scope = {}) catch(:rule_failed) do return expr.parse(scanner, rules, scope) end false end |
#with_expr(new_expr) ⇒ Object
45 46 47 |
# File 'lib/rattler/parsers/rule.rb', line 45 def with_expr(new_expr) Rule[name, new_expr, attrs] end |
#with_ws(ws) ⇒ Parser
Returns a new parser that uses ws
to skip whitespace.
51 52 53 |
# File 'lib/rattler/parsers/rule.rb', line 51 def with_ws(ws) self.with_expr expr.with_ws(ws) end |