Module: DrgDSL::Ast::Node

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(node_class) ⇒ Object



19
20
21
# File 'lib/drgdsl/ast.rb', line 19

def included(node_class)
  node_classes << node_class
end

.node_classesObject



15
16
17
# File 'lib/drgdsl/ast.rb', line 15

def node_classes
  @node_classes ||= []
end

.type(node_class) ⇒ Object



23
24
25
# File 'lib/drgdsl/ast.rb', line 23

def type(node_class)
  node_class.to_s[/\w+$/]
end

Instance Method Details

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



62
63
64
# File 'lib/drgdsl/ast.rb', line 62

def ==(other)
  type == other.type && hash == other.hash
end

#accept(visitor) ⇒ Object



28
29
30
# File 'lib/drgdsl/ast.rb', line 28

def accept(visitor)
  visitor.visit(self)
end

#hashInteger

Returns object hash for this AST node. Node instances for the same expression should always return the same hash code. This is useful for optimizations.

Returns:

  • (Integer)

    object hash for this AST node. Node instances for the same expression should always return the same hash code. This is useful for optimizations.

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/drgdsl/ast.rb', line 58

def hash
  raise NotImplementedError
end

#mdc_equality?Boolean

Returns whether this node represents a MDC equality check, e.g. “MDC = ‘01’”.

Returns:

  • (Boolean)

    whether this node represents a MDC equality check, e.g. “MDC = ‘01’”



40
41
42
# File 'lib/drgdsl/ast.rb', line 40

def mdc_equality?
  false
end

#pretty_print(**pretty_printer_options) ⇒ Object Also known as: to_s



68
69
70
# File 'lib/drgdsl/ast.rb', line 68

def pretty_print(**pretty_printer_options)
  accept PrettyPrinter.new(**pretty_printer_options)
end

#sep_equality?Boolean

Returns whether this node represents a SEP equality check, e.g. “SEP = ‘07’”.

Returns:

  • (Boolean)

    whether this node represents a SEP equality check, e.g. “SEP = ‘07’”



46
47
48
# File 'lib/drgdsl/ast.rb', line 46

def sep_equality?
  false
end

#to_hashHash

Returns Hash representation of the node.

Returns:

  • (Hash)

    Hash representation of the node

Raises:

  • (NotImplementedError)


51
52
53
# File 'lib/drgdsl/ast.rb', line 51

def to_hash
  raise NotImplementedError
end

#typeObject

Class name of the concrete node without the module name. Do not override. Used by Visitor to determine which method to call.



34
35
36
# File 'lib/drgdsl/ast.rb', line 34

def type
  Node.type(self.class)
end