Class: Rattler::Parsers::DirectAction
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::DirectAction
- Includes:
- Combining
- Defined in:
- lib/rattler/parsers/direct_action.rb
Overview
DirectAction
decorates a parser to peform a symantic action on success by evaluating ruby code.
Class Method Summary collapse
Instance Method Summary collapse
- #bind(scope, bind_args) ⇒ Object
- #bindable_code ⇒ Object
-
#parse(scanner, rules, scope = {}) ⇒ Object
If the wrapped parser matches at the parse position, return the result of applying the symantic action, otherwise return a false value.
Methods included from Combining
Methods inherited from Parser
#&, #capturing?, #labeled?, #one_or_more, #optional, #skip, #variable_capture_count?, #with_ws, #zero_or_more, #|
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
.[](child, code) ⇒ Object
20 21 22 |
# File 'lib/rattler/parsers/direct_action.rb', line 20 def self.[](child, code) self.new(child, :code => code) end |
.parsed(results, *_) ⇒ Object
25 26 27 |
# File 'lib/rattler/parsers/direct_action.rb', line 25 def self.parsed(results, *_) #:nodoc: self[*results] end |
Instance Method Details
#bind(scope, bind_args) ⇒ Object
52 53 54 |
# File 'lib/rattler/parsers/direct_action.rb', line 52 def bind(scope, bind_args) bindable_code.bind(scope, bind_args) end |
#bindable_code ⇒ Object
48 49 50 |
# File 'lib/rattler/parsers/direct_action.rb', line 48 def bindable_code @bindable_code ||= ActionCode.new(code) end |
#parse(scanner, rules, scope = {}) ⇒ Object
If the wrapped parser matches at the parse position, return the result of applying the symantic action, otherwise return a false value.
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/rattler/parsers/direct_action.rb', line 36 def parse(scanner, rules, scope = {}) if result = parse_child(child, scanner, rules, scope) {|_| scope = _ } if not capturing? apply([]) elsif result.respond_to?(:to_ary) apply(result, scope) else apply([result], scope) end end end |