tree-sitter/compile-macros.sh
Martin Pluskal bedc578f43 - update to 0.24.4:
* loader: Add language_for_configuration
  * loader: Add error message when a tree-sitter.json file is invalid
  * node: Support single-file executables via bun build --compile
  * node: Update bindings when necessary
  * Return LanguageRef in Parser::language
  * bindings: Update CMakeLists.txt file
  * cli: Pass all fields to tree-sitter.json in init
  * cli: Use contains over is in warning
  * cmake: Use current source dir for EXISTS check
  * generate: Do not set the unit reduction symbol if it's in the extras array
  * init: Use current path if unspecified
  * init: Use camel name from config in missing spots
  * lib: Simplify edge cases with zero-width tokens
  * lib: Correctly fetch the node name in query errors
  * loader: Don't print warnings if the file is not found
  * loader: Improve language lookup speed
  * bindings: Rename cmake test target
  * Memory errors in wasm_store

OBS-URL: https://build.opensuse.org/package/show/editors/tree-sitter?expand=0&rev=35
2024-11-25 19:56:30 +00:00

65 lines
2.1 KiB
Bash

#!/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