Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

include generated files #245

Merged
merged 7 commits into from
Jun 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jobs:
- uses: actions/checkout@v3
- uses: actions/setup-node@v3
with:
node-version: 16
node-version: 20

- name: Display Node versions
run: |
Expand Down
4 changes: 0 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
bindings/
node_modules/
src/*
!src/scanner.c
log.html
binding.gyp
test_wild/
build/
21 changes: 21 additions & 0 deletions binding.gyp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"targets": [
{
"target_name": "tree_sitter_rescript_binding",
"dependencies": [
"<!(node -p \"require('node-addon-api').targets\"):node_addon_api_except",
],
"include_dirs": [
"src",
],
"sources": [
"bindings/node/binding.cc",
"src/parser.c",
# NOTE: if your language has an external scanner, add it here.
FreddieGilbraith marked this conversation as resolved.
Show resolved Hide resolved
],
"cflags_c": [
"-std=c11",
],
}
]
}
16 changes: 16 additions & 0 deletions bindings/c/tree-sitter-rescript.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TREE_SITTER_RESCRIPT_H_
#define TREE_SITTER_RESCRIPT_H_

typedef struct TSLanguage TSLanguage;

#ifdef __cplusplus
extern "C" {
#endif

const TSLanguage *tree_sitter_rescript(void);

#ifdef __cplusplus
}
#endif

#endif // TREE_SITTER_RESCRIPT_H_
11 changes: 11 additions & 0 deletions bindings/c/tree-sitter-rescript.pc.in
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@

Name: tree-sitter-rescript
Description: Rescript grammar for tree-sitter
URL: @URL@
Version: @VERSION@
Requires: @REQUIRES@
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-rescript
Cflags: -I${includedir}
13 changes: 13 additions & 0 deletions bindings/go/binding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package tree_sitter_rescript

// #cgo CFLAGS: -std=c11 -fPIC
// #include "../../src/parser.c"
// // NOTE: if your language has an external scanner, add it here.
import "C"

import "unsafe"

// Get the tree-sitter Language for this grammar.
func Language() unsafe.Pointer {
return unsafe.Pointer(C.tree_sitter_rescript())
}
15 changes: 15 additions & 0 deletions bindings/go/binding_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package tree_sitter_rescript_test

import (
"testing"

tree_sitter "github.com/smacker/go-tree-sitter"
"github.com/tree-sitter/tree-sitter-rescript"
)

func TestCanLoadGrammar(t *testing.T) {
language := tree_sitter.NewLanguage(tree_sitter_rescript.Language())
if language == nil {
t.Errorf("Error loading Rescript grammar")
}
}
5 changes: 5 additions & 0 deletions bindings/go/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module github.com/tree-sitter/tree-sitter-rescript

go 1.22

require github.com/smacker/go-tree-sitter v0.0.0-20230720070738-0d0a9f78d8f8
20 changes: 20 additions & 0 deletions bindings/node/binding.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include <napi.h>

typedef struct TSLanguage TSLanguage;

extern "C" TSLanguage *tree_sitter_rescript();

// "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, "rescript");
auto language = Napi::External<TSLanguage>::New(env, tree_sitter_rescript());
language.TypeTag(&LANGUAGE_TYPE_TAG);
exports["language"] = language;
return exports;
}

NODE_API_MODULE(tree_sitter_rescript_binding, Init)
28 changes: 28 additions & 0 deletions bindings/node/index.d.ts
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;
7 changes: 7 additions & 0 deletions bindings/node/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
const root = require("path").join(__dirname, "..", "..");

module.exports = require("node-gyp-build")(root);

try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}
5 changes: 5 additions & 0 deletions bindings/python/tree_sitter_rescript/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
"Rescript grammar for tree-sitter"

from ._binding import language

__all__ = ["language"]
1 change: 1 addition & 0 deletions bindings/python/tree_sitter_rescript/__init__.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
def language() -> int: ...
27 changes: 27 additions & 0 deletions bindings/python/tree_sitter_rescript/binding.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <Python.h>

typedef struct TSLanguage TSLanguage;

TSLanguage *tree_sitter_rescript(void);

static PyObject* _binding_language(PyObject *self, PyObject *args) {
return PyLong_FromVoidPtr(tree_sitter_rescript());
}

static PyMethodDef methods[] = {
{"language", _binding_language, METH_NOARGS,
"Get the tree-sitter language for this grammar."},
{NULL, NULL, 0, NULL}
};

static struct PyModuleDef module = {
.m_base = PyModuleDef_HEAD_INIT,
.m_name = "_binding",
.m_doc = NULL,
.m_size = -1,
.m_methods = methods
};

PyMODINIT_FUNC PyInit__binding(void) {
return PyModule_Create(&module);
}
Empty file.
19 changes: 19 additions & 0 deletions bindings/rust/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
fn main() {
let src_dir = std::path::Path::new("src");

let mut c_config = cc::Build::new();
c_config.std("c11").include(src_dir);

let parser_path = src_dir.join("parser.c");
c_config.file(&parser_path);
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());

// NOTE: if your language uses an external scanner, uncomment this block:
/*
let scanner_path = src_dir.join("scanner.c");
c_config.file(&scanner_path);
println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap());
*/

c_config.compile("tree-sitter-rescript");
}
54 changes: 54 additions & 0 deletions bindings/rust/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
//! This crate provides Rescript language support for the [tree-sitter][] parsing library.
//!
//! Typically, you will use the [language][language func] function to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//!
//! ```
//! let code = r#"
//! "#;
//! let mut parser = tree_sitter::Parser::new();
//! parser.set_language(&tree_sitter_rescript::language()).expect("Error loading Rescript grammar");
//! let tree = parser.parse(code, None).unwrap();
//! assert!(!tree.root_node().has_error());
//! ```
//!
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
//! [language func]: fn.language.html
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/

use tree_sitter::Language;

extern "C" {
fn tree_sitter_rescript() -> Language;
}

/// Get the tree-sitter [Language][] for this grammar.
///
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
pub fn language() -> Language {
unsafe { tree_sitter_rescript() }
}

/// The content of the [`node-types.json`][] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");

// Uncomment these to include any queries that this grammar contains

// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");

#[cfg(test)]
mod tests {
#[test]
fn test_can_load_grammar() {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(&super::language())
.expect("Error loading Rescript grammar");
}
}
16 changes: 16 additions & 0 deletions bindings/swift/TreeSitterRescript/rescript.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#ifndef TREE_SITTER_RESCRIPT_H_
#define TREE_SITTER_RESCRIPT_H_

typedef struct TSLanguage TSLanguage;

#ifdef __cplusplus
extern "C" {
#endif

const TSLanguage *tree_sitter_rescript(void);

#ifdef __cplusplus
}
#endif

#endif // TREE_SITTER_RESCRIPT_H_
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
"author": "Victor Nakoryakov",
"license": "MIT",
"dependencies": {
"nan": "^2.15.0"
"nan": "^2.15.0",
"node-addon-api": "^8.0.0"
},
"devDependencies": {
"tree-sitter-cli": "^0.22.2"
Expand Down
Loading
Loading