mirror of
https://github.com/laosb/SvelteNova.git
synced 2025-07-11 13:35:34 +00:00
Basic (not working) tree-sitter
syntax highlighting.
This commit is contained in:
parent
1bf00890cd
commit
7c813791aa
9 changed files with 246 additions and 38 deletions
65
build_scripts/Makefile
Normal file
65
build_scripts/Makefile
Normal file
|
@ -0,0 +1,65 @@
|
|||
# Repository
|
||||
SRC_DIR := src
|
||||
|
||||
PARSER_REPO_URL ?= $(shell git -C $(SRC_DIR) remote get-url origin )
|
||||
# the # in the sed pattern has to be escaped or it will be interpreted as a comment
|
||||
PARSER_NAME ?= $(shell basename $(PARSER_REPO_URL) | cut -d '-' -f3 | sed 's\#.git\#\#')
|
||||
UPPER_PARSER_NAME := $(shell echo $(PARSER_NAME) | tr a-z A-Z )
|
||||
|
||||
# install directory layout
|
||||
PREFIX ?= /usr/local
|
||||
INCLUDEDIR ?= $(PREFIX)/include
|
||||
LIBDIR ?= $(PREFIX)/lib
|
||||
|
||||
# collect sources, and link if necessary
|
||||
# Some Tree Sitter grammars include .cc files directly in others,
|
||||
# so we shouldn't just wildcard select them all.
|
||||
# Only collect known file names.
|
||||
ifneq ("$(wildcard $(SRC_DIR)/parser.c)", "")
|
||||
SRC += $(SRC_DIR)/parser.c
|
||||
endif
|
||||
ifneq ("$(wildcard $(SRC_DIR)/scanner.c)", "")
|
||||
SRC += $(SRC_DIR)/scanner.c
|
||||
endif
|
||||
ifneq ("$(wildcard $(SRC_DIR)/parser.cc)", "")
|
||||
CPPSRC += $(SRC_DIR)/parser.cc
|
||||
endif
|
||||
ifneq ("$(wildcard $(SRC_DIR)/scanner.cc)", "")
|
||||
CPPSRC += $(SRC_DIR)/scanner.cc
|
||||
endif
|
||||
|
||||
ifeq (, $(CPPSRC))
|
||||
ADDITIONALLIBS :=
|
||||
else
|
||||
ADDITIONALLIBS := -lc++
|
||||
endif
|
||||
|
||||
SRC += $(CPPSRC)
|
||||
OBJ := $(addsuffix .o,$(basename $(SRC)))
|
||||
|
||||
CFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
|
||||
CXXFLAGS ?= -O3 -Wall -Wextra -I$(SRC_DIR)
|
||||
override CFLAGS += -std=gnu99 -fPIC
|
||||
override CXXFLAGS += -fPIC
|
||||
|
||||
LINKSHARED := $(LINKSHARED)-dynamiclib -Wl,
|
||||
ifneq ($(ADDITIONALLIBS),)
|
||||
LINKSHARED := $(LINKSHARED)$(ADDITIONALLIBS),
|
||||
endif
|
||||
LINKSHARED := $(LINKSHARED)-install_name,$(LIBDIR)/libtree-sitter-$(PARSER_NAME).dylib,-rpath,@executable_path/../Frameworks
|
||||
|
||||
all: libtree-sitter-$(PARSER_NAME).dylib
|
||||
|
||||
libtree-sitter-$(PARSER_NAME).dylib: $(OBJ)
|
||||
$(CC) $(LDFLAGS) $(LINKSHARED) $^ $(LDLIBS) -o $@
|
||||
|
||||
install: all
|
||||
install -d '$(DESTDIR)$(LIBDIR)'
|
||||
install -m755 libtree-sitter-$(PARSER_NAME).dylib '$(DESTDIR)$(LIBDIR)'/libtree-sitter-$(PARSER_NAME).dylib
|
||||
install -d '$(DESTDIR)$(INCLUDEDIR)'/tree_sitter
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ) libtree-sitter-$(PARSER_NAME).dylib
|
||||
rm -rf build/
|
||||
|
||||
.PHONY: all install clean
|
16
build_scripts/README.md
Normal file
16
build_scripts/README.md
Normal file
|
@ -0,0 +1,16 @@
|
|||
# `build_scripts`
|
||||
|
||||
Both `compile_parser.sh` and `Makefile` are provided by Panic
|
||||
[on their doc site](https://docs.nova.app/syntax-reference/tree-sitter/#compiling-a-parser),
|
||||
and may be retrieved from
|
||||
[here](https://docs.nova.app/syntax-reference/build_script.zip).
|
||||
|
||||
Run `build_parser.sh` (from project root) to build the
|
||||
`tree-sitter-svelte.dylib`:
|
||||
|
||||
```sh
|
||||
./build_scripts/build_parser.sh /Applications/Nova.app
|
||||
```
|
||||
|
||||
You may need to adjust the path to `Nova.app`. It will also copy the build
|
||||
output to correct place and cleanup temp files.
|
18
build_scripts/build_parser.sh
Executable file
18
build_scripts/build_parser.sh
Executable file
|
@ -0,0 +1,18 @@
|
|||
#!/bin/zsh
|
||||
|
||||
# This script is supposed to be ran from the project root.
|
||||
# ./build_scripts/build_parser.sh path/to/Nova.app
|
||||
|
||||
NOVAAPP=$1
|
||||
|
||||
cp build_scripts/Makefile tree-sitter-svelte/
|
||||
|
||||
pushd tree-sitter-svelte
|
||||
../build_scripts/compile_parser.sh . $NOVAAPP
|
||||
popd
|
||||
|
||||
mv tree-sitter-svelte/build/lib/libtree-sitter-svelte.dylib SvelteNova.novaextension/Syntaxes/tree-sitter-svelte.dylib
|
||||
|
||||
# Clean up the submodule folder to avoid problems
|
||||
rm -rf tree-sitter-svelte/build
|
||||
rm tree-sitter-svelte/Makefile
|
25
build_scripts/compile_parser.sh
Executable file
25
build_scripts/compile_parser.sh
Executable file
|
@ -0,0 +1,25 @@
|
|||
#!/bin/zsh
|
||||
set -euxo pipefail
|
||||
|
||||
BASEDIR=$1
|
||||
APPBUNDLE=$2
|
||||
FRAMEWORKS_PATH="${APPBUNDLE}/Contents/Frameworks/"
|
||||
WORKINGDIR=$(pwd)
|
||||
|
||||
# - Build both arm64 (Apple Silicon) and x86_64 (Intel)
|
||||
# - Require a minimum of macOS 11.0
|
||||
# - Include the /src/ directory for headers (for `tree_sitter/parser.h`)
|
||||
BUILD_FLAGS="-arch arm64 -arch x86_64 -mmacosx-version-min=11.0 -I${BASEDIR}/src/"
|
||||
|
||||
# Build in a temporary `build/` directory.
|
||||
TMP_BUILD_DIR=$WORKINGDIR/build
|
||||
mkdir -p $TMP_BUILD_DIR
|
||||
|
||||
pushd $BASEDIR
|
||||
|
||||
CFLAGS="${BUILD_FLAGS} -O3" \
|
||||
CXXFLAGS="${BUILD_FLAGS} -O3" \
|
||||
LDFLAGS="${BUILD_FLAGS} -F${FRAMEWORKS_PATH} -framework SyntaxKit -rpath @loader_path/../Frameworks" \
|
||||
PREFIX="$TMP_BUILD_DIR" make install
|
||||
|
||||
popd
|
Loading…
Add table
Add a link
Reference in a new issue