Skip to content

Commit

Permalink
No longer use a global code formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
beef331 committed Jan 4, 2024
1 parent 36590a9 commit e2f2168
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 23 deletions.
38 changes: 18 additions & 20 deletions seeya.nim
Original file line number Diff line number Diff line change
Expand Up @@ -71,26 +71,24 @@ var
procDefs {.compileTime, used.} = ""
variables {.compileTime, used.} = ""
generatedTypes {.compileTime, used.}: HashSet[TypedNimNode]
codeFormatter* {.compileTime, used.} = ""

template makeHeader*(location: static string) =
macro makeHeader*(location: static string, formatter: static string = "") =
when defined(genHeader):
static:
var file = ""
for header {.inject.} in headers:
file.add fmt "#include {header}\n"
file.add "\n"

file.add typeDefs
file.add variables
file.add "\n"
file.add procDefs

writeFile(location, file)
if codeFormatter.len > 0:
let resp = staticExec(codeFormatter.replace("$file", location))
if resp.len > 0:
error(resp)
var file = ""
for header in headers:
file.add fmt "#include {header}\n"
file.add "\n"

file.add typeDefs
file.add variables
file.add "\n"
file.add procDefs

writeFile(location, file)
if formatter.len > 0:
let resp = staticExec(formatter.replace("$file", location))
if resp.len > 0:
error(resp)
else:
discard

Expand Down Expand Up @@ -541,7 +539,7 @@ when isMainModule:

static:
setFormatter(nameStr)
codeFormatter = "clang-format -i $file"

{.pragma: exporter, cdecl, dynlib, exportc: nameStr.}
{.pragma: exporterVar, dynlib, exportc: nameStr.}

Expand Down Expand Up @@ -608,4 +606,4 @@ when isMainModule:

var myGlobal {.exporterVar, expose.} = MyOtherType(rng: 3, otherRange: 3)
var inheritance {.exporterVar, expose.} = Child(x: 300)
makeHeader("tests/gend.h")
makeHeader("tests/gend.h", "clang-format -i $file")
2 changes: 1 addition & 1 deletion seeya.nimble
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Package

version = "0.1.2"
version = "0.1.3"
author = "Jason"
description = "Generates headers from nim code"
license = "MIT"
Expand Down
4 changes: 2 additions & 2 deletions tests/mylib.nim
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const nameStr = "mylib_$1"

static:
setFormatter(nameStr)
codeFormatter = "clang-format -i $file"

{.pragma: exporter, cdecl, dynlib, exportc: nameStr.}
{.pragma: exporterVar, dynlib, exportc: nameStr.}

Expand Down Expand Up @@ -57,4 +57,4 @@ let
do_stuff_float {.exporterVar, expose.} = doStuff[float]
do_stuff_seq_float {.exporterVar, expose.} = doStuff[seq[float]]

static: makeHeader("tests/mylib.h")
static: makeHeader("tests/mylib.h", "clang-format -i $file")

0 comments on commit e2f2168

Please sign in to comment.