Skip to content

Commit 3afb9f0

Browse files
Merge pull request #33 from hkimura-intersys/crates
feat: split tree-sitter-objectscript into two rust crates
2 parents d2d81d3 + 4216ace commit 3afb9f0

28 files changed

Lines changed: 295 additions & 98 deletions

.github/workflows/publish.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,3 +50,19 @@ jobs:
5050
run: ./scripts/rust_playground_crate.sh publish
5151
env:
5252
CARGO_REGISTRY_TOKEN: ${{secrets.CARGO_REGISTRY_TOKEN}}
53+
54+
crates_routine:
55+
name: Publish Rust routine package
56+
runs-on: ubuntu-latest
57+
environment:
58+
name: crates
59+
url: https://crates.io/crates/tree-sitter-objectscript-routine
60+
steps:
61+
- name: Checkout repository
62+
uses: actions/checkout@v6
63+
- name: Set up Rust
64+
uses: actions-rust-lang/setup-rust-toolchain@v1
65+
- name: Publish to crates.io
66+
run: ./scripts/rust_routine_crate.sh publish
67+
env:
68+
CARGO_REGISTRY_TOKEN: ${{secrets.CARGO_REGISTRY_TOKEN}}

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

CONTRIBUTING.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,10 +95,11 @@ make query
9595

9696
Run from repository root.
9797

98-
- Rust (UDL + routine crate):
98+
- Rust (UDL crate + staged routine/playground crates):
9999

100100
```bash
101101
cargo test --lib --package tree-sitter-objectscript
102+
./scripts/rust_routine_crate.sh package --allow-dirty --no-verify
102103
./scripts/rust_playground_crate.sh package --allow-dirty --no-verify
103104
```
104105

Cargo.toml

Lines changed: 1 addition & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
[![CI][ci]](https://github.com/intersystems/tree-sitter-objectscript/actions/workflows/ci.yml)
44
[![npm][npm]](https://www.npmjs.com/package/tree-sitter-objectscript)
55
[![crates-udl][crates-udl]](https://crates.io/crates/tree-sitter-objectscript)
6+
[![crates-routine][crates-routine]](https://crates.io/crates/tree-sitter-objectscript-routine)
67
[![crates-playground][crates-playground]](https://crates.io/crates/tree-sitter-objectscript-playground)
78
[![pypi][pypi]](https://pypi.org/project/tree-sitter-objectscript/)
89

@@ -27,7 +28,8 @@ Grammar extension graph:
2728
- npm: `tree-sitter-objectscript`
2829
- PyPI: `tree-sitter-objectscript` (ships `tree_sitter_objectscript`, `tree_sitter_objectscript_udl`, and `tree_sitter_objectscript_routine`)
2930
- Rust crates:
30-
- `tree-sitter-objectscript` (UDL + routine grammars)
31+
- `tree-sitter-objectscript` (UDL grammar)
32+
- `tree-sitter-objectscript-routine` (routine grammar)
3133
- `tree-sitter-objectscript-playground` (playground grammar)
3234

3335
## Bindings
@@ -38,7 +40,7 @@ Language bindings are available under `bindings/`:
3840
- Go: `bindings/go`
3941
- Node.js: `bindings/node`
4042
- Python: `bindings/python`
41-
- Rust: `bindings/rust` and `bindings/rust-playground`
43+
- Rust: `bindings/rust`, `bindings/rust-routine`, and `bindings/rust-playground`
4244
- Swift: `bindings/swift`
4345

4446
Quick binding checks from repo root:
@@ -127,5 +129,6 @@ MIT. See [LICENSE](LICENSE).
127129
[ci]: https://img.shields.io/github/actions/workflow/status/intersystems/tree-sitter-objectscript/ci.yml?logo=github&label=CI
128130
[npm]: https://img.shields.io/npm/v/tree-sitter-objectscript?logo=npm
129131
[crates-udl]: https://img.shields.io/crates/v/tree-sitter-objectscript?logo=rust
132+
[crates-routine]: https://img.shields.io/crates/v/tree-sitter-objectscript-routine?logo=rust
130133
[crates-playground]: https://img.shields.io/crates/v/tree-sitter-objectscript-playground?logo=rust
131134
[pypi]: https://img.shields.io/pypi/v/tree-sitter-objectscript?logo=pypi&logoColor=ffd242

bindings/rust-playground/Cargo.toml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/rust-routine/Cargo.toml

Lines changed: 39 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindings/rust-routine/build.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use std::path::Path;
2+
3+
fn main() {
4+
let root_dir = Path::new(".");
5+
let routine_dir = root_dir.join("objectscript_routine").join("src");
6+
let common_dir = root_dir.join("common");
7+
let mut config = cc::Build::new();
8+
9+
config.include(&routine_dir);
10+
11+
for path in &[
12+
routine_dir.join("parser.c"),
13+
routine_dir.join("scanner.c"),
14+
] {
15+
config.file(path);
16+
println!("cargo:rerun-if-changed={}", path.to_str().unwrap());
17+
}
18+
19+
println!(
20+
"cargo:rerun-if-changed={}",
21+
common_dir.join("scanner.h").to_str().unwrap()
22+
);
23+
24+
// MSVC quirk
25+
if cfg!(target_env = "msvc") {
26+
config.define("TREE_SITTER_DISABLE_ATOMIC", None);
27+
}
28+
29+
config.compile("tree-sitter-objectscript-routine");
30+
}

bindings/rust-routine/lib.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//! This crate provides ObjectScript routine language support for the [tree-sitter][] parsing library.
2+
//!
3+
//! [tree-sitter]: https://tree-sitter.github.io/
4+
5+
use tree_sitter_language::LanguageFn;
6+
7+
extern "C" {
8+
fn tree_sitter_objectscript_routine() -> *const ();
9+
}
10+
11+
/// The tree-sitter [`LanguageFn`] for ObjectScript routine grammar.
12+
///
13+
/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
14+
pub const LANGUAGE_OBJECTSCRIPT_ROUTINE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_objectscript_routine) };
15+
16+
/// The content of the [`node-types.json`][] file for ObjectScript routine grammar.
17+
///
18+
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers#static-node-types
19+
pub const NODE_TYPES: &str = include_str!("objectscript_routine/src/node-types.json");
20+
21+
/// The syntax highlighting query for ObjectScript routine grammar.
22+
pub const HIGHLIGHTS_QUERY: &str = include_str!("objectscript_routine/queries/highlights.scm");
23+
24+
/// The injections query for ObjectScript routine grammar.
25+
pub const INJECTIONS_QUERY: &str = include_str!("objectscript_routine/queries/injections.scm");
26+
27+
/// The indents query for ObjectScript routine grammar.
28+
pub const INDENTS_QUERY: &str = include_str!("objectscript_routine/queries/indents.scm");
29+
30+
#[cfg(test)]
31+
mod tests {
32+
#[test]
33+
fn test_can_load_objectscript_routine_grammar() {
34+
let mut parser = tree_sitter::Parser::new();
35+
parser
36+
.set_language(&super::LANGUAGE_OBJECTSCRIPT_ROUTINE.into())
37+
.expect("Error loading ObjectScript routine parser");
38+
}
39+
40+
#[test]
41+
fn test_indents_query_is_loaded() {
42+
assert!(super::INDENTS_QUERY.contains("indent"));
43+
}
44+
45+
#[test]
46+
fn test_injections_query_is_loaded() {
47+
assert!(super::INJECTIONS_QUERY.contains("injection"));
48+
}
49+
50+
#[test]
51+
fn test_highlights_query_is_loaded() {
52+
assert!(super::HIGHLIGHTS_QUERY.contains("@keyword"));
53+
}
54+
}

bindings/rust/build.rs

Lines changed: 3 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)