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 macros, os, osproc, regex, strformat, strutils
|
||||||
|
|
||||||
import "."/globals
|
|
||||||
|
|
||||||
proc execAction*(cmd: string, nostderr=false): string =
|
proc execAction*(cmd: string, nostderr=false): string =
|
||||||
var
|
var
|
||||||
ccmd = ""
|
ccmd = ""
|
||||||
|
|
@ -78,7 +76,9 @@ macro gitPull*(url: static string, outdirN = "", plistN = "", checkoutN = ""): u
|
||||||
gitReset(`outdirN`)
|
gitReset(`outdirN`)
|
||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
echo execAction(&"mkdir \"{outdir}\"")
|
let
|
||||||
|
flag = when not defined(Windows): "-p" else: ""
|
||||||
|
echo execAction(&"mkdir {flag} \"{outdir}\"")
|
||||||
|
|
||||||
echo "Setting up Git repo: " & url
|
echo "Setting up Git repo: " & url
|
||||||
discard execAction(&"cd \"{outdir}\" && git init .")
|
discard execAction(&"cd \"{outdir}\" && git init .")
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import tables
|
||||||
|
|
||||||
import regex
|
import regex
|
||||||
|
|
||||||
when not defined(CIMPORT):
|
when not declared(CIMPORT):
|
||||||
import "."/treesitter/runtime
|
import "."/treesitter/runtime
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
@ -17,7 +17,7 @@ type
|
||||||
name*: string
|
name*: string
|
||||||
kind*: Kind
|
kind*: Kind
|
||||||
children*: seq[ref Ast]
|
children*: seq[ref Ast]
|
||||||
when not defined(CIMPORT):
|
when not declared(CIMPORT):
|
||||||
tonim*: proc (ast: ref Ast, node: TSNode)
|
tonim*: proc (ast: ref Ast, node: TSNode)
|
||||||
regex*: Regex
|
regex*: Regex
|
||||||
|
|
||||||
|
|
@ -33,7 +33,7 @@ type
|
||||||
|
|
||||||
ast*: Table[string, seq[ref Ast]]
|
ast*: Table[string, seq[ref Ast]]
|
||||||
data*: seq[tuple[name, val: string]]
|
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.}]]
|
grammar*: seq[tuple[grammar: string, call: proc(ast: ref Ast, node: TSNode) {.nimcall.}]]
|
||||||
|
|
||||||
var
|
var
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import os, strutils
|
||||||
|
|
||||||
import "."/git
|
import "."/git
|
||||||
|
|
||||||
static:
|
proc treesitterSetup*() =
|
||||||
gitPull("https://github.com/tree-sitter/tree-sitter/", "inc/treesitter", """
|
gitPull("https://github.com/tree-sitter/tree-sitter/", "inc/treesitter", """
|
||||||
include/*
|
include/*
|
||||||
src/runtime/*
|
src/runtime/*
|
||||||
|
|
@ -13,12 +13,27 @@ src/runtime/*
|
||||||
*.h
|
*.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", """
|
gitPull("https://github.com/tree-sitter/tree-sitter-c", "inc/treesitter_c", """
|
||||||
src/*.h
|
src/*.h
|
||||||
src/*.c
|
src/*.c
|
||||||
src/*.cc
|
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", """
|
gitPull("https://github.com/tree-sitter/tree-sitter-cpp", "inc/treesitter_cpp", """
|
||||||
src/*.h
|
src/*.h
|
||||||
src/*.c
|
src/*.c
|
||||||
|
|
@ -26,17 +41,8 @@ src/*.cc
|
||||||
""")
|
""")
|
||||||
|
|
||||||
let
|
let
|
||||||
stack = "inc/treesitter/src/runtime/stack.c"
|
|
||||||
headerc = "inc/treesitter_c/src/parser.h"
|
|
||||||
headercpp = "inc/treesitter_cpp/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("""
|
headercpp.writeFile("""
|
||||||
typedef struct TSLanguage TSLanguage;
|
typedef struct TSLanguage TSLanguage;
|
||||||
const TSLanguage *tree_sitter_cpp();
|
const TSLanguage *tree_sitter_cpp();
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
|
import ".."/setup
|
||||||
|
|
||||||
|
static:
|
||||||
|
treesitterCSetup()
|
||||||
|
|
||||||
import "."/runtime
|
import "."/runtime
|
||||||
|
|
||||||
{.compile: ("../../inc/treesitter_c/src/parser.c", "parserc.o").}
|
{.compile: ("../../inc/treesitter_c/src/parser.c", "parserc.o").}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,10 @@
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
|
import ".."/setup
|
||||||
|
|
||||||
|
static:
|
||||||
|
treesitterCppSetup()
|
||||||
|
|
||||||
import "."/runtime
|
import "."/runtime
|
||||||
|
|
||||||
{.compile: ("../../inc/treesitter_cpp/src/parser.c", "parsercpp.o").}
|
{.compile: ("../../inc/treesitter_cpp/src/parser.c", "parsercpp.o").}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,11 @@
|
||||||
|
|
||||||
import strutils
|
import strutils
|
||||||
|
|
||||||
|
import ".."/setup
|
||||||
|
|
||||||
|
static:
|
||||||
|
treesitterSetup()
|
||||||
|
|
||||||
const sourcePath = currentSourcePath().split({'\\', '/'})[0..^4].join("/") & "/inc/treesitter"
|
const sourcePath = currentSourcePath().split({'\\', '/'})[0..^4].join("/") & "/inc/treesitter"
|
||||||
|
|
||||||
{.passC: "-std=c11 -DUTF8PROC_STATIC".}
|
{.passC: "-std=c11 -DUTF8PROC_STATIC".}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,3 @@
|
||||||
import nimterop/setup
|
|
||||||
|
|
||||||
import os, strformat, strutils
|
import os, strformat, strutils
|
||||||
|
|
||||||
import nimterop/treesitter/[runtime, c, cpp]
|
import nimterop/treesitter/[runtime, c, cpp]
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue