Fix nested module structure after regenerating with 0.19

ida_star
Max Brunsfeld 2021-03-08 11:16:51 +07:00
parent be5e1aa39a
commit 892494ddbd
31 changed files with 187 additions and 649 deletions

@ -5,3 +5,5 @@ appveyor.yml
.gitattributes .gitattributes
build build
script script
target
test.ts

@ -1,5 +1,31 @@
[workspace] [package]
members = [ name = "tree-sitter-typescript"
"bindings/rust/typescript", description = "Typescript grammar for the tree-sitter parsing library"
"bindings/rust/tsx", version = "0.16.0"
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
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"

@ -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: Because TSX and TypeScript are actually two different dialects, this module defines two grammars. Require them as follows:
```js ```js
require('tree-sitter-typescript/typescript'); // TypeScript grammar require('tree-sitter-typescript').typescript; // TypeScript grammar
require('tree-sitter-typescript/tsx'); // TSX grammar require('tree-sitter-typescript').tsx; // TSX grammar
``` ```
[tree-sitter]: https://github.com/tree-sitter/tree-sitter [tree-sitter]: https://github.com/tree-sitter/tree-sitter

@ -9,27 +9,13 @@
"sources": [ "sources": [
"typescript/src/parser.c", "typescript/src/parser.c",
"typescript/src/scanner.c", "typescript/src/scanner.c",
"typescript/bindings/node/binding.cc"
],
"cflags_c": [
"-std=c99",
]
},
{
"target_name": "tree_sitter_tsx_binding",
"include_dirs": [
"<!(node -e \"require('nan')\")",
"tsx/src"
],
"sources": [
"tsx/src/parser.c", "tsx/src/parser.c",
"tsx/src/scanner.c", "tsx/src/scanner.c",
"tsx/bindings/node/binding.cc" "bindings/node/binding.cc"
], ],
"cflags_c": [ "cflags_c": [
"-std=c99", "-std=c99",
] ]
}, },
] ]
} }

@ -0,0 +1,37 @@
#include "tree_sitter/parser.h"
#include <node.h>
#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<Object> exports, Local<Object> module) {
Local<FunctionTemplate> ts_tpl = Nan::New<FunctionTemplate>(New);
ts_tpl->SetClassName(Nan::New("Language").ToLocalChecked());
ts_tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> ts_constructor = Nan::GetFunction(ts_tpl).ToLocalChecked();
Local<Object> 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<FunctionTemplate> tsx_tpl = Nan::New<FunctionTemplate>(New);
tsx_tpl->SetClassName(Nan::New("Language").ToLocalChecked());
tsx_tpl->InstanceTemplate()->SetInternalFieldCount(1);
Local<Function> tsx_constructor = Nan::GetFunction(tsx_tpl).ToLocalChecked();
Local<Object> 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

@ -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 (_) {}

@ -0,0 +1 @@
module.exports = require('./index').tsx;

@ -0,0 +1 @@
module.exports = require('./index').typescript;

@ -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");
}

@ -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");

@ -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 <maxbrunsfeld@gmail.com>"]
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"

@ -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

@ -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");
}

@ -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");
}
}

@ -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 <maxbrunsfeld@gmail.com>"]
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"

@ -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

@ -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");
}

@ -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");
}
}

@ -12,6 +12,7 @@
"dependencies": { "dependencies": {
"nan": "^2.14.0" "nan": "^2.14.0"
}, },
"main": "./bindings/node",
"devDependencies": { "devDependencies": {
"tree-sitter-cli": "^0.19.1", "tree-sitter-cli": "^0.19.1",
"tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#v0.19.0" "tree-sitter-javascript": "github:tree-sitter/tree-sitter-javascript#v0.19.0"

@ -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.

@ -1,28 +0,0 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_tsx();
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_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

@ -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 (_) {}

@ -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");
*/
}

@ -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");
}
}

@ -1,19 +1,3 @@
{ {
"name": "tree-sitter-tsx", "main": "../bindings/node/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"
}
} }

@ -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.

@ -1,28 +0,0 @@
#include "tree_sitter/parser.h"
#include <node.h>
#include "nan.h"
using namespace v8;
extern "C" TSLanguage * tree_sitter_typescript();
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_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

@ -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 (_) {}

@ -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");
*/
}

@ -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");
}
}

@ -1,19 +1,3 @@
{ {
"name": "tree-sitter-typescript", "main": "../bindings/node/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"
}
} }