Skip to content

Commit e0ab53d

Browse files
authored
feat: update tree-sitter (#91)
1 parent 7dcac54 commit e0ab53d

36 files changed

+589
-687
lines changed

.github/workflows/ci.yml

Lines changed: 6 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ jobs:
2424
- name: test language
2525
uses: tree-sitter/parser-test-action@v2
2626
with:
27-
test-parser-cmd: cd ${{matrix.language}} && tree-sitter test
27+
test-rust: ${{ runner.os == 'Linux' }}
28+
test-node: true
29+
test-python: true
30+
test-go: true
31+
test-swift: ${{ runner.os == 'macOS' }}
32+
2833
parse-examples:
2934
name: Parse examples
3035
runs-on: ${{matrix.os}}
@@ -51,98 +56,6 @@ jobs:
5156
name: failures-${{runner.os}}
5257
path: ${{steps.parse-files.outputs.failures}}
5358

54-
test-go:
55-
name: Test Go binding
56-
runs-on: ${{matrix.os}}
57-
strategy:
58-
fail-fast: false
59-
matrix:
60-
os: [ubuntu-latest, windows-latest, macos-latest]
61-
steps:
62-
- name: Checkout
63-
uses: actions/checkout@v4
64-
- name: Set up Go
65-
uses: actions/setup-go@v5
66-
with:
67-
go-version: "1.22"
68-
cache-dependency-path: bindings/go/go.mod
69-
- name: Get dependencies
70-
working-directory: bindings/go
71-
run: go get -t .
72-
- name: Test
73-
working-directory: bindings/go
74-
run: go test -v
75-
76-
test-node:
77-
name: Test Node binding
78-
runs-on: ${{matrix.os}}
79-
strategy:
80-
fail-fast: false
81-
matrix:
82-
os: [ubuntu-latest, macos-latest]
83-
steps:
84-
- name: Checkout
85-
uses: actions/checkout@v4
86-
- name: Set up Node
87-
uses: actions/setup-node@v4
88-
- name: Install dependencies
89-
run: npm install
90-
- name: Test
91-
run: npm run test-binding
92-
93-
test-python:
94-
name: Test Python binding
95-
runs-on: ${{matrix.os}}
96-
strategy:
97-
fail-fast: false
98-
matrix:
99-
os: [ubuntu-latest, windows-latest, macos-latest]
100-
steps:
101-
- name: Checkout
102-
uses: actions/checkout@v4
103-
- name: Set up Python
104-
uses: actions/setup-python@v5
105-
with:
106-
cache: pip
107-
python-version: 3.12
108-
cache-dependency-path: pyproject.toml
109-
- name: Build
110-
run: pip install -e .[core]
111-
- name: Test
112-
run: python -munittest discover -v -s bindings/python/tests
113-
114-
test-rust:
115-
name: Test Rust binding
116-
runs-on: ${{matrix.os}}
117-
strategy:
118-
fail-fast: false
119-
matrix:
120-
os: [ubuntu-latest, windows-latest, macos-latest]
121-
steps:
122-
- name: Checkout
123-
uses: actions/checkout@v4
124-
- name: Set up Rust
125-
uses: actions-rust-lang/setup-rust-toolchain@v1
126-
- name: Build
127-
run: cargo build -v
128-
- name: Test
129-
run: cargo test -v
130-
131-
# test-swift:
132-
# name: Test Swift binding
133-
# runs-on: ${{matrix.os}}
134-
# strategy:
135-
# fail-fast: false
136-
# matrix:
137-
# os: [ubuntu-latest, macos-latest]
138-
# steps:
139-
# - name: Checkout
140-
# uses: actions/checkout@v4
141-
# - name: Build
142-
# run: swift build
143-
# - name: Test
144-
# run: swift test
145-
14659
fuzz:
14760
name: Fuzz fsharp
14861
runs-on: ubuntu-latest

Cargo.toml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@ include = [
2323
path = "bindings/rust/lib.rs"
2424

2525
[dependencies]
26-
tree-sitter = ">=0.21.0"
26+
tree-sitter-language = "0.1.0"
2727

2828
[build-dependencies]
29-
cc = "1.0.89"
29+
cc = "1.0.104"
30+
31+
[dev-dependencies]
32+
tree-sitter = "0.23"

Package.swift

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,30 @@ let package = Package(
1212
targets: [
1313
.target(
1414
name: "TreeSitterFSharp",
15-
dependencies: [],
1615
path: ".",
16+
exclude: [
17+
"Cargo.toml",
18+
"Makefile",
19+
"binding.gyp",
20+
"bindings/c",
21+
"bindings/go",
22+
"bindings/node",
23+
"bindings/python",
24+
"bindings/rust",
25+
"prebuilds",
26+
"grammar.js",
27+
"package.json",
28+
"package-lock.json",
29+
"pyproject.toml",
30+
"setup.py",
31+
"test",
32+
"examples",
33+
".editorconfig",
34+
".github",
35+
".gitignore",
36+
".gitattributes",
37+
".gitmodules",
38+
],
1739
sources: [
1840
"fsharp/src/parser.c",
1941
"fsharp/src/scanner.c",
@@ -34,7 +56,6 @@ let package = Package(
3456
],
3557
path: "bindings/swift/TreeSitterFSharpTests"
3658
)
37-
],
38-
cLanguageStandard: .c11
59+
]
3960
)
4061

bindings/go/binding_fsharp.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import "C"
88
import "unsafe"
99

1010
// Get the tree-sitter Language for FSharp.
11-
func FSharp() unsafe.Pointer {
11+
func LanguageFSharp() unsafe.Pointer {
1212
return unsafe.Pointer(C.tree_sitter_fsharp())
1313
}

bindings/go/binding_signature.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@ import "C"
88
import "unsafe"
99

1010
// Get the tree-sitter Language for FSharp signature.
11-
func FSharpSignature() unsafe.Pointer {
11+
func LanguageFSharpSignature() unsafe.Pointer {
1212
return unsafe.Pointer(C.tree_sitter_fsharp_signature())
1313
}

bindings/go/binding_test.go

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,42 @@
11
package tree_sitter_fsharp_test
22

33
import (
4-
"context"
54
"testing"
65

7-
tree_sitter "github.com/smacker/go-tree-sitter"
8-
tree_sitter_fsharp "github.com/ionide/tree-sitter-fsharp"
6+
tree_sitter "github.com/tree-sitter/go-tree-sitter"
7+
tree_sitter_fsharp "github.com/tree-sitter/tree-sitter-fsharp/bindings/go"
98
)
109

1110
func TestFSharpGrammar(t *testing.T) {
12-
language := tree_sitter.NewLanguage(tree_sitter_fsharp.FSharp())
11+
language := tree_sitter.NewLanguage(tree_sitter_fsharp.LanguageFSharp())
1312
if language == nil {
1413
t.Errorf("Error loading FSharp grammar")
1514
}
1615

1716
sourceCode := []byte("module M = ()")
17+
parser := tree_sitter.NewParser()
18+
defer parser.Close()
19+
parser.SetLanguage(language)
1820

19-
node, err := tree_sitter.ParseCtx(context.Background(), sourceCode, language)
20-
if err != nil || node.HasError() {
21+
tree := parser.Parse(sourceCode, nil)
22+
if tree == nil || tree.RootNode().HasError() {
2123
t.Errorf("Error parsing FSharp")
2224
}
2325
}
2426

2527
func TestFSharpSignatureGrammar(t *testing.T) {
26-
language := tree_sitter.NewLanguage(tree_sitter_fsharp.FSharpSignature())
28+
language := tree_sitter.NewLanguage(tree_sitter_fsharp.LanguageFSharpSignature())
2729
if language == nil {
2830
t.Errorf("Error loading FSharpSignature grammar")
2931
}
3032

3133
sourceCode := []byte("val x : int -> int")
34+
parser := tree_sitter.NewParser()
35+
defer parser.Close()
36+
parser.SetLanguage(language)
3237

33-
node, err := tree_sitter.ParseCtx(context.Background(), sourceCode, language)
34-
if err != nil || node.HasError() {
38+
tree := parser.Parse(sourceCode, nil)
39+
if tree == nil || tree.RootNode().HasError() {
3540
t.Errorf("Error parsing FSharpSignature")
3641
}
3742
}

bindings/go/go.mod

Lines changed: 0 additions & 5 deletions
This file was deleted.

bindings/python/tree_sitter_fsharp/binding.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ static PyMethodDef methods[] = {
1919
{"fsharp", _binding_language_fsharp, METH_NOARGS,
2020
"Get the tree-sitter language for FSharp."},
2121
{"signature", _binding_language_fsharp_signature, METH_NOARGS,
22-
"Get the tree-sitter language for FSharp signature."},
22+
"Get the tree-sitter language for FSharp interfaces."},
2323
{NULL, NULL, 0, NULL}};
2424

2525
static struct PyModuleDef module = {.m_base = PyModuleDef_HEAD_INIT,

bindings/rust/lib.rs

Lines changed: 25 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,57 @@
1-
2-
//! This crate provides FSharp language support for the [tree-sitter][] parsing
3-
//! library. There are separate languages for implementation, (`.fs`),
4-
//! signature (`.fsi`).
1+
//! This crate provides Fsharp language support for the [tree-sitter][] parsing library.
52
//!
6-
//! Typically, you will use the [language_fsharp][language func] function to add
7-
//! this language to a tree-sitter [Parser][], and then use the parser to parse
8-
//! some code:
3+
//! Typically, you will use the [language][language func] function to add this language to a
4+
//! tree-sitter [Parser][], and then use the parser to parse some code:
95
//!
106
//! ```
117
//! let code = r#"
12-
//! module M =
13-
//! let x = 0
148
//! "#;
159
//! let mut parser = tree_sitter::Parser::new();
10+
//! let language = tree_sitter_fsharp::LANGUAGE_FSHARP;
1611
//! parser
17-
//! .set_language(&tree_sitter_fsharp::language_fsharp())
18-
//! .expect("Error loading FSharp grammar");
12+
//! .set_language(&language.into())
13+
//! .expect("Error loading Fsharp parser");
1914
//! let tree = parser.parse(code, None).unwrap();
2015
//! assert!(!tree.root_node().has_error());
2116
//! ```
2217
//!
2318
//! [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
24-
//! [language func]: fn.language_fsharp.html
19+
//! [language func]: fn.language.html
2520
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
2621
//! [tree-sitter]: https://tree-sitter.github.io/
2722
28-
use tree_sitter::Language;
23+
use tree_sitter_language::LanguageFn;
2924

3025
extern "C" {
31-
fn tree_sitter_fsharp() -> Language;
32-
fn tree_sitter_fsharp_signature() -> Language;
33-
}
34-
35-
/// Get the tree-sitter [Language][] for FSharp.
36-
///
37-
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
38-
pub fn language_fsharp() -> Language {
39-
unsafe { tree_sitter_fsharp() }
26+
fn tree_sitter_fsharp() -> *const ();
27+
fn tree_sitter_fsharp_signature() -> *const ();
4028
}
4129

42-
/// Get the tree-sitter [Language][] for FSharp signature.
43-
///
44-
/// [Language]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Language.html
45-
pub fn language_fsharp_signature() -> Language {
46-
unsafe { tree_sitter_fsharp_signature() }
47-
}
30+
/// The tree-sitter [`LanguageFn`] for this grammar.
31+
pub const LANGUAGE_FSHARP: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_fsharp) };
32+
pub const LANGUAGE_SIGNATURE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_fsharp_signature) };
4833

49-
/// The content of the [`node-types.json`][] file for FSharp.
34+
/// The content of the [`node-types.json`][] file for this grammar.
5035
///
5136
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
52-
pub const FSHARP_NODE_TYPES: &'static str = include_str!("../../fsharp/src/node-types.json");
37+
pub const FSHARP_NODE_TYPES: &str = include_str!("../../fsharp/src/node-types.json");
38+
pub const SIGNATURE_NODE_TYPES: &str = include_str!("../../fsharp_signature/src/node-types.json");
5339

54-
/// The content of the [`node-types.json`][] file for FSharp signature.
55-
///
56-
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
57-
pub const SIGNATURE_NODE_TYPES: &'static str = include_str!("../../fsharp_signature/src/node-types.json");
58-
59-
/// The syntax highlighting query for FSharp.
60-
pub const HIGHLIGHTS_QUERY: &'static str = include_str!("../../queries/highlights.scm");
40+
// NOTE: uncomment these to include any queries that this grammar contains:
6141

62-
/// The local-variable syntax highlighting query for FSharp.
63-
pub const LOCALS_QUERY: &'static str = include_str!("../../queries/locals.scm");
64-
65-
/// The symbol tagging query for FSharp.
66-
pub const TAGGING_QUERY: &'static str = include_str!("../../queries/tags.scm");
42+
pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
43+
pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
44+
pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
45+
pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
6746

6847
#[cfg(test)]
6948
mod tests {
7049
#[test]
7150
fn test_fsharp() {
7251
let mut parser = tree_sitter::Parser::new();
7352
parser
74-
.set_language(&super::language_fsharp())
75-
.expect("Error loading FSharp grammar");
53+
.set_language(&super::LANGUAGE_FSHARP.into())
54+
.expect("Error loading Fsharp parser");
7655

7756
let code = r#"
7857
module M =
@@ -88,8 +67,8 @@ mod tests {
8867
fn test_fsharp_signature() {
8968
let mut parser = tree_sitter::Parser::new();
9069
parser
91-
.set_language(&super::language_fsharp_signature())
92-
.expect("Error loading FSharp signature grammar");
70+
.set_language(&super::LANGUAGE_SIGNATURE.into())
71+
.expect("Error loading Fsharp parser");
9372

9473
let code = r#"
9574
module M =
@@ -101,4 +80,3 @@ mod tests {
10180
assert!(!root.has_error());
10281
}
10382
}
104-

bindings/swift/TreeSitterFSharpTests/TreeSitterFSharpTests.swift

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ final class TreeSitterFSharpTests: XCTestCase {
1010
let parser = Parser()
1111
try parser.setLanguage(language)
1212

13-
let source = """
14-
module M =
15-
let x = 0
16-
"""
13+
let source = "module M = ()"
1714

1815
let tree = try XCTUnwrap(parser.parse(source))
1916
let root = try XCTUnwrap(tree.rootNode)
@@ -27,10 +24,7 @@ final class TreeSitterFSharpTests: XCTestCase {
2724
let parser = Parser()
2825
try parser.setLanguage(language)
2926

30-
let source = """
31-
module M =
32-
val x : int -> int
33-
"""
27+
let source = "val x : int -> int"
3428

3529
let tree = try XCTUnwrap(parser.parse(source))
3630
let root = try XCTUnwrap(tree.rootNode)

0 commit comments

Comments
 (0)