Class: Glyph::ParameterNode

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

Overview

A Glyph macro parameter 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 parameter contents.

Returns:

  • (String)

    a textual representation of the parameter contents

Since:

  • 0.3.0


189
190
191
# File 'lib/glyph/syntax_node.rb', line 189

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

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

Returns the evaluated child nodes.

Parameters:

  • context (Glyph::MacroNode)

    the context of the macro

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

    a hash of options

Options Hash (options):

  • :params (Boolean)

    whether to evaluate child nodes or not

Returns:

  • (String)

    the evaluated child nodes

Since:

  • 0.3.0


198
199
200
201
202
# File 'lib/glyph/syntax_node.rb', line 198

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

#to_sString

Returns a textual representation of the parameter node.

Returns:

  • (String)

    a textual representation of the parameter node

Since:

  • 0.3.0


183
184
185
# File 'lib/glyph/syntax_node.rb', line 183

def to_s
	children.join
end