Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
--input -i cli args
Browse files Browse the repository at this point in the history
  • Loading branch information
iwl-lyam committed Jan 25, 2022
1 parent c1d4648 commit 25bdb89
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
29 changes: 19 additions & 10 deletions bin/index.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,29 @@
#!/usr/bin/env node

const argdef = [
{name: 'input', alias: 'i', type: String, defaultOption: true},
]

import stopwatch from 'statman-stopwatch'
import args from 'command-line-args'
import {Interpret} from '../interpreter.js'
import {Lexer} from '../lexer.js'
import {Parse} from '../parser.js'
import * as fs from 'fs'
import {Lexer} from '../lexer.js'
import {Parse} from '../parser.js'
import * as fs from 'fs'

export default function runner() {
const timer = new stopwatch(true)
let program = process.argv[2]
try {
const timer = new stopwatch(true)
const options = args(argdef)

if (!program) process.exit(1)
if (!options.input) process.exit(1)

let tokens = Lexer(fs.readFileSync(program).toString())
let script = Parse(tokens)
Interpret(script, false)
console.log("Executed in " + Math.floor(timer.stop()) + " ms")
let tokens = Lexer(fs.readFileSync(options.input).toString())
let script = Parse(tokens)
Interpret(script, false)
console.log("Executed in " + Math.floor(timer.stop()) + " ms")
} catch(err) {
console.log("Invalid argument")
}
}
runner()
34 changes: 34 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"bin": "0.0.0",
"caxa": "^2.1.0",
"chalk": "^4.1.2",
"command-line-args": "^5.2.0",
"fifo": "^2.4.1",
"math.js": "^1.1.46",
"mathjs": "^10.0.2",
Expand Down

0 comments on commit 25bdb89

Please sign in to comment.