feat!: update bindings

This commit is contained in:
ObserverOfTime
2025-05-09 10:06:33 +03:00
committed by Michael Hoffmann
parent 41a2e70241
commit 8b209bbb95
23 changed files with 337 additions and 114 deletions

10
bindings/c/tree-sitter-hcl.pc.in generated Normal file
View File

@@ -0,0 +1,10 @@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@
Name: tree-sitter-hcl
Description: @PROJECT_DESCRIPTION@
URL: @PROJECT_HOMEPAGE_URL@
Version: @PROJECT_VERSION@
Libs: -L${libdir} -ltree-sitter-hcl
Cflags: -I${includedir}

View File

@@ -16,4 +16,4 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) {
return exports;
}
NODE_API_MODULE(tree_sitter_PARSER_NAME_binding, Init)
NODE_API_MODULE(tree_sitter_hcl_binding, Init)

View File

@@ -1,9 +1,9 @@
/// <reference types="node" />
const assert = require("node:assert");
const { test } = require("node:test");
const Parser = require("tree-sitter");
test("can load grammar", () => {
const parser = new (require("tree-sitter"))();
const parser = new Parser();
assert.doesNotThrow(() => parser.setLanguage(require(".")));
});
});

View File

@@ -1,7 +1,11 @@
const root = require("path").join(__dirname, "..", "..");
module.exports = require("node-gyp-build")(root);
module.exports =
typeof process.versions.bun === "string"
// Support `bun build --compile` by being statically analyzable enough to find the .node file at build-time
? require(`../../prebuilds/${process.platform}-${process.arch}/tree-sitter-hcl.node`)
: require("node-gyp-build")(root);
try {
module.exports.nodeTypeInfo = require("../../src/node-types.json");
} catch (_) {}
} catch (_) {}

View File

@@ -7,11 +7,6 @@ fn main() {
#[cfg(target_env = "msvc")]
c_config.flag("-utf-8");
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);
println!("cargo:rerun-if-changed={}", parser_path.to_str().unwrap());

30
bindings/rust/lib.rs generated
View File

@@ -1,21 +1,24 @@
//! This crate provides hcl language support for the [tree-sitter][] parsing library.
//! This crate provides HCL language support for the [tree-sitter] parsing library.
//!
//! Typically, you will use the [LANGUAGE][] constant to add this language to a
//! tree-sitter [Parser][], and then use the parser to parse some code:
//! Typically, you will use the [`LANGUAGE`] constant to add this language to a
//! tree-sitter [`Parser`], and then use the parser to parse some code:
//!
//! ```
//! let code = r#"
//! example "test" {
//! foo = "bar"
//! }
//! "#;
//! let mut parser = tree_sitter::Parser::new();
//! let language = tree_sitter_PARSER_NAME::LANGUAGE;
//! let language = tree_sitter_hcl::LANGUAGE;
//! parser
//! .set_language(&language.into())
//! .expect("Error loading TITLE_PARSER_NAME parser");
//! .expect("Error loading HCL parser");
//! let tree = parser.parse(code, None).unwrap();
//! assert!(!tree.root_node().has_error());
//! ```
//!
//! [Parser]: https://docs.rs/tree-sitter/*/tree_sitter/struct.Parser.html
//! [`Parser`]: https://docs.rs/tree-sitter/0.25.3/tree_sitter/struct.Parser.html
//! [tree-sitter]: https://tree-sitter.github.io/
use tree_sitter_language::LanguageFn;
@@ -24,23 +27,14 @@ extern "C" {
fn tree_sitter_hcl() -> *const ();
}
/// The tree-sitter [`LanguageFn`][LanguageFn] for this grammar.
///
/// [LanguageFn]: https://docs.rs/tree-sitter-language/*/tree_sitter_language/struct.LanguageFn.html
/// The tree-sitter [`LanguageFn`] for this grammar.
pub const LANGUAGE: LanguageFn = unsafe { LanguageFn::from_raw(tree_sitter_hcl) };
/// The content of the [`node-types.json`][] file for this grammar.
/// The content of the [`node-types.json`] file for this grammar.
///
/// [`node-types.json`]: https://tree-sitter.github.io/tree-sitter/using-parsers/6-static-node-types
pub const NODE_TYPES: &str = include_str!("../../src/node-types.json");
// NOTE: uncomment these to include any queries that this grammar contains:
// pub const HIGHLIGHTS_QUERY: &str = include_str!("../../queries/highlights.scm");
// pub const INJECTIONS_QUERY: &str = include_str!("../../queries/injections.scm");
// pub const LOCALS_QUERY: &str = include_str!("../../queries/locals.scm");
// pub const TAGS_QUERY: &str = include_str!("../../queries/tags.scm");
#[cfg(test)]
mod tests {
#[test]
@@ -48,6 +42,6 @@ mod tests {
let mut parser = tree_sitter::Parser::new();
parser
.set_language(&super::LANGUAGE.into())
.expect("Error loading hcl parser");
.expect("Error loading HCL parser");
}
}

16
bindings/swift/TreeSitterHCL/hcl.h generated Normal file
View File

@@ -0,0 +1,16 @@
#ifndef TREE_SITTER_HCL_H_
#define TREE_SITTER_HCL_H_
typedef struct TSLanguage TSLanguage;
#ifdef __cplusplus
extern "C" {
#endif
const TSLanguage *tree_sitter_hcl(void);
#ifdef __cplusplus
}
#endif
#endif // TREE_SITTER_HCL_H_

View File

@@ -1,12 +1,12 @@
import XCTest
import SwiftTreeSitter
import TreeSitterHcl
import TreeSitterHCL
final class TreeSitterHclTests: XCTestCase {
final class TreeSitterHCLTests: XCTestCase {
func testCanLoadGrammar() throws {
let parser = Parser()
let language = Language(language: tree_sitter_hcl())
XCTAssertNoThrow(try parser.setLanguage(language),
"Error loading Hcl grammar")
"Error loading HCL grammar")
}
}