Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update to tree-sitter 0.24 #166

Merged
merged 2 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 6 additions & 5 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ root = true

[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{json,toml,yml,gyp}]
indent_style = space
Expand All @@ -13,12 +10,13 @@ indent_size = 2
[*.js]
indent_style = space
indent_size = 2
quote_type = single

[*.rs]
[*.{c,cc,h}]
indent_style = space
indent_size = 4

[*.{c,cc,h}]
[*.rs]
indent_style = space
indent_size = 4

Expand All @@ -37,3 +35,6 @@ indent_size = 8
[Makefile]
indent_style = tab
indent_size = 8

[parser.c]
indent_size = 2
36 changes: 28 additions & 8 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -1,17 +1,37 @@
* text eol=lf
* text=auto eol=lf

*.png -text

# Generated source files
*/src/*.json linguist-generated
*/src/parser.c linguist-generated
*/src/tree_sitter/* linguist-generated
*/bindings/** linguist-generated

common/common.mak linguist-generated
bindings/** linguist-generated
# C bindings
*/bindings/c/* linguist-generated

# Rust bindings
bindings/rust/build.rs linguist-generated
Cargo.lock linguist-generated

# Node.js bindings
bindings/node/* linguist-generated
binding.gyp linguist-generated
package.json linguist-generated
package-lock.json linguist-generated

# Python bindings
bindings/python/** linguist-generated
setup.py linguist-generated
Package.swift linguist-generated
pyproject.toml linguist-generated

# Go bindings
bindings/go/* linguist-generated
go.mod linguist-generated
go.sum linguist-generated

bindings/rust/lib.rs -linguist-generated
bindings/rust/parser.rs -linguist-generated
bindings/rust/benchmark.rs -linguist-generated
# Swift bindings
/bindings/swift/** linguist-generated
*/bindings/swift/** linguist-generated
Package.swift linguist-generated
Package.resolved linguist-generated
File renamed without changes
14 changes: 11 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,21 @@ on:
- "*/grammar.js"
- "*/src/**"
- "*/test/**"
- "*/bindings/**"
- "bindings/**"
- "binding.gyp"
- "setup.py"
pull_request:
paths:
- "scripts/*"
- "common/*"
- "*/grammar.js"
- "*/src/**"
- "*/test/**"
- "*/bindings/**"
- "bindings/**"
- "binding.gyp"
- "setup.py"

jobs:
test:
Expand All @@ -34,17 +38,21 @@ jobs:
uses: actions/checkout@v4
- name: Install tree-sitter CLI
uses: tree-sitter/setup-action/cli@v1
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: ${{vars.NODE_VERSION}}
- name: Build with all extensions
run: npm run build
run: node scripts/build.js
env:
ALL_EXTENSIONS: 1
- name: Run tests
uses: tree-sitter/parser-test-action@v2
with:
test-rust: true
test-parser-cmd: npm test
test-parser-cmd: node scripts/test.js
- name: Rebuild with default extensions
run: npm run build
run: node scripts/build.js
- name: Verify grammar consistency
run: git diff --exit-code -- */src/grammar.json
fuzz:
Expand Down
5 changes: 5 additions & 0 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ on:
tags: ["*"]

jobs:
github:
uses: tree-sitter/workflows/.github/workflows/release.yml@main
permissions:
contents: write
id-token: write
npm:
uses: tree-sitter/workflows/.github/workflows/package-npm.yml@main
with:
Expand Down
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,8 @@ dist/
*.wasm
*.obj
*.o

# Moved bindings
bindings/c/
bindings/swift/TreeSitterMarkdown/
bindings/swift/TreeSitterMarkdownInline/
65 changes: 65 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
cmake_minimum_required(VERSION 3.13)

project(tree-sitter-markdown
VERSION "0.4.0"
DESCRIPTION "Markdown grammar for tree-sitter"
HOMEPAGE_URL "https://github.com/tree-sitter-grammars/tree-sitter-markdown"
LANGUAGES C)

option(BUILD_SHARED_LIBS "Build using shared libraries" ON)
option(TREE_SITTER_REUSE_ALLOCATOR "Reuse the library allocator" OFF)
option(ALL_EXTENSIONS "Enable all Markdown extensions" 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}/grammar.js"
COMMAND "${CMAKE_COMMAND}" -E env ALL_EXTENSIONS=$<BOOL:${ALL_EXTENSIONS}>
-- "${TREE_SITTER_CLI}" generate --abi=${TREE_SITTER_ABI_VERSION}
BYPRODUCTS "${CMAKE_CURRENT_SOURCE_DIR}/src/grammar.json"
"${CMAKE_CURRENT_SOURCE_DIR}/src/node-types.json"
"${CMAKE_CURRENT_SOURCE_DIR}/src/tree_sitter/alloc.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/tree_sitter/array.h"
"${CMAKE_CURRENT_SOURCE_DIR}/src/tree_sitter/parser.h"
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_CURRENT_SOURCE_DIR}/bindings/c/tree-sitter-${name}.pc.in"
"${CMAKE_CURRENT_BINARY_DIR}/tree-sitter-${name}.pc" @ONLY)

install(FILES "${CMAKE_CURRENT_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(tree-sitter-markdown tree-sitter-markdown)

add_subdirectory(tree-sitter-markdown-inline tree-sitter-markdown-inline)
11 changes: 6 additions & 5 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ parts of either grammar can be found in the `common` folder.
For either of the grammar the most important files are the `grammar.js` which
defines most nodes and the `src/scanner.c` which defines nodes that cannot
be parsed with normal tree-sitter rules. All other files in the `src` subfolder
are auto-generated by running `tree-sitter generate --no-bindings`. (You need to
install the [tree-sitter cli tool][tree-sitter-cli] first.)
are auto-generated by running `tree-sitter generate`. (You need to install the
[tree-sitter cli tool][tree-sitter-cli] and [Node.js][nodejs] first.)

Some syntactical components can be enabled or disabled by environment variables
at compile time. The logic for this can be found in the `common/grammar.js`
Expand All @@ -52,7 +52,7 @@ I will happily accept any pull requests.

Before submitting any code please check the following:

* You ran `tree-sitter generate --no-bindings` in the `tree-sitter-markdown` or
* You ran `tree-sitter generate` in the `tree-sitter-markdown` or
`tree-sitter-markdown-inline` directories respectively after modifying any
`grammar.js` file.
* When running `tree-sitter test` only the cases defined in `failing.txt` or
Expand All @@ -68,8 +68,8 @@ To run the tests, first install the development dependencies (see above), then
execute:

```sh
ALL_EXTENSIONS=1 npm run build
npm test
ALL_EXTENSIONS=1 node scripts/build.js
node scripts/test.js
```

[issue]: https://github.com/tree-sitter-grammars/tree-sitter-markdown/issues/new
Expand All @@ -78,3 +78,4 @@ npm test
[commonmark]: https://spec.commonmark.org/
[tree-sitter spec]: https://tree-sitter.github.io/tree-sitter/
[tree-sitter-cli]: https://github.com/tree-sitter/tree-sitter/blob/master/cli/README.md
[nodejs]: https://nodejs.org/
12 changes: 6 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
[package]
name = "tree-sitter-md"
description = "Markdown grammar for tree-sitter"
version = "0.3.2"
version = "0.4.0"
authors = ["MDeiml"]
license = "MIT"
readme = "README.md"
keywords = ["incremental", "parsing", "tree-sitter", "markdown"]
categories = ["parsing", "text-editors"]
repository = "https://github.com/tree-sitter-grammars/tree-sitter-markdown"
authors = ["MDeiml"]
edition = "2021"
autoexamples = false

Expand All @@ -31,14 +31,14 @@ parser = ["tree-sitter"]
path = "bindings/rust/lib.rs"

[dependencies]
tree-sitter-language = "0.1.0"
tree-sitter = { version = "0.23", optional = true }
tree-sitter-language = "0.1"
tree-sitter = { version = "0.24", optional = true }

[dev-dependencies]
tree-sitter = "0.23.0"
tree-sitter = "0.24.3"

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

[[bin]]
name = "benchmark"
Expand Down
16 changes: 16 additions & 0 deletions Package.resolved

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

74 changes: 42 additions & 32 deletions Package.swift

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

Loading