From 8b209bbb95110e5372bba06c15b81abd0a962d29 Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Fri, 9 May 2025 10:06:33 +0300 Subject: [PATCH] feat!: update bindings --- .gitattributes | 2 +- .gitignore | 1 - CMakeLists.txt | 66 ++++++++++++ Cargo.lock | 26 ++--- Cargo.toml | 7 +- Makefile | 100 ++++++++++++++++++ Package.resolved | 25 +++++ Package.swift | 52 +++++---- binding.gyp | 2 +- bindings/c/tree-sitter-hcl.pc.in | 10 ++ .../hcl.h => c/tree_sitter/tree-sitter-hcl.h} | 0 bindings/node/binding.cc | 2 +- bindings/node/binding_test.js | 8 +- bindings/node/index.js | 8 +- bindings/rust/build.rs | 5 - bindings/rust/lib.rs | 30 +++--- bindings/swift/TreeSitterHCL/hcl.h | 16 +++ .../TreeSitterHCLTests.swift} | 6 +- dialects/terraform/package.json | 10 +- make_grammar.js | 8 +- package-lock.json | 31 ++++-- package.json | 24 ++--- tree-sitter.json | 12 +-- 23 files changed, 337 insertions(+), 114 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 Makefile create mode 100644 Package.resolved create mode 100644 bindings/c/tree-sitter-hcl.pc.in rename bindings/{swift/TreeSitterHcl/hcl.h => c/tree_sitter/tree-sitter-hcl.h} (100%) create mode 100644 bindings/swift/TreeSitterHCL/hcl.h rename bindings/swift/{TreeSitterHclTests/TreeSitterHclTests.swift => TreeSitterHCLTests/TreeSitterHCLTests.swift} (66%) diff --git a/.gitattributes b/.gitattributes index 9220f16..79475a5 100644 --- a/.gitattributes +++ b/.gitattributes @@ -38,4 +38,4 @@ Package.resolved linguist-generated # Zig bindings build.zig linguist-generated -build.zig.zon linguist-generated \ No newline at end of file +build.zig.zon linguist-generated diff --git a/.gitignore b/.gitignore index e575030..00e3c9f 100644 --- a/.gitignore +++ b/.gitignore @@ -47,7 +47,6 @@ zig-out/ *.zip # Project misc. -queries npm-debug.log log.html .env diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e74a124 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,66 @@ +cmake_minimum_required(VERSION 3.13) + +project(tree-sitter-hcl + VERSION "1.1.0" + DESCRIPTION "HCL and terraform grammar for tree-sitter" + HOMEPAGE_URL "https://github.com/tree-sitter-grammars/tree-sitter-hcl" + LANGUAGES C) + +option(BUILD_SHARED_LIBS "Build using shared libraries" ON) +option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF) + +set(TREE_SITTER_ABI_VERSION 15 CACHE STRING "Tree-sitter ABI version") +if(NOT ${TREE_SITTER_ABI_VERSION} MATCHES "^[0-9]+$") + unset(TREE_SITTER_ABI_VERSION CACHE) + message(FATAL_ERROR "TREE_SITTER_ABI_VERSION must be an integer") +endif() + +find_program(TREE_SITTER_CLI tree-sitter DOC "Tree-sitter CLI") + +add_custom_command(OUTPUT "${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c" + DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json" + COMMAND "${TREE_SITTER_CLI}" generate src/grammar.json + --abi=${TREE_SITTER_ABI_VERSION} + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT "Generating parser.c") + +add_library(tree-sitter-hcl src/parser.c) +if(EXISTS ${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c) + target_sources(tree-sitter-hcl PRIVATE src/scanner.c) +endif() +target_include_directories(tree-sitter-hcl + PRIVATE src + INTERFACE $ + $) + +target_compile_definitions(tree-sitter-hcl PRIVATE + $<$:TREE_SITTER_REUSE_ALLOCATOR> + $<$:TREE_SITTER_DEBUG>) + +set_target_properties(tree-sitter-hcl + PROPERTIES + C_STANDARD 11 + POSITION_INDEPENDENT_CODE ON + SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}" + DEFINE_SYMBOL "") + +configure_file(bindings/c/tree-sitter-hcl.pc.in + "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-hcl.pc" @ONLY) + +include(GNUInstallDirs) + +install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/bindings/c/tree_sitter" + DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}" + FILES_MATCHING PATTERN "*.h") +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-hcl.pc" + DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig") +install(TARGETS tree-sitter-hcl + LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}") + +file(GLOB QUERIES queries/*.scm) +install(FILES ${QUERIES} + DESTINATION "${CMAKE_INSTALL_DATADIR}/tree-sitter/queries/hcl") + +add_custom_target(ts-test "${TREE_SITTER_CLI}" test + WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}" + COMMENT "tree-sitter test") diff --git a/Cargo.lock b/Cargo.lock index ccd01a2..37d4307 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -13,9 +13,9 @@ dependencies = [ [[package]] name = "cc" -version = "1.2.14" +version = "1.2.21" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c3d1b2e905a3a7b00a6141adb0e4c0bb941d11caf55349d863942a1cc44e3c9" +checksum = "8691782945451c1c383942c4874dbe63814f61cb57ef773cda2972682b7bb3c0" dependencies = [ "shlex", ] @@ -28,15 +28,15 @@ checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" [[package]] name = "hashbrown" -version = "0.15.2" +version = "0.15.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bf151400ff0baff5465007dd2f3e717f3fe502074ca563069ce3a6629d07b289" +checksum = "84b26c544d002229e640969970a2e74021aadf6e2f96372b9c58eff97de08eb3" [[package]] name = "indexmap" -version = "2.8.0" +version = "2.9.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3954d50fe15b02142bf25d3b8bdadb634ec3948f103d04ffe3031bc8fe9d7058" +checksum = "cea70ddb795996207ad57735b50c5982d8844f38ba9ee5f1aedcfb708a2aa11e" dependencies = [ "equivalent", "hashbrown", @@ -56,9 +56,9 @@ checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" [[package]] name = "proc-macro2" -version = "1.0.94" +version = "1.0.95" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84" +checksum = "02b3e5e68a3a1a02aad3ec490a98007cbc13c37cbe84a3cd7b8e406d76e7f778" dependencies = [ "unicode-ident", ] @@ -154,9 +154,9 @@ checksum = "2b2231b7c3057d5e4ad0156fb3dc807d900806020c5ffa3ee6ff2c8c76fb8520" [[package]] name = "syn" -version = "2.0.100" +version = "2.0.101" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0" +checksum = "8ce2b7fc941b3a24138a0a7cf8e858bfc6a992e7978a068a5c760deb0ed43caf" dependencies = [ "proc-macro2", "quote", @@ -179,7 +179,7 @@ dependencies = [ [[package]] name = "tree-sitter-hcl" -version = "0.0.1" +version = "1.1.0" dependencies = [ "cc", "tree-sitter", @@ -188,9 +188,9 @@ dependencies = [ [[package]] name = "tree-sitter-language" -version = "0.1.4" +version = "0.1.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "38eee4db33814de3d004de9d8d825627ed3320d0989cce0dea30efaf5be4736c" +checksum = "c4013970217383f67b18aef68f6fb2e8d409bc5755227092d32efb0422ba24b8" [[package]] name = "unicode-ident" diff --git a/Cargo.toml b/Cargo.toml index 4102e8f..d25921b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,7 +1,7 @@ [package] name = "tree-sitter-hcl" -description = "HCL grammar for tree-sitter" -version = "0.0.1" +description = "HCL and terraform grammar for tree-sitter" +version = "1.1.0" license = "Apache-2.0" readme = "README.md" keywords = ["incremental", "parsing", "tree-sitter", "hcl"] @@ -14,6 +14,7 @@ build = "bindings/rust/build.rs" include = [ "bindings/rust/*", "grammar.js", + "make_grammar.js", "queries/*", "src/*", "tree-sitter.json", @@ -30,4 +31,4 @@ tree-sitter-language = "0.1" cc = "1.2" [dev-dependencies] -tree-sitter = "0.25" \ No newline at end of file +tree-sitter = "0.25.3" diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ec47011 --- /dev/null +++ b/Makefile @@ -0,0 +1,100 @@ +ifeq ($(OS),Windows_NT) +$(error Windows is not supported) +endif + +LANGUAGE_NAME := tree-sitter-hcl +HOMEPAGE_URL := https://github.com/tree-sitter-grammars/tree-sitter-hcl +VERSION := 1.1.0 + +# repository +SRC_DIR := src + +TS ?= tree-sitter + +# install directory layout +PREFIX ?= /usr/local +DATADIR ?= $(PREFIX)/share +INCLUDEDIR ?= $(PREFIX)/include +LIBDIR ?= $(PREFIX)/lib +PCLIBDIR ?= $(LIBDIR)/pkgconfig + +# source/object files +PARSER := $(SRC_DIR)/parser.c +EXTRAS := $(filter-out $(PARSER),$(wildcard $(SRC_DIR)/*.c)) +OBJS := $(patsubst %.c,%.o,$(PARSER) $(EXTRAS)) + +# flags +ARFLAGS ?= rcs +override CFLAGS += -I$(SRC_DIR) -std=c11 -fPIC + +# ABI versioning +SONAME_MAJOR = $(shell sed -n 's/\#define LANGUAGE_VERSION //p' $(PARSER)) +SONAME_MINOR = $(word 1,$(subst ., ,$(VERSION))) + +# OS-specific bits +ifeq ($(shell uname),Darwin) + SOEXT = dylib + SOEXTVER_MAJOR = $(SONAME_MAJOR).$(SOEXT) + SOEXTVER = $(SONAME_MAJOR).$(SONAME_MINOR).$(SOEXT) + LINKSHARED = -dynamiclib -Wl,-install_name,$(LIBDIR)/lib$(LANGUAGE_NAME).$(SOEXTVER),-rpath,@executable_path/../Frameworks +else + SOEXT = so + SOEXTVER_MAJOR = $(SOEXT).$(SONAME_MAJOR) + SOEXTVER = $(SOEXT).$(SONAME_MAJOR).$(SONAME_MINOR) + LINKSHARED = -shared -Wl,-soname,lib$(LANGUAGE_NAME).$(SOEXTVER) +endif +ifneq ($(filter $(shell uname),FreeBSD NetBSD DragonFly),) + PCLIBDIR := $(PREFIX)/libdata/pkgconfig +endif + +all: lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) $(LANGUAGE_NAME).pc + +lib$(LANGUAGE_NAME).a: $(OBJS) + $(AR) $(ARFLAGS) $@ $^ + +lib$(LANGUAGE_NAME).$(SOEXT): $(OBJS) + $(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@ +ifneq ($(STRIP),) + $(STRIP) $@ +endif + +$(LANGUAGE_NAME).pc: bindings/c/$(LANGUAGE_NAME).pc.in + sed -e 's|@PROJECT_VERSION@|$(VERSION)|' \ + -e 's|@CMAKE_INSTALL_LIBDIR@|$(LIBDIR:$(PREFIX)/%=%)|' \ + -e 's|@CMAKE_INSTALL_INCLUDEDIR@|$(INCLUDEDIR:$(PREFIX)/%=%)|' \ + -e 's|@PROJECT_DESCRIPTION@|$(DESCRIPTION)|' \ + -e 's|@PROJECT_HOMEPAGE_URL@|$(HOMEPAGE_URL)|' \ + -e 's|@CMAKE_INSTALL_PREFIX@|$(PREFIX)|' $< > $@ + +$(PARSER): $(SRC_DIR)/grammar.json + $(TS) generate $^ + +install: all + install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter '$(DESTDIR)$(PCLIBDIR)' '$(DESTDIR)$(LIBDIR)' + install -m644 bindings/c/tree_sitter/$(LANGUAGE_NAME).h '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h + install -m644 $(LANGUAGE_NAME).pc '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc + install -m644 lib$(LANGUAGE_NAME).a '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a + install -m755 lib$(LANGUAGE_NAME).$(SOEXT) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) + ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) + ln -sf lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) +ifneq ($(wildcard queries/*.scm),) + install -d '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/hcl + install -m644 queries/*.scm '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/hcl +endif + +uninstall: + $(RM) '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).a \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER) \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXTVER_MAJOR) \ + '$(DESTDIR)$(LIBDIR)'/lib$(LANGUAGE_NAME).$(SOEXT) \ + '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter/$(LANGUAGE_NAME).h \ + '$(DESTDIR)$(PCLIBDIR)'/$(LANGUAGE_NAME).pc + $(RM) -r '$(DESTDIR)$(DATADIR)'/tree-sitter/queries/hcl + +clean: + $(RM) $(OBJS) $(LANGUAGE_NAME).pc lib$(LANGUAGE_NAME).a lib$(LANGUAGE_NAME).$(SOEXT) + +test: + $(TS) test + +.PHONY: all install uninstall clean test diff --git a/Package.resolved b/Package.resolved new file mode 100644 index 0000000..5a834cd --- /dev/null +++ b/Package.resolved @@ -0,0 +1,25 @@ +{ + "object": { + "pins": [ + { + "package": "SwiftTreeSitter", + "repositoryURL": "https://github.com/tree-sitter/swift-tree-sitter", + "state": { + "branch": null, + "revision": "36aa61d1b531f744f35229f010efba9c6d6cbbdd", + "version": "0.9.0" + } + }, + { + "package": "TreeSitter", + "repositoryURL": "https://github.com/tree-sitter/tree-sitter", + "state": { + "branch": null, + "revision": "d97db6d63507eb62c536bcb2c4ac7d70c8ec665e", + "version": "0.23.2" + } + } + ] + }, + "version": 1 +} diff --git a/Package.swift b/Package.swift index e1944bf..d3207f1 100644 --- a/Package.swift +++ b/Package.swift @@ -4,36 +4,32 @@ import PackageDescription let package = Package( name: "TreeSitterHCL", - platforms: [.macOS(.v10_13), .iOS(.v11)], products: [ .library(name: "TreeSitterHCL", targets: ["TreeSitterHCL"]), ], - dependencies: [], + dependencies: [ + .package(name: "SwiftTreeSitter", url: "https://github.com/tree-sitter/swift-tree-sitter", from: "0.9.0"), + ], targets: [ - .target(name: "TreeSitterHCL", - path: ".", - exclude: [ - "binding.gyp", - "bindings", - "Cargo.toml", - "CHANGELOG.md", - "docs", - "example", - "grammar.js", - "LICENSE", - "package.json", - "README.md", - "shell.nix", - "src/grammar.json", - "src/node-types.json", - "test", - ], - sources: [ - "src/parser.c", - "src/scanner.c", - ], - publicHeadersPath: "bindings/swift", - cSettings: [.headerSearchPath("src")], - linkerSettings: [.linkedLibrary("c++")]) - ] + .target( + name: "TreeSitterHCL", + dependencies: [], + path: ".", + sources: [ + "src/parser.c", + "src/scanner.c" + ], + publicHeadersPath: "bindings/swift", + cSettings: [.headerSearchPath("src")] + ), + .testTarget( + name: "TreeSitterHCLTests", + dependencies: [ + "SwiftTreeSitter", + "TreeSitterHCL", + ], + path: "bindings/swift/TreeSitterHCLTests" + ) + ], + cLanguageStandard: .c11 ) diff --git a/binding.gyp b/binding.gyp index 45c18d3..bab1a9d 100644 --- a/binding.gyp +++ b/binding.gyp @@ -32,4 +32,4 @@ ], } ] -} \ No newline at end of file +} diff --git a/bindings/c/tree-sitter-hcl.pc.in b/bindings/c/tree-sitter-hcl.pc.in new file mode 100644 index 0000000..b2a005c --- /dev/null +++ b/bindings/c/tree-sitter-hcl.pc.in @@ -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} diff --git a/bindings/swift/TreeSitterHcl/hcl.h b/bindings/c/tree_sitter/tree-sitter-hcl.h similarity index 100% rename from bindings/swift/TreeSitterHcl/hcl.h rename to bindings/c/tree_sitter/tree-sitter-hcl.h diff --git a/bindings/node/binding.cc b/bindings/node/binding.cc index cbd446a..f9bdd97 100644 --- a/bindings/node/binding.cc +++ b/bindings/node/binding.cc @@ -16,4 +16,4 @@ Napi::Object Init(Napi::Env env, Napi::Object exports) { return exports; } -NODE_API_MODULE(tree_sitter_PARSER_NAME_binding, Init) \ No newline at end of file +NODE_API_MODULE(tree_sitter_hcl_binding, Init) diff --git a/bindings/node/binding_test.js b/bindings/node/binding_test.js index beadfc1..55becac 100644 --- a/bindings/node/binding_test.js +++ b/bindings/node/binding_test.js @@ -1,9 +1,9 @@ -/// - 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("."))); -}); \ No newline at end of file +}); diff --git a/bindings/node/index.js b/bindings/node/index.js index e92af32..c6eb3d6 100644 --- a/bindings/node/index.js +++ b/bindings/node/index.js @@ -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 (_) {} \ No newline at end of file +} catch (_) {} diff --git a/bindings/rust/build.rs b/bindings/rust/build.rs index 81fe5c1..4038ae8 100644 --- a/bindings/rust/build.rs +++ b/bindings/rust/build.rs @@ -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()); diff --git a/bindings/rust/lib.rs b/bindings/rust/lib.rs index e3d3c67..058ed42 100644 --- a/bindings/rust/lib.rs +++ b/bindings/rust/lib.rs @@ -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"); } } diff --git a/bindings/swift/TreeSitterHCL/hcl.h b/bindings/swift/TreeSitterHCL/hcl.h new file mode 100644 index 0000000..d0220ca --- /dev/null +++ b/bindings/swift/TreeSitterHCL/hcl.h @@ -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_ diff --git a/bindings/swift/TreeSitterHclTests/TreeSitterHclTests.swift b/bindings/swift/TreeSitterHCLTests/TreeSitterHCLTests.swift similarity index 66% rename from bindings/swift/TreeSitterHclTests/TreeSitterHclTests.swift rename to bindings/swift/TreeSitterHCLTests/TreeSitterHCLTests.swift index 1503481..aee38e9 100644 --- a/bindings/swift/TreeSitterHclTests/TreeSitterHclTests.swift +++ b/bindings/swift/TreeSitterHCLTests/TreeSitterHCLTests.swift @@ -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") } } diff --git a/dialects/terraform/package.json b/dialects/terraform/package.json index 1270331..79d7263 100644 --- a/dialects/terraform/package.json +++ b/dialects/terraform/package.json @@ -1,3 +1,9 @@ { - "main": "../bindings/node" -} \ No newline at end of file + "main": "../../bindings/node", + "private": true, + "scripts": { + "generate": "tree-sitter generate", + "prestart": "tree-sitter build --wasm", + "start": "tree-sitter playground" + } +} diff --git a/make_grammar.js b/make_grammar.js index 8bbbbd1..57c96a5 100644 --- a/make_grammar.js +++ b/make_grammar.js @@ -1,3 +1,7 @@ +/// +// @ts-check + +/** @param {string} dialect */ module.exports = function make_grammar(dialect) { const PREC = { unary: 7, @@ -52,8 +56,8 @@ module.exports = function make_grammar(dialect) { identifier: ($) => token( seq( - choice(/\p{ID_Start}/, "_"), - repeat(choice(/\p{ID_Continue}/, "-", "::")), + choice(/\p{ID_Start}/u, "_"), + repeat(choice(/\p{ID_Continue}/u, "-", "::")), ), ), diff --git a/package-lock.json b/package-lock.json index 0260782..0c6105f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,24 +1,24 @@ { "name": "@tree-sitter-grammars/tree-sitter-hcl", - "version": "0.2.0-snapshot", + "version": "1.1.0", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "@tree-sitter-grammars/tree-sitter-hcl", - "version": "0.2.0-snapshot", + "version": "1.1.0", "hasInstallScript": true, "license": "Apache-2.0", "dependencies": { - "node-addon-api": "^8.2.1", - "node-gyp-build": "^4.8.2" + "node-addon-api": "^8.3.1", + "node-gyp-build": "^4.8.4" }, "devDependencies": { "prebuildify": "^6.0.1", - "tree-sitter-cli": "^0.25" + "tree-sitter-cli": "^0.25.3" }, "peerDependencies": { - "tree-sitter": "^0.21.1" + "tree-sitter": "^0.22.4" }, "peerDependenciesMeta": { "tree-sitter": { @@ -154,9 +154,9 @@ "license": "MIT" }, "node_modules/node-abi": { - "version": "3.74.0", - "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.74.0.tgz", - "integrity": "sha512-c5XK0MjkGBrQPGYG24GBADZud0NCbznxNx0ZkS+ebUTrmV1qTDxPxSL8zEAPURXSbLRWVexxmP4986BziahL5w==", + "version": "3.75.0", + "resolved": "https://registry.npmjs.org/node-abi/-/node-abi-3.75.0.tgz", + "integrity": "sha512-OhYaY5sDsIka7H7AtijtI9jwGYLyl29eQn/W623DiN/MIv5sUqc4g7BIDThX+gb7di9f6xK02nkp8sdfFWZLTg==", "dev": true, "license": "MIT", "dependencies": { @@ -337,6 +337,19 @@ "node": ">=6" } }, + "node_modules/tree-sitter": { + "version": "0.22.4", + "resolved": "https://registry.npmjs.org/tree-sitter/-/tree-sitter-0.22.4.tgz", + "integrity": "sha512-usbHZP9/oxNsUY65MQUsduGRqDHQOou1cagUSwjhoSYAmSahjQDAVsh9s+SlZkn8X8+O1FULRGwHu7AFP3kjzg==", + "hasInstallScript": true, + "license": "MIT", + "optional": true, + "peer": true, + "dependencies": { + "node-addon-api": "^8.3.0", + "node-gyp-build": "^4.8.4" + } + }, "node_modules/tree-sitter-cli": { "version": "0.25.3", "resolved": "https://registry.npmjs.org/tree-sitter-cli/-/tree-sitter-cli-0.25.3.tgz", diff --git a/package.json b/package.json index be939e8..834bdaf 100644 --- a/package.json +++ b/package.json @@ -1,10 +1,9 @@ { "name": "@tree-sitter-grammars/tree-sitter-hcl", - "version": "0.2.0-snapshot", + "version": "1.1.0", "description": "HCL and terraform grammar for tree-sitter", - "repository": "github:tree-sitter-grammars/tree-sitter-hcl", + "repository": "https://github.com/tree-sitter-grammars/tree-sitter-hcl", "license": "Apache-2.0", - "author": "", "main": "bindings/node", "types": "bindings/node", "keywords": [ @@ -15,11 +14,8 @@ "terraform" ], "files": [ - "dialects/**/grammar.js", - "dialects/**/queries/*", - "dialects/**/src/**", - "dialects/**/*.wasm", "grammar.js", + "make_grammar.js", "tree-sitter.json", "binding.gyp", "prebuilds/**", @@ -29,15 +25,15 @@ "*.wasm" ], "dependencies": { - "node-addon-api": "^8.2.1", - "node-gyp-build": "^4.8.2" + "node-addon-api": "^8.3.1", + "node-gyp-build": "^4.8.4" }, "devDependencies": { "prebuildify": "^6.0.1", - "tree-sitter-cli": "^0.25" + "tree-sitter-cli": "^0.25.3" }, "peerDependencies": { - "tree-sitter": "^0.21.1" + "tree-sitter": "^0.22.4" }, "peerDependenciesMeta": { "tree-sitter": { @@ -45,12 +41,10 @@ } }, "scripts": { + "build": "tree-sitter generate", "install": "node-gyp-build", "prestart": "tree-sitter build --wasm", "start": "tree-sitter playground", - "test": "tree-sitter test", - "generate": "npm run generate-hcl && npm run generate-terraform", - "generate-hcl": "tree-sitter generate", - "generate-terraform": "cd dialects/terraform && tree-sitter generate" + "test": "node --test bindings/node/*_test.js" } } diff --git a/tree-sitter.json b/tree-sitter.json index 5a8b998..5666d2c 100644 --- a/tree-sitter.json +++ b/tree-sitter.json @@ -2,7 +2,7 @@ "grammars": [ { "name": "hcl", - "camelcase": "Hcl", + "camelcase": "HCL", "scope": "source.hcl", "path": ".", "file-types": [ @@ -13,7 +13,7 @@ "name": "terraform", "camelcase": "Terraform", "scope": "source.terraform", - "path": "./dialects/terraform/", + "path": "dialects/terraform", "file-types": [ "tf", "tfvars" @@ -21,15 +21,15 @@ } ], "metadata": { - "version": "0.2.0-snapshot", + "version": "1.1.0", "license": "Apache-2.0", - "description": "HCL grammar for tree-sitter", + "description": "HCL and terraform grammar for tree-sitter", "links": { - "repository": "https://github.com/tree-sitter/tree-sitter-hcl" + "repository": "https://github.com/tree-sitter-grammars/tree-sitter-hcl" } }, "bindings": { - "c": false, + "c": true, "go": false, "node": true, "python": false,