~deciduously/nlox

6dc0caee503234b11cc7f326eee36e66e02baa7e — Ben Lovy 29 days ago ea8f8a1
CLI
4 files changed, 30 insertions(+), 11 deletions(-)

M src/nlox.nim
M src/nloxpkg/lox.nim
A test.lox
M tests/test1.nim
M src/nlox.nim => src/nlox.nim +13 -1
@@ 2,6 2,18 @@
# uses this file as the main entry point of the application.

import nloxpkg/lox
import os

let usage*: string = "Usage: nlox [script]"

when isMainModule:
  run()
    let params = commandLineParams()
    let num_params = params.len()

    if num_params > 1:
        echo usage
        quit(64)
    elif num_params == 1:
      run_file(params[0])
    else:
      run_prompt()
\ No newline at end of file

M src/nloxpkg/lox.nim => src/nloxpkg/lox.nim +15 -9
@@ 1,11 1,17 @@
# This is just an example to get you started. Users of your hybrid library will
# import this file by writing ``import treewalkpkg/submodule``. Feel free to rename or
# remove this file altogether. You may create additional modules alongside
# this file as required.
#! The top-level of the Lox interpreter.

let usage*: string = "Usage: nlox [script]"
# Interpret Lox input, results to stdout
proc run(source: string) =
    echo source

# Entrypoint - java's main
proc run*() =
    echo usage
    # Check arg num
# Interpret a source file
proc run_file*(path: string) =
    run(readFile(path))

# Open a REPL
proc run_prompt*() =
    while true:
        stdout.write("> ")
        let line = stdin.readLine()
        if line.len() == 0: break
        run(line)
\ No newline at end of file

A test.lox => test.lox +1 -0
@@ 0,0 1,1 @@
print "hello, world";
\ No newline at end of file

M tests/test1.nim => tests/test1.nim +1 -1
@@ 7,6 7,6 @@

import unittest

import nloxpkg/lox
import nlox
test "correct usage message":
  check usage == "Usage: nlox [script]"