(300 lines)
1 NOMSU_VERSION = {5 }8 package.path = tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(table.concat(NOMSU_VERSION, ".")) .. "/?.lua;" .. package.path9 package.cpath = tostring(NOMSU_PREFIX) .. "/lib/nomsu/" .. tostring(table.concat(NOMSU_VERSION, ".")) .. "/?." .. tostring(clibtype) .. ";" .. package.cpath10 end23 end25 do27 List, Dict = _obj_0.List, _obj_0.Dict28 end29 NOMSU_VERSION = List(NOMSU_VERSION)34 local usage = [=[Nomsu Usage: nomsu [-V version] [--help | -h] [--version] [-O optimization level] [-v] [-c] [-s] [-d debugger] [--no-core] [(file | -t tool | -e "nomsu code..." | files... -- ) [nomsu args...]]36 OPTIONS37 -t <tool> Run a tool.38 -e Execute the specified string.39 -O <level> Run the compiler with the given optimization level (>0: use precompiled .lua versions of Nomsu files, when available).40 -v Verbose: print compiled lua code.41 -c Compile the input files into a .lua files.42 -s Check the input files for syntax errors.43 -d <debugger> Attempt to use the specified debugger to wrap the main body of execution.44 -h/--help Print this message.45 --version Print the version number and exit.46 --no-core Skip loading the Nomsu core by default.47 -V specify which Nomsu version is desired.48 <file> The Nomsu file to run (can be "-" to use stdin).49 ]=]55 print("Error: unable to find the 'lpeg' Lua module. Please install LPEG either from http://www.inf.puc-rio.br/~roberto/lpeg/re.html or, if you use luarocks: `luarocks install lpeg`")57 end60 do62 NomsuCode, LuaCode, Source = _obj_0.NomsuCode, _obj_0.LuaCode, _obj_0.Source63 end66 {:files: {|67 ( ("-m" %sep)? (file %sep)+ "--" %sep68 / file %sep69 / {~ '' %sep? -> 'nomsu://tools/repl.nom' ~}) |} :}70 {:nomsu_args: {| (nomsu_flag %sep)* {:extras: {| ({[^%sep]+} %sep)* |} :} |} :}71 |} ({.+}?)73 file <-74 ( "-e" %sep ({[^%sep]+} -> spoof)75 / "-t" %sep {~ {[^%sep]+} -> "nomsu://tools/%1.nom" ~}76 / !"--" {[^%sep]+})78 flag <- longflag / shortflag / "-" shortboolflag+79 longflag <-80 {:help: "--help" %true :}81 / {:version: "--version" %true :}82 / {:no_core: "--no-core" %true :}83 shortflag <-84 {:optimization: "-O" %sep? %number :}85 / {:debugger: ("-d" %sep? {[^%sep]+}) :}86 / {:requested_version: "-V" %sep? {([0-9.])+} :}87 shortboolflag <-88 {:check_syntax: "s" %true:}89 / {:compile: "c" %true:}90 / {:verbose: "v" %true :}91 / {:help: "h" %true :}93 nomsu_flag <- nomsu_longflag / "-" nomsu_shortboolflag+94 nomsu_shortboolflag <- {| {:key: [a-zA-Z] :} {:value: %true :} |}95 nomsu_longflag <- '--' {| {:key: [^%sep=]+ :} {:value: ('=' {[^%sep]+}) / %true :} |}96 ]], {99 sep = lpeg.P(sep),100 spoof = Files.spoof101 })110 end112 print("Nomsu - A dynamically typed programming language with natural syntax and strong metaprogramming abilities.")116 end120 end125 nomsu_args[argpair.key] = argpair.value126 end127 nomsu_args.extras = List(args.nomsu_args.extras or { })132 suffixes = {137 }138 else139 suffixes = {142 }143 end150 end152 add_path(tostring(NOMSU_PREFIX) .. "/share/nomsu/" .. tostring(NOMSU_VERSION:joined_with(".")) .. "/lib")153 else155 end157 add_path(NOMSU_PACKAGEPATH)160 package.nomsuloaded = Dict({ })162 nomsu_environment.NOMSU_VERSION = NOMSU_VERSION163 nomsu_environment.COMMAND_LINE_ARGS = nomsu_args164 nomsu_environment.OPTIMIZATION = optimization165 nomsu_environment.NOMSU_PACKAGEPATH = NOMSU_PACKAGEPATH166 nomsu_environment.NOMSU_PREFIX = NOMSU_PREFIX167 nomsu_environment.COLOR_ENABLED = COLOR_ENABLED198 nomsu_environment._1_parsed(NomsuCode:from(source, code))215 code = NomsuCode:from(source, code)217 env.MODULE_NAME = filename220 output:write(tree.shebang)223 tree = {224 tree225 }229 lua:declare_locals()230 lua:prepend((chunk_no > 1) and '\n' or '', "-- File " .. tostring(filename) .. " chunk #" .. tostring(chunk_no) .. "\n")234 env:run(chunk)238 output:close()241 env.MODULE_NAME = filename248 env:run(code)250 code = NomsuCode:from(source, code)253 tree = {254 tree255 }259 lua:declare_locals()260 lua:prepend((chunk_no > 1) and '\n' or '', "-- File " .. tostring(filename) .. " chunk #" .. tostring(chunk_no) .. "\n")262 env:run(lua)280 env.MODULE_NAME = filename282 env:run(f)285 end288 debugger = { }289 else291 end294 guard = debugger295 else299 end