Skip to content

Commit

Permalink
add suppor tfor transform module
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Feb 3, 2018
1 parent 9e36baa commit 491f235
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 3 additions & 1 deletion bin/moonc
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ local parser = argparse()
parser:flag("-l --lint", "Perform a lint on the file instead of compiling")
parser:flag("-v --version", "Print version")
parser:flag("-w --watch", "Watch file/directory for updates")
parser:option("--transform", "Transform syntax tree with module")
parser:mutex(
parser:flag("-t --output-to", "Specify where to place compiled files"),
parser:flag("-o", "Write output to file"):args(1),
parser:option("-o", "Write output to file"),
parser:flag("-p", "Write output to standard output"),
parser:flag("-T", "Write parse tree instead of code (to stdout)"),
parser:flag("-b", "Write parse and compile time instead of code(to stdout)"),
Expand Down Expand Up @@ -218,6 +219,7 @@ else
benchmark = opts.b,
show_posmap = opts.X,
show_parse_tree = opts.T,
transform_module = opts.transform
})

if not success then
Expand Down
6 changes: 6 additions & 0 deletions moonscript/cmd/moonc.lua
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,12 @@ compile_file_text = function(text, opts)
if opts.benchmark then
compile_time = gettime()
end
do
local mod = opts.transform_module
if mod then
tree = assert(require(mod)(tree))
end
end
local code, posmap_or_err, err_pos = compile.tree(tree)
if not (code) then
return nil, compile.format_error(posmap_or_err, err_pos, text)
Expand Down
3 changes: 3 additions & 0 deletions moonscript/cmd/moonc.moon
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ compile_file_text = (text, opts={}) ->
compile_time = if opts.benchmark
gettime!

if mod = opts.transform_module
tree = assert require(mod) tree

code, posmap_or_err, err_pos = compile.tree tree

unless code
Expand Down

0 comments on commit 491f235

Please sign in to comment.