Skip to content

Commit

Permalink
update cli commands
Browse files Browse the repository at this point in the history
Signed-off-by: George Lemon <[email protected]>
  • Loading branch information
georgelemon committed Apr 17, 2024
1 parent 356ab98 commit 37ced0f
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/tim/app/astCmd.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import std/os
import pkg/flatty
import pkg/kapsis/[cli, runtime]
import ../engine/[parser, ast, compilers/html]

proc astCommand*(v: Values) =
## Build binary AST from a `timl` file
let fpath = v.get("timl").getPath.path
let opath = normalizedPath(getCurrentDir() / v.get("output").getFilename)
let p = parseSnippet(fpath, readFile(getCurrentDir() / fpath))
if likely(not p.hasErrors):
writeFile(opath, flatty.toFlatty(parser.getAst(p)))
11 changes: 11 additions & 0 deletions src/tim/app/compileCmd.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import std/[os, strutils]
import pkg/kapsis/[cli, runtime]
import ../engine/[parser, compilers/html]

proc cCommand*(v: Values) =
## Transpiles a `.timl` file to a target source
let fpath = v.get("timl").getPath.path
let p = parseSnippet(fpath, readFile(getCurrentDir() / fpath))
if likely(not p.hasErrors):
let c = newCompiler(parser.getAst(p), false)
display(c.getHtml().strip)
11 changes: 11 additions & 0 deletions src/tim/app/reprCmd.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import std/[os, strutils]
import pkg/flatty
import pkg/kapsis/[cli, runtime]
import ../engine/[parser, ast, compilers/html]

proc reprCommand*(v: Values) =
## Read a binary AST to target source
let fpath = v.get("ast").getPath.path
let c = newCompiler(flatty.fromFlatty(readFile(fpath), Ast), false)
if likely(not c.hasErrors):
display(c.getHtml().strip)

0 comments on commit 37ced0f

Please sign in to comment.