Class: Rattler::Parsers::NodeAction
- Inherits:
-
Parser
- Object
- Util::Node
- Parser
- Rattler::Parsers::NodeAction
- Includes:
- Semantic
- Defined in:
- lib/rattler/parsers/node_action.rb
Overview
NodeAction
is a pseudo-parser that creates a parse node object from captured parse results
Constant Summary collapse
- DEFAULT_NODE_TYPE =
'Rattler::Runtime::ParseNode'
- DEFAULT_FACTORY_METHOD =
:parsed
Class Method Summary collapse
-
.[](node_type, attrs = {}) ⇒ NodeAction
A pseudo-parser that creates parse nodes.
- .parsed(results, *_) ⇒ Object
Instance Method Summary collapse
-
#factory_method ⇒ Symbol
The class method used to create new parse nodes.
-
#node_attrs ⇒ Hash
Attributes to add to the instantiated node.
-
#node_type ⇒ Symbol
The name of the class to instantiate nodes from.
-
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
Create a new parse node from parse results in
scope
.
Methods included from Semantic
#bind, #bindable_code, #semantic?
Methods inherited from Parser
#&, #>>, #capturing?, #capturing_decidable?, #labeled?, #list, #one_or_more, #optional, #repeat, #semantic?, #sequence?, #skip, #variable_capture_count?, #with_ws, #zero_or_more, #|
Methods included from Runtime::ParserHelper
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
.[](node_type, attrs = {}) ⇒ NodeAction
Returns a pseudo-parser that creates parse nodes.
35 36 37 |
# File 'lib/rattler/parsers/node_action.rb', line 35 def self.[](node_type, attrs={}) self.new(attrs.merge :node_type => node_type) end |
.parsed(results, *_) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/rattler/parsers/node_action.rb', line 12 def self.parsed(results, *_) #:nodoc: optional_node_def, optional_name = results attrs = {} unless optional_name.empty? attrs[:node_attrs] = {:name => eval(optional_name[0], TOPLEVEL_BINDING)} end if optional_node_def.empty? self[DEFAULT_NODE_TYPE, attrs] else node_type, optional_method = optional_node_def[0] attrs[:method] = optional_method[0] unless optional_method.empty? self[node_type, attrs] end end |
Instance Method Details
#factory_method ⇒ Symbol
Returns the class method used to create new parse nodes.
50 51 52 |
# File 'lib/rattler/parsers/node_action.rb', line 50 def factory_method (attrs[:method] || DEFAULT_FACTORY_METHOD).to_sym end |
#node_attrs ⇒ Hash
Returns attributes to add to the instantiated node.
45 46 47 |
# File 'lib/rattler/parsers/node_action.rb', line 45 def node_attrs attrs[:node_attrs] || {} end |
#node_type ⇒ Symbol
Returns the name of the class to instantiate nodes from.
40 41 42 |
# File 'lib/rattler/parsers/node_action.rb', line 40 def node_type (attrs[:node_type] || DEFAULT_NODE_TYPE).to_sym end |
#parse(scanner, rules, scope = ParserScope.empty) ⇒ Object
Create a new parse node from parse results in scope
59 60 61 |
# File 'lib/rattler/parsers/node_action.rb', line 59 def parse(scanner, rules, scope = ParserScope.empty) apply scope end |