Merge pull request #360 from JunoLab/avi/refc

yet another clean up:
pull/363/head
Shuhei Kadowaki 2020-06-02 19:52:46 +09:00 committed by GitHub
commit f1d8838bc5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 12 additions and 29 deletions

View File

@ -29,7 +29,6 @@ function restore_chunk(chunk::CodeChunk, cached)
new_chunks = []
for c in chunks
newc = CodeChunk(c.content, c.number, c.start_line, c.optionstring, c.options)
newc.result_no = c.result_no
newc.figures = c.figures
newc.result = c.result
newc.output = c.output

View File

@ -182,28 +182,23 @@ function reset_report(report::Report)
end
function run_code(chunk::CodeChunk, report::Report, SandBox::Module)
expressions = parse_input(chunk.content)
N = length(expressions)
# @show expressions
result_no = 1
exs = parse_input(chunk.content)
n = length(exs)
results = ChunkOutput[]
for (str_expr, expr) in expressions
for (i, (str_expr, expr)) in enumerate(exs)
reset_report(report)
lastline = (result_no == N)
(obj, out) = capture_output(
obj, out = capture_output(
expr,
SandBox,
chunk.options[:term],
chunk.options[:display],
lastline,
i == n,
report.throw_errors,
)
figures = report.figures # Captured figures
result = ChunkOutput(str_expr, out, report.cur_result, report.rich_output, figures)
report.rich_output = ""
push!(results, result)
result_no += 1
end
return results
end
@ -271,12 +266,12 @@ function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)
chunk = Base.invokelatest(hook, chunk)
end
if chunk.options[:term]
chunks = collect_results(chunk, TermResult())
chunks = if chunk.options[:term]
collect_term_results(chunk)
elseif chunk.options[:hold]
chunks = collect_results(chunk, CollectResult())
collect_hold_results(chunk)
else
chunks = collect_results(chunk, ScriptResult())
collect_results(chunk)
end
# else
@ -366,9 +361,8 @@ function set_rc_params(doc::WeaveDoc, fig_path, fig_ext)
doc.chunk_defaults[:fig_path] = fig_path
end
function collect_results(chunk::CodeChunk, fmt::ScriptResult)
function collect_results(chunk::CodeChunk)
content = ""
result_no = 1
result_chunks = CodeChunk[]
for r in chunk.result
# Check if there is any output from chunk
@ -384,8 +378,6 @@ function collect_results(chunk::CodeChunk, fmt::ScriptResult)
copy(chunk.options),
)
content = ""
rchunk.result_no = result_no
result_no *= 1
rchunk.figures = r.figures
rchunk.output = r.stdout * r.displayed
rchunk.rich_output = r.rich_output
@ -407,10 +399,9 @@ function collect_results(chunk::CodeChunk, fmt::ScriptResult)
return result_chunks
end
function collect_results(chunk::CodeChunk, fmt::TermResult)
function collect_term_results(chunk::CodeChunk)
output = ""
prompt = chunk.options[:prompt]
result_no = 1
result_chunks = CodeChunk[]
for r in chunk.result
output *= prompt * r.code
@ -444,8 +435,7 @@ function collect_results(chunk::CodeChunk, fmt::TermResult)
return result_chunks
end
function collect_results(chunk::CodeChunk, fmt::CollectResult)
result_no = 1
function collect_hold_results(chunk::CodeChunk)
for r in chunk.result
chunk.output *= r.stdout
chunk.rich_output *= r.rich_output

View File

@ -28,7 +28,6 @@ end
mutable struct CodeChunk <: WeaveChunk
content::String
number::Int
result_no::Int
start_line::Int
optionstring::String
options::Dict{Symbol,Any}
@ -42,7 +41,6 @@ function CodeChunk(content, number, start_line, optionstring, options)
return CodeChunk(
string(rstrip(content), '\n'), # normalize end of chunk)
number,
0,
start_line,
optionstring,
options,
@ -73,7 +71,3 @@ mutable struct InlineCode <: Inline
figures::Vector{String}
end
InlineCode(content, number, ctype) = InlineCode(content, number, ctype, "", "", String[])
struct TermResult end
struct ScriptResult end
struct CollectResult end