Made main.nim a bit nicer with command-line options
This commit is contained in:
parent
a6d22f740d
commit
990b54fa3e
52
src/main.nim
52
src/main.nim
|
@ -2,7 +2,9 @@
|
||||||
import strformat
|
import strformat
|
||||||
import strutils
|
import strutils
|
||||||
import terminal
|
import terminal
|
||||||
|
import parseopt
|
||||||
import os
|
import os
|
||||||
|
|
||||||
# Thanks art <3
|
# Thanks art <3
|
||||||
import jale/editor as ed
|
import jale/editor as ed
|
||||||
import jale/templates
|
import jale/templates
|
||||||
|
@ -18,6 +20,7 @@ import frontend/parser as p
|
||||||
import frontend/compiler as c
|
import frontend/compiler as c
|
||||||
import backend/vm as v
|
import backend/vm as v
|
||||||
import util/serializer as s
|
import util/serializer as s
|
||||||
|
import config
|
||||||
|
|
||||||
# Forward declarations
|
# Forward declarations
|
||||||
proc fillSymbolTable(tokenizer: Lexer)
|
proc fillSymbolTable(tokenizer: Lexer)
|
||||||
|
@ -290,11 +293,54 @@ proc runFile(f: string) =
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
setControlCHook(proc () {.noconv.} = quit(0))
|
setControlCHook(proc () {.noconv.} = quit(0))
|
||||||
let args = commandLineParams()
|
var optParser = initOptParser(commandLineParams())
|
||||||
if args.len() == 0:
|
var file: string = ""
|
||||||
|
var fromString: bool = false
|
||||||
|
var interactive: bool = false
|
||||||
|
for kind, key, value in optParser.getopt():
|
||||||
|
case kind:
|
||||||
|
of cmdArgument:
|
||||||
|
file = key
|
||||||
|
of cmdLongOption:
|
||||||
|
case key:
|
||||||
|
of "help":
|
||||||
|
echo HELP_MESSAGE
|
||||||
|
quit()
|
||||||
|
of "version":
|
||||||
|
echo PEON_VERSION_STRING
|
||||||
|
quit()
|
||||||
|
of "string":
|
||||||
|
file = key
|
||||||
|
fromString = true
|
||||||
|
of "interactive":
|
||||||
|
interactive = true
|
||||||
|
else:
|
||||||
|
echo &"error: unkown option '{key}'"
|
||||||
|
quit()
|
||||||
|
of cmdShortOption:
|
||||||
|
case key:
|
||||||
|
of "h":
|
||||||
|
echo HELP_MESSAGE
|
||||||
|
quit()
|
||||||
|
of "v":
|
||||||
|
echo PEON_VERSION_STRING
|
||||||
|
quit()
|
||||||
|
of "s":
|
||||||
|
file = key
|
||||||
|
fromString = true
|
||||||
|
of "i":
|
||||||
|
interactive = true
|
||||||
|
else:
|
||||||
|
echo &"error: unkown option '{key}'"
|
||||||
|
quit()
|
||||||
|
else:
|
||||||
|
echo "usage: peon [options] [filename.pn]"
|
||||||
|
quit()
|
||||||
|
# TODO: Use interactive/fromString options
|
||||||
|
if file == "":
|
||||||
repl()
|
repl()
|
||||||
else:
|
else:
|
||||||
runFile(args[0])
|
runFile(file)
|
||||||
|
|
||||||
|
|
||||||
proc fillSymbolTable(tokenizer: Lexer) =
|
proc fillSymbolTable(tokenizer: Lexer) =
|
||||||
|
|
Loading…
Reference in New Issue