Sepated reading and parsing to different methods

pull/29/head
Matti Pastell 2015-01-06 00:31:24 +02:00
parent 3407564589
commit 3c4cc04e14
2 changed files with 14 additions and 7 deletions

View File

@ -78,7 +78,7 @@ function tangle(source ; out_path=:doc, informat="noweb")
outname = "$(cwd)/$(basename).jl"
open(outname, "w") do io
for chunk in read_document(source, informat)
for chunk in read(source, informat)
if typeof(chunk) == CodeChunk
write(io, chunk.content*"\n")
end
@ -153,7 +153,7 @@ function weave(source ; doctype = "pandoc", plotlib="Gadfly", informat="noweb",
end
pushdisplay(report)
parsed = read_document(source, informat)
parsed = read(source, informat)
executed = run(parsed)
popdisplay(report)
formatted = format(executed, doctype)

View File

@ -12,12 +12,19 @@ const input_formats = @compat Dict{String, Any}(
)
)
@doc "Read input document" ->
function read_document(document, format="noweb")
@doc "Read and parse input document" ->
function Base.read(document, format="noweb")
document = bytestring(open(document) do io
mmap_array(Uint8,(filesize(document),),io)
end)
return parse(document, format)
end
@doc "Parse document from string" ->
function Base.parse(document, format="noweb")
#doctext = readall(open(document))
lines = split(bytestring(open(document) do io
mmap_array(Uint8,(filesize(document),),io)
end), "\n")
lines = split(document, "\n")
codestart = input_formats[format][:codestart]
codeend = input_formats[format][:codeend]