Skip to content

Commit 915fc36

Browse files
committed
convert more modules
1 parent 38463a0 commit 915fc36

7 files changed

Lines changed: 25 additions & 22 deletions

File tree

bin/moonc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
module("moonscript", package.seeall)
44

5-
require "moonscript.parse"
5+
local parse = require "moonscript.parse"
66
local compile = require "moonscript.compile"
77
local util = require "moonscript.util"
88

moonscript/init.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module("moonscript", package.seeall)
22
local compile = require("moonscript.compile")
3-
require("moonscript.parse")
3+
local parse = require("moonscript.parse")
44
local concat, insert = table.concat, table.insert
55
local split, dump
66
do

moonscript/init.moon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
module "moonscript", package.seeall
33

44
compile = require "moonscript.compile"
5-
require "moonscript.parse"
5+
parse = require "moonscript.parse"
66

77
import concat, insert from table
88
import split, dump from require "moonscript.util"

moonscript/parse.lua

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
module("moonscript.parse", package.seeall)
21

32
local util = require"moonscript.util"
43

@@ -117,7 +116,7 @@ local function wrap_env(fn)
117116
}))
118117
end
119118

120-
function extract_line(str, start_pos)
119+
local function extract_line(str, start_pos)
121120
str = str:sub(start_pos)
122121
m = str:match"^(.-)\n"
123122
if m then return m end
@@ -633,13 +632,16 @@ local build_grammar = wrap_env(function()
633632
return tree
634633
end
635634
}
636-
637635
end)
638636

639-
-- parse a string
640-
-- returns tree, or nil and error message
641-
function string(str)
642-
local g = build_grammar()
643-
return g:match(str)
644-
end
637+
return {
638+
extract_line = extract_line,
639+
640+
-- parse a string
641+
-- returns tree, or nil and error message
642+
string = function (str)
643+
local g = build_grammar()
644+
return g:match(str)
645+
end
646+
}
645647

moonscript/transform.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
module("moonscript.transform", package.seeall)
21
local types = require("moonscript.types")
32
local util = require("moonscript.util")
43
local data = require("moonscript.data")
@@ -24,6 +23,7 @@ do
2423
end
2524
end
2625
local implicitly_return
26+
local Run
2727
do
2828
local _parent_0 = nil
2929
local _base_0 = {
@@ -335,7 +335,7 @@ construct_comprehension = function(inner, clauses)
335335
end
336336
return current_stms[1]
337337
end
338-
Statement = Transformer({
338+
local Statement = Transformer({
339339
root_stms = function(self, body)
340340
return apply_to_last(body, implicitly_return(self))
341341
end,
@@ -1309,7 +1309,7 @@ implicitly_return = function(scope)
13091309
end
13101310
return fn
13111311
end
1312-
Value = Transformer({
1312+
local Value = Transformer({
13131313
["for"] = default_accumulator,
13141314
["while"] = default_accumulator,
13151315
foreach = default_accumulator,
@@ -1549,3 +1549,8 @@ Value = Transformer({
15491549
})
15501550
end
15511551
})
1552+
return {
1553+
Statement = Statement,
1554+
Value = Value,
1555+
Run = Run
1556+
}

moonscript/transform.moon

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11

2-
module "moonscript.transform", package.seeall
3-
42
types = require "moonscript.types"
53
util = require "moonscript.util"
64
data = require "moonscript.data"
@@ -22,8 +20,6 @@ mtype = do
2220
else
2321
t
2422

25-
export Statement, Value, Run
26-
2723
local implicitly_return
2824

2925
class Run
@@ -879,3 +875,4 @@ Value = Transformer {
879875
build.chain { base: {"parens", fn}, {"call", arg_list} }
880876
}
881877

878+
{ :Statement, :Value, :Run }

test.lua

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@ pcall(function()
1010
gettime = socket.gettime
1111
end)
1212

13-
require "moonscript.parse"
14-
require "moonscript.compile"
15-
local parse, compile = moonscript.parse, moonscript.compile
13+
parse = require "moonscript.parse"
14+
compile = require "moonscript.compile"
1615

1716
local opts, ind = alt_getopt.get_opts(arg, "qd:", { })
1817

0 commit comments

Comments
 (0)