Class: TL1::AST::Node

Inherits:
Object
  • Object
show all
Includes:
Comparable
Defined in:
lib/tl1/ast.rb

Overview

The base class for all AST nodes

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



79
80
81
# File 'lib/tl1/ast.rb', line 79

def fields
  @fields
end

Instance Method Details

#<=>(other) ⇒ Object



81
82
83
84
# File 'lib/tl1/ast.rb', line 81

def <=>(other)
  return unless other.is_a?(Node)
  fields <=> other.fields
end

#as_json(fields = nil) ⇒ Object



86
87
88
89
# File 'lib/tl1/ast.rb', line 86

def as_json(fields = nil)
  fields ||= @fields
  { node: NODES_BY_CLASS[self.class], fields: fields }
end

#to_jsonObject



91
92
93
# File 'lib/tl1/ast.rb', line 91

def to_json
  as_json.to_json
end