Class: AbstractMapper::AST::Node

Inherits:
Object
  • Object
show all
Extended by:
AttributesDSL
Includes:
Comparable
Defined in:
lib/abstract_mapper/ast/node.rb

Overview

An immutable node of the abstract syntax tree (AST), that describes either some “end-up” transformation, or a level of nested input data.

Every node is expected to accept attributes and (possibly) block, and implement ‘#transproc` that implements the `#call` method to transform input data to the output.

AST::Nodes describe only the structure of AST, they know neither how to build the tree with DSL (see [AbstractMapper::Builder]), nor how to optimize it later (see [AbstractMapper::Optimizer]).

Direct Known Subclasses

Branch

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_ = {}, &block) ⇒ Node

Returns a new instance of Node.



32
33
34
35
36
# File 'lib/abstract_mapper/ast/node.rb', line 32

def initialize(_ = {}, &block)
  super
  @block = block
  IceNine.deep_freeze(self)
end

Instance Attribute Details

#blockProc (readonly)

Returns The block given to initializer.

Returns:

  • (Proc)

    The block given to initializer



29
30
31
# File 'lib/abstract_mapper/ast/node.rb', line 29

def block
  @block
end

Instance Method Details

#==(other) ⇒ Boolean Also known as: eql?

Compares the node to another one by type and attributes

Parameters:

  • other (Object)

Returns:

  • (Boolean)


71
72
73
# File 'lib/abstract_mapper/ast/node.rb', line 71

def ==(other)
  other.instance_of?(self.class) && attributes.eql?(other.attributes)
end

#inspectString

Returns a human-readable string representating the node

Returns:

  • (String)


53
54
55
# File 'lib/abstract_mapper/ast/node.rb', line 53

def inspect
  "<#{self}>"
end

#to_sString

Converts the node into string with its name and attributes

Returns:

  • (String)


61
62
63
# File 'lib/abstract_mapper/ast/node.rb', line 61

def to_s
  "#{__name__}#{__attributes__}"
end

#transprocTransproc::Function

This method is abstract.

The transformation function for the branch

Returns:

  • (Transproc::Function)


45
46
47
# File 'lib/abstract_mapper/ast/node.rb', line 45

def transproc
  Functions[:identity]
end