lib/qed/evaluator.rb in qed-2.2.2 vs lib/qed/evaluator.rb in qed-2.3.0

- old
+ new

@@ -18,62 +18,61 @@ @observers = observers end # def run - advise!(:before_document, @script) + advise!(:before_demo, @script) process - advise!(:after_document, @script) + advise!(:after_demo, @script) end # def process @ast.each do |section| - case section.type - when :code - evaluate_code(section) - when :text - evaluate_text(section) - end + evaluate(section) end end - # - def evaluate_code(section) - advise!(:before_code, section, @script.file) + # Evaluate a demo section. + def evaluate(section) + advise!(:text, section) # TODO: rename to :step? + evaluate_links(section) + advise!(:before_step, section, @script.file) begin - advise!(:code, section) - @script.evaluate(section.text, section.line) - pass!(section) - rescue Assertion => exception - fail!(section, exception) - rescue Exception => exception - error!(section, exception) + advise!(:when, section) + # TODO: how to handle catching asserts in advice? end - advise!(:after_code, section, @script.file) + if section.code? + begin + advise!(:code, section) + @script.evaluate(section.eval_code, section.lineno) + rescue SystemExit + pass!(section) + rescue Assertion => exception + fail!(section, exception) + rescue Exception => exception + error!(section, exception) + else + pass!(section) + end + end + advise!(:after_step, section, @script.file) end - # - def evaluate_text(section) - advise!(:text, section) - evaluate_links(section) - advise!(:when, section) - end - - # + # TODO: Not sure how to handle loading links in comment mode. def evaluate_links(section) - section.text.scan(/\[qed:\/\/(.*?)\]/) do |match| + section.commentary.scan(/\[qed:\/\/(.*?)\]/) do |match| file = $1 # relative to demo script if File.exist?(File.join(@script.directory,file)) file = File.join(@script.directory,file) end # ruby or another demo case File.extname(file) when '.rb' import!(file) else - Script.new(@script.applique, file, @script.scope).run + Demo.new(file, @script.applique, :scope=>@script.scope).run end end end #