From 3c4cc04e14c3e5a37068249b8275fbb66e51183d Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Tue, 6 Jan 2015 00:31:24 +0200 Subject: [PATCH] Sepated reading and parsing to different methods --- src/Weave.jl | 4 ++-- src/readers.jl | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/Weave.jl b/src/Weave.jl index 94d18f9..c4c0d94 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -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) diff --git a/src/readers.jl b/src/readers.jl index e6b1905..f3d7884 100644 --- a/src/readers.jl +++ b/src/readers.jl @@ -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]