Class: Rattler::Runtime::ParseNode
- Inherits:
-
Util::Node
- Object
- Util::Node
- Rattler::Runtime::ParseNode
- Defined in:
- lib/rattler/runtime/parse_node.rb
Overview
ParseNode is intended as s a convenient class to use as a parsing result type.
Class Method Summary collapse
-
.parsed(children, attrs = {}) ⇒ ParseNode
Create a parse node from the results of a parsing expression.
Instance Method Summary collapse
-
#[](*args) ⇒ Object
Access the parse node’s children.
-
#eql?(other) ⇒ Boolean
Return
trueif the node has the same value asother, i.e. -
#labeled ⇒ Hash
Return a hash associating labels with the labeled children.
-
#method_missing(symbol, *args) ⇒ Object
Allow labeled children to be accessed as methods.
- #respond_to?(symbol) ⇒ Boolean
Methods inherited from Util::Node
#==, [], #attrs, #can_equal?, #child, #children, #each, #empty?, #initialize, #inspect, #name, #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
#method_missing(symbol, *args) ⇒ Object
Allow labeled children to be accessed as methods.
76 77 78 |
# File 'lib/rattler/runtime/parse_node.rb', line 76 def method_missing(symbol, *args) (args.empty? and labeled.has_key?(symbol)) ? labeled[symbol] : super end |
Class Method Details
.parsed(children, attrs = {}) ⇒ ParseNode
Create a parse node from the results of a parsing expression.
26 27 28 |
# File 'lib/rattler/runtime/parse_node.rb', line 26 def self.parsed(children, attrs={}) self.new(children, attrs.reject {|_, val| val.nil? }) end |
Instance Method Details
#[](index) ⇒ Object #[](start, length) ⇒ Array #[](range) ⇒ Array #[](label) ⇒ Object
Access the parse node’s children.
51 52 53 54 55 56 57 |
# File 'lib/rattler/runtime/parse_node.rb', line 51 def [](*args) if args.size == 1 and args.first.is_a?(Symbol) labeled[args[0]] else super end end |
#eql?(other) ⇒ Boolean
Return true if the node has the same value as other, i.e. other is an instance of the same class and has equal children and attributes and the children are labeled the same.
70 71 72 73 |
# File 'lib/rattler/runtime/parse_node.rb', line 70 def eql?(other) #:nodoc super && self.labeled == other.labeled end |
#labeled ⇒ Hash
Return a hash associating labels with the labeled children
61 62 63 |
# File 'lib/rattler/runtime/parse_node.rb', line 61 def labeled attrs.fetch(:labeled, {}) end |
#respond_to?(symbol) ⇒ Boolean
81 82 83 |
# File 'lib/rattler/runtime/parse_node.rb', line 81 def respond_to?(symbol) #:nodoc: super || labeled.has_key?(symbol) end |