2017-04-01 21:28:57 +03:00
|
|
|
module Vool
|
|
|
|
class Statements < Statement
|
2018-03-15 20:40:21 +05:30
|
|
|
attr_reader :statements
|
|
|
|
def initialize(statements)
|
2019-08-16 20:39:08 +03:00
|
|
|
case statements
|
|
|
|
when nil
|
|
|
|
@statements = []
|
|
|
|
when Array
|
|
|
|
@statements = statements
|
|
|
|
when Statement
|
|
|
|
@statements = statements.statements
|
|
|
|
when Statement
|
|
|
|
@statements = [statements]
|
|
|
|
else
|
|
|
|
raise "Invalid class, must be Statement or Array, not #{statements.class}"
|
|
|
|
end
|
2018-03-15 20:40:21 +05:30
|
|
|
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)
|
2019-08-16 20:39:08 +03:00
|
|
|
if(o.is_a?(Statements))
|
2019-08-19 11:33:12 +03:00
|
|
|
o.statements.each do |s|
|
|
|
|
raise "not a statement #{s}" unless s.is_a?(Statement)
|
|
|
|
@statements << s
|
|
|
|
end
|
2019-08-16 20:39:08 +03:00
|
|
|
else
|
2019-08-19 11:33:12 +03:00
|
|
|
raise "not a statement #{o}" unless o.is_a?(Statement)
|
2019-08-16 20:39:08 +03:00
|
|
|
@statements << o
|
|
|
|
end
|
2018-03-15 20:40:21 +05:30
|
|
|
self
|
|
|
|
end
|
2018-07-20 20:06:14 +03:00
|
|
|
def prepend(o)
|
2019-08-19 11:33:12 +03:00
|
|
|
raise "not a statement #{o}" unless o.is_a?(Statement)
|
2018-07-20 20:06:14 +03:00
|
|
|
@statements = [o] + @statements
|
|
|
|
end
|
2019-08-15 21:30:36 +03:00
|
|
|
def shift
|
|
|
|
@statements.shift
|
|
|
|
end
|
2019-08-16 14:09:56 +03:00
|
|
|
def pop
|
|
|
|
@statements.pop
|
|
|
|
end
|
2017-04-12 11:52:23 +03:00
|
|
|
|
2018-11-02 17:27:46 -07:00
|
|
|
# to_mom all the statements. Append subsequent ones to the first, and return the
|
|
|
|
# first.
|
|
|
|
#
|
|
|
|
# For ClassStatements this creates and returns a MomCompiler
|
|
|
|
#
|
2018-07-05 14:02:38 +03:00
|
|
|
def to_mom( compiler )
|
2018-06-29 23:29:10 +03:00
|
|
|
raise "Empty list ? #{statements.length}" if empty?
|
2018-06-30 19:20:17 +03:00
|
|
|
stats = @statements.dup
|
2018-11-02 17:27:46 -07:00
|
|
|
first = stats.shift.to_mom(compiler)
|
2018-06-30 19:20:17 +03:00
|
|
|
while( nekst = stats.shift )
|
2019-08-19 11:33:12 +03:00
|
|
|
next_mom = nekst.to_mom(compiler)
|
|
|
|
if next_mom.is_a?(Mom::BlockCompiler)
|
|
|
|
compiler.block_compilers << next_mom
|
|
|
|
else
|
|
|
|
first.append next_mom
|
|
|
|
end
|
2018-03-15 20:33:38 +05:30
|
|
|
end
|
2018-11-02 17:27:46 -07:00
|
|
|
first
|
2017-04-08 12:10:42 +03:00
|
|
|
end
|
2017-04-09 10:14:28 +03:00
|
|
|
|
2018-03-15 17:22:56 +05:30
|
|
|
def each(&block)
|
|
|
|
block.call(self)
|
2018-03-15 20:40:21 +05:30
|
|
|
@statements.each{|a| a.each(&block)}
|
2018-03-15 17:22:56 +05:30
|
|
|
end
|
|
|
|
|
2018-07-03 22:18:19 +03:00
|
|
|
def to_s(depth = 0)
|
2019-09-19 20:48:21 +03:00
|
|
|
at_depth(depth , @statements.collect{|st| st.to_s(depth)}.join("\n"))
|
2018-07-03 22:18:19 +03:00
|
|
|
end
|
|
|
|
|
2017-04-02 13:24:09 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
class ScopeStatement < Statements
|
2017-04-01 21:28:57 +03:00
|
|
|
end
|
|
|
|
end
|