2018-07-19 13:46:51 +02:00
|
|
|
module Ruby
|
|
|
|
class Statements < Statement
|
|
|
|
attr_reader :statements
|
|
|
|
def initialize(statements)
|
2019-09-06 20:00:37 +02:00
|
|
|
@statements = []
|
|
|
|
statements.each{|st| self << st}
|
2018-07-19 13:46:51 +02:00
|
|
|
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
|
2019-08-15 20:30:36 +02:00
|
|
|
def shift
|
|
|
|
@statements.shift
|
|
|
|
end
|
2019-08-17 22:27:55 +02:00
|
|
|
def pop
|
|
|
|
@statements.pop
|
|
|
|
end
|
2018-07-19 13:46:51 +02:00
|
|
|
def [](i)
|
|
|
|
@statements[i]
|
|
|
|
end
|
|
|
|
def <<(o)
|
2019-09-06 20:00:37 +02:00
|
|
|
raise "Not Statement #{o.class}=#{o.to_s[0..100]}" unless o.is_a?(Statement)
|
2018-07-19 13:46:51 +02:00
|
|
|
@statements << o
|
|
|
|
self
|
2019-08-15 20:30:36 +02:00
|
|
|
end
|
2019-10-03 23:36:49 +02:00
|
|
|
def to_sol
|
|
|
|
return first.to_sol if( single? )
|
|
|
|
brother = sol_brother.new(nil)
|
2019-08-19 10:33:12 +02:00
|
|
|
@statements.each do |s|
|
2019-10-03 23:36:49 +02:00
|
|
|
brother << s.to_sol
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
2019-08-19 10:33:12 +02:00
|
|
|
brother
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def to_s(depth = 0)
|
2019-09-19 19:48:21 +02:00
|
|
|
at_depth(depth , @statements.collect{|st| st.to_s(depth)}.join("\n"))
|
2018-07-19 13:46:51 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
class ScopeStatement < Statements
|
|
|
|
end
|
|
|
|
end
|