class Rattler::Parsers::NodeAction
NodeAction
is a pseudo-parser that creates a parse node object from captured parse results
Constants
- DEFAULT_FACTORY_METHOD
- DEFAULT_NODE_TYPE
Public Class Methods
@param [String,Symbol] node_type
the name of the class to instantiate
nodes from
@param [Hash] attrs attributes defining how to instantiate the node @option attrs [Hash] :node_attrs ({}) attributes to add to new parse
nodes
@option attrs [Strin,Symbol] :method (:parsed) the class method used to
create new parse nodes
@return [NodeAction] a pseudo-parser that creates parse nodes
# File lib/rattler/parsers/node_action.rb, line 35 def self.[](node_type, attrs={}) self.new(attrs.merge :node_type => node_type) end
Public Instance Methods
@return [Symbol] the class method used to create new parse nodes
# File lib/rattler/parsers/node_action.rb, line 50 def factory_method (attrs[:method] || DEFAULT_FACTORY_METHOD).to_sym end
@return [Hash] attributes to add to the instantiated node
# File lib/rattler/parsers/node_action.rb, line 45 def node_attrs attrs[:node_attrs] || {} end
@return [Symbol] the name of the class to instantiate nodes from
# File lib/rattler/parsers/node_action.rb, line 40 def node_type (attrs[:node_type] || DEFAULT_NODE_TYPE).to_sym end
Create a new parse node from parse results in scope
@param (see Match#parse
)
@return a new parse node created from parse results in scope
# File lib/rattler/parsers/node_action.rb, line 59 def parse(scanner, rules, scope = ParserScope.empty) apply scope end
Protected Instance Methods
@return [NodeCode] an object that be bound to a parser scope to return
ruby code that creates a new node
# File lib/rattler/parsers/node_action.rb, line 67 def create_bindable_code NodeCode.new(node_type, factory_method, node_attrs) end