rubyx/lib/vool/statements.rb

66 lines
1.3 KiB
Ruby
Raw Normal View History

2017-04-01 20:28:57 +02:00
module Vool
class Statements < Statement
attr_reader :statements
def initialize(statements)
@statements = statements
end
def empty?
@statements.empty?
end
def single?
@statements.length == 1
end
def first
@statements.first
end
def last
@statements.last
end
def length
@statements.length
end
def [](i)
@statements[i]
end
def <<(o)
@statements << o
self
end
2018-07-20 19:06:14 +02:00
def prepend(o)
@statements = [o] + @statements
end
def shift
@statements.shift
end
2018-11-03 01:27:46 +01:00
# to_mom all the statements. Append subsequent ones to the first, and return the
# first.
#
# For ClassStatements this creates and returns a MomCompiler
#
def to_mom( compiler )
raise "Empty list ? #{statements.length}" if empty?
stats = @statements.dup
2018-11-03 01:27:46 +01:00
first = stats.shift.to_mom(compiler)
while( nekst = stats.shift )
2018-11-03 01:27:46 +01:00
first.append nekst.to_mom(compiler)
end
2018-11-03 01:27:46 +01:00
first
2017-04-08 11:10:42 +02:00
end
2017-04-09 09:14:28 +02:00
def each(&block)
block.call(self)
@statements.each{|a| a.each(&block)}
end
2018-07-03 21:18:19 +02:00
def to_s(depth = 0)
at_depth(depth , *@statements.collect{|st| st.to_s(depth)})
end
end
class ScopeStatement < Statements
2017-04-01 20:28:57 +02:00
end
end