Class: Serpent::Node::Astnode

Inherits:
Object
  • Object
show all
Defined in:
lib/serpent/node.rb

Instance Method Summary collapse

Constructor Details

#initialize(val, args, metadata) ⇒ Astnode

Returns a new instance of Astnode.



35
36
37
38
39
# File 'lib/serpent/node.rb', line 35

def initialize(val, args, )
  @val = val
  @args = args.map {|arg| Node.build arg }
   = .new()
end

Instance Method Details

#outObject



41
42
43
# File 'lib/serpent/node.rb', line 41

def out
  [1, @val, .out] + @args.map(&:out)
end

#to_sObject Also known as: inspect



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/serpent/node.rb', line 45

def to_s
  o = "(#{@val}"
  subs = @args.map(&:to_s)

  k = 0
  out = " "
  while k < subs.size && o != "(seq"
    break if subs[k].include?("\n") || (out + subs[k]).size >= 80
    out += subs[k] + " "
    k += 1
  end

  if k < subs.size
    o += out + "\n  "
    o += subs[k..-1].join("\n").split("\n").join("\n  ")
    o += "\n)"
  else
    o += out[0...-1] + ')'
  end

  o
end