@@ -9,7 +9,7 @@ require "moonscript.util"
99require " alt_getopt"
1010require " lfs"
1111
12- local opts , ind = alt_getopt .get_opts (arg , " vhwt:pTb " , {
12+ local opts , ind = alt_getopt .get_opts (arg , " vhwt:pTXb " , {
1313 print = " p" , tree = " T" , version = " v" , help = " h"
1414})
1515
@@ -24,6 +24,7 @@ local help = [[Usage: %s [options] files...
2424 -t path Specify where to place compiled files
2525 -p Write output to standard out
2626 -T Write parse tree instead of code (to stdout)
27+ -X Write line rewrite map instead of code (to stdout)
2728 -b Dump parse and compile time (doesn't write output)
2829 -v Print version
2930
@@ -122,10 +123,18 @@ function compile_file(text, fname)
122123 return " "
123124 else
124125 local compile_time = gettime ()
125- local code , err , pos = compile .tree (tree )
126+ local code , posmap_or_err , err_pos = compile .tree (tree )
126127 compile_time = gettime () - compile_time
128+
127129 if not code then
128- return nil , compile .format_error (err , pos , text )
130+ return nil , compile .format_error (posmap_or_err , err_pos , text )
131+ end
132+
133+ if opts .X then
134+ opts .p = true
135+ print (" Pos" , " Lua" , " >>" , " Moon" )
136+ print (util .debug_posmap (posmap_or_err , text , code ))
137+ return " "
129138 end
130139
131140 if opts .b then
0 commit comments