Class: Glyph::SyntaxNode

Inherits:
Node show all
Defined in:
lib/glyph/syntax_node.rb

Overview

A subclass of Glyph::SyntaxNode is instantiated by Glyph::Parser whenever a known text element is parsed.

Since:

  • 0.3.0

Instance Attribute Summary

Attributes inherited from Node

#children, #parent

Instance Method Summary collapse

Methods inherited from Node

#&, #<<, #==, #>>, #ascend, #child, #clear, #descend, #each_child, #find_child, #find_parent, #from, #initialize, #root, #to_hash, #to_node

Methods inherited from Hash

#to_node, #to_options

Constructor Details

This class inherits a constructor from Node

Instance Method Details

#evaluate(context, options = {}) ⇒ String

Returns the value of the :value key

Returns:

  • (String)

    the value of the :value key

Since:

  • 0.3.0



30
31
32
# File 'lib/glyph/syntax_node.rb', line 30

def evaluate(context, options={})
	self[:value]
end

#inspectString

Returns a textual representation of self

Returns:

  • (String)

    a textual representation of self

Since:

  • 0.4.0



18
19
20
21
22
23
24
25
26
# File 'lib/glyph/syntax_node.rb', line 18

def inspect
	string = ""
	descend do |e, level|
		# Remove document key to avoid endless resursion
		hash = e.to_hash.reject{|k,v| k == :document}
		string << "  "*level+"(#{e.class})"+hash.inspect+"\n"
	end
	string.chomp
end

#parent_macroGlyph::MacroNode

Returns the first Glyph::MacroNode ancestor

Returns:

Since:

  • 0.3.0



36
37
38
# File 'lib/glyph/syntax_node.rb', line 36

def parent_macro
	find_parent{|n| n.is_a?(MacroNode)}
end

#to_sString

Returns an empty string

Returns:

  • (String)

    an empty string

Since:

  • 0.3.0



12
13
14
# File 'lib/glyph/syntax_node.rb', line 12

def to_s
	""
end