Implemented help, compile, and help commands.
h3rald h3rald@h3rald.com
Sat, 07 Oct 2023 16:54:07 +0200
2 files changed,
48 insertions(+),
21 deletions(-)
M
min.nim
→
min.nim
@@ -188,7 +188,7 @@ except CatchableError:
discard i.close() -proc minFile*(filename: string, op = "interpret", main = true): seq[ +proc minFile*(fn: string, op = "interpret", main = true): seq[ string] {.discardable.} proc compile*(i: In, s: Stream, main = true): seq[string] =@@ -236,11 +236,8 @@
proc minStr*(buffer: string) = minStream(newStringStream(buffer), "input") -proc minFile*(filename: string, op = "interpret", main = true): seq[ +proc minFile*(fn: string, op = "interpret", main = true): seq[ string] {.discardable.} = - var fn = filename - if not filename.endsWith(".min"): - fn &= ".min" var fileLines = newSeq[string](0) var contents = "" try:@@ -263,7 +260,6 @@ minpkg/core/meta
var REPL = false var SIMPLEREPL = false - var COMPILE = false var MODULEPATH = "" var exeName = "min"@@ -342,20 +338,31 @@ proc minSimpleRepl*() =
var i = newMinInterpreter(filename = "<repl>") i.minSimpleRepl() + proc resolveFile(file: string): string = + if (file.endsWith(".min") or file.endsWith(".mn")) and fileExists(file): + return file + elif fileExists(file&".min"): + return file&".min" + elif fileExists(file&".mn"): + return file&".mn" + return "" let usage* = """ $exe v$version - a small but practical concatenative programming language (c) 2014-$year Fabio Cevasco Usage: - $exe [options] [filename] + $exe [options] [filename | command] [...comamand-arguments] Arguments: filename A $exe file to interpret or compile + command A command to execute + Commands: + compile <file>.min Compile <file>.min. + eval <string> Evaluate <string> as a min program. + help <symbol> Print the help contents related to <symbol>. Options: -a, --asset-path Specify a directory containing the asset files to include in the compiled executable (if -c is set) - -c, --compile Compile the specified file - -e, --evaluate Evaluate a $exe program inline -d, --dev Enable "development mode" (runtime checks) -h, --help Print this help -i, --interactive Start $exe shell (with advanced prompt, default if no file specidied)"@@ -372,7 +379,7 @@ "version", pkgVersion,
"year", $(now().year) ] - var file, s: string = "" + var file = "" var args = newSeq[string](0) logging.setLogFilter(logging.lvlNotice) var p = initOptParser()@@ -385,8 +392,6 @@ if file == "":
file = key of cmdLongOption, cmdShortOption: case key: - of "compile", "c": - COMPILE = true of "module-path", "m": MODULEPATH = val of "asset-path", "a":@@ -401,9 +406,6 @@ var val = val
niftylogger.setLogLevel(val) of "passN", "n": NIMOPTIONS = val - of "evaluate", "e": - if file == "": - s = val of "help", "h": if file == "": echo usage@@ -423,8 +425,6 @@ discard
else: discard var op = "interpret" - if COMPILE: - op = "compile" if MODULEPATH.len > 0: for f in walkDirRec(MODULEPATH): if f.endsWith(".min"):@@ -432,10 +432,31 @@ MINMODULES.add f
elif REPL: minRepl() quit(0) - if s != "": - minStr(s) - elif file != "": - minFile file, op + if file != "": + var fn = resolveFile(file) + if fn == "": + if file == "compile": + op = "compile" + if args.len < 2: + logging.error "[compile] No file was specified." + quit(8) + fn = resolveFile(args[1]) + if fn == "": + logging.error "[compile] File '$#' does not exist." % [args[1]] + quit(9) + elif file == "eval": + if args.len < 2: + logging.error "[eval] No string to evaluate was specified." + quit(9) + minStr args[1] + quit(0) + elif file == "help": + if args.len < 2: + logging.error "[help] No symbol to lookup was specified." + quit(9) + minStr("\"$#\" help" % [args[1]]) + quit(0) + minFile fn, op elif SIMPLEREPL: minSimpleRepl() quit(0)
M
next-release.md
→
next-release.md
@@ -1,9 +1,15 @@
+### BREAKING CHANGES + +* The `-c` option has been removed, use `min compile <file>.min` to compile a min file. +* The `-e` option has been removed, use `min eval <string>` to evaluate a string as a min program. + ### New Features * Added support for binary (0b) octal (0o), and hexadecimal (0x) integers in parser. * Added `base` and `base?` symbols to set and get the current number base (dec, hex, bin or oct). * Added `bitand`, `bitor`, `bitxor`, `bitparity`, `bitclear`, `bitflip`, `bitset`, `bitmask` symbols for biwise operations. * Added `to-(hex|bin|dec|oct)` and `from-(hex|bin|dec|oct)` symbols to convert integers to and from different string representations. +* Added `help`, `compile` and `eval` commands to the min executable. ### Fixes and Improvements