Add rust tree-sitter runtime binding in lib directory
This commit is contained in:
commit
97ca3bc2d1
18 changed files with 1964 additions and 25 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
|
@ -1,2 +1,3 @@
|
|||
/target
|
||||
**/*.rs.bk
|
||||
fixtures/tree-sitter-rust
|
||||
|
|
|
|||
3
.gitmodules
vendored
Normal file
3
.gitmodules
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[submodule "vendor/tree-sitter"]
|
||||
path = vendor/tree-sitter
|
||||
url = https://github.com/tree-sitter/tree-sitter
|
||||
14
.travis.yml
Normal file
14
.travis.yml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
language: rust
|
||||
|
||||
rust:
|
||||
- stable
|
||||
|
||||
env:
|
||||
- TREE_SITTER_TEST=1
|
||||
|
||||
before_install:
|
||||
- ./script/fetch-test-fixtures.sh
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
44
Cargo.lock
generated
44
Cargo.lock
generated
|
|
@ -471,26 +471,6 @@ dependencies = [
|
|||
"time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rust-tree-sitter-cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashbrown 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ignore 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rusqlite 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallbitvec 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tree-sitter 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustc-demangle"
|
||||
version = "0.1.9"
|
||||
|
|
@ -648,8 +628,7 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "tree-sitter"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
version = "0.3.5"
|
||||
dependencies = [
|
||||
"cc 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex 1.1.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
|
@ -658,6 +637,26 @@ dependencies = [
|
|||
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tree-sitter-cli"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap 2.32.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dirs 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"hashbrown 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"ignore 0.4.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"lazy_static 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"libloading 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"regex-syntax 0.6.4 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"rusqlite 0.14.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_derive 1.0.80 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"serde_json 1.0.33 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"smallbitvec 2.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"tree-sitter 0.3.5",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "ucd-util"
|
||||
version = "0.1.3"
|
||||
|
|
@ -822,7 +821,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
"checksum textwrap 0.10.0 (registry+https://github.com/rust-lang/crates.io-index)" = "307686869c93e71f94da64286f9a9524c0f308a9e1c87a583de8e9c9039ad3f6"
|
||||
"checksum thread_local 0.3.6 (registry+https://github.com/rust-lang/crates.io-index)" = "c6b53e329000edc2b34dbe8545fd20e55a333362d0a321909685a19bd28c3f1b"
|
||||
"checksum time 0.1.40 (registry+https://github.com/rust-lang/crates.io-index)" = "d825be0eb33fda1a7e68012d51e9c7f451dc1a69391e7fdc197060bb8c56667b"
|
||||
"checksum tree-sitter 0.3.3 (registry+https://github.com/rust-lang/crates.io-index)" = "311adf1e004ac816285a1196c93ea36364857c3adc37ffc9fd5ed0d70545391a"
|
||||
"checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86"
|
||||
"checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526"
|
||||
"checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc"
|
||||
|
|
|
|||
21
LICENSE
Normal file
21
LICENSE
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2018 Max Brunsfeld
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
27
appveyor.yml
Normal file
27
appveyor.yml
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
environment:
|
||||
RUST_TREE_SITTER_TEST: true
|
||||
|
||||
build: false
|
||||
|
||||
install:
|
||||
- git submodule update --init --recursive
|
||||
|
||||
- appveyor DownloadFile https://win.rustup.rs/ -FileName rustup-init.exe
|
||||
- rustup-init -yv --default-toolchain stable
|
||||
- set PATH=%PATH%;%USERPROFILE%\.cargo\bin
|
||||
- rustc -vV
|
||||
- cargo -vV
|
||||
|
||||
- script\fetch-test-fixtures.cmd
|
||||
|
||||
test_script:
|
||||
- cargo build
|
||||
- cargo test
|
||||
|
||||
branches:
|
||||
only:
|
||||
- master
|
||||
|
||||
cache:
|
||||
- fixtures
|
||||
- C:\Users\appveyor\.cargo
|
||||
|
|
@ -1,9 +1,13 @@
|
|||
[package]
|
||||
name = "rust-tree-sitter-cli"
|
||||
name = "tree-sitter-cli"
|
||||
version = "0.1.0"
|
||||
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[[bin]]
|
||||
name = "tree-sitter"
|
||||
path = "src/main.rs"
|
||||
|
||||
[dependencies]
|
||||
lazy_static = "1.2.0"
|
||||
smallbitvec = "2.3.0"
|
||||
|
|
@ -15,9 +19,11 @@ libloading = "0.5"
|
|||
rusqlite = "0.14.0"
|
||||
serde = "1.0"
|
||||
serde_derive = "1.0"
|
||||
tree-sitter = "0.3.1"
|
||||
regex-syntax = "0.6.4"
|
||||
|
||||
[dependencies.tree-sitter]
|
||||
path = "../lib"
|
||||
|
||||
[dependencies.serde_json]
|
||||
version = "1.0"
|
||||
features = ["preserve_order"]
|
||||
|
|
|
|||
0
fixtures/.gitkeep
Normal file
0
fixtures/.gitkeep
Normal file
32
lib/Cargo.toml
Normal file
32
lib/Cargo.toml
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
[package]
|
||||
name = "tree-sitter"
|
||||
description = "Rust bindings to the Tree-sitter parsing library"
|
||||
version = "0.3.5"
|
||||
authors = ["Max Brunsfeld <maxbrunsfeld@gmail.com>"]
|
||||
license = "MIT"
|
||||
readme = "README.md"
|
||||
keywords = ["incremental", "parsing"]
|
||||
categories = ["api-bindings", "parsing", "text-editors"]
|
||||
|
||||
include = [
|
||||
"/build.rs",
|
||||
"/Cargo.toml",
|
||||
"/LICENSE",
|
||||
"/README.md",
|
||||
"/src/*",
|
||||
"/core/tree-sitter/externals/utf8proc/utf8proc*",
|
||||
"/core/tree-sitter/include/*",
|
||||
"/core/tree-sitter/src/runtime/*",
|
||||
]
|
||||
|
||||
[dependencies]
|
||||
regex = "1"
|
||||
serde = "1.0"
|
||||
serde_json = "1.0"
|
||||
serde_derive = "1.0"
|
||||
|
||||
[build-dependencies]
|
||||
cc = "1.0"
|
||||
|
||||
[lib]
|
||||
path = "binding/lib.rs"
|
||||
98
lib/README.md
Normal file
98
lib/README.md
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
Rust Tree-sitter
|
||||
===========================
|
||||
|
||||
[](https://travis-ci.org/tree-sitter/rust-tree-sitter)
|
||||
[](https://ci.appveyor.com/project/maxbrunsfeld/rust-tree-sitter/branch/master)
|
||||
[](https://crates.io/crates/tree-sitter)
|
||||
|
||||
Rust bindings to the [Tree-sitter][] parsing library.
|
||||
|
||||
### Basic Usage
|
||||
|
||||
First, create a parser:
|
||||
|
||||
```rust
|
||||
use tree_sitter::{Parser, Language};
|
||||
|
||||
// ...
|
||||
|
||||
let mut parser = Parser::new();
|
||||
```
|
||||
|
||||
Then assign a language to the parser. Tree-sitter languages consist of generated C code. To use them from rust, you must declare them as `extern "C"` functions and invoke them with `unsafe`:
|
||||
|
||||
```rust
|
||||
extern "C" { fn tree_sitter_c() -> Language; }
|
||||
extern "C" { fn tree_sitter_rust() -> Language; }
|
||||
extern "C" { fn tree_sitter_javascript() -> Language; }
|
||||
|
||||
let language = unsafe { tree_sitter_rust() };
|
||||
parser.set_language(language).unwrap();
|
||||
```
|
||||
|
||||
Now you can parse source code:
|
||||
|
||||
```rust
|
||||
let source_code = "fn test() {}";
|
||||
let tree = parser.parse_str(source_code, None);
|
||||
let root_node = tree.root_node();
|
||||
|
||||
assert_eq!(root_node.kind(), "source_file");
|
||||
assert_eq!(root_node.start_position().column, 0);
|
||||
assert_eq!(root_node.end_position().column, 12);
|
||||
```
|
||||
|
||||
### Editing
|
||||
|
||||
Once you have a syntax tree, you can update it when your source code changes. Passing in the previous edited tree makes `parse` run much more quickly:
|
||||
|
||||
```rust
|
||||
let new_source_code = "fn test(a: u32) {}"
|
||||
|
||||
tree.edit(InputEdit {
|
||||
start_byte: 8,
|
||||
old_end_byte: 8,
|
||||
new_end_byte: 14,
|
||||
start_position: Point::new(0, 8),
|
||||
old_end_position: Point::new(0, 8),
|
||||
new_end_position: Point::new(0, 14),
|
||||
});
|
||||
|
||||
let new_tree = parser.parse_str(new_source_code, Some(&tree));
|
||||
```
|
||||
|
||||
### Text Input
|
||||
|
||||
The source code to parse can be provided either as a string or as a function that returns text encoded as either UTF8 or UTF16:
|
||||
|
||||
```rust
|
||||
// Store some source code in an array of lines.
|
||||
let lines = &[
|
||||
"pub fn foo() {",
|
||||
" 1",
|
||||
"}",
|
||||
];
|
||||
|
||||
// Parse the source code using a custom callback. The callback is called
|
||||
// with both a byte offset and a row/column offset.
|
||||
let tree = parser.parse_utf8(&mut |_byte: u32, position: Point| -> &[u8] {
|
||||
let row = position.row as usize;
|
||||
let column = position.column as usize;
|
||||
if row < lines.len() {
|
||||
if column < lines[row].as_bytes().len() {
|
||||
&lines[row].as_bytes()[column..]
|
||||
} else {
|
||||
"\n".as_bytes()
|
||||
}
|
||||
} else {
|
||||
&[]
|
||||
}
|
||||
}, None).unwrap();
|
||||
|
||||
assert_eq!(
|
||||
tree.root_node().to_sexp(),
|
||||
"(source_file (function_item (visibility_modifier) (identifier) (parameters) (block (number_literal))))"
|
||||
);
|
||||
```
|
||||
|
||||
[tree-sitter]: https://github.com/tree-sitter/tree-sitter
|
||||
310
lib/binding/bindings.rs
Normal file
310
lib/binding/bindings.rs
Normal file
|
|
@ -0,0 +1,310 @@
|
|||
/* automatically generated by rust-bindgen */
|
||||
|
||||
pub type FILE = [u64; 19usize];
|
||||
pub type TSSymbol = u16;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSLanguage {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSParser {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSTree {
|
||||
_unused: [u8; 0],
|
||||
}
|
||||
pub const TSInputEncoding_TSInputEncodingUTF8: TSInputEncoding = 0;
|
||||
pub const TSInputEncoding_TSInputEncodingUTF16: TSInputEncoding = 1;
|
||||
pub type TSInputEncoding = u32;
|
||||
pub const TSSymbolType_TSSymbolTypeRegular: TSSymbolType = 0;
|
||||
pub const TSSymbolType_TSSymbolTypeAnonymous: TSSymbolType = 1;
|
||||
pub const TSSymbolType_TSSymbolTypeAuxiliary: TSSymbolType = 2;
|
||||
pub type TSSymbolType = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSPoint {
|
||||
pub row: u32,
|
||||
pub column: u32,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSRange {
|
||||
pub start_point: TSPoint,
|
||||
pub end_point: TSPoint,
|
||||
pub start_byte: u32,
|
||||
pub end_byte: u32,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSInput {
|
||||
pub payload: *mut ::std::os::raw::c_void,
|
||||
pub read: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
payload: *mut ::std::os::raw::c_void,
|
||||
byte_index: u32,
|
||||
position: TSPoint,
|
||||
bytes_read: *mut u32,
|
||||
) -> *const ::std::os::raw::c_char,
|
||||
>,
|
||||
pub encoding: TSInputEncoding,
|
||||
}
|
||||
pub const TSLogType_TSLogTypeParse: TSLogType = 0;
|
||||
pub const TSLogType_TSLogTypeLex: TSLogType = 1;
|
||||
pub type TSLogType = u32;
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSLogger {
|
||||
pub payload: *mut ::std::os::raw::c_void,
|
||||
pub log: ::std::option::Option<
|
||||
unsafe extern "C" fn(
|
||||
payload: *mut ::std::os::raw::c_void,
|
||||
arg1: TSLogType,
|
||||
arg2: *const ::std::os::raw::c_char,
|
||||
),
|
||||
>,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSInputEdit {
|
||||
pub start_byte: u32,
|
||||
pub old_end_byte: u32,
|
||||
pub new_end_byte: u32,
|
||||
pub start_point: TSPoint,
|
||||
pub old_end_point: TSPoint,
|
||||
pub new_end_point: TSPoint,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSNode {
|
||||
pub context: [u32; 4usize],
|
||||
pub id: *const ::std::os::raw::c_void,
|
||||
pub tree: *const TSTree,
|
||||
}
|
||||
#[repr(C)]
|
||||
#[derive(Debug, Copy, Clone)]
|
||||
pub struct TSTreeCursor {
|
||||
pub context: [u32; 2usize],
|
||||
pub id: *const ::std::os::raw::c_void,
|
||||
pub tree: *const ::std::os::raw::c_void,
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_new() -> *mut TSParser;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_delete(arg1: *mut TSParser);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_language(arg1: *const TSParser) -> *const TSLanguage;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_set_language(arg1: *mut TSParser, arg2: *const TSLanguage) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_logger(arg1: *const TSParser) -> TSLogger;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_set_logger(arg1: *mut TSParser, arg2: TSLogger);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_print_dot_graphs(arg1: *mut TSParser, arg2: *mut FILE);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_halt_on_error(arg1: *mut TSParser, arg2: bool);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_parse(arg1: *mut TSParser, arg2: *const TSTree, arg3: TSInput) -> *mut TSTree;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_parse_string(
|
||||
arg1: *mut TSParser,
|
||||
arg2: *const TSTree,
|
||||
arg3: *const ::std::os::raw::c_char,
|
||||
arg4: u32,
|
||||
) -> *mut TSTree;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_enabled(arg1: *const TSParser) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_set_enabled(arg1: *mut TSParser, arg2: bool);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_operation_limit(arg1: *const TSParser) -> usize;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_set_operation_limit(arg1: *mut TSParser, arg2: usize);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_reset(arg1: *mut TSParser);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_set_included_ranges(arg1: *mut TSParser, arg2: *const TSRange, arg3: u32);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_parser_included_ranges(arg1: *const TSParser, arg2: *mut u32) -> *const TSRange;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_copy(arg1: *const TSTree) -> *mut TSTree;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_delete(arg1: *mut TSTree);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_root_node(arg1: *const TSTree) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_edit(arg1: *mut TSTree, arg2: *const TSInputEdit);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_get_changed_ranges(
|
||||
arg1: *const TSTree,
|
||||
arg2: *const TSTree,
|
||||
arg3: *mut u32,
|
||||
) -> *mut TSRange;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_print_dot_graph(arg1: *const TSTree, arg2: *mut FILE);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_language(arg1: *const TSTree) -> *const TSLanguage;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_start_byte(arg1: TSNode) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_start_point(arg1: TSNode) -> TSPoint;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_end_byte(arg1: TSNode) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_end_point(arg1: TSNode) -> TSPoint;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_symbol(arg1: TSNode) -> TSSymbol;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_type(arg1: TSNode) -> *const ::std::os::raw::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_string(arg1: TSNode) -> *mut ::std::os::raw::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_eq(arg1: TSNode, arg2: TSNode) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_is_null(arg1: TSNode) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_is_named(arg1: TSNode) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_is_missing(arg1: TSNode) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_has_changes(arg1: TSNode) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_has_error(arg1: TSNode) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_parent(arg1: TSNode) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_child(arg1: TSNode, arg2: u32) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_named_child(arg1: TSNode, arg2: u32) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_child_count(arg1: TSNode) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_named_child_count(arg1: TSNode) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_next_sibling(arg1: TSNode) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_next_named_sibling(arg1: TSNode) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_prev_sibling(arg1: TSNode) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_prev_named_sibling(arg1: TSNode) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_first_child_for_byte(arg1: TSNode, arg2: u32) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_first_named_child_for_byte(arg1: TSNode, arg2: u32) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_descendant_for_byte_range(arg1: TSNode, arg2: u32, arg3: u32) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_named_descendant_for_byte_range(arg1: TSNode, arg2: u32, arg3: u32) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_descendant_for_point_range(arg1: TSNode, arg2: TSPoint, arg3: TSPoint)
|
||||
-> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_named_descendant_for_point_range(
|
||||
arg1: TSNode,
|
||||
arg2: TSPoint,
|
||||
arg3: TSPoint,
|
||||
) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_node_edit(arg1: *mut TSNode, arg2: *const TSInputEdit);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_cursor_new(arg1: TSNode) -> TSTreeCursor;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_cursor_delete(arg1: *mut TSTreeCursor);
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_cursor_goto_first_child(arg1: *mut TSTreeCursor) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_cursor_goto_first_child_for_byte(arg1: *mut TSTreeCursor, arg2: u32) -> i64;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_cursor_goto_next_sibling(arg1: *mut TSTreeCursor) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_cursor_goto_parent(arg1: *mut TSTreeCursor) -> bool;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_tree_cursor_current_node(arg1: *const TSTreeCursor) -> TSNode;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_language_symbol_count(arg1: *const TSLanguage) -> u32;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_language_symbol_name(
|
||||
arg1: *const TSLanguage,
|
||||
arg2: TSSymbol,
|
||||
) -> *const ::std::os::raw::c_char;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_language_symbol_for_name(
|
||||
arg1: *const TSLanguage,
|
||||
arg2: *const ::std::os::raw::c_char,
|
||||
) -> TSSymbol;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_language_symbol_type(arg1: *const TSLanguage, arg2: TSSymbol) -> TSSymbolType;
|
||||
}
|
||||
extern "C" {
|
||||
pub fn ts_language_version(arg1: *const TSLanguage) -> u32;
|
||||
}
|
||||
|
||||
pub const TREE_SITTER_LANGUAGE_VERSION: usize = 9;
|
||||
4
lib/binding/ffi.rs
Normal file
4
lib/binding/ffi.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#![allow(dead_code)]
|
||||
#![allow(non_upper_case_globals)]
|
||||
|
||||
include!("./bindings.rs");
|
||||
1349
lib/binding/lib.rs
Normal file
1349
lib/binding/lib.rs
Normal file
File diff suppressed because it is too large
Load diff
26
lib/build.rs
Normal file
26
lib/build.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
extern crate cc;
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
|
||||
fn main() {
|
||||
let mut config = cc::Build::new();
|
||||
let src_path: PathBuf = ["src"].iter().collect();
|
||||
|
||||
config
|
||||
.define("UTF8PROC_STATIC", "")
|
||||
.flag_if_supported("-std=c99")
|
||||
.flag_if_supported("-Wno-unused-parameter")
|
||||
.include("include")
|
||||
.include("utf8proc")
|
||||
.file(src_path.join("runtime.c"));
|
||||
|
||||
if env::var("RUST_TREE_SITTER_TEST").is_ok() {
|
||||
let parser_dir: PathBuf = ["fixtures", "tree-sitter-rust", "src"].iter().collect();
|
||||
config
|
||||
.file(parser_dir.join("parser.c"))
|
||||
.file(parser_dir.join("scanner.c"));
|
||||
}
|
||||
|
||||
config.compile("tree-sitter-runtime");
|
||||
}
|
||||
17
script/bindgen.sh
Executable file
17
script/bindgen.sh
Executable file
|
|
@ -0,0 +1,17 @@
|
|||
#!/bin/bash
|
||||
|
||||
output_path=src/bindings.rs
|
||||
header_path='vendor/tree-sitter/include/tree_sitter/runtime.h'
|
||||
|
||||
bindgen \
|
||||
--no-layout-tests \
|
||||
--whitelist-type '^TS.*' \
|
||||
--whitelist-function '^ts_.*' \
|
||||
--opaque-type FILE \
|
||||
--distrust-clang-mangling \
|
||||
$header_path > $output_path
|
||||
|
||||
echo "" >> $output_path
|
||||
version_constant='TREE_SITTER_LANGUAGE_VERSION'
|
||||
version_number=$(egrep "#define $version_constant (.*)" $header_path | cut -d' ' -f3)
|
||||
echo "pub const $version_constant: usize = $version_number;" >> $output_path
|
||||
16
script/fetch-test-fixtures.cmd
Executable file
16
script/fetch-test-fixtures.cmd
Executable file
|
|
@ -0,0 +1,16 @@
|
|||
@Echo off
|
||||
SETLOCAL
|
||||
|
||||
Set grammar_dir=fixtures\tree-sitter-rust
|
||||
Set grammar_url=https://github.com/tree-sitter/tree-sitter-rust
|
||||
|
||||
@IF NOT EXIST %grammar_dir% (
|
||||
git clone %grammar_url% %grammar_dir% --depth=1
|
||||
)
|
||||
|
||||
pushd %grammar_dir%
|
||||
git fetch origin master --depth=1
|
||||
git reset --hard origin/master
|
||||
popd
|
||||
|
||||
ENDLOCAL
|
||||
14
script/fetch-test-fixtures.sh
Executable file
14
script/fetch-test-fixtures.sh
Executable file
|
|
@ -0,0 +1,14 @@
|
|||
#!/bin/bash
|
||||
|
||||
grammar_dir='fixtures/tree-sitter-rust'
|
||||
grammar_url='https://github.com/tree-sitter/tree-sitter-rust'
|
||||
|
||||
if [ ! -d $grammar_dir ]; then
|
||||
git clone $grammar_url $grammar_dir --depth=1
|
||||
fi
|
||||
|
||||
(
|
||||
cd $grammar_dir;
|
||||
git fetch origin master --depth=1
|
||||
git reset --hard origin/master;
|
||||
)
|
||||
3
script/test.sh
Executable file
3
script/test.sh
Executable file
|
|
@ -0,0 +1,3 @@
|
|||
#!/bin/bash
|
||||
|
||||
RUST_TREE_SITTER_TEST=1 cargo test $@
|
||||
Loading…
Add table
Add a link
Reference in a new issue