-
Notifications
You must be signed in to change notification settings - Fork 108
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
68,190 additions
and
68,736 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
root = true | ||
|
||
[*] | ||
charset = utf-8 | ||
end_of_line = lf | ||
insert_final_newline = true | ||
trim_trailing_whitespace = true | ||
|
||
[*.{json,toml,yml,gyp}] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.js] | ||
indent_style = space | ||
indent_size = 2 | ||
|
||
[*.rs] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.{c,cc,h}] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.{py,pyi}] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.swift] | ||
indent_style = space | ||
indent_size = 4 | ||
|
||
[*.go] | ||
indent_style = tab | ||
indent_size = 8 | ||
|
||
[Makefile] | ||
indent_style = tab | ||
indent_size = 8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
[package] | ||
name = "tree-sitter-c" | ||
name = "tree-sitter-idac" | ||
description = "C grammar for the tree-sitter parsing library" | ||
version = "0.20.6" | ||
authors = ["Max Brunsfeld <[email protected]>"] | ||
license = "MIT" | ||
readme = "bindings/rust/README.md" | ||
keywords = ["incremental", "parsing", "c"] | ||
categories = ["parsing", "text-editors"] | ||
repository = "https://github.com/tree-sitter/tree-sitter-c" | ||
repository = "https://github.com/tree-sitter/tree-sitter-idac" | ||
edition = "2021" | ||
autoexamples = false | ||
|
||
|
@@ -18,7 +18,7 @@ include = ["bindings/rust/*", "grammar.js", "queries/*", "src/*"] | |
path = "bindings/rust/lib.rs" | ||
|
||
[dependencies] | ||
tree-sitter = "0.20.10" | ||
tree-sitter = ">=0.21.0" | ||
|
||
[build-dependencies] | ||
cc = "~1.0" | ||
cc = "1.0.94" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
VERSION := 0.0.1 | ||
|
||
# Repository | ||
SRC_DIR := src | ||
|
||
LANGUAGE_NAME := c | ||
UPPER_LANGUAGE_NAME := C | ||
|
||
PARSER_REPO_URL := $(shell git -C $(SRC_DIR) remote get-url origin ) | ||
|
||
ifeq (, $(PARSER_URL)) | ||
PARSER_URL := $(subst .git,,$(PARSER_REPO_URL)) | ||
ifeq ($(shell echo $(PARSER_URL) | grep '^[a-z][-+.0-9a-z]*://'),) | ||
PARSER_URL := $(subst :,/,$(PARSER_URL)) | ||
PARSER_URL := $(subst git@,https://,$(PARSER_URL)) | ||
endif | ||
endif | ||
|
||
# install directory layout | ||
PREFIX ?= /usr/local | ||
INCLUDEDIR ?= $(PREFIX)/include | ||
LIBDIR ?= $(PREFIX)/lib | ||
PCLIBDIR ?= $(LIBDIR)/pkgconfig | ||
|
||
# collect C++ sources, and link if necessary | ||
CPPSRC := $(wildcard $(SRC_DIR)/*.cc) | ||
|
||
ifeq (, $(CPPSRC)) | ||
ADDITIONALLIBS := | ||
else | ||
ADDITIONALLIBS := -lc++ | ||
endif | ||
|
||
# collect sources | ||
SRC := $(wildcard $(SRC_DIR)/*.c) | ||
SRC += $(CPPSRC) | ||
OBJ := $(addsuffix .o,$(basename $(SRC))) | ||
|
||
# ABI versioning | ||
SONAME_MAJOR := 0 | ||
SONAME_MINOR := 0 | ||
|
||
CFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR) | ||
CXXFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR) | ||
override CFLAGS += -std=gnu99 -fPIC | ||
override CXXFLAGS += -fPIC | ||
|
||
# OS-specific bits | ||
ifeq ($(shell uname),Darwin) | ||
SOEXT = dylib | ||
SOEXTVER_MAJOR = $(SONAME_MAJOR).dylib | ||
SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).dylib | ||
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl, | ||
ifneq ($(ADDITIONALLIBS),) | ||
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS), | ||
endif | ||
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(LANGUAGE_NAME).$(SONAME_MAJOR).dylib,-rpath,@executable_path/../Frameworks | ||
else ifneq (,$(filter $(shell uname),Linux FreeBSD NetBSD DragonFly)) | ||
SOEXT = so | ||
SOEXTVER_MAJOR = so.$(SONAME_MAJOR) | ||
SOEXTVER = so.$(SONAME_MAJOR).$(SONAME_MINOR) | ||
LINKSHARED := $(LINKSHARED)-shared -Wl, | ||
ifneq ($(ADDITIONALLIBS),) | ||
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS) | ||
endif | ||
LINKSHARED := $(LINKSHARED)-soname,libtree-sitter-$(LANGUAGE_NAME).so.$(SONAME_MAJOR) | ||
else ifeq ($(OS),Windows_NT) | ||
$(error "Windows is not supported") | ||
endif | ||
ifneq (,$(filter $(shell uname),FreeBSD NetBSD DragonFly)) | ||
PCLIBDIR := $(PREFIX)/libdata/pkgconfig | ||
endif | ||
|
||
all: libtree-sitter-$(LANGUAGE_NAME).a libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) bindings/c/$(LANGUAGE_NAME).h bindings/c/tree-sitter-$(LANGUAGE_NAME).pc | ||
|
||
libtree-sitter-$(LANGUAGE_NAME).a: $(OBJ) | ||
$(AR) rcs $@ $^ | ||
|
||
libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER): $(OBJ) | ||
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ | ||
ln -sf $@ libtree-sitter-$(LANGUAGE_NAME).$(SOEXT) | ||
ln -sf $@ libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) | ||
|
||
bindings/c/$(LANGUAGE_NAME).h: | ||
sed -e 's|@UPPER_LANGUAGENAME@|$(UPPER_LANGUAGE_NAME)|' \ | ||
-e 's|@LANGUAGENAME@|$(LANGUAGE_NAME)|' \ | ||
bindings/c/tree-sitter.h.in > $@ | ||
|
||
bindings/c/tree-sitter-$(LANGUAGE_NAME).pc: | ||
sed -e 's|@LIBDIR@|$(LIBDIR)|;s|@INCLUDEDIR@|$(INCLUDEDIR)|;s|@VERSION@|$(VERSION)|' \ | ||
-e 's|=$(PREFIX)|=$${prefix}|' \ | ||
-e 's|@PREFIX@|$(PREFIX)|' \ | ||
-e 's|@ADDITIONALLIBS@|$(ADDITIONALLIBS)|' \ | ||
-e 's|@LANGUAGENAME@|$(LANGUAGE_NAME)|' \ | ||
-e 's|@PARSERURL@|$(PARSER_URL)|' \ | ||
bindings/c/tree-sitter.pc.in > $@ | ||
|
||
install: all | ||
install -d '$(DESTDIR)$(LIBDIR)' | ||
install -m755 libtree-sitter-$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(LANGUAGE_NAME).a | ||
install -m755 libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) | ||
ln -sf libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) | ||
ln -sf libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(LANGUAGE_NAME).$(SOEXT) | ||
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter | ||
install -m644 bindings/c/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/ | ||
install -d '$(DESTDIR)$(PCLIBDIR)' | ||
install -m644 bindings/c/tree-sitter-$(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/ | ||
|
||
clean: | ||
rm -f $(OBJ) libtree-sitter-$(LANGUAGE_NAME).a libtree-sitter-$(LANGUAGE_NAME).$(SOEXT) libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) libtree-sitter-$(LANGUAGE_NAME).$(SOEXTVER) | ||
rm -f bindings/c/$(LANGUAGE_NAME).h bindings/c/tree-sitter-$(LANGUAGE_NAME).pc | ||
|
||
.PHONY: all install clean |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef TREE_SITTER_IDAC_H_ | ||
#define TREE_SITTER_IDAC_H_ | ||
|
||
typedef struct TSLanguage TSLanguage; | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
const TSLanguage *tree_sitter_idac(void); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // TREE_SITTER_IDAC_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
prefix=@PREFIX@ | ||
libdir=@LIBDIR@ | ||
includedir=@INCLUDEDIR@ | ||
|
||
Name: tree-sitter-idac | ||
Description: Idac grammar for tree-sitter | ||
URL: @URL@ | ||
Version: @VERSION@ | ||
Requires: @REQUIRES@ | ||
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-idac | ||
Cflags: -I${includedir} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package tree_sitter_c | ||
|
||
// #cgo CFLAGS: -O3 -Wall -Wextra -std=gnu99 -fPIC -I../../src | ||
// #include "../../src/tree_sitter/parser.h" | ||
// #include "../../src/parser.c" | ||
// // if you have a scanner, you need to include it here too | ||
import "C" | ||
|
||
import ( | ||
"unsafe" | ||
|
||
tree_sitter "github.com/smacker/go-tree-sitter" | ||
) | ||
|
||
// Get the tree-sitter Language for this grammar. | ||
func Language() *tree_sitter.Language { | ||
ptr := unsafe.Pointer(C.tree_sitter_c()) | ||
return tree_sitter.NewLanguage(ptr) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package tree_sitter_c_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/tree-sitter/tree-sitter-idac" | ||
) | ||
|
||
func TestCanLoadGrammar(t *testing.T) { | ||
parser := tree_sitter_c.Language() | ||
if parser == nil { | ||
t.Errorf("Error loading C grammar") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module github.com/tree-sitter/tree-sitter-c | ||
|
||
go 1.20 | ||
|
||
require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,20 @@ | ||
#include "nan.h" | ||
#include "tree_sitter/parser.h" | ||
#include <node.h> | ||
#include <napi.h> | ||
|
||
using namespace v8; | ||
typedef struct TSLanguage TSLanguage; | ||
|
||
extern "C" TSLanguage *tree_sitter_c(); | ||
|
||
namespace { | ||
|
||
NAN_METHOD(New) {} | ||
|
||
void Init(Local<Object> exports, Local<Object> module) { | ||
Local<FunctionTemplate> tpl = Nan::New<FunctionTemplate>(New); | ||
tpl->SetClassName(Nan::New("Language").ToLocalChecked()); | ||
tpl->InstanceTemplate()->SetInternalFieldCount(1); | ||
|
||
Local<Function> constructor = Nan::GetFunction(tpl).ToLocalChecked(); | ||
Local<Object> instance = | ||
constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); | ||
Nan::SetInternalFieldPointer(instance, 0, tree_sitter_c()); | ||
|
||
Nan::Set(instance, Nan::New("name").ToLocalChecked(), | ||
Nan::New("c").ToLocalChecked()); | ||
Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); | ||
// "tree-sitter", "language" hashed with BLAKE2 | ||
const napi_type_tag LANGUAGE_TYPE_TAG = { | ||
0x8AF2E5212AD58ABF, 0xD5006CAD83ABBA16 | ||
}; | ||
|
||
Napi::Object Init(Napi::Env env, Napi::Object exports) { | ||
exports["name"] = Napi::String::New(env, "c"); | ||
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_c()); | ||
language.TypeTag(&LANGUAGE_TYPE_TAG); | ||
exports["language"] = language; | ||
return exports; | ||
} | ||
|
||
NODE_MODULE(tree_sitter_c_binding, Init) | ||
|
||
} // namespace | ||
NODE_API_MODULE(tree_sitter_c_binding, Init) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
type BaseNode = { | ||
type: string; | ||
named: boolean; | ||
}; | ||
|
||
type ChildNode = { | ||
multiple: boolean; | ||
required: boolean; | ||
types: BaseNode[]; | ||
}; | ||
|
||
type NodeInfo = | ||
| (BaseNode & { | ||
subtypes: BaseNode[]; | ||
}) | ||
| (BaseNode & { | ||
fields: { [name: string]: ChildNode }; | ||
children: ChildNode[]; | ||
}); | ||
|
||
type Language = { | ||
name: string; | ||
language: unknown; | ||
nodeTypeInfo: NodeInfo[]; | ||
}; | ||
|
||
declare const language: Language; | ||
export = language; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,7 @@ | ||
try { | ||
module.exports = require('../../build/Release/tree_sitter_c_binding'); | ||
} catch (error1) { | ||
if (error1.code !== 'MODULE_NOT_FOUND') { | ||
throw error1; | ||
} | ||
try { | ||
module.exports = require('../../build/Debug/tree_sitter_c_binding'); | ||
} catch (error2) { | ||
if (error2.code !== 'MODULE_NOT_FOUND') { | ||
throw error2; | ||
} | ||
throw error1; | ||
} | ||
} | ||
const root = require("path").join(__dirname, "..", ".."); | ||
|
||
module.exports = require("node-gyp-build")(root); | ||
|
||
try { | ||
module.exports.nodeTypeInfo = require('../../src/node-types.json'); | ||
module.exports.nodeTypeInfo = require("../../src/node-types.json"); | ||
} catch (_) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
"Idac grammar for tree-sitter" | ||
|
||
from ._binding import language | ||
|
||
__all__ = ["language"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
def language() -> int: ... |
Oops, something went wrong.