Skip to content

Commit 014e8e0

Browse files
committed
idac
1 parent 212a80f commit 014e8e0

29 files changed

Lines changed: 68190 additions & 68736 deletions

.editorconfig

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
trim_trailing_whitespace = true
8+
9+
[*.{json,toml,yml,gyp}]
10+
indent_style = space
11+
indent_size = 2
12+
13+
[*.js]
14+
indent_style = space
15+
indent_size = 2
16+
17+
[*.rs]
18+
indent_style = space
19+
indent_size = 4
20+
21+
[*.{c,cc,h}]
22+
indent_style = space
23+
indent_size = 4
24+
25+
[*.{py,pyi}]
26+
indent_style = space
27+
indent_size = 4
28+
29+
[*.swift]
30+
indent_style = space
31+
indent_size = 4
32+
33+
[*.go]
34+
indent_style = tab
35+
indent_size = 8
36+
37+
[Makefile]
38+
indent_style = tab
39+
indent_size = 8

Cargo.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
[package]
2-
name = "tree-sitter-c"
2+
name = "tree-sitter-idac"
33
description = "C grammar for the tree-sitter parsing library"
44
version = "0.20.6"
55
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
66
license = "MIT"
77
readme = "bindings/rust/README.md"
88
keywords = ["incremental", "parsing", "c"]
99
categories = ["parsing", "text-editors"]
10-
repository = "https://github.com/tree-sitter/tree-sitter-c"
10+
repository = "https://github.com/tree-sitter/tree-sitter-idac"
1111
edition = "2021"
1212
autoexamples = false
1313

@@ -18,7 +18,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"]
1818
path = "bindings/rust/lib.rs"
1919

2020
[dependencies]
21-
tree-sitter = "0.20.10"
21+
tree-sitter = ">=0.21.0"
2222

2323
[build-dependencies]
24-
cc = "~1.0"
24+
cc = "1.0.94"

Makefile

Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
VERSION := 0.0.1
2+
3+
# Repository
4+
SRC_DIR := src
5+
6+
LANGUAGE_NAME := c
7+
UPPER_LANGUAGE_NAME := C
8+
9+
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin )
10+
11+
ifeq (, $(PARSER_URL))
12+
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL))
13+
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),)
14+
PARSER_URL := $(subst :,/,$(PARSER_URL))
15+
PARSER_URL := $(subst git@,https://,$(PARSER_URL))
16+
endif
17+
endif
18+
19+
# install directory layout
20+
PREFIX ?= /usr/local
21+
INCLUDEDIR ?= $(PREFIX)/include
22+
LIBDIR ?= $(PREFIX)/lib
23+
PCLIBDIR ?= $(LIBDIR)/pkgconfig
24+
25+
# collect C++ sources, and link if necessary
26+
CPPSRC := $(wildcard $(SRC_DIR)/*.cc)
27+
28+
ifeq (, $(CPPSRC))
29+
ADDITIONALLIBS :=
30+
else
31+
ADDITIONALLIBS := -lc++
32+
endif
33+
34+
# collect sources
35+
SRC := $(wildcard $(SRC_DIR)/*.c)
36+
SRC += $(CPPSRC)
37+
OBJ := $(addsuffix .o,$(basename $(SRC)))
38+
39+
# ABI versioning
40+
SONAME_MAJOR := 0
41+
SONAME_MINOR := 0
42+
43+
CFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
44+
CXXFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
45+
override CFLAGS += -std=gnu99 -fPIC
46+
override CXXFLAGS += -fPIC
47+
48+
# OS-specific bits
49+
ifeq ($(shell uname),Darwin)
50+
SOEXT = dylib
51+
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib
52+
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib
53+
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
54+
ifneq ($(ADDITIONALLIBS),)
55+
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS),
56+
endif
57+
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks
58+
else ifneq (,$(filter $(shell uname),Linux FreeBSD NetBSD DragonFly))
59+
SOEXT = so
60+
SOEXTVER_MAJOR = so.$(SONAME_MAJOR)
61+
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR)
62+
LINKSHARED := $(LINKSHARED)-shared -Wl,
63+
ifneq ($(ADDITIONALLIBS),)
64+
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS)
65+
endif
66+
LINKSHARED := $(LINKSHARED)-soname,libtree-sitter-$(LANGUAGE_NAME).so.$(SONAME_MAJOR)
67+
else ifeq ($(OS),Windows_NT)
68+
$(error "Windows is not supported")
69+
endif
70+
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly))
71+
PCLIBDIR := $(PREFIX)/libdata/pkgconfig
72+
endif
73+
74+
all: libtree-sitter-$(LANGUAGE_NAME).a libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) bindings/c/$(LANGUAGE_NAME).h bindings/c/tree-sitter-$(LANGUAGE_NAME).pc
75+
76+
libtree-sitter-$(LANGUAGE_NAME).a: $(OBJ)
77+
$(AR) rcs $@ $^
78+
79+
libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER): $(OBJ)
80+
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
81+
ln -sf $@ libtree-sitter-$(LANGUAGE_NAME).$(SOEXT)
82+
ln -sf $@ libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
83+
84+
bindings/c/$(LANGUAGE_NAME).h:
85+
sed -e 's|@UPPER_LANGUAGENAME@|$(UPPER_LANGUAGE_NAME)|' \
86+
-e 's|@LANGUAGENAME@|$(LANGUAGE_NAME)|' \
87+
bindings/c/tree-sitter.h.in > $@
88+
89+
bindings/c/tree-sitter-$(LANGUAGE_NAME).pc:
90+
sed -e 's|@LIBDIR@|$(LIBDIR)|;s|@INCLUDEDIR@|$(INCLUDEDIR)|;s|@VERSION@|$(VERSION)|' \
91+
-e 's|=$(PREFIX)|=$${prefix}|' \
92+
-e 's|@PREFIX@|$(PREFIX)|' \
93+
-e 's|@ADDITIONALLIBS@|$(ADDITIONALLIBS)|' \
94+
-e 's|@LANGUAGENAME@|$(LANGUAGE_NAME)|' \
95+
-e 's|@PARSERURL@|$(PARSER_URL)|' \
96+
bindings/c/tree-sitter.pc.in > $@
97+
98+
install: all
99+
install -d '$(DESTDIR)$(LIBDIR)'
100+
install -m755 libtree-sitter-$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(LANGUAGE_NAME).a
101+
install -m755 libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER)
102+
ln -sf libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER_MAJOR)
103+
ln -sf libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(LANGUAGE_NAME).$(SOEXT)
104+
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter
105+
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/
106+
install -d '$(DESTDIR)$(PCLIBDIR)'
107+
install -m644 bindings/c/tree-sitter-$(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/
108+
109+
clean:
110+
rm -f $(OBJ) libtree-sitter-$(LANGUAGE_NAME).a libtree-sitter-$(LANGUAGE_NAME).$(SOEXT) libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER)
111+
rm -f bindings/c/$(LANGUAGE_NAME).h bindings/c/tree-sitter-$(LANGUAGE_NAME).pc
112+
113+
.PHONY: all install clean

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# tree-sitter-c
1+
# tree-sitter-idac
22

33
[![CI](https://github.com/tree-sitter/tree-sitter-c/actions/workflows/ci.yml/badge.svg)](https://github.com/tree-sitter/tree-sitter-c/actions/workflows/ci.yml)
44
[![Discord](https://img.shields.io/discord/1063097320771698699?logo=discord)](https://discord.gg/w7nTvsVJhm)

binding.gyp

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,29 @@
22
"targets": [
33
{
44
"target_name": "tree_sitter_c_binding",
5+
"dependencies": [
6+
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
7+
],
58
"include_dirs": [
6-
"<!(node -e \"require('nan')\")",
7-
"src"
9+
"src",
810
],
911
"sources": [
12+
"bindings/node/binding.cc",
1013
"src/parser.c",
11-
"bindings/node/binding.cc"
14+
# NOTE: if your language has an external scanner, add it here.
15+
],
16+
"conditions": [
17+
["OS!='win'", {
18+
"cflags_c": [
19+
"-std=c11",
20+
],
21+
}, { # OS == "win"
22+
"cflags_c": [
23+
"/std:c11",
24+
"/utf-8",
25+
],
26+
}],
1227
],
13-
"cflags_c": [
14-
"-std=c99",
15-
]
1628
}
1729
]
1830
}

bindings/c/tree-sitter-idac.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#ifndef TREE_SITTER_IDAC_H_
2+
#define TREE_SITTER_IDAC_H_
3+
4+
typedef struct TSLanguage TSLanguage;
5+
6+
#ifdef __cplusplus
7+
extern "C" {
8+
#endif
9+
10+
const TSLanguage *tree_sitter_idac(void);
11+
12+
#ifdef __cplusplus
13+
}
14+
#endif
15+
16+
#endif // TREE_SITTER_IDAC_H_

bindings/c/tree-sitter-idac.pc.in

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
prefix=@PREFIX@
2+
libdir=@LIBDIR@
3+
includedir=@INCLUDEDIR@
4+
5+
Name: tree-sitter-idac
6+
Description: Idac grammar for tree-sitter
7+
URL: @URL@
8+
Version: @VERSION@
9+
Requires: @REQUIRES@
10+
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-idac
11+
Cflags: -I${includedir}

bindings/go/binding.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package tree_sitter_c
2+
3+
// #cgo CFLAGS: -O3 -Wall -Wextra -std=gnu99 -fPIC -I../../src
4+
// #include "../../src/tree_sitter/parser.h"
5+
// #include "../../src/parser.c"
6+
// // if you have a scanner, you need to include it here too
7+
import "C"
8+
9+
import (
10+
"unsafe"
11+
12+
tree_sitter "github.com/smacker/go-tree-sitter"
13+
)
14+
15+
// Get the tree-sitter Language for this grammar.
16+
func Language() *tree_sitter.Language {
17+
ptr := unsafe.Pointer(C.tree_sitter_c())
18+
return tree_sitter.NewLanguage(ptr)
19+
}

bindings/go/binding_test.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package tree_sitter_c_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/tree-sitter/tree-sitter-idac"
7+
)
8+
9+
func TestCanLoadGrammar(t *testing.T) {
10+
parser := tree_sitter_c.Language()
11+
if parser == nil {
12+
t.Errorf("Error loading C grammar")
13+
}
14+
}

bindings/go/go.mod

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
module github.com/tree-sitter/tree-sitter-c
2+
3+
go 1.20
4+
5+
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8

0 commit comments

Comments
 (0)