Class: Glyph::AttributeNode

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

Overview

A Glyph macro attribute in Glyph Abstract Syntax Tree

Since:

  • 0.3.0

Instance Attribute Summary

Attributes inherited from Node

#children, #parent

Instance Method Summary collapse

Methods inherited from SyntaxNode

#inspect, #parent_macro

Methods inherited from Node

#&, #<<, #==, #>>, #ascend, #child, #clear, #descend, #each_child, #find_child, #find_parent, #from, #initialize, #inspect, #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

#contentsString

Returns a textual representation of the attribute contents.

Returns:

  • (String)

    a textual representation of the attribute contents

Since:

  • 0.3.0



219
220
221
# File 'lib/glyph/syntax_node.rb', line 219

def contents
	self[:escape] ? ".[=#{children.join}=]" : children.join
end

#evaluate(context, options = {:attrs => false}) ⇒ String

Returns the evaluated child nodes.

Parameters:

  • context (Glyph::MacroNode)

    the context of the macro

  • options (Hash) (defaults to: {:attrs => false})

    a hash of options

Options Hash (options):

  • :attrs (Boolean)

    whether to evaluate child nodes or not

Returns:

  • (String)

    the evaluated child nodes

Since:

  • 0.3.0



228
229
230
231
232
# File 'lib/glyph/syntax_node.rb', line 228

def evaluate(context, options={:attrs => false})
	self[:value] = ""
	self.children.each {|c| self[:value] << c.evaluate(context) } if options[:attrs]
	self[:value]
end

#to_sString

Returns a textual representation of the attribute node.

Returns:

  • (String)

    a textual representation of the attribute node

Since:

  • 0.3.0



212
213
214
215
# File 'lib/glyph/syntax_node.rb', line 212

def to_s
	e = self[:escape] ? "=" : ""
	"@#{self[:name]}["+e+children.join+e+"]"
end