Class: Maccro::DSL::Node

Inherits:
Object
  • Object
show all
Includes:
ASTNodeWrapper
Defined in:
lib/maccro/dsl/node.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, code_range) ⇒ Node

Returns a new instance of Node.



42
43
44
45
46
47
48
49
# File 'lib/maccro/dsl/node.rb', line 42

def initialize(name, code_range)
  @name = name
  @code_range = code_range
  @first_lineno = code_range.first_lineno
  @first_column = code_range.first_column
  @last_lineno = code_range.last_lineno
  @last_column = code_range.last_column
end

Instance Attribute Details

#first_columnObject (readonly)

Returns the value of attribute first_column.



38
39
40
# File 'lib/maccro/dsl/node.rb', line 38

def first_column
  @first_column
end

#first_linenoObject (readonly)

Returns the value of attribute first_lineno.



38
39
40
# File 'lib/maccro/dsl/node.rb', line 38

def first_lineno
  @first_lineno
end

#last_columnObject (readonly)

Returns the value of attribute last_column.



38
39
40
# File 'lib/maccro/dsl/node.rb', line 38

def last_column
  @last_column
end

#last_linenoObject (readonly)

Returns the value of attribute last_lineno.



38
39
40
# File 'lib/maccro/dsl/node.rb', line 38

def last_lineno
  @last_lineno
end

#nameObject (readonly)

Returns the value of attribute name.



38
39
40
# File 'lib/maccro/dsl/node.rb', line 38

def name
  @name
end

Instance Method Details

#capture(ast, placeholders) ⇒ Object



74
75
76
# File 'lib/maccro/dsl/node.rb', line 74

def capture(ast, placeholders)
  placeholders[@name] = ast.to_code_range
end

#childrenObject



59
60
61
# File 'lib/maccro/dsl/node.rb', line 59

def children
  []
end

#match?(node) ⇒ Boolean

Returns:

  • (Boolean)


63
64
65
66
67
68
69
70
71
72
# File 'lib/maccro/dsl/node.rb', line 63

def match?(node)
  # literals are not Node in any cases
  return false unless node.respond_to?(:type)

  if self.class.respond_to?(:match?)
    self.class.match?(node)
  else
    super
  end
end

#to_code_rangeObject



51
52
53
# File 'lib/maccro/dsl/node.rb', line 51

def to_code_range
  @code_range
end

#typeObject



55
56
57
# File 'lib/maccro/dsl/node.rb', line 55

def type
  :MACCRO_NODE
end