From 892494ddbd7ed7b1737140e189aa9f0e9d0d2189 Mon Sep 17 00:00:00 2001 From: Max Brunsfeld Date: Mon, 8 Mar 2021 11:16:51 -0800 Subject: [PATCH] Fix nested module structure after regenerating with 0.19 --- .npmignore | 2 + Cargo.toml | 34 +++++++++++-- README.md | 4 +- binding.gyp | 16 +----- bindings/node/binding.cc | 37 ++++++++++++++ bindings/node/index.js | 20 ++++++++ bindings/node/tsx.js | 1 + bindings/node/typescript.js | 1 + bindings/rust/build.rs | 28 +++++++++++ bindings/rust/lib.rs | 62 +++++++++++++++++++++++ bindings/rust/tsx/Cargo.toml | 28 ----------- bindings/rust/tsx/README.md | 37 -------------- bindings/rust/tsx/src/build.rs | 19 ------- bindings/rust/tsx/src/lib.rs | 72 --------------------------- bindings/rust/typescript/Cargo.toml | 28 ----------- bindings/rust/typescript/README.md | 37 -------------- bindings/rust/typescript/src/build.rs | 19 ------- bindings/rust/typescript/src/lib.rs | 72 --------------------------- package.json | 1 + tsx/binding.gyp | 2 - tsx/bindings/node/binding.cc | 28 ----------- tsx/bindings/node/index.js | 19 ------- tsx/bindings/rust/build.rs | 40 --------------- tsx/bindings/rust/lib.rs | 52 ------------------- tsx/package.json | 18 +------ typescript/binding.gyp | 2 - typescript/bindings/node/binding.cc | 28 ----------- typescript/bindings/node/index.js | 19 ------- typescript/bindings/rust/build.rs | 40 --------------- typescript/bindings/rust/lib.rs | 52 ------------------- typescript/package.json | 18 +------ 31 files changed, 187 insertions(+), 649 deletions(-) create mode 100644 bindings/node/binding.cc create mode 100644 bindings/node/index.js create mode 100644 bindings/node/tsx.js create mode 100644 bindings/node/typescript.js create mode 100644 bindings/rust/build.rs create mode 100644 bindings/rust/lib.rs delete mode 100644 bindings/rust/tsx/Cargo.toml delete mode 100644 bindings/rust/tsx/README.md delete mode 100644 bindings/rust/tsx/src/build.rs delete mode 100644 bindings/rust/tsx/src/lib.rs delete mode 100644 bindings/rust/typescript/Cargo.toml delete mode 100644 bindings/rust/typescript/README.md delete mode 100644 bindings/rust/typescript/src/build.rs delete mode 100644 bindings/rust/typescript/src/lib.rs delete mode 100644 tsx/binding.gyp delete mode 100644 tsx/bindings/node/binding.cc delete mode 100644 tsx/bindings/node/index.js delete mode 100644 tsx/bindings/rust/build.rs delete mode 100644 tsx/bindings/rust/lib.rs delete mode 100644 typescript/binding.gyp delete mode 100644 typescript/bindings/node/binding.cc delete mode 100644 typescript/bindings/node/index.js delete mode 100644 typescript/bindings/rust/build.rs delete mode 100644 typescript/bindings/rust/lib.rs diff --git a/.npmignore b/.npmignore index dcb067e34..d5fc53933 100644 --- a/.npmignore +++ b/.npmignore @@ -5,3 +5,5 @@ appveyor.yml .gitattributes build script +target +test.ts diff --git a/Cargo.toml b/Cargo.toml index 6db3760ae..a959d887b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,5 +1,31 @@ -[workspace] -members = [ - "bindings/rust/typescript", - "bindings/rust/tsx", +[package] +name = "tree-sitter-typescript" +description = "Typescript grammar for the tree-sitter parsing library" +version = "0.16.0" +authors = ["Max Brunsfeld "] +license = "MIT" +readme = "README.md" +keywords = ["incremental", "parsing", "typescript", "tsx"] +categories = ["parsing", "text-editors"] +repository = "https://github.com/tree-sitter/tree-sitter-typescript" +edition = "2018" + +build = "bindings/rust/build.rs" +include = [ + "./common", + "./bindings/rust", + "./typescript/grammar.js", + "./typescript/src", + "./tsx/grammar.js", + "./tsx/src", + "./queries" ] + +[lib] +path = "bindings/rust/lib.rs" + +[dependencies] +tree-sitter = "0.19" + +[build-dependencies] +cc = "1.0" diff --git a/README.md b/README.md index 74e1e3f1d..19acb03fb 100644 --- a/README.md +++ b/README.md @@ -9,8 +9,8 @@ TypeScript and TSX grammars for [tree-sitter][]. Because TSX and TypeScript are actually two different dialects, this module defines two grammars. Require them as follows: ```js -require('tree-sitter-typescript/typescript'); // TypeScript grammar -require('tree-sitter-typescript/tsx'); // TSX grammar +require('tree-sitter-typescript').typescript; // TypeScript grammar +require('tree-sitter-typescript').tsx; // TSX grammar ``` [tree-sitter]: https://github.com/tree-sitter/tree-sitter diff --git a/binding.gyp b/binding.gyp index 117b0401c..3b4daf46a 100644 --- a/binding.gyp +++ b/binding.gyp @@ -9,27 +9,13 @@ "sources": [ "typescript/src/parser.c", "typescript/src/scanner.c", - "typescript/bindings/node/binding.cc" - ], - "cflags_c": [ - "-std=c99", - ] - }, - { - "target_name": "tree_sitter_tsx_binding", - "include_dirs": [ - " +#include "nan.h" + +using namespace v8; + +extern "C" TSLanguage * tree_sitter_typescript(); +extern "C" TSLanguage * tree_sitter_tsx(); + +namespace { + +NAN_METHOD(New) {} + +void Init(Local exports, Local module) { + Local ts_tpl = Nan::New(New); + ts_tpl->SetClassName(Nan::New("Language").ToLocalChecked()); + ts_tpl->InstanceTemplate()->SetInternalFieldCount(1); + Local ts_constructor = Nan::GetFunction(ts_tpl).ToLocalChecked(); + Local ts_instance = ts_constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); + Nan::SetInternalFieldPointer(ts_instance, 0, tree_sitter_typescript()); + Nan::Set(ts_instance, Nan::New("name").ToLocalChecked(), Nan::New("typescript").ToLocalChecked()); + + Local tsx_tpl = Nan::New(New); + tsx_tpl->SetClassName(Nan::New("Language").ToLocalChecked()); + tsx_tpl->InstanceTemplate()->SetInternalFieldCount(1); + Local tsx_constructor = Nan::GetFunction(tsx_tpl).ToLocalChecked(); + Local tsx_instance = tsx_constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); + Nan::SetInternalFieldPointer(tsx_instance, 0, tree_sitter_tsx()); + Nan::Set(tsx_instance, Nan::New("name").ToLocalChecked(), Nan::New("tsx").ToLocalChecked()); + + Nan::Set(exports, Nan::New("typescript").ToLocalChecked(), ts_instance); + Nan::Set(exports, Nan::New("tsx").ToLocalChecked(), tsx_instance); +} + +NODE_MODULE(tree_sitter_typescript_binding, Init) + +} // namespace diff --git a/bindings/node/index.js b/bindings/node/index.js new file mode 100644 index 000000000..b929899da --- /dev/null +++ b/bindings/node/index.js @@ -0,0 +1,20 @@ +try { + module.exports = require("../../build/Release/tree_sitter_typescript_binding"); +} catch (error1) { + if (error1.code !== 'MODULE_NOT_FOUND') { + throw error1; + } + try { + module.exports = require("../../build/Debug/tree_sitter_typescript_binding"); + } catch (error2) { + if (error2.code !== 'MODULE_NOT_FOUND') { + throw error2; + } + throw error1 + } +} + +try { + module.exports.typescript.nodeTypeInfo = require("../../typescript/src/node-types.json"); + module.exports.tsx.nodeTypeInfo = require("../../tsx/src/node-types.json"); +} catch (_) {} diff --git a/bindings/node/tsx.js b/bindings/node/tsx.js new file mode 100644 index 000000000..a970e7633 --- /dev/null +++ b/bindings/node/tsx.js @@ -0,0 +1 @@ +module.exports = require('./index').tsx; diff --git a/bindings/node/typescript.js b/bindings/node/typescript.js new file mode 100644 index 000000000..49141147e --- /dev/null +++ b/bindings/node/typescript.js @@ -0,0 +1 @@ +module.exports = require('./index').typescript; diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs new file mode 100644 index 000000000..b7cda9251 --- /dev/null +++ b/bindings/rust/build.rs @@ -0,0 +1,28 @@ +fn main() { + let root_dir = std::path::Path::new("."); + let typescript_dir = root_dir.join("typescript").join("src"); + let tsx_dir = root_dir.join("tsx").join("src"); + + let mut config = cc::Build::new(); + config.include(&typescript_dir); + config + .flag_if_supported("-Wno-unused-parameter") + .flag_if_supported("-Wno-unused-but-set-variable"); + + for path in &[ + typescript_dir.join("parser.c"), + typescript_dir.join("scanner.c"), + tsx_dir.join("parser.c"), + tsx_dir.join("scanner.c"), + ] { + config.file(&path); + println!("cargo:rerun-if-changed={}", path.to_str().unwrap()); + } + + println!( + "cargo:rerun-if-changed={}", + root_dir.join("common").join("scanner.h").to_str().unwrap() + ); + + config.compile("parser-scanner"); +} diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs new file mode 100644 index 000000000..c61eeba3b --- /dev/null +++ b/bindings/rust/lib.rs @@ -0,0 +1,62 @@ +//! This crate provides Typescript and TSX grammars for the [tree-sitter][] parsing library. +//! +//! Typically, you will use the [language_typescript][language func] function to add this grammar to a +//! tree-sitter [Parser][], and then use the parser to parse some code: +//! +//! ``` +//! use tree_sitter::Parser; +//! +//! let code = r#" +//! function double(x: number): number { +//! return x * 2; +//! } +//! "#; +//! let mut parser = Parser::new(); +//! parser +//! .set_language(tree_sitter_typescript::language_typescript()) +//! .expect("Error loading typescript grammar"); +//! let parsed = parser.parse(code, None).unwrap(); +//! let root = parsed.root_node(); +//! assert!(!root.has_error()); +//! ``` +//! +//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html +//! [language func]: fn.language_typescript.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_typescript() -> Language; + fn tree_sitter_tsx() -> Language; +} + +/// Returns the tree-sitter [Language][] for this Typescript. +/// +/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html +pub fn language_typescript() -> Language { + unsafe { tree_sitter_typescript() } +} + +/// Returns the tree-sitter [Language][] for TSX. +/// +/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html +pub fn language_tsx() -> Language { + unsafe { tree_sitter_tsx() } +} + +/// The syntax highlighting query for this language. +pub const HIGHLIGHT_QUERY: &str = include_str!("../../queries/highlights.scm"); + +/// The local-variable syntax highlighting query for this language. +pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm"); + +/// The symbol tagging query for this language. +pub const TAGGING_QUERY: &str = include_str!("../../queries/tags.scm"); + +/// 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 TYPESCRIPT_NODE_TYPES: &str = include_str!("../../typescript/src/node-types.json"); +pub const TSX_NODE_TYPES: &str = include_str!("../../tsx/src/node-types.json"); diff --git a/bindings/rust/tsx/Cargo.toml b/bindings/rust/tsx/Cargo.toml deleted file mode 100644 index d3190a248..000000000 --- a/bindings/rust/tsx/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "tree-sitter-tsx" -description = "Tsx grammar for the tree-sitter parsing library" -version = "0.16.0" -authors = ["Max Brunsfeld "] -license = "MIT" -readme = "README.md" -keywords = ["incremental", "parsing", "tsx"] -categories = ["parsing", "text-editors"] -repository = "https://github.com/tree-sitter/tree-sitter-tsx" -edition = "2018" - -build = "src/build.rs" -include = [ - "./*", - "../../../tsx/grammar.js", - "../../../queries/*", - "../../../tsx/src/*", -] - -[lib] -path = "src/lib.rs" - -[dependencies] -tree-sitter = "0.17" - -[build-dependencies] -cc = "1.0" diff --git a/bindings/rust/tsx/README.md b/bindings/rust/tsx/README.md deleted file mode 100644 index 7b4e5983d..000000000 --- a/bindings/rust/tsx/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# tree-sitter-tsx - -This crate provides a Tsx grammar for the [tree-sitter][] parsing library. To -use this crate, add it to the `[dependencies]` section of your `Cargo.toml` -file. (Note that you will probably also need to depend on the -[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful -way.) - -``` toml -[dependencies] -tree-sitter = "0.17" -tree-sitter-tsx = "0.16" -``` - -Typically, you will use the [language][language func] function to add this -grammar to a tree-sitter [Parser][], and then use the parser to parse some code: - -``` rust -let code = r#" - function double(x) { - return x * 2; - } -"#; -let mut parser = Parser::new(); -parser.set_language(tree_sitter_tsx::language()).expect("Error loading Tsx grammar"); -let parsed = parser.parse(code, None); -``` - -If you have any questions, please reach out to us in the [tree-sitter -discussions] page. - -[Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html -[language func]: https://docs.rs/tree-sitter-tsx/*/tree_sitter_tsx/fn.language.html -[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html -[tree-sitter]: https://tree-sitter.github.io/ -[tree-sitter crate]: https://crates.io/crates/tree-sitter -[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions diff --git a/bindings/rust/tsx/src/build.rs b/bindings/rust/tsx/src/build.rs deleted file mode 100644 index 0ee432267..000000000 --- a/bindings/rust/tsx/src/build.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::path::Path; -extern crate cc; - -fn main() { - let src_dir = Path::new("../../../tsx/src"); - - let mut c_config = cc::Build::new(); - c_config.include(&src_dir); - c_config - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-unused-but-set-variable") - .flag_if_supported("-Wno-trigraphs"); - let parser_path = src_dir.join("parser.c"); - c_config.file(&parser_path); - let scanner_path = src_dir.join("scanner.c"); - c_config.file(&scanner_path); - println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); - c_config.compile("parser-scanner"); -} diff --git a/bindings/rust/tsx/src/lib.rs b/bindings/rust/tsx/src/lib.rs deleted file mode 100644 index 24a0879d8..000000000 --- a/bindings/rust/tsx/src/lib.rs +++ /dev/null @@ -1,72 +0,0 @@ -// -*- coding: utf-8 -*- -// ------------------------------------------------------------------------------------------------ -// Copyright © 2021, tree-sitter-tsx authors. -// See the LICENSE file in this repo for license details. -// ------------------------------------------------------------------------------------------------ - -//! This crate provides a Tsx grammar for the [tree-sitter][] parsing library. -//! -//! Typically, you will use the [language][language func] function to add this grammar to a -//! tree-sitter [Parser][], and then use the parser to parse some code: -//! -//! ``` -//! use tree_sitter::Parser; -//! -//! let code = r#" -//! function double(x) { -//! return x * 2; -//! } -//! "#; -//! let mut parser = Parser::new(); -//! parser.set_language(tree_sitter_tsx::language()).expect("Error loading Tsx grammar"); -//! let parsed = parser.parse(code, None); -//! # let parsed = parsed.unwrap(); -//! # let root = parsed.root_node(); -//! # assert!(!root.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_tsx() -> Language; -} - -/// Returns 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_tsx() } -} - -/// The source of the Tsx tree-sitter grammar description. -pub const GRAMMAR: &str = include_str!("../../../../tsx/grammar.js"); - -/// The syntax highlighting query for this language. -pub const HIGHLIGHT_QUERY: &str = include_str!("../../../../queries/highlights.scm"); - -/// The local-variable syntax highlighting query for this language. -pub const LOCALS_QUERY: &str = include_str!("../../../../queries/locals.scm"); - -/// 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!("../../../../tsx/src/node-types.json"); - -/// The symbol tagging query for this language. -pub const TAGGING_QUERY: &str = include_str!("../../../../queries/tags.scm"); - -#[cfg(test)] -mod tests { - #[test] - fn can_load_grammar() { - let mut parser = tree_sitter::Parser::new(); - parser - .set_language(super::language()) - .expect("Error loading Tsx grammar"); - } -} diff --git a/bindings/rust/typescript/Cargo.toml b/bindings/rust/typescript/Cargo.toml deleted file mode 100644 index 067b7ad58..000000000 --- a/bindings/rust/typescript/Cargo.toml +++ /dev/null @@ -1,28 +0,0 @@ -[package] -name = "tree-sitter-typescript" -description = "TypeScript grammar for the tree-sitter parsing library" -version = "0.16.0" -authors = ["Max Brunsfeld "] -license = "MIT" -readme = "README.md" -keywords = ["incremental", "parsing", "typescript"] -categories = ["parsing", "text-editors"] -repository = "https://github.com/tree-sitter/tree-sitter-typescript" -edition = "2018" - -build = "src/build.rs" -include = [ - "./*", - "../../../typescript/grammar.js", - "../../../queries/*", - "../../../typescript/src/*", -] - -[lib] -path = "src/lib.rs" - -[dependencies] -tree-sitter = "0.17" - -[build-dependencies] -cc = "1.0" diff --git a/bindings/rust/typescript/README.md b/bindings/rust/typescript/README.md deleted file mode 100644 index cb88871ee..000000000 --- a/bindings/rust/typescript/README.md +++ /dev/null @@ -1,37 +0,0 @@ -# tree-sitter-typescript - -This crate provides a TypeScript grammar for the [tree-sitter][] parsing library. To -use this crate, add it to the `[dependencies]` section of your `Cargo.toml` -file. (Note that you will probably also need to depend on the -[`tree-sitter`][tree-sitter crate] crate to use the parsed result in any useful -way.) - -``` toml -[dependencies] -tree-sitter = "0.17" -tree-sitter-typescript = "0.16" -``` - -Typically, you will use the [language][language func] function to add this -grammar to a tree-sitter [Parser][], and then use the parser to parse some code: - -``` rust -let code = r#" - function double(x) { - return x * 2; - } -"#; -let mut parser = Parser::new(); -parser.set_language(tree_sitter_typescript::language()).expect("Error loading TypeScript grammar"); -let parsed = parser.parse(code, None); -``` - -If you have any questions, please reach out to us in the [tree-sitter -discussions] page. - -[Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html -[language func]: https://docs.rs/tree-sitter-typescript/*/tree_sitter_typescript/fn.language.html -[Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html -[tree-sitter]: https://tree-sitter.github.io/ -[tree-sitter crate]: https://crates.io/crates/tree-sitter -[tree-sitter discussions]: https://github.com/tree-sitter/tree-sitter/discussions diff --git a/bindings/rust/typescript/src/build.rs b/bindings/rust/typescript/src/build.rs deleted file mode 100644 index 597fade24..000000000 --- a/bindings/rust/typescript/src/build.rs +++ /dev/null @@ -1,19 +0,0 @@ -use std::path::Path; -extern crate cc; - -fn main() { - let src_dir = Path::new("../../../typescript/src"); - - let mut c_config = cc::Build::new(); - c_config.include(&src_dir); - c_config - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-unused-but-set-variable") - .flag_if_supported("-Wno-trigraphs"); - let parser_path = src_dir.join("parser.c"); - c_config.file(&parser_path); - let scanner_path = src_dir.join("scanner.c"); - c_config.file(&scanner_path); - println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); - c_config.compile("parser-scanner"); -} diff --git a/bindings/rust/typescript/src/lib.rs b/bindings/rust/typescript/src/lib.rs deleted file mode 100644 index c0bd7e76e..000000000 --- a/bindings/rust/typescript/src/lib.rs +++ /dev/null @@ -1,72 +0,0 @@ -// -*- coding: utf-8 -*- -// ------------------------------------------------------------------------------------------------ -// Copyright © 2021, tree-sitter-typescript authors. -// See the LICENSE file in this repo for license details. -// ------------------------------------------------------------------------------------------------ - -//! This crate provides a TypeScript grammar for the [tree-sitter][] parsing library. -//! -//! Typically, you will use the [language][language func] function to add this grammar to a -//! tree-sitter [Parser][], and then use the parser to parse some code: -//! -//! ``` -//! use tree_sitter::Parser; -//! -//! let code = r#" -//! function double(x) { -//! return x * 2; -//! } -//! "#; -//! let mut parser = Parser::new(); -//! parser.set_language(tree_sitter_typescript::language()).expect("Error loading TypeScript grammar"); -//! let parsed = parser.parse(code, None); -//! # let parsed = parsed.unwrap(); -//! # let root = parsed.root_node(); -//! # assert!(!root.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_typescript() -> Language; -} - -/// Returns 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_typescript() } -} - -/// The source of the TypeScript tree-sitter grammar description. -pub const GRAMMAR: &str = include_str!("../../../../typescript/grammar.js"); - -/// The syntax highlighting query for this language. -pub const HIGHLIGHT_QUERY: &str = include_str!("../../../../queries/highlights.scm"); - -/// The local-variable syntax highlighting query for this language. -pub const LOCALS_QUERY: &str = include_str!("../../../../queries/locals.scm"); - -/// 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!("../../../../typescript/src/node-types.json"); - -/// The symbol tagging query for this language. -pub const TAGGING_QUERY: &str = include_str!("../../../../queries/tags.scm"); - -#[cfg(test)] -mod tests { - #[test] - fn can_load_grammar() { - let mut parser = tree_sitter::Parser::new(); - parser - .set_language(super::language()) - .expect("Error loading TypeScript grammar"); - } -} diff --git a/package.json b/package.json index 8b874279a..0da2f1590 100644 --- a/package.json +++ b/package.json @@ -12,6 +12,7 @@ "dependencies": { "nan": "^2.14.0" }, + "main": "./bindings/node", "devDependencies": { "tree-sitter-cli": "^0.19.1", "tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#v0.19.0" diff --git a/tsx/binding.gyp b/tsx/binding.gyp deleted file mode 100644 index e5437395f..000000000 --- a/tsx/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# This is a placeholder to prevent tree-sitter from generating this file. -# Refer to the binding.gyp at the root of the repository instead. diff --git a/tsx/bindings/node/binding.cc b/tsx/bindings/node/binding.cc deleted file mode 100644 index 47ff2b469..000000000 --- a/tsx/bindings/node/binding.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include "tree_sitter/parser.h" -#include -#include "nan.h" - -using namespace v8; - -extern "C" TSLanguage * tree_sitter_tsx(); - -namespace { - -NAN_METHOD(New) {} - -void Init(Local exports, Local module) { - Local tpl = Nan::New(New); - tpl->SetClassName(Nan::New("Language").ToLocalChecked()); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); - Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); - Nan::SetInternalFieldPointer(instance, 0, tree_sitter_tsx()); - - Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("tsx").ToLocalChecked()); - Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); -} - -NODE_MODULE(tree_sitter_tsx_binding, Init) - -} // namespace diff --git a/tsx/bindings/node/index.js b/tsx/bindings/node/index.js deleted file mode 100644 index 364f927f2..000000000 --- a/tsx/bindings/node/index.js +++ /dev/null @@ -1,19 +0,0 @@ -try { - module.exports = require("../../../build/Release/tree_sitter_tsx_binding"); -} catch (error1) { - if (error1.code !== 'MODULE_NOT_FOUND') { - throw error1; - } - try { - module.exports = require("../../../build/Debug/tree_sitter_tsx_binding"); - } catch (error2) { - if (error2.code !== 'MODULE_NOT_FOUND') { - throw error2; - } - throw error1 - } -} - -try { - module.exports.nodeTypeInfo = require("../../src/node-types.json"); -} catch (_) {} diff --git a/tsx/bindings/rust/build.rs b/tsx/bindings/rust/build.rs deleted file mode 100644 index 0a878ba69..000000000 --- a/tsx/bindings/rust/build.rs +++ /dev/null @@ -1,40 +0,0 @@ -fn main() { - let src_dir = std::path::Path::new("src"); - - let mut c_config = cc::Build::new(); - c_config.include(&src_dir); - c_config - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-unused-but-set-variable") - .flag_if_supported("-Wno-trigraphs"); - let parser_path = src_dir.join("parser.c"); - c_config.file(&parser_path); - - // If your language uses an external scanner written in C, - // then include this block of code: - - /* - let scanner_path = src_dir.join("scanner.c"); - c_config.file(&scanner_path); - println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); - */ - - println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); - c_config.compile("parser"); - - // If your language uses an external scanner written in C++, - // then include this block of code: - - /* - let mut cpp_config = cc::Build::new(); - cpp_config.cpp(true); - cpp_config.include(&src_dir); - cpp_config - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-unused-but-set-variable"); - let scanner_path = src_dir.join("scanner.cc"); - cpp_config.file(&scanner_path); - println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); - cpp_config.compile("scanner"); - */ -} diff --git a/tsx/bindings/rust/lib.rs b/tsx/bindings/rust/lib.rs deleted file mode 100644 index c21a0bff5..000000000 --- a/tsx/bindings/rust/lib.rs +++ /dev/null @@ -1,52 +0,0 @@ -//! This crate provides tsx 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 = ""; -//! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(tree_sitter_javascript::language()).expect("Error loading tsx grammar"); -//! let tree = parser.parse(code, None).unwrap(); -//! ``` -//! -//! [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_tsx() -> 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_tsx() } -} - -/// 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: &'static str = include_str!("../../src/node-types.json"); - -// Uncomment these to include any queries that this grammar contains - -// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); -// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); -// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); -// pub const TAGS_QUERY: &'static 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 tsx language"); - } -} diff --git a/tsx/package.json b/tsx/package.json index 970d8d421..0ed56917f 100644 --- a/tsx/package.json +++ b/tsx/package.json @@ -1,19 +1,3 @@ { - "name": "tree-sitter-tsx", - "version": "0.0.1", - "description": "tsx grammar for tree-sitter", - "main": "bindings/node", - "keywords": [ - "parsing", - "incremental" - ], - "dependencies": { - "nan": "^2.12.1" - }, - "devDependencies": { - "tree-sitter-cli": "^0.17.3" - }, - "scripts": { - "test": "tree-sitter test" - } + "main": "../bindings/node/tsx" } diff --git a/typescript/binding.gyp b/typescript/binding.gyp deleted file mode 100644 index e5437395f..000000000 --- a/typescript/binding.gyp +++ /dev/null @@ -1,2 +0,0 @@ -# This is a placeholder to prevent tree-sitter from generating this file. -# Refer to the binding.gyp at the root of the repository instead. diff --git a/typescript/bindings/node/binding.cc b/typescript/bindings/node/binding.cc deleted file mode 100644 index 4565c304d..000000000 --- a/typescript/bindings/node/binding.cc +++ /dev/null @@ -1,28 +0,0 @@ -#include "tree_sitter/parser.h" -#include -#include "nan.h" - -using namespace v8; - -extern "C" TSLanguage * tree_sitter_typescript(); - -namespace { - -NAN_METHOD(New) {} - -void Init(Local exports, Local module) { - Local tpl = Nan::New(New); - tpl->SetClassName(Nan::New("Language").ToLocalChecked()); - tpl->InstanceTemplate()->SetInternalFieldCount(1); - - Local constructor = Nan::GetFunction(tpl).ToLocalChecked(); - Local instance = constructor->NewInstance(Nan::GetCurrentContext()).ToLocalChecked(); - Nan::SetInternalFieldPointer(instance, 0, tree_sitter_typescript()); - - Nan::Set(instance, Nan::New("name").ToLocalChecked(), Nan::New("typescript").ToLocalChecked()); - Nan::Set(module, Nan::New("exports").ToLocalChecked(), instance); -} - -NODE_MODULE(tree_sitter_typescript_binding, Init) - -} // namespace diff --git a/typescript/bindings/node/index.js b/typescript/bindings/node/index.js deleted file mode 100644 index ad076ebff..000000000 --- a/typescript/bindings/node/index.js +++ /dev/null @@ -1,19 +0,0 @@ -try { - module.exports = require("../../../build/Release/tree_sitter_typescript_binding"); -} catch (error1) { - if (error1.code !== 'MODULE_NOT_FOUND') { - throw error1; - } - try { - module.exports = require("../../../build/Debug/tree_sitter_typescript_binding"); - } catch (error2) { - if (error2.code !== 'MODULE_NOT_FOUND') { - throw error2; - } - throw error1 - } -} - -try { - module.exports.nodeTypeInfo = require("../../src/node-types.json"); -} catch (_) {} diff --git a/typescript/bindings/rust/build.rs b/typescript/bindings/rust/build.rs deleted file mode 100644 index 0a878ba69..000000000 --- a/typescript/bindings/rust/build.rs +++ /dev/null @@ -1,40 +0,0 @@ -fn main() { - let src_dir = std::path::Path::new("src"); - - let mut c_config = cc::Build::new(); - c_config.include(&src_dir); - c_config - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-unused-but-set-variable") - .flag_if_supported("-Wno-trigraphs"); - let parser_path = src_dir.join("parser.c"); - c_config.file(&parser_path); - - // If your language uses an external scanner written in C, - // then include this block of code: - - /* - let scanner_path = src_dir.join("scanner.c"); - c_config.file(&scanner_path); - println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); - */ - - println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap()); - c_config.compile("parser"); - - // If your language uses an external scanner written in C++, - // then include this block of code: - - /* - let mut cpp_config = cc::Build::new(); - cpp_config.cpp(true); - cpp_config.include(&src_dir); - cpp_config - .flag_if_supported("-Wno-unused-parameter") - .flag_if_supported("-Wno-unused-but-set-variable"); - let scanner_path = src_dir.join("scanner.cc"); - cpp_config.file(&scanner_path); - println!("cargo:rerun-if-changed={}", scanner_path.to_str().unwrap()); - cpp_config.compile("scanner"); - */ -} diff --git a/typescript/bindings/rust/lib.rs b/typescript/bindings/rust/lib.rs deleted file mode 100644 index 6472113bb..000000000 --- a/typescript/bindings/rust/lib.rs +++ /dev/null @@ -1,52 +0,0 @@ -//! This crate provides typescript 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 = ""; -//! let mut parser = tree_sitter::Parser::new(); -//! parser.set_language(tree_sitter_javascript::language()).expect("Error loading typescript grammar"); -//! let tree = parser.parse(code, None).unwrap(); -//! ``` -//! -//! [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_typescript() -> 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_typescript() } -} - -/// 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: &'static str = include_str!("../../src/node-types.json"); - -// Uncomment these to include any queries that this grammar contains - -// pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm"); -// pub const INJECTIONS_QUERY: &'static str = include_str!("../../queries/injections.scm"); -// pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm"); -// pub const TAGS_QUERY: &'static 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 typescript language"); - } -} diff --git a/typescript/package.json b/typescript/package.json index 243f5dab2..fdec2689c 100644 --- a/typescript/package.json +++ b/typescript/package.json @@ -1,19 +1,3 @@ { - "name": "tree-sitter-typescript", - "version": "0.0.1", - "description": "typescript grammar for tree-sitter", - "main": "bindings/node", - "keywords": [ - "parsing", - "incremental" - ], - "dependencies": { - "nan": "^2.12.1" - }, - "devDependencies": { - "tree-sitter-cli": "^0.17.3" - }, - "scripts": { - "test": "tree-sitter test" - } + "main": "../bindings/node/typescript" }