Skip to content

Commit

Permalink
feat!: update parsers & bindings
Browse files Browse the repository at this point in the history
- Migrate JS files to ESM
- Don't inherit from DTD in XML
- Add tree-sitter.json file
- Update the bindings
- Add release workflow
  • Loading branch information
ObserverOfTime committed Oct 14, 2024
1 parent 809266e commit fc4724e
Show file tree
Hide file tree
Showing 60 changed files with 9,611 additions and 9,467 deletions.
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
* text eol=lf
* text=auto eol=lf

**/src/*.json linguist-generated
**/src/parser.c linguist-generated
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,13 @@ on:
push:
branches: [master]
paths:
- "scripts.js"
- "common/*"
- "*/grammar.js"
- "*/src/**"
- "bindings/**"
- "binding.gyp"
pull_request:
paths:
- "scripts.js"
- "common/*"
- "*/grammar.js"
- "*/src/**"
Expand Down Expand Up @@ -42,7 +40,7 @@ jobs:
path: examples/lemminx
repository: eclipse/lemminx
sparse-checkout: org.eclipse.lemminx/src/test/resources
ref: 6b12cd0a89205c2791ef1240e0d8401103f8c9a9
ref: d3a123531c8b48d6139759beab6ea1fdaeefe158
- name: Run tests
uses: tree-sitter/parser-test-action@v2
with:
Expand Down Expand Up @@ -78,7 +76,7 @@ jobs:
fetch-depth: 2
- name: Check for scanner changes
id: scanner-changes
uses: tj-actions/changed-files@v42
uses: tj-actions/changed-files@v45
with:
files: |-
common/scanner.h
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ on:
tags: ["*"]

jobs:
github:
uses: tree-sitter/workflows/.github/workflows/release.yml@main
npm:
uses: tree-sitter/workflows/.github/workflows/package-npm.yml@main
with:
Expand Down
9 changes: 5 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# Rust artifacts
Cargo.lock
target/

# Node artifacts
Expand All @@ -9,10 +8,8 @@ node_modules/

# Swift artifacts
.build/
Package.resolved

# Go artifacts
go.sum
_obj/

# Python artifacts
Expand All @@ -33,7 +30,11 @@ dist/
/examples/*/

# Grammar volatiles
dsl.d.ts
*.wasm
*.obj
*.o

# Archives
*.tar.gz
*.tgz
*.zip
63 changes: 63 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
cmake_minimum_required(VERSION 3.13)

project(tree-sitter-xml
VERSION "0.7.0"
DESCRIPTION "XML & DTD grammars for tree-sitter"
HOMEPAGE_URL "https://github.com/tree-sitter-grammars/tree-sitter-xml"
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 14 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")

include(GNUInstallDirs)

macro(add_parser name)
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-${name}
"${CMAKE_CURRENT_SOURCE_DIR}/src/parser.c"
"${CMAKE_CURRENT_SOURCE_DIR}/src/scanner.c")
target_include_directories(tree-sitter-${name} PRIVATE "${CMAKE_CURRENT_SOURCE_DIR}/src")

target_compile_definitions(tree-sitter-${name} PRIVATE
$<$<BOOL:${TREE_SITTER_REUSE_ALLOCATOR}>:TREE_SITTER_REUSE_ALLOCATOR>
$<$<CONFIG:Debug>:TREE_SITTER_DEBUG>)

set_target_properties(tree-sitter-${name}
PROPERTIES
C_STANDARD 11
POSITION_INDEPENDENT_CODE ON
SOVERSION "${TREE_SITTER_ABI_VERSION}.${PROJECT_VERSION_MAJOR}"
DEFINE_SYMBOL "")

configure_file("${CMAKE_SOURCE_DIR}/bindings/c/tree-sitter-${name}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-${name}.pc" @ONLY)

install(FILES "${CMAKE_SOURCE_DIR}/bindings/c/tree-sitter-${name}.h"
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/tree_sitter")
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-${name}.pc"
DESTINATION "${CMAKE_INSTALL_DATAROOTDIR}/pkgconfig")
install(TARGETS tree-sitter-${name}
LIBRARY DESTINATION "${CMAKE_INSTALL_LIBDIR}")
endmacro()

add_subdirectory(xml tree-sitter-xml)

add_subdirectory(dtd tree-sitter-dtd)

add_custom_target(test "${TREE_SITTER_CLI}" test
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}"
COMMENT "tree-sitter test")
96 changes: 96 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
name = "tree-sitter-xml"
description = "XML & DTD grammars for tree-sitter"
version = "0.6.4"
version = "0.7.0"
license = "MIT"
readme = "README.md"
keywords = ["incremental", "parsing", "tree-sitter", "dtd", "xml"]
Expand Down Expand Up @@ -29,7 +29,10 @@ include = [
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter = "^0.22.2"
tree-sitter-language = "0.1"

[build-dependencies]
cc = "^1.0.90"
cc = "1.1.22"

[dev-dependencies]
tree-sitter = "0.24.3"
9 changes: 1 addition & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,4 @@ all install uninstall clean:
test:
$(TS) test

update: VERSION := $(shell awk -F '"' '/^ "version"/{print $$4}' package.json)
update:
sed -i common/common.mak -e 's/^VERSION := .*/VERSION := $(VERSION)/'
sed -i Cargo.toml -e 's/^version = .*/version = "$(VERSION)"/'
sed -i pyproject.toml -e 's/^version = .*/version = "$(VERSION)"/'
git add package.json package-lock.json Cargo.toml pyproject.toml common/common.mak

.PHONY: all install uninstall clean test update
.PHONY: all install uninstall clean test
16 changes: 16 additions & 0 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"object": {
"pins": [
{
"package": "SwiftTreeSitter",
"repositoryURL": "https://github.com/ChimeHQ/SwiftTreeSitter",
"state": {
"branch": null,
"revision": "2599e95310b3159641469d8a21baf2d3d200e61f",
"version": "0.8.0"
}
}
]
},
"version": 1
}
52 changes: 15 additions & 37 deletions Package.swift
Original file line number Diff line number Diff line change
@@ -1,68 +1,46 @@
// swift-tools-version:5.3
import PackageDescription

let excludes = [
"Cargo.toml",
"Makefile",
"binding.gyp",
"bindings/go",
"bindings/node",
"bindings/python",
"bindings/rust",
"common/common.mak",
"common/index.js",
"package.json",
"package-lock.json",
"pyproject.toml",
"setup.py",
"test",
".editorconfig",
".github",
".gitignore",
".gitattributes",
]

let package = Package(
name: "TreeSitterXML",
products: [
.library(name: "TreeSitterXML", targets: ["TreeSitterXML", "TreeSitterDTD"]),
],
dependencies: [],
dependencies: [
.package(url: "https://github.com/ChimeHQ/SwiftTreeSitter", from: "0.8.0"),
],
targets: [
.target(name: "TreeSitterXML",
path: ".",
exclude: excludes + [
"bindings/swift/TreeSitterDTD",
"xml/Makefile",
"xml/grammar.js",
"dtd",
],
sources: [
"xml/src/parser.c",
"xml/src/scanner.c",
],
resources: [
.copy("queries/xml")
],
publicHeadersPath: "bindings/swift",
publicHeadersPath: "bindings/swift/xml",
cSettings: [.headerSearchPath("xml/src")]),
.target(name: "TreeSitterDTD",
path: ".",
exclude: excludes + [
"bindings/swift/TreeSitterXML",
"dtd/Makefile",
"dtd/grammar.js",
"xml",
],
sources: [
"dtd/src/parser.c",
"dtd/src/scanner.c",
],
resources: [
.copy("queries/dtd")
],
publicHeadersPath: "bindings/swift",
cSettings: [.headerSearchPath("dtd/src")])
publicHeadersPath: "bindings/swift/dtd",
cSettings: [.headerSearchPath("dtd/src")]),
.testTarget(
name: "TreeSitterXMLTests",
dependencies: [
"SwiftTreeSitter",
"TreeSitterXML",
"TreeSitterDTD",
],
path: "bindings/swift/TreeSitterXMLTests"
)
],
cLanguageStandard: .c11
)
16 changes: 8 additions & 8 deletions bindings/c/tree-sitter-dtd.pc.in
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
prefix=@PREFIX@
libdir=@LIBDIR@
includedir=@INCLUDEDIR@
prefix=@CMAKE_INSTALL_PREFIX@
libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@
includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@

Name: tree-sitter-dtd
Description: DTD grammar for tree-sitter
URL: @URL@
Version: @VERSION@
Requires: @REQUIRES@
Libs: -L${libdir} @ADDITIONAL_LIBS@ -ltree-sitter-dtd
Description: @PROJECT_DESCRIPTION@
URL: @CMAKE_PROJECT_HOMEPAGE_URL@
Version: @CMAKE_PROJECT_VERSION@
Requires: @TS_REQUIRES@
Libs: -L${libdir} -ltree-sitter-dtd
Cflags: -I${includedir}
Loading

0 comments on commit fc4724e

Please sign in to comment.