Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitb3dfdc9

Browse files
committed
fix indentation in file
1 parentb7efcd1 commitb3dfdc9

File tree

1 file changed

+163
-160
lines changed

1 file changed

+163
-160
lines changed

‎bin/moonc‎

Lines changed: 163 additions & 160 deletions
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,41 @@ local lfs = require "lfs"
66
localparser=argparse()
77

88
parser:flag("-l --lint","Perform a lint on the file instead of compiling")
9+
910
parser:flag("-v --version","Print version")
1011
parser:flag("-w --watch","Watch file/directory for updates")
1112
parser:option("--transform","Transform syntax tree with module")
13+
1214
parser:mutex(
13-
parser:option("-t --output-to","Specify where to place compiled files"),
14-
parser:option("-o","Write output to file"),
15-
parser:flag("-p","Write output to standard output"),
16-
parser:flag("-T","Write parse tree instead of code (to stdout)"),
17-
parser:flag("-b","Write parse and compile time instead of code(to stdout)"),
18-
parser:flag("-X","Write line rewrite map instead of code (to stdout)")
15+
parser:option("-t --output-to","Specify where to place compiled files"),
16+
parser:option("-o","Write output to file"),
17+
parser:flag("-p","Write output to standard output"),
18+
parser:flag("-T","Write parse tree instead of code (to stdout)"),
19+
parser:flag("-b","Write parse and compile time instead of code(to stdout)"),
20+
parser:flag("-X","Write line rewrite map instead of code (to stdout)")
1921
)
22+
2023
parser:flag("-",
21-
"Read from standard in, print to standard out (Must be only argument)")
24+
"Read from standard in, print to standard out (Must be only argument)")
2225

2326
localread_stdin=arg[1]=="--"-- luacheck: ignore 113
2427

2528
ifnotread_stdinthen
26-
parser:argument("file/directory"):args("+")
29+
parser:argument("file/directory"):args("+")
2730
end
2831

2932
localopts=parser:parse()
3033

3134
ifopts.versionthen
32-
localv=require"moonscript.version"
33-
v.print_version()
34-
os.exit()
35+
localv=require"moonscript.version"
36+
v.print_version()
37+
os.exit()
3538
end
3639

3740
functionlog_msg(...)
38-
ifnotopts.pthen
39-
io.stderr:write(table.concat({...},"").."\n")
40-
end
41+
ifnotopts.pthen
42+
io.stderr:write(table.concat({...},"").."\n")
43+
end
4144
end
4245

4346
localmoonc=require("moonscript.cmd.moonc")
@@ -47,186 +50,186 @@ local compile_and_write = moonc.compile_and_write
4750
localpath_to_target=moonc.path_to_target
4851

4952
localfunctionscan_directory(root,collected)
50-
root=normalize_dir(root)
51-
collected=collectedor {}
52-
53-
forfnameinlfs.dir(root)do
54-
ifnotfname:match("^%.")then
55-
localfull_path=root..fname
56-
57-
iflfs.attributes(full_path,"mode")=="directory"then
58-
scan_directory(full_path,collected)
59-
elseiffname:match("%.moon$")then
60-
table.insert(collected,full_path)
61-
end
62-
end
63-
end
64-
65-
returncollected
53+
root=normalize_dir(root)
54+
collected=collectedor {}
55+
56+
forfnameinlfs.dir(root)do
57+
ifnotfname:match("^%.")then
58+
localfull_path=root..fname
59+
60+
iflfs.attributes(full_path,"mode")=="directory"then
61+
scan_directory(full_path,collected)
62+
elseiffname:match("%.moon$")then
63+
table.insert(collected,full_path)
64+
end
65+
end
66+
end
67+
68+
returncollected
6669
end
6770

6871
localfunctionremove_dups(tbl,key_fn)
69-
localhash= {}
70-
localfinal= {}
71-
72-
for_,vinipairs(tbl)do
73-
localdup_key=key_fnandkey_fn(v)orv
74-
ifnothash[dup_key]then
75-
table.insert(final,v)
76-
hash[dup_key]=true
77-
end
78-
end
79-
80-
returnfinal
72+
localhash= {}
73+
localfinal= {}
74+
75+
for_,vinipairs(tbl)do
76+
localdup_key=key_fnandkey_fn(v)orv
77+
ifnothash[dup_key]then
78+
table.insert(final,v)
79+
hash[dup_key]=true
80+
end
81+
end
82+
83+
returnfinal
8184
end
8285

8386
-- creates tuples of input and target
8487
localfunctionget_files(fname,files)
85-
files=filesor {}
86-
87-
iflfs.attributes(fname,"mode")=="directory"then
88-
for_,sub_fnameinipairs(scan_directory(fname))do
89-
table.insert(files, {
90-
sub_fname,
91-
path_to_target(sub_fname,opts.output_to,fname)
92-
})
93-
end
94-
else
95-
table.insert(files, {
96-
fname,
97-
path_to_target(fname,opts.output_to)
98-
})
99-
end
100-
101-
returnfiles
88+
files=filesor {}
89+
90+
iflfs.attributes(fname,"mode")=="directory"then
91+
for_,sub_fnameinipairs(scan_directory(fname))do
92+
table.insert(files, {
93+
sub_fname,
94+
path_to_target(sub_fname,opts.output_to,fname)
95+
})
96+
end
97+
else
98+
table.insert(files, {
99+
fname,
100+
path_to_target(fname,opts.output_to)
101+
})
102+
end
103+
104+
returnfiles
102105
end
103106

104107
ifread_stdinthen
105-
localparse=require"moonscript.parse"
106-
localcompile=require"moonscript.compile"
108+
localparse=require"moonscript.parse"
109+
localcompile=require"moonscript.compile"
107110

108-
localtext=io.stdin:read("*a")
109-
localtree,err=parse.string(text)
111+
localtext=io.stdin:read("*a")
112+
localtree,err=parse.string(text)
110113

111-
ifnottreethenerror(err)end
112-
localcode,err,pos=compile.tree(tree)
114+
ifnottreethenerror(err)end
115+
localcode,err,pos=compile.tree(tree)
113116

114-
ifnotcodethen
115-
error(compile.format_error(err,pos,text))
116-
end
117+
ifnotcodethen
118+
error(compile.format_error(err,pos,text))
119+
end
117120

118-
print(code)
119-
os.exit()
121+
print(code)
122+
os.exit()
120123
end
121124

122125
localinputs=opts["file/directory"]
123126

124127
localfiles= {}
125128
for_,inputinipairs(inputs)do
126-
get_files(input,files)
129+
get_files(input,files)
127130
end
128131

129132
files=remove_dups(files,function(f)
130-
returnf[2]
133+
returnf[2]
131134
end)
132135

133136
-- returns an iterator that returns files that have been updated
134137
localfunctioncreate_watcher(files)
135-
localwatchers=require("moonscript.cmd.watchers")
138+
localwatchers=require("moonscript.cmd.watchers")
136139

137-
ifwatchers.InotifyWacher:available()then
138-
returnwatchers.InotifyWacher(files):each_update()
139-
end
140+
ifwatchers.InotifyWacher:available()then
141+
returnwatchers.InotifyWacher(files):each_update()
142+
end
140143

141-
returnwatchers.SleepWatcher(files):each_update()
144+
returnwatchers.SleepWatcher(files):each_update()
142145
end
143146

144147
ifopts.watchthen
145-
-- build function to check for lint or compile in watch
146-
localhandle_file
147-
ifopts.lintthen
148-
locallint=require"moonscript.cmd.lint"
149-
handle_file=lint.lint_file
150-
else
151-
handle_file=compile_and_write
152-
end
153-
154-
localwatcher=create_watcher(files)
155-
-- catches interrupt error for ctl-c
156-
localprotected=function()
157-
localstatus,file=true,watcher()
158-
ifstatusthen
159-
returnfile
160-
elseiffile~="interrupted!"then
161-
error(file)
162-
end
163-
end
164-
165-
forfnameinprotecteddo
166-
localtarget=path_to_target(fname,opts.t)
167-
168-
ifopts.othen
169-
target=opts.o
170-
end
171-
172-
localsuccess,err=handle_file(fname,target)
173-
ifopts.lintthen
174-
ifsuccessthen
175-
io.stderr:write(success.."\n\n")
176-
elseiferrthen
177-
io.stderr:write(fname.."\n"..err.."\n\n")
178-
end
179-
elseifnotsuccessthen
180-
io.stderr:write(table.concat({
181-
"",
182-
"Error:"..fname,
183-
err,
184-
"\n",
185-
},"\n"))
186-
elseifsuccess=="build"then
187-
log_msg("Built",fname,"->",target)
188-
end
189-
end
190-
191-
io.stderr:write("\nQuitting...\n")
148+
-- build function to check for lint or compile in watch
149+
localhandle_file
150+
ifopts.lintthen
151+
locallint=require"moonscript.cmd.lint"
152+
handle_file=lint.lint_file
153+
else
154+
handle_file=compile_and_write
155+
end
156+
157+
localwatcher=create_watcher(files)
158+
-- catches interrupt error for ctl-c
159+
localprotected=function()
160+
localstatus,file=true,watcher()
161+
ifstatusthen
162+
returnfile
163+
elseiffile~="interrupted!"then
164+
error(file)
165+
end
166+
end
167+
168+
forfnameinprotecteddo
169+
localtarget=path_to_target(fname,opts.t)
170+
171+
ifopts.othen
172+
target=opts.o
173+
end
174+
175+
localsuccess,err=handle_file(fname,target)
176+
ifopts.lintthen
177+
ifsuccessthen
178+
io.stderr:write(success.."\n\n")
179+
elseiferrthen
180+
io.stderr:write(fname.."\n"..err.."\n\n")
181+
end
182+
elseifnotsuccessthen
183+
io.stderr:write(table.concat({
184+
"",
185+
"Error:"..fname,
186+
err,
187+
"\n",
188+
},"\n"))
189+
elseifsuccess=="build"then
190+
log_msg("Built",fname,"->",target)
191+
end
192+
end
193+
194+
io.stderr:write("\nQuitting...\n")
192195
elseifopts.lintthen
193-
localhas_linted_with_error;
194-
locallint=require"moonscript.cmd.lint"
195-
for_,tupleinpairs(files)do
196-
localfname=tuple[1]
197-
localres,err=lint.lint_file(fname)
198-
ifresthen
199-
has_linted_with_error=true
200-
io.stderr:write(res.."\n\n")
201-
elseiferrthen
202-
has_linted_with_error=true
203-
io.stderr:write(fname.."\n"..err.."\n\n")
204-
end
205-
end
206-
ifhas_linted_with_errorthen
207-
os.exit(1)
208-
end
196+
localhas_linted_with_error;
197+
locallint=require"moonscript.cmd.lint"
198+
for_,tupleinpairs(files)do
199+
localfname=tuple[1]
200+
localres,err=lint.lint_file(fname)
201+
ifresthen
202+
has_linted_with_error=true
203+
io.stderr:write(res.."\n\n")
204+
elseiferrthen
205+
has_linted_with_error=true
206+
io.stderr:write(fname.."\n"..err.."\n\n")
207+
end
208+
end
209+
ifhas_linted_with_errorthen
210+
os.exit(1)
211+
end
209212
else
210-
for_,tupleinipairs(files)do
211-
localfname,target=util.unpack(tuple)
212-
ifopts.othen
213-
target=opts.o
214-
end
215-
216-
localsuccess,err=compile_and_write(fname,target, {
217-
print=opts.p,
218-
fname=fname,
219-
benchmark=opts.b,
220-
show_posmap=opts.X,
221-
show_parse_tree=opts.T,
222-
transform_module=opts.transform
223-
})
224-
225-
ifnotsuccessthen
226-
io.stderr:write(fname.."\t"..err.."\n")
227-
os.exit(1)
228-
end
229-
end
213+
for_,tupleinipairs(files)do
214+
localfname,target=util.unpack(tuple)
215+
ifopts.othen
216+
target=opts.o
217+
end
218+
219+
localsuccess,err=compile_and_write(fname,target, {
220+
print=opts.p,
221+
fname=fname,
222+
benchmark=opts.b,
223+
show_posmap=opts.X,
224+
show_parse_tree=opts.T,
225+
transform_module=opts.transform
226+
})
227+
228+
ifnotsuccessthen
229+
io.stderr:write(fname.."\t"..err.."\n")
230+
os.exit(1)
231+
end
232+
end
230233
end
231234

232235

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp