Added sandbox for running code, fixes scoping problems

pull/17/head
Matti Pastell 2014-12-03 09:21:56 +02:00
parent d65cd9dfe5
commit f56ad978d6
2 changed files with 19 additions and 6 deletions

View File

@ -15,10 +15,15 @@ end
const report = Report("", false, "", "", Any[], "", "")
function listformats()
pweave.listformats()
#function listformats()
#pweave.listformats() TODO: implement
#end
#Module for report scope, idea from Judo.jl
module ReportSandBox
end
function weave(source ; doctype = "pandoc", plotlib="PyPlot", informat="noweb", figdir = "figures", figformat = nothing)
cwd, fname = splitdir(abspath(source))
@ -64,7 +69,16 @@ function run_block(code_str)
#If there is nothing to read code will hang
println()
rw, wr = redirect_stdout()
include_string(code_str)
#include_string(code_str)
n = length(code_str)
pos = 2 #The first character is extra line end
while pos < n
oldpos = pos
code, pos = parse(code_str, pos)
eval(ReportSandBox, code)
end
redirect_stdout(oldSTDOUT)
close(wr)
result = readall(rw)
@ -86,7 +100,7 @@ function run_term(code_str)
oldpos = pos
code, pos = parse(code_str, pos)
println(string("\njulia> ", rstrip(code_str[oldpos:(pos-1)])))
s = eval(code)
s = eval(ReportSandBox, code)
s == nothing || (smime = reprmime(MIME("text/plain"), s)) #display(s)
println(smime)
end

View File

@ -94,6 +94,7 @@ const tex = Tex(@compat Dict{Symbol,Any}(:codestart => "\\begin{juliacode}",
:width => "\\linewidth",
:doctype => "tex"
))
const texminted = Tex(@compat Dict{Symbol,Any}(:codestart => "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}",
:codeend => "\\end{minted}",
:outputstart => "\\begin{minted}[fontsize=\\small, xleftmargin=0.5em, mathescape, frame = leftline]{text}",
@ -106,8 +107,6 @@ const texminted = Tex(@compat Dict{Symbol,Any}(:codestart => "\\begin{minted}[ma
:doctype => "texminted"
))
type Pandoc
formatdict::Dict{Symbol,Any}
end