From 915fc36b2ec81e04613be012125fc20e700e4c60 Mon Sep 17 00:00:00 2001 From: leaf corcoran Date: Wed, 28 Nov 2012 20:53:47 -0800 Subject: [PATCH] convert more modules --- bin/moonc | 2 +- moonscript/init.lua | 2 +- moonscript/init.moon | 2 +- moonscript/parse.lua | 20 +++++++++++--------- moonscript/transform.lua | 11 ++++++++--- moonscript/transform.moon | 5 +---- test.lua | 5 ++--- 7 files changed, 25 insertions(+), 22 deletions(-) diff --git a/bin/moonc b/bin/moonc index 1a1f4fe..15cc49a 100755 --- a/bin/moonc +++ b/bin/moonc @@ -2,7 +2,7 @@ module("moonscript", package.seeall) -require "moonscript.parse" +local parse = require "moonscript.parse" local compile = require "moonscript.compile" local util = require "moonscript.util" diff --git a/moonscript/init.lua b/moonscript/init.lua index b284adf..17d9c48 100644 --- a/moonscript/init.lua +++ b/moonscript/init.lua @@ -1,6 +1,6 @@ module("moonscript", package.seeall) local compile = require("moonscript.compile") -require("moonscript.parse") +local parse = require("moonscript.parse") local concat, insert = table.concat, table.insert local split, dump do diff --git a/moonscript/init.moon b/moonscript/init.moon index 34d4f9c..290a8a4 100644 --- a/moonscript/init.moon +++ b/moonscript/init.moon @@ -2,7 +2,7 @@ module "moonscript", package.seeall compile = require "moonscript.compile" -require "moonscript.parse" +parse = require "moonscript.parse" import concat, insert from table import split, dump from require "moonscript.util" diff --git a/moonscript/parse.lua b/moonscript/parse.lua index b706104..fd40976 100644 --- a/moonscript/parse.lua +++ b/moonscript/parse.lua @@ -1,4 +1,3 @@ -module("moonscript.parse", package.seeall) local util = require"moonscript.util" @@ -117,7 +116,7 @@ local function wrap_env(fn) })) end -function extract_line(str, start_pos) +local function extract_line(str, start_pos) str = str:sub(start_pos) m = str:match"^(.-)\n" if m then return m end @@ -633,13 +632,16 @@ local build_grammar = wrap_env(function() return tree end } - end) --- parse a string --- returns tree, or nil and error message -function string(str) - local g = build_grammar() - return g:match(str) -end +return { + extract_line = extract_line, + + -- parse a string + -- returns tree, or nil and error message + string = function (str) + local g = build_grammar() + return g:match(str) + end +} diff --git a/moonscript/transform.lua b/moonscript/transform.lua index 1039ad9..3d185f9 100644 --- a/moonscript/transform.lua +++ b/moonscript/transform.lua @@ -1,4 +1,3 @@ -module("moonscript.transform", package.seeall) local types = require("moonscript.types") local util = require("moonscript.util") local data = require("moonscript.data") @@ -24,6 +23,7 @@ do end end local implicitly_return +local Run do local _parent_0 = nil local _base_0 = { @@ -335,7 +335,7 @@ construct_comprehension = function(inner, clauses) end return current_stms[1] end -Statement = Transformer({ +local Statement = Transformer({ root_stms = function(self, body) return apply_to_last(body, implicitly_return(self)) end, @@ -1309,7 +1309,7 @@ implicitly_return = function(scope) end return fn end -Value = Transformer({ +local Value = Transformer({ ["for"] = default_accumulator, ["while"] = default_accumulator, foreach = default_accumulator, @@ -1549,3 +1549,8 @@ Value = Transformer({ }) end }) +return { + Statement = Statement, + Value = Value, + Run = Run +} diff --git a/moonscript/transform.moon b/moonscript/transform.moon index c34035d..1f865c2 100644 --- a/moonscript/transform.moon +++ b/moonscript/transform.moon @@ -1,6 +1,4 @@ -module "moonscript.transform", package.seeall - types = require "moonscript.types" util = require "moonscript.util" data = require "moonscript.data" @@ -22,8 +20,6 @@ mtype = do else t -export Statement, Value, Run - local implicitly_return class Run @@ -879,3 +875,4 @@ Value = Transformer { build.chain { base: {"parens", fn}, {"call", arg_list} } } +{ :Statement, :Value, :Run } diff --git a/test.lua b/test.lua index 073a450..0b95e35 100755 --- a/test.lua +++ b/test.lua @@ -10,9 +10,8 @@ pcall(function() gettime = socket.gettime end) -require "moonscript.parse" -require "moonscript.compile" -local parse, compile = moonscript.parse, moonscript.compile +parse = require "moonscript.parse" +compile = require "moonscript.compile" local opts, ind = alt_getopt.get_opts(arg, "qd:", { })