|
4 | 4 |
|
5 | 5 | --#include "src/libluacomp.lua" |
6 | 6 |
|
| 7 | +__DSYM = {} |
| 8 | + |
7 | 9 | local parser = argparse(arg[0]:match("[^/]+$"), "LuaComp v"..LUACOMP_VERSION.."\nA preprocessor+postprocessor written in Lua.") |
8 | 10 | parser:argument("input", "Input file (- for STDIN)") |
9 | 11 | parser:option("-O --output", "Output file. (- for STDOUT)", "-") |
10 | 12 | parser:option("-m --minifier", "Sets the postprocessor", "none") |
11 | 13 | parser:option("-x --executable", "Makes the script an executable (default: current lua version)"):args "?" |
| 14 | +parser:flag("-g --debugging", "Adds inline debugging utils to assist in debugging."):action(function() DEBUGGING=true end) |
12 | 15 | parser:flag("--generator-code", "Outputs only the code from the generator.") |
13 | 16 | parser:flag("--verbose", "Verbose output. (Debugging)"):action(function() VERBOSE=true end) |
14 | 17 | parser:flag("--post-processors", "Lists postprocessors"):action(function() |
|
48 | 51 | f = io.stdin |
49 | 52 | end |
50 | 53 | local ocode = luacomp.process_file(f, (file == "-") and "stdin" or file, args.generator_code) |
| 54 | +if DEBUGGING then |
| 55 | + -- generate debugging symbols |
| 56 | + local dsyms = {"LEM:LCDEBUG!!!"} |
| 57 | + for i=1, #__DSYM do |
| 58 | + local sym = __DSYM[i] |
| 59 | + local sym_str = string.format("FILE[%s]:START[%d,%d]:END[%d:%d]:FILE[%d,%d]", sym.file, sym.sx or 0, sym.sy or 0, sym.ex or 0, sym.ey or 0, sym.fx or -1, sym.fy or -1) |
| 60 | + if sym.tag then |
| 61 | + sym_str = sym_str .. ":"..sym.tag |
| 62 | + end |
| 63 | + table.insert(dsyms, sym_str) |
| 64 | + end |
| 65 | + ocode = ocode .. "\n--[["..table.concat(dsyms, "\n").."\n]]" |
| 66 | +end |
| 67 | + |
| 68 | +if DEBUGGING then |
| 69 | + local dsymt = {} |
| 70 | + for i=1, #__DSYM do |
| 71 | + local sym = __DSYM[i] |
| 72 | + local symstr = string.format("file=%q,sx=%q,sy=%q,ex=%q,ey=%q,fx=%q,fy=%q", sym.file, sym.sx or 0, sym.sy or 0, sym.ex or 0, sym.ey or 0, sym.fx or -1, sym.fy or -1) |
| 73 | + if sym.tagv then |
| 74 | + for i=1, #sym.tagv.vals do |
| 75 | + sym.tagv.vals[i]=string.format("%q", sym.tagv.vals[i]) |
| 76 | + end |
| 77 | + symstr = symstr .. ",tag={" ..string.format("type=%q,vals={%s}", sym.tagv.type, table.concat(sym.tagv.vals, ",")).."}" |
| 78 | + end |
| 79 | + table.insert(dsymt,"{"..symstr.."}") |
| 80 | + end |
| 81 | + ocode = "_G['LCDEBUG!!!'] = {\n"..table.concat(dsymt, ",\n").."\n}\n" .. ocode |
| 82 | +end |
51 | 83 |
|
52 | 84 | local minifier = providers[args.minifier] |
53 | 85 | dprint("Minifier: "..args.minifier, minifier) |
|
0 commit comments