Class: Treetop::Runtime::SyntaxNode
- Defined in:
- lib/rulex/tex/node_extensions.rb
Direct Known Subclasses
Instance Method Summary collapse
- #content ⇒ Object
-
#node_content ⇒ Object
Goes through all its SyntaxNode children to build a Hash and Array based tree of the parsed document.
-
#to_a ⇒ Array
Build an Array of its children and returns it.
Instance Method Details
#content ⇒ Object
32 33 34 |
# File 'lib/rulex/tex/node_extensions.rb', line 32 def content {} end |
#node_content ⇒ Object
Goes through all its SyntaxNode children to build a Hash and Array based tree of the parsed document. A node_content is a Hash, containing a :type, and maybe containing :children. If node_content contains :children, they must form an Array. That is:
* node_content MUST be a Hash that
* MUST contain an entry :type of type Symbol or String
* MAY contain an entry :children, which then MUST be of type Array
* MAY contain any other kind of entries
The before it is returned, the node_content is merged with the result from #content.
19 20 21 22 23 24 |
# File 'lib/rulex/tex/node_extensions.rb', line 19 def node_content h = {type: :node} #, log: elements.to_s} h.merge!(:children => elements.map{|e| e.node_content}) if elements && !elements.empty? h.merge!(log: text_value) h.merge! content end |
#to_a ⇒ Array
Build an Array of its children and returns it. Each children is a Hash (description in #node_content).
28 29 30 |
# File 'lib/rulex/tex/node_extensions.rb', line 28 def to_a elements.map{|e| e.node_content} if elements end |