diff options
| author | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-17 08:28:57 -0600 |
|---|---|---|
| committer | Ganesh Viswanathan <dev@genotrance.com> | 2019-01-17 08:28:57 -0600 |
| commit | a491201bb2508c48bfb3ef34164c4dc3845fb1cb (patch) | |
| tree | f29d53a38512a679c905bbf43e73c6a02439de4e | |
| parent | ab3543cbdaed38fa4f79ce5479e2db37110a53ee (diff) | |
| download | nimterop-a491201bb2508c48bfb3ef34164c4dc3845fb1cb.tar.gz nimterop-a491201bb2508c48bfb3ef34164c4dc3845fb1cb.zip | |
Call setup on per wrapper basis
| -rw-r--r-- | nimterop/git.nim | 6 | ||||
| -rw-r--r-- | nimterop/globals.nim | 6 | ||||
| -rw-r--r-- | nimterop/setup.nim | 26 | ||||
| -rw-r--r-- | nimterop/treesitter/c.nim | 5 | ||||
| -rw-r--r-- | nimterop/treesitter/cpp.nim | 5 | ||||
| -rw-r--r-- | nimterop/treesitter/runtime.nim | 5 | ||||
| -rw-r--r-- | toast.nim | 2 |
7 files changed, 37 insertions, 18 deletions
diff --git a/nimterop/git.nim b/nimterop/git.nim index bebf75e..8617b8b 100644 --- a/nimterop/git.nim +++ b/nimterop/git.nim @@ -1,7 +1,5 @@ import macros, os, osproc, regex, strformat, strutils -import "."/globals - proc execAction*(cmd: string, nostderr=false): string = var ccmd = "" @@ -78,7 +76,9 @@ macro gitPull*(url: static string, outdirN = "", plistN = "", checkoutN = ""): u gitReset(`outdirN`) return else: - echo execAction(&"mkdir \"{outdir}\"") + let + flag = when not defined(Windows): "-p" else: "" + echo execAction(&"mkdir {flag} \"{outdir}\"") echo "Setting up Git repo: " & url discard execAction(&"cd \"{outdir}\" && git init .") diff --git a/nimterop/globals.nim b/nimterop/globals.nim index 5fb100c..121b799 100644 --- a/nimterop/globals.nim +++ b/nimterop/globals.nim @@ -2,7 +2,7 @@ import tables import regex -when not defined(CIMPORT): +when not declared(CIMPORT): import "."/treesitter/runtime type @@ -17,7 +17,7 @@ type name*: string kind*: Kind children*: seq[ref Ast] - when not defined(CIMPORT): + when not declared(CIMPORT): tonim*: proc (ast: ref Ast, node: TSNode) regex*: Regex @@ -33,7 +33,7 @@ type ast*: Table[string, seq[ref Ast]] data*: seq[tuple[name, val: string]] - when not defined(CIMPORT): + when not declared(CIMPORT): grammar*: seq[tuple[grammar: string, call: proc(ast: ref Ast, node: TSNode) {.nimcall.}]] var diff --git a/nimterop/setup.nim b/nimterop/setup.nim index baa9ecb..c3edb99 100644 --- a/nimterop/setup.nim +++ b/nimterop/setup.nim @@ -2,7 +2,7 @@ import os, strutils import "."/git -static: +proc treesitterSetup*() = gitPull("https://github.com/tree-sitter/tree-sitter/", "inc/treesitter", """ include/* src/runtime/* @@ -13,12 +13,27 @@ src/runtime/* *.h """) + let + stack = "inc/treesitter/src/runtime/stack.c" + + stack.writeFile(stack.readFile().replace("inline Stack", "Stack")) + +proc treesitterCSetup*() = gitPull("https://github.com/tree-sitter/tree-sitter-c", "inc/treesitter_c", """ src/*.h src/*.c src/*.cc """) + let + headerc = "inc/treesitter_c/src/parser.h" + + headerc.writeFile(""" + typedef struct TSLanguage TSLanguage; + const TSLanguage *tree_sitter_c(); + """) + +proc treesitterCppSetup*() = gitPull("https://github.com/tree-sitter/tree-sitter-cpp", "inc/treesitter_cpp", """ src/*.h src/*.c @@ -26,17 +41,8 @@ src/*.cc """) let - stack = "inc/treesitter/src/runtime/stack.c" - headerc = "inc/treesitter_c/src/parser.h" headercpp = "inc/treesitter_cpp/src/parser.h" - stack.writeFile(stack.readFile().replace("inline Stack", "Stack")) - - headerc.writeFile(""" - typedef struct TSLanguage TSLanguage; - const TSLanguage *tree_sitter_c(); - """) - headercpp.writeFile(""" typedef struct TSLanguage TSLanguage; const TSLanguage *tree_sitter_cpp(); diff --git a/nimterop/treesitter/c.nim b/nimterop/treesitter/c.nim index 9310f97..da13f2e 100644 --- a/nimterop/treesitter/c.nim +++ b/nimterop/treesitter/c.nim @@ -1,5 +1,10 @@ import strutils +import ".."/setup + +static: + treesitterCSetup() + import "."/runtime {.compile: ("../../inc/treesitter_c/src/parser.c", "parserc.o").} diff --git a/nimterop/treesitter/cpp.nim b/nimterop/treesitter/cpp.nim index 794d6c0..ec6cf2c 100644 --- a/nimterop/treesitter/cpp.nim +++ b/nimterop/treesitter/cpp.nim @@ -1,5 +1,10 @@ import strutils +import ".."/setup + +static: + treesitterCppSetup() + import "."/runtime {.compile: ("../../inc/treesitter_cpp/src/parser.c", "parsercpp.o").} diff --git a/nimterop/treesitter/runtime.nim b/nimterop/treesitter/runtime.nim index ca93fd4..b255eba 100644 --- a/nimterop/treesitter/runtime.nim +++ b/nimterop/treesitter/runtime.nim @@ -2,6 +2,11 @@ import strutils +import ".."/setup + +static: + treesitterSetup() + const sourcePath = currentSourcePath().split({'\\', '/'})[0..^4].join("/") & "/inc/treesitter" {.passC: "-std=c11 -DUTF8PROC_STATIC".} @@ -1,5 +1,3 @@ -import nimterop/setup - import os, strformat, strutils import nimterop/treesitter/[runtime, c, cpp] |
