- update to 0.23.0:

* test: modernize scanner files
  * fix: always reset to the first language when iterating over language
  * feat(zig): update outdated path syntax
  * feat(bindings): add query constants to python
  * style(bindings): fix indent & line endings
  * feat(dsl)!: support other JS runtimes
  * feat(bindings): add node, python, swift tests 
  * introduce tree-sitter-language crate for grammar crates to depend on
  * refactor: remove ansi_term dependency
  * refactor: remove difference dependency
  * feat: add fuzz subcommand
  * fix(wasm): update test
  * feat(lib): add ts_query_end_byte_for_pattern
  * fix(rust): fix new clippy warnings
  * feat(lib): support no_std
  * Reset language when resetting wasm store
  * docs: clean up binding & parser lists
  * clone wasm store engine
  * fix(cli): dedup preceding_auxiliary_symbols
- use of ldconfig_scriptlets, and removal of the duplicate setting of buildflags

OBS-URL: https://build.opensuse.org/package/show/editors/tree-sitter?expand=0&rev=29
This commit is contained in:
Björn Bidar 2024-09-16 08:18:59 +00:00 committed by Git OBS Bridge
commit c23cd3b70c
16 changed files with 1132 additions and 0 deletions

23
.gitattributes vendored Normal file
View File

@ -0,0 +1,23 @@
## Default LFS
*.7z filter=lfs diff=lfs merge=lfs -text
*.bsp filter=lfs diff=lfs merge=lfs -text
*.bz2 filter=lfs diff=lfs merge=lfs -text
*.gem filter=lfs diff=lfs merge=lfs -text
*.gz filter=lfs diff=lfs merge=lfs -text
*.jar filter=lfs diff=lfs merge=lfs -text
*.lz filter=lfs diff=lfs merge=lfs -text
*.lzma filter=lfs diff=lfs merge=lfs -text
*.obscpio filter=lfs diff=lfs merge=lfs -text
*.oxt filter=lfs diff=lfs merge=lfs -text
*.pdf filter=lfs diff=lfs merge=lfs -text
*.png filter=lfs diff=lfs merge=lfs -text
*.rpm filter=lfs diff=lfs merge=lfs -text
*.tbz filter=lfs diff=lfs merge=lfs -text
*.tbz2 filter=lfs diff=lfs merge=lfs -text
*.tgz filter=lfs diff=lfs merge=lfs -text
*.ttf filter=lfs diff=lfs merge=lfs -text
*.txz filter=lfs diff=lfs merge=lfs -text
*.whl filter=lfs diff=lfs merge=lfs -text
*.xz filter=lfs diff=lfs merge=lfs -text
*.zip filter=lfs diff=lfs merge=lfs -text
*.zst filter=lfs diff=lfs merge=lfs -text

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
.osc

7
_service Normal file
View File

@ -0,0 +1,7 @@
<services>
<service name="download_files" mode="manual" />
<service name="cargo_vendor" mode="manual">
<param name="srctar">tree-sitter-*.tar.gz</param>
<param name="update">true</param>
</service>
</services>

1
baselibs.conf Normal file
View File

@ -0,0 +1 @@
libtree-sitter0_23

64
compile-macros.sh Normal file
View File

@ -0,0 +1,64 @@
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0
# SPDX-FileCopyrightText: 2024 Björn Bidar
# based of compile-macros.sh from python-rpm-macros
mkdir -p macros
### Lua: generate automagic from macros.in and macros.lua
(
# copy macros.in up to LUA-MACROS
sed -n -e '1,/^### LUA-MACROS ###$/p' macros.in
# include "functions.lua", without empty lines, as %_treesitter_definitions
echo "%_treesitter_definitions %{lua:"
sed -n -r \
-e 's/\\/\\\\/g' \
-e '/^.+$/p' \
functions.lua
echo "}"
INFUNC=0
INMULTILINE_MACRO=0
# brute line-by-line read of macros.lua
IFS=""
while read -r line; do
if [ $INFUNC = 0 ] ; then
if [ $INMULTILINE_MACRO = 1 ] ;then
if echo "$line" | grep -qE '^.*\]\]' ; then
INMULTILINE_MACRO=0
fi
echo "# $line"
elif echo "$line" | grep -qE -- '--\[\[' ; then
INMULTILINE_MACRO=1
echo "# $line"
elif echo "$line" | grep -qE -- '^--' ; then
echo "# $line"
elif echo "$line" | grep -q '^function '; then
# entering top-level Lua function
INFUNC=1;
echo "$line" | sed -r -e 's/^function (.*)\((.*)\)$/%\1(\2) %{lua: \\/'
else
# outside function, copy
# (usually this is newline)
echo "$line"
fi
else
if [ "$line" = "end" ]; then
# leaving top-level Lua function
INFUNC=0;
echo '}'
elif [ $INFUNC = 1 ]; then
# inside function
# double backslashes and add backslash to end of line
echo "$line" | sed -e 's/\\/\\\\/g' -e 's/$/\\/'
fi
fi
done < macros.lua
# copy rest of macros.in
sed -n -e '/^### LUA-MACROS ###$/,$p' macros.in
) > macros/050-automagic
### final step: cat macros/*, but with files separated by additional newlines
sed -e '$s/$/\n/' -s macros/* > macros.treesitter

60
functions.lua Normal file
View File

@ -0,0 +1,60 @@
--[[
SPDX-License-Identifier: GPL-2.0
SPDX-FileCopyrightText: 2024 Björn Bidar
partly based of functions.lua from python-rpm-macros
--]]
-- declare common functions
function string.startswith(str, prefix)
return str:sub(1, prefix:len()) == prefix
end
function string.endswith(str, suffix)
return str:sub(-suffix:len()) == suffix
end
function string.dirname(str)
if str:match("(.*)/") == "" then
return nil
else
return str:match("(.*)/")
end
end
function string.basename(str)
while true do
local idx = str:find("/")
if not idx then return str end
str = str:sub(idx + 1)
end
end
function string.split(str, sep)
if sep == nil then
sep = '%s'
end
local res = {}
local func = function(w)
table.insert(res, w)
end
string.gsub(str, '[^'..sep..']+', func)
return res
end
function arg_compat()
--[[
Compat macro as workaround for older rpm not having function
arguments available as table arg(uments)
--]]
local arg_count = rpm.expand("%#")
local arg = {}
for arg_num = 1,arg_count do
arg[arg_num] = rpm.expand(("%" .. arg_num))
end
return arg
end

26
macros.in Normal file
View File

@ -0,0 +1,26 @@
# -*- rpm-spec -*-
# SPDX-License-Identifier: GPL-2.0
# SPDX-FileCopyrightText: 2024 Björn Bidar
%_treesitter_base_name tree-sitter
%_treesitter_grammardir %{_libdir}
%_treesitter_grammar_develdir %{_includedir}/%{_treesitter_base_name}/grammars
%_treesitter_grammar_base_libname lib%{_treesitter_base_name}
%treesitter_target() %{_rpmconfigdir}/tree-sitter-target.py
%treesitter_set_flags export NODE_PATH=$NODE_PATH:%{_treesitter_grammar_develdir}:$PWD
%__treesitter_devel_package_name() %name-devel
%treesitter_devel_package \
%package -n %{__treesitter_devel_package_name} \
Summary: Devel package for %{name} containing it's grammar source \
BuildArch: noarch \
%{_treesitter_devel_provides} \
%description -n %{__treesitter_devel_package_name} \
This package contains grammar sources for use in other grammars. \
%files -n %{__treesitter_devel_package_name} \
%{treesitter_devel_files}
### LUA-MACROS ###
%_treesitter_macro_init %{_treesitter_definitions}%{lua: rpm.define("_treesitter_macro_init %{nil}")}

227
macros.lua Normal file
View File

@ -0,0 +1,227 @@
--[[
SPDX-License-Identifier: GPL-2.0
SPDX-FileCopyrightText: 2024 Björn Bidar
partly based of functions.lua from python-rpm-macros
--]]
--[[
Main Package should look like this:
%%treesitter_grammars foo bar
%%build
%%treesitter_configure
%%treesitter_build
%%install
%%treesitter_install
%%files
%%treesitter_files
--]]
function treesitter_grammars()
--[[
Define any grammars to be included inside the package
--]]
rpm.expand("%_treesitter_macro_init")
local base_name = rpm.expand("%_treesitter_base_name")
local base_libname = rpm.expand("%_treesitter_grammar_base_libname")
local treesitter_grammar_names = ""
local treesitter_grammar_libnames = ""
local arg = arg
local suse_version = tonumber(rpm.expand("%suse_version"))
if suse_version < 1600 then
arg = arg_compat()
end
for arg_num = 1,#arg do
treesitter_grammar_libnames=treesitter_grammar_libnames .. base_libname .. "-" .. arg[arg_num] .. ".so "
end
rpm.define("treesitter_grammar_libnames " .. treesitter_grammar_libnames)
for arg_num = 1,#arg do
treesitter_grammar_names=treesitter_grammar_names .. " " .. arg[arg_num]
print("Provides: treesitter_grammar(" .. base_name .. "-" .. arg[arg_num] .. ")\n")
end
rpm.define("treesitter_grammar_names " .. treesitter_grammar_names)
end
function treesitter_configure()
--[[
Generate grammar sources for all the grammars provided earlier akin
to %configure.
--]]
rpm.expand("%_treesitter_macro_init")
local grammars = string.split(rpm.expand("%{treesitter_grammar_names}"))
print(rpm.expand("%treesitter_set_flags"))
print("\n")
if #grammars > 1 then
for k,grammar in pairs(grammars) do
print("(cd " .. grammar .. ";tree-sitter generate)")
print("\n")
end
else
print("tree-sitter generate")
end
end
function treesitter_build()
--[[
Similar to %make_build build all grammars if possible read from
an alternative file instead of binding.gyp
--]]
rpm.expand("%_treesitter_macro_init")
local basename = rpm.expand("%{_treesitter_grammar_base_libname}")
local grammar_names = rpm.expand("%treesitter_grammar_names")
local arg = arg
local suse_version = tonumber(rpm.expand("%suse_version"))
if suse_version < 1600 then
arg = arg_compat()
end
local left_over_args = arg[1]
local grammar_arg_binding = ""
if left_over_args then
grammar_arg_binding=" -b "..arg[1]
end
local treesitter_target = rpm.expand("%{treesitter_target}")
local grammar_names_tbl = string.split(grammar_names, " ")
if #grammar_names_tbl > 1 then
for k,target in pairs(grammar_names_tbl) do
print("eval $(" .. treesitter_target .. grammar_arg_binding .. " -g " .. target ..") " .. " -o " .. basename .. "-" .. target .. ".so ${RPM_OPT_FLAGS}")
print("\n")
end
else
print("eval $(" .. treesitter_target .. grammar_arg_binding .. ") " .. " -o " .. basename.. "-" .. grammar_names .. ".so ${RPM_OPT_FLAGS}")
end
end
function treesitter_install()
--[[
Install all previously build grammars
--]]
rpm.expand("%_treesitter_macro_init")
local grammars = string.split(rpm.expand("%{treesitter_grammar_libnames}"))
local install_path = rpm.expand("%{buildroot}%{_treesitter_grammardir}")
for k,grammar in pairs(grammars) do
print("install -Dm755 " .. grammar .. " " .. install_path .. "/" .. grammar)
print("\n")
end
end
function treesitter_files()
rpm.expand("%_treesitter_macro_init")
local grammars = string.split(rpm.expand("%{treesitter_grammar_libnames}"))
local grammardir = rpm.expand("%{_treesitter_grammardir}")
local _libdir = rpm.expand("%{_libdir}")
if not grammardir == libdir then
print(rpm.expand("%dir " .. grammardir.."\n"))
end
for k,grammar in pairs(grammars) do
print(rpm.expand(grammardir .. "/"..grammar.."\n"))
end
end
--[[
Optional -devel package for grammars that are needed for other grammars to be built.
If the -devel package is needed it should look like this:
%%install
[...] # Main page here
%%treesitter_devel_install
# Or if the package has shared files between grammars:
%%treesitter_devel_install foobar.js
%%treesitter_devel_package
--]]
function treesitter_devel_install()
--[[
Install all grammars sources defined earlier.
If passed these can also include additional files such as shared fragments
that are used between multiple grammars in the same package.
--]]
rpm.expand("%_treesitter_macro_init")
--local grammar_names = rpm.expand("%{treesitter_grammar_names}")
local grammars = string.split(rpm.expand("%{treesitter_grammar_names}"))
local treesitter = rpm.expand("%_treesitter_base_name")
local install_cmd_base = "install -Dm644 "
local install_path = rpm.expand("%{buildroot}%{_treesitter_grammar_develdir}/")
local rpm_provides_macro = ""
--print(grammar_names)
for k,grammar in pairs(grammars) do
if grammar then
rpm_provides_macro=rpm_provides_macro.. "Provides: treesitter_grammar_src(" ..treesitter .. "-" .. grammar ..")\n"
end
end
rpm.define("_treesitter_devel_provides "..rpm_provides_macro)
if #grammars == 1 then
print(install_cmd_base .. "grammar.js " .. install_path .. treesitter .. "-" .. grammars[1].. "/grammar.js")
return
end
local arg = arg
local suse_version = tonumber(rpm.expand("%suse_version"))
if suse_version < 1600 then
arg = arg_compat()
end
if #arg > 0 then
--[[ FIXME: This maybe not be the best solution if packages can have a single grammar
but also addon files
]]--
for arg_num = 1,#arg do
print(rpm.expand(install_cmd_base .. arg[arg_num] .. " " .. install_path .. "%{name}/" .. arg[arg_num] .. "\n"))
print("\n")
end
end
for k,grammar in pairs(grammars) do
if grammar then
print(rpm.expand(install_cmd_base .. grammar .. "/grammar.js " .. install_path .. "%{name}/" .. grammar .. "/grammar.js\n"))
print("\n")
end
end
end
function treesitter_devel_files()
--[[
Install -devel files to %%{_treesitter_grammar_develdir}
--]]
rpm.expand("%_treesitter_macro_init")
local grammars = string.split(rpm.expand("%{treesitter_grammar_names}"))
local grammar_develdir = rpm.expand("%{_treesitter_grammar_develdir}")
local fpp
print(rpm.expand("%dir %{_treesitter_grammar_develdir} \n"))
--[[
Own all directories leading up to %%_includedir which we include in
%%_treesitter_grammar_develdir
--]]
while not (grammar_develdir == rpm.expand("%_includedir")) do
print(rpm.expand("%dir " .. grammar_develdir .. "\n"))
grammar_develdir = grammar_develdir:dirname()
end
print(rpm.expand("%{_treesitter_grammar_develdir}/%{name}\n"))
end

BIN
tree-sitter-0.22.6.tar.xz (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:6403b361b0014999e96f61b9c84d6950d42f0c7d6e806be79382e0232e48a11b
size 2977346

93
tree-sitter-target.py Normal file
View File

@ -0,0 +1,93 @@
#!/usr/bin/python3
# SPDX-License-Identifier: GPL-2.0
# SPDX-FileCopyrightText: 2024 Björn Bidar
"""Generate compile commands by reading binding.gyp"""
# pylint: disable=invalid-name
# pylint: disable=too-many-branches
import argparse
from pathlib import Path
from typing import List, Dict, Optional
import ast
from copy import copy
parser = argparse.ArgumentParser(prog = Path(__file__).name,
description = "Generate compile commands by reading binding.gyp")
parser.add_argument('-b', '--binding', dest = "binding",
action="store", help="Path to binding file")
parser.add_argument('-g', '--grammar', dest = "grammars",
action= "append",
required = False,
help="Specify grammars in case binding file contains more than one grammar")
args = parser.parse_args()
if args.binding:
binding_gyp = Path(args.binding)
else:
binding_gyp = Path("binding.gyp")
if not binding_gyp.exists():
raise FileNotFoundError(f"bindings {binding_gyp.absolute()} not found")
with open(binding_gyp, 'r', encoding='utf8') as binding_raw:
binding = ast.literal_eval(binding_raw.read())
targets = binding['targets'][0]
def buildCompileCommand(target: Dict, grammars: Optional[List[str]] = None) -> Dict[
str,
List
]:
"""Generate compile commands from TARGET supplied found in GRAMMARS or src"""
cc = 'cc'
cflags_c = []
cflags_cc = []
commands = {}
base_command = [ cc, '-shared', '-fPIC']
suffixes_cc = ['cc', 'cxx', 'cpp']
if 'cflags_c' in target:
cflags_c = target['cflags_c']
if 'clfags_cc' in target:
cflags_cc = target['cflags_cc']
include_dirs = []
for include_dir in target['include_dirs']:
# Don't include any node commands
if not include_dir.startswith('<!'):
include_dirs+=[ include_dir ]
if not grammars:
grammars = { "src" }
for _grammar in grammars:
command = copy(base_command)
for include_dir in include_dirs:
command += '-I', include_dir
for source in target['sources']:
source = Path(source)
# We don't need node bindings
if source.parts[0] == "node":
continue
if not source.parts[0] == _grammar:
continue
for suffix_cc in suffixes_cc:
if source.name.endswith(suffix_cc):
command+= '-xc++', source
break
if source.name.endswith('.c'):
command+= '-xc', source
for flag in cflags_c, cflags_cc:
if flag:
command += flag
commands[_grammar] = command
return commands
if not args.grammars:
args.grammars = ["src"]
cc_cmd = buildCompileCommand(targets, args.grammars)
for grammar in args.grammars:
print(*cc_cmd[grammar])

390
tree-sitter.changes Normal file
View File

@ -0,0 +1,390 @@
-------------------------------------------------------------------
Mon Aug 26 16:33:54 UTC 2024 - Richard Rahl <rrahl0@opensuse.org>
- update to 0.23.0:
* test: modernize scanner files
* fix: always reset to the first language when iterating over language
* feat(zig): update outdated path syntax
* feat(bindings): add query constants to python
* style(bindings): fix indent & line endings
* feat(dsl)!: support other JS runtimes
* feat(bindings): add node, python, swift tests
* introduce tree-sitter-language crate for grammar crates to depend on
* refactor: remove ansi_term dependency
* refactor: remove difference dependency
* feat: add fuzz subcommand
* fix(wasm): update test
* feat(lib): add ts_query_end_byte_for_pattern
* fix(rust): fix new clippy warnings
* feat(lib): support no_std
* Reset language when resetting wasm store
* docs: clean up binding & parser lists
* clone wasm store engine
* fix(cli): dedup preceding_auxiliary_symbols
- use of ldconfig_scriptlets, and removal of the duplicate setting of buildflags
-------------------------------------------------------------------
Fri Jun 21 20:32:46 UTC 2024 - Richard Rahl <rrahl0@disroot.org>
- update to version 0.22.6:
* Improve handling of serialization buffer overflows
* Reverse iteration through node parents
* cli: Support NO_COLOR
* cli: Add test listing and allow users to parse a specific test number
* grammar: Add "inherits" field if available
* Correctly load field data from wasm languages
* Improve error message when the tree-sitter field is malformed
* Don't error out on package.json lookup errors if --no-bindings is passed
* cli: Keep default cc flags in build
* cli: Properly account for multi-grammar repos when using docker to build a wasm parser
* generate: Don't check arbitrarily named dirs
* generate: Take AsRef<Path> for the path parameter to avoid clones
* highlight: Correct signature of ts_highlighter_add_language
* lib: Do not return field names for extras
* lib: Advance the lookahead end byte by 4 when there's an invalid code point
* rust: Update README example
* rust: Use unix + wasi cfg instead of not windows for fd
* wasm: Correct childrenFromFieldXXX method signatures
* xtask: Always bump every crate in tandem
* zig: Make usable as a zig dependency
* Documentation: Mention build command variables
- update to version 0.22.5:
* Avoid generating unused character set constants
* rust: Compilation on wasm32-wasi
- update to version 0.22.4:
* Fix sorting of transitions within a lex state
* Include 2-character ranges in array-based state transitions
- update to version 0.22.3:
* Add strncat to wasm stdlib
* Generate simpler code for matching large character sets
* When loading languages via WASM, gracefully handle memory errors and leaks in external scanners
* bindings: Add utf-8 flag to python & node
* bindings: Generate parser.c if missing
* bindings: Remove required platforms for swift
* cli: Fix mismatched parenthesis when accounting for &&
* lib: Do not consider childless nodes for ts_node_parent
* lib: Properly account for aliased root nodes and root nodes with
children in ts_subtree_string
* lib: Account for the root node of a tree cursor being an alias
* lib: Use correct format specifier in log message
* parser: Fix variadic macro
* render: Proper function prototypes
* Add a semicolon after SKIP macros
* Add back build-wasm temporarily
* Add lifetime to matches function
* Default output directory for build --wasm should use current_dir
* Fix sorting of wasm stdlib symbols
* Insert "tree-sitter" section in current directory's package.json if it exists
* Tie the lifetime of the cursor to the query in QueryCursor::captures()
* Wrong flag check in build.rs
* cli: Reduced the compile time of generated parsers by generating C code with fewer conditionals
* parser: Make REDUCE macro non-variadic
* js: Misc fixes & tidying
* rust: Misc fixes & tidying
-------------------------------------------------------------------
Mon Mar 25 21:58:38 UTC 2024 - Björn Bidar <bjorn.bidar@thaodan.de>
- Add workaround to packaging macros for RPM being to old on current Leap
- Add workaround for Python below 3.9 on Leap
-------------------------------------------------------------------
Fri Mar 22 19:35:31 UTC 2024 - Björn Bidar <bjorn.bidar@thaodan.de>
- Add packaging macros for tree-sitter grammar
- Add missing dependency for tree-sitter generate
-------------------------------------------------------------------
Tue Mar 19 07:17:25 UTC 2024 - Soc Virnyl Estela <uncomfy+openbuildservice@uncomfyhalomacro.pl>
- Update to version 0.22.2:
* fix(lib): allow hiding symbols
* feat(lib): implement Display for Node
* test: fix header writes
* chore: turbofish styling
* feat(cli)!: add a separate build command to compile parsers
* ci: simplify workflows
* docs(license): update year
* fix(lib): avoid possible UB of calling memset on a null ptr when 0 is passed into `array_grow_by`
* fix(lib): makefile installation
- Update _service file
* replace obsoleted mode "disabled" with "manual"
* use download_files instead of performing scm
-------------------------------------------------------------------
Thu Apr 6 19:36:21 UTC 2023 - Andreas Schneider <asn@cryptomilk.org>
- Build AVX2 enabled hwcaps library for x86_64-v3
- Add baselibs.conf for proper generation of libraries.
-------------------------------------------------------------------
Wed Apr 5 18:02:16 UTC 2023 - Matej Cepl <mcepl@suse.com>
- Update to version 0.20.8:
- 0.20.8 - recovered
- cicd: fix bug in release workflow
- Bumps [webbrowser](https://github.com/amodm/webbrowser-rs)
from 0.5.5 to 0.8.3.
- cli: Bump tree-sitter dependency to 0.20.10
- Update python error corpus to reflect grammar changes
- Improve the performance of running a query in a small range
of a large file
- Add API for checking if a pattern in a query is non-local
- Fix bug in maintenance of query cursor's tree depth
- Restructure query_cursor_advance to explicitly control which
hidden nodes it descends into
- Extract 'internal' versions of tree cursor movement fns that
allow visiting hidden nodes
- Group analysis state sets into QueryAnalysis struct
- Precompute the set of repetition symbols that can match
rootless patterns
- Add --row-range, --quiet, and --time flags to query
subcommand
- Fix CLI build on windows
- Clear the parse stack when terminating parsing early due to
error cost
- This fixes a bug where the parse tree would not be rebalanced
if this code path was taken.
- Add --dot flag to parse subcommand, for printing tree as DOT
graph
- Derive Hash for Language
- docs: apply `scheme` marker for all query syntax snippets
- fix: possible rollover of nanoseconds in clock.h
- cli: make error message more specific for building in
`docker`
- cli: Improve init-config with respect to TREE_SITTER_DIR
- docs: merge of all binding and grammar link PRs
- Exclude huge generated files from `git diff` output
- loader: use portable way of path joining
- loader: add TREE_SITTER_LIBDIR; cli: add --libdir to
`tree-sitter generate`
- cli: add -b, --build flags for `tree-sitter generate`
- Remove unused no-minimize arg for the generate command
- cli: Fix build.rs in case of the current branch ref was
packed
- Support SHA lookup in .git/packed-refs
- fix: possible rollover of nanoseconds in clock.h
- Fix permanent rebuild triggering in a git worktree due to
wrong git branch file path
- fix(cli): Racing on playground webserver port binding
- Fix test output formatting for rules starting with M/U
- Allow web-tree-sitter to work with Emscripten 3
- Add __cxa_atexit to exports
- Add `memset` to exports
- Add 'stringToUTF16' and 'AsciiToString' to exported method
- Configure compiled WASM grammars to not catch rejections
- Add Erlang to list of Available Parsers
- Fix test output formatting for rules starting with M/U
- Previously the rule names could not begin with an uppercase
M or U because the test output formatter assumed that they
represent special tokens: MISSING or UEXPECTED.
- Allow retrieving a tree's list of included ranges, fix some
included range bugs
- Add tests that randomly edit files with disjoint included
ranges
- Fix suppression of empty tokens during error handling at
included range boundaries
- Fix parse error when reusing a node at the end of an included
range
- fix(cli): Racing on playground webserver port binding
- Add doc comments for tree included ranges getter
- Fix adjustment of trees' included ranges on edits
- Add D grammar - it is quite complete for D 2.100.
- Add Erlang to list of Available Parsers
- Add twig parser in documentation
- Fix integer size of subtree's child count field
- Explain in the docs that npm install supports limited
platforms
- Removed upstreamed patch CVE-2022-45299-update-webbrowser.patch
-------------------------------------------------------------------
Wed Mar 1 13:55:27 UTC 2023 - Matej Cepl <mcepl@suse.com>
- VERSION string used in generating *.pc file
(among other things) has been hardcoded to 0.6.3
(gh#tree-sitter/tree-sitter#1608), we should at least fix it
using sed.
-------------------------------------------------------------------
Wed Jan 18 10:05:05 UTC 2023 - Matej Cepl <mcepl@suse.com>
- Add CVE-2022-45299-update-webbrowser.patch (copied from
gh#tree-sitter/tree-sitter#2042) to use more recent version
of webbrowser-rs, which has been fixed against CVE-2022-45299
(bsc#1207196).
-------------------------------------------------------------------
Sat Sep 24 09:49:29 UTC 2022 - socvirnyl.estela@gmail.com
- Update to version 0.20.7:
* 0.20.7
* Bump library versions
* Build core wasm library with C++ exceptions disabled
* Generate parsers with ABI version 14 by default
* Tolerate tree edits whose old range extends beyond the end of the tree
* Added documentation on web-tree-sitter edge cases
* Add ts_tree_root_node_with_offset API
* Fix typos
* Update section-2-using-parsers.md
* Add link to Racket language parser
-------------------------------------------------------------------
Sun Jun 19 09:12:46 UTC 2022 - socvirnyl.estela@gmail.com
- Update to version 0.20.6:
* 0.20.6
* libs: 0.20.6
* Properly incorporate lookahead bytes when recovering via missing token
* Improve randomized testing setup
* Run cargo test directly on CI
* Set CLI as default workspace member
* Don't generate primary states array if it will be unused due to abi version setting
* tags: 0.20.2
* 0.20.5
* libs: 0.20.5
-------------------------------------------------------------------
Tue Feb 22 16:46:36 UTC 2022 - Matej Cepl <mcepl@suse.com>
- Update to 0.20.4:
- Always generate parser.h, regardless of chosen ABI version
- add test for removals in eager query matches
- remove non-local query matches for locals
- remove unfinished queries from 'ts_query_cursor_remove_match'
- prevent future matches for '#is-not? local' patterns
- Represent quantifiers using bytes instead of ints
- Prefix globally visible TSquantifier values
- Rewrite quantifier oeprations
- Add pointer indirection to AnalysisStateSet
- Fixed rust build, updated docs
- get_column now counts codepoints
- Add realloc to wasm exports
- Add link to Protocol Buffers grammar
- Convert more fixture grammars from JSON to JS
- Simplify allocation-recording in test suite using new
ts_set_allocator API
- Address feedback
- Make SubtreeInlineData work on Big-Endian
- Replace allocator struct with function pointers
- cli: Fix parsing of test files with newlines in test names
- Avoid allocator from being switched more than once
- Remove ts_allocator from api.h
- Add TSAllocator and ts_set_allocator in api.h
- Fix declaration of ts_toggle_allocation_recording
- Allow to change the allocator dynamically
- Support @module as a highlight key.
- add link to in-development Elixir parser
- Added bindings for Java and Kotlin to `index.md`
- Remove unnecessary types from binding.rs
- Always include playground.html in the CLI binary
- playground: Make query error underlines render in safari
- web: Fix script directory that's passed to locateFile
- Use serde's derive feature everywhere
- Improve query execution logging
- Rename Query::step_is_definite ->
is_pattern_guaranteed_at_step
- Add link to Lua bindings
- Convert more test grammars from JSON to JS
- Add link to swift bindings package
- Convert some of the fixture grammars from JSON to JS
- Use serde's derive feature
- Simplified corpus test output comparisons
- Add link to elisp parser
- Add tree-sitter-cuda, tree-sitter-glsl,
tree-sitter-commonlisp
- Avoid dynamic regex construction when parsing test files
- chore(cli): Rename all internal web_ui stuff to playground
- cli(query): Improve and unify query subcommand output
- binding(rust): Mark set_cancellation_flag self as mutable
- fix(wasm): Fix predicates in alternations, resolves #1392
- fix(cli): Panic on queries containing alternation with
predicates
- Add WGSL WebGPU Shading Language
- Add HCL (Terraform) and Hack to the list of supported
languages
- Add link to OCaml bindings to list and sort list
alphabetically.
- Add Objective-C language parser
- feat(rust): Add an id() method for QueryMatch
- Assign ids to query matches only when the matches are
returned
- feat(cli): add a flag to compile a parser in debug mode with
-O0 C/C++ compiler flag
- Put emscripten-version file in cli directory
- Fix 'include!' error when building the CLI outside of the
repo
- fix(lib): fix segfault on ts_query_new with incompatible
grammar version, close #1318
- Add Graphviz DOT parser
- chore(web): Add the LICENSE file to the web-tree-sitter npm
package
- chore(cli): Add the LICENSE file to the tree-sitter-cli npm
package
- Support for suffixes in test file separators Some languages
use the non-suffixed separators in their syntax Fixes #982
- Handle aliases in unicode property escapes in regexes
- Update `smallbitvec` dependency
- `Generator::add_parse_table`: Store entries in hash map
- Use `IndexMap` and `FxHash` for some hot hash maps
- fix(cli): Remove tree-sitter grammar ./... call limitation
- Always print where the playground is running
- Correct quiet description for playground
- fix(cli): allow dead code in Logger
- docs(Using parsers): Fix spelling, remove unusual keyword
- Fix highlighting typo on "creating parsers" site
- feat(cli): Make "test" output more readable
- fix(cli): Improve error messages on config.json loading,
closes #1227
- fix(parser): count rows in the debug log from 0
- Docs: document `_` wildcard node
- Add SQL parser
- feat(cli): Add a lot of help messages for CLI options
- fix(cli): fix theme key loading from config.json, closes
#1232
- fix(cli): Avoid ENOENT if config.json is not in
TREE_SITTER_DIR
- feat(cli/loader): Add TREE_SITTER_INTERNAL_BUILD C/C++
compiler definition
- feat(cli): Set TREE_SITTER_DEBUG env var on 'tree-sitter
parse -d'
- allow `~` or `$HOME` in `parser-directories`
- update set_included_ranges to modify extent if the current
position is at the very beginning of the included range
-------------------------------------------------------------------
Fri Nov 5 03:18:24 UTC 2021 - William Brown <william.brown@suse.com>
- Add cargo audit service to detect potential security issues
-------------------------------------------------------------------
Fri Jul 2 22:49:27 UTC 2021 - Matej Cepl <mcepl@suse.com>
- Update to 0.20.0.
-------------------------------------------------------------------
Tue Apr 27 06:22:19 UTC 2021 - Duncan Mac-Vicar <duncan@mac-vicar.eu>
- Update to 0.19.4.
-------------------------------------------------------------------
Thu Mar 18 13:35:15 UTC 2021 - Matej Cepl <mcepl@suse.com>
- Update to 0.19.3.
-------------------------------------------------------------------
Wed Feb 24 16:54:15 UTC 2021 - Matej Cepl <mcepl@suse.com>
- Update to 0.18.2:
There isnt good changelog, so the best I have is
https://github.com/tree-sitter/tree-sitter/compare/0.17.3...v0.18.2
-------------------------------------------------------------------
Sun Nov 15 17:58:56 UTC 2020 - Matej Cepl <mcepl@suse.com>
- Add fix_build_aarch64.patch (gh#tree-sitter/tree-sitter#804) to fix
build on aarch64.
-------------------------------------------------------------------
Sat Nov 7 19:13:04 UTC 2020 - Matej Cepl <mcepl@suse.com>
- The initial packaging of tree-sitter 0.17.3.

131
tree-sitter.spec Normal file
View File

@ -0,0 +1,131 @@
#
# spec file for package tree-sitter
#
# Copyright (c) 2024 SUSE LLC
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
# upon. The license for this file, and modifications and additions to the
# file, is the same license as for the pristine package itself (unless the
# license for the pristine package is not an Open Source License, in which
# case the license is the MIT License). An "Open Source License" is a
# license that conforms to the Open Source Definition (Version 1.9)
# published by the Open Source Initiative.
# Please submit bugfixes or comments via https://bugs.opensuse.org/
#
%define somajor 0_23
Name: tree-sitter
Version: 0.23.0
Release: 0
Summary: An incremental parsing system for programming tools
License: GPL-2.0-only AND MIT
URL: https://tree-sitter.github.io/
Source0: https://github.com/tree-sitter/%{name}/archive/v%{version}.tar.gz#/%{name}-%{version}.tar.gz
Source1: vendor.tar.zst
Source11: baselibs.conf
Source20: tree-sitter-target.py
Source21: macros.in
Source22: macros.lua
Source23: functions.lua
Source24: compile-macros.sh
Source25: treesitter_grammar.attr
Source26: treesitter_grammar.req
BuildRequires: cargo-packaging
BuildRequires: rust > 1.74.1
Requires: lib%{name}%{somajor} = %{version}
Requires: nodejs
%{?suse_build_hwcaps_libs}
%description
Tree-sitter is a parser generator tool and an incremental parsing
library. It can build a concrete syntax tree for a source file
and efficiently update the syntax tree as the source file is
edited. Tree-sitter aims to be:
* General enough to parse any programming language
* Fast enough to parse on every keystroke in a text editor
* Robust enough to provide useful results even in the presence
of syntax errors
* Dependency-free so that the runtime library (which is written
in pure C) can be embedded in any application
%package -n lib%{name}%{somajor}
Summary: Asychronous I/O support library
Obsoletes: lib%{name}0 < %{version}
%description -n lib%{name}%{somajor}
Tree-sitter is a parser generator tool and an incremental parsing
library. It can build a concrete syntax tree for a source file
and efficiently update the syntax tree as the source file is
edited. This is the package with the dynamically linked C library.
%package devel
Summary: Development files for %{name}
Requires: lib%{name}%{somajor} = %{version}
%description devel
The %{name}-devel package contains libraries and header files for
developing applications that use %{name}.
%prep
%autosetup -p1 -a1
#remove gitignore file from docs
rm %{_builddir}/%{name}-%{version}/docs/.gitignore
cp %{SOURCE21} .
cp %{SOURCE22} .
cp %{SOURCE23} .
# fix VERSION in Makefile
sed -i -e '/^VERSION/s/:= .*$/:= %{version}/' Makefile
%build
%{cargo_build}
%make_build PREFIX=%{_prefix} LIBDIR=%{_libdir} INCLUDEDIR=%{_includedir}
sh %{SOURCE24}
%install
%make_install DESTDIR=%{buildroot} PREFIX=%{_prefix} LIBDIR=%{_libdir} INCLUDEDIR=%{_includedir}
install -p -m 0755 -D %{_builddir}/%{name}-%{version}/target/release/%{name} \
%{buildroot}%{_bindir}/%{name}
install -Dm644 macros.treesitter %{buildroot}%{_rpmmacrodir}/macros.treesitter
install -Dm755 %{SOURCE20} %{buildroot}%{_rpmconfigdir}/$(basename %{SOURCE20})
install -Dm644 %{SOURCE25} %{buildroot}%{_fileattrsdir}/$(basename %{SOURCE25})
install -Dm755 %{SOURCE26} %{buildroot}%{_rpmconfigdir}/$(basename %{SOURCE26})
#remove .a/.la files
find %{buildroot} -type f \( -name "*.la" -o -name "*.a" \) -delete -print
# stupid workaround for "integrating" the grammars into neovim
install -d %{buildroot}%{_libdir}/tree_sitter
%ldconfig_scriptlets -n lib%{name}%{somajor}
%files
%license LICENSE
%doc README.md CONTRIBUTING.md
%{_bindir}/%{name}
%{_rpmconfigdir}/%{name}-target.py
%{_rpmmacrodir}/macros.treesitter
%{_rpmconfigdir}/treesitter_grammar.req
%{_fileattrsdir}/treesitter_grammar.attr
%files -n lib%{name}%{somajor}
%license LICENSE
%{_libdir}/lib%{name}.so.*
%dir %{_libdir}/tree_sitter
%files devel
%doc docs/
%{_includedir}/tree_sitter
%{_libdir}/lib%{name}.so
%{_libdir}/pkgconfig/%{name}.pc
%changelog

2
treesitter_grammar.attr Normal file
View File

@ -0,0 +1,2 @@
%__treesitter_grammar_requires %{_rpmconfigdir}/treesitter_grammar.req
%__treesitter_grammar_path ^%{_treesitter_grammar_develdir}/.*\.js

98
treesitter_grammar.req Normal file
View File

@ -0,0 +1,98 @@
#!/usr/bin/python3
"""Scan grammar JavaScript sources for their dependencies"""
# SPDX-License-Identifier: MIT
# SPDX-FileCopyrightText: 2024 Björn Bidar
# pylint: disable=invalid-name
import platform
import fileinput
import re
from typing import Optional
from pathlib import Path
if platform.sys.version_info.minor < 9:
def remove_prefix(text, prefix):
if text.startswith(prefix):
return text[len(prefix):]
return text
def remove_suffix(text, suffix):
if text.endswith(suffix):
return text[:-len(suffix):]
return text
treeSitterGrammarSrcPath = "/usr/include/tree_sitter"
treeSitterGrammarSymbolToken = "treesitter_grammar_src"
grammarPaths = []
def resolveFile(grammarFile: str) -> str:
"""Resolve GRAMMARFILE from grammarPaths return found file"""
fullGrammarFilePath = Path(grammarFile)
currentGrammarPath = fullGrammarFilePath.parent
currentGrammarFile = Path(grammarFile)
if currentGrammarPath != Path('.') and currentGrammarPath.parts[0] == "..":
# resolve path relative to file found last
currentGrammarPath = grammarPaths[-1] / fullGrammarFilePath
if not currentGrammarPath.exists():
return False
return currentGrammarPath
if currentGrammarPath.is_absolute():
grammarPaths.append(currentGrammarPath)
if Path(grammarFile).exists():
return fullGrammarFilePath
for path in grammarPaths:
maybeFound = path / currentGrammarFile
if maybeFound.exists():
return maybeFound.exists()
return False
def dummyRequire(requiredFile_fd: str, maxDepth: Optional[int] = 5 ) -> str:
"""Dummy version of node's require function that spits out dependency symbols"""
if maxDepth <= 0:
return
if not requiredFile_fd.endswith(".js"):
# Append .js to required file name in case is not specified
# we have to remove .js suffix later in any case.
requiredFile_fd+=".js"
resolvedFile_fd = resolveFile(requiredFile_fd)
if resolvedFile_fd:
try:
with open(resolvedFile_fd, mode='r', encoding='utf8') as requiredFile:
for r_line in requiredFile:
require_re = r'.*require\((.*)\).*'
requiredLvl2 = re.match(require_re, r_line)
#print(r_line)
if requiredLvl2 is not None:
if platform.sys.version_info.minor < 9:
requiredLvl2_grp_cleaned = \
remove_suffix(remove_prefix(requiredLvl2.group(1), "'"), "'")
requiredLvl2_grp_cleaned = \
remove_suffix(remove_prefix(requiredLvl2_grp_cleaned, "\""),
"\"")
else:
requiredLvl2_grp_cleaned = \
requiredLvl2.group(1).removeprefix("'").removesuffix("'")
requiredLvl2_grp_cleaned = \
requiredLvl2_grp_cleaned.removeprefix("\"").removesuffix("\"")
if not requiredLvl2_grp_cleaned.split('/')[0] == "..":
# Don't emit dependencies which are local
pass
dummyRequire(requiredLvl2_grp_cleaned, maxDepth - 1)
except FileNotFoundError:
pass
else:
if maxDepth == 5:
# In case we immediately fail to open the first grammar source file
return
# We only want to resolve dependencies outside of the package
print(f"{treeSitterGrammarSymbolToken}({Path(requiredFile_fd).parent})")
for line in fileinput.input():
line = line.rstrip('\n')
if line.endswith('.js'):
dummyRequire(line)

3
vendor.tar.zst Normal file
View File

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:26d129ab3c17daceee0dbc8e6fec6dd3f45b487f8eae664e0b06f935320efd64
size 26713084