Class: SolidRail::Parser::ASTNode

Inherits:
Object
  • Object
show all
Defined in:
lib/solidrail/parser.rb

Overview

AST Node representation

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node_data) ⇒ ASTNode

Returns a new instance of ASTNode.



21
22
23
24
25
26
27
28
29
# File 'lib/solidrail/parser.rb', line 21

def initialize(node_data)
  if node_data.is_a?(Array) && node_data.length >= 2
    @type = node_data[0]
    @children = node_data[1..].compact.map { |child| ASTNode.new(child) }
  else
    @type = :literal
    @value = node_data
  end
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/solidrail/parser.rb', line 31

def method_missing(method_name, *args)
  if method_name.to_s.end_with?('?')
    type == method_name.to_s.chomp('?').to_sym
  else
    super
  end
end

Instance Attribute Details

#childrenObject (readonly)

Returns the value of attribute children.



19
20
21
# File 'lib/solidrail/parser.rb', line 19

def children
  @children
end

#columnObject (readonly)

Returns the value of attribute column.



19
20
21
# File 'lib/solidrail/parser.rb', line 19

def column
  @column
end

#lineObject (readonly)

Returns the value of attribute line.



19
20
21
# File 'lib/solidrail/parser.rb', line 19

def line
  @line
end

#typeObject (readonly)

Returns the value of attribute type.



19
20
21
# File 'lib/solidrail/parser.rb', line 19

def type
  @type
end

#valueObject (readonly)

Returns the value of attribute value.



19
20
21
# File 'lib/solidrail/parser.rb', line 19

def value
  @value
end

Instance Method Details

#respond_to_missing?(method_name, include_private = false) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/solidrail/parser.rb', line 39

def respond_to_missing?(method_name, include_private = false)
  method_name.to_s.end_with?('?') || super
end