Class: Treetop::Runtime::SyntaxNode

Inherits:
Object
  • Object
show all
Defined in:
lib/rulex/tex/node_extensions.rb

Direct Known Subclasses

Rulex::Tex::Grammar::CustomNode

Instance Method Summary collapse

Instance Method Details

#contentObject



32
33
34
# File 'lib/rulex/tex/node_extensions.rb', line 32

def content
  {}
end

#node_contentObject

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.

Returns:

  • the Hash object of the node’s 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_aArray

Build an Array of its children and returns it. Each children is a Hash (description in #node_content).

Returns:

  • (Array)

    the Array of children



28
29
30
# File 'lib/rulex/tex/node_extensions.rb', line 28

def to_a
  elements.map{|e| e.node_content} if elements 
end