Call setup on per wrapper basis
This commit is contained in:
parent
ab3543cbda
commit
a491201bb2
7 changed files with 37 additions and 18 deletions
|
|
@ -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 .")
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
import strutils
|
||||
|
||||
import ".."/setup
|
||||
|
||||
static:
|
||||
treesitterCSetup()
|
||||
|
||||
import "."/runtime
|
||||
|
||||
{.compile: ("../../inc/treesitter_c/src/parser.c", "parserc.o").}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,10 @@
|
|||
import strutils
|
||||
|
||||
import ".."/setup
|
||||
|
||||
static:
|
||||
treesitterCppSetup()
|
||||
|
||||
import "."/runtime
|
||||
|
||||
{.compile: ("../../inc/treesitter_cpp/src/parser.c", "parsercpp.o").}
|
||||
|
|
|
|||
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue