Next: cl-tree-sitter Setup, Previous: Setting up libtree-sitter, Up: Source Code with tree-sitter
[Contents][Index]
Each language has its own module that can be used with tree-sitter. All of the languages that are currently supported can be found here: https://github.com/tree-sitter.
For convience:
To set-up a language, the following script can be used from the base directory of the language module’s directory:
#!/bin/bash language=$1 [ $# -eq 0 ] && { echo "Usage: $0 language_name"; exit 1; } cd src/ if test -f "scanner.cc"; then clang++ -fPIC scanner.cc -c -lstdc++ clang -std=c99 -fPIC parser.c -c clang++ -shared scanner.o parser.o -o /usr/lib/tree-sitter-$(echo ${language}|sed 's|/|-|').so elif test -f "scanner.c"; then clang -std=c99 -fPIC scanner.c -c clang -std=c99 -fPIC parser.c -c clang -shared scanner.o parser.o -o /usr/lib/tree-sitter-$(echo ${language}|sed 's|/|-|').so else clang -std=c99 -fPIC parser.c -c clang -shared parser.o -o /usr/lib/tree-sitter-$(echo ${language}|sed 's|/|-|').so fi sudo mkdir -p /usr/share/tree-sitter/${language}/ sudo cp grammar.json node-types.json /usr/share/tree-sitter/${language} |
If everything is desired, the following can be used:
#!/bin/bash for language in agda bash c c-sharp cpp css go html java javascript jsdoc json julia ocaml/ocaml ocaml/interface php python ql regex ruby rust scala typescript/tsx typescript/typescript;do [ -d tree-sitter-${language%/*} ] || git clone --depth=1 https://github.com/tree-sitter/tree-sitter-${language%/*} cd tree-sitter-${language}/src if test -f "scanner.cc"; then clang++ -fPIC scanner.cc -c -lstdc++ clang -std=c99 -fPIC parser.c -c clang++ -shared scanner.o parser.o -o /usr/lib/tree-sitter-$(echo ${language}|sed 's|/|-|').so elif test -f "scanner.c"; then clang -std=c99 -fPIC scanner.c -c clang -std=c99 -fPIC parser.c -c clang -shared scanner.o parser.o -o /usr/lib/tree-sitter-$(echo ${language}|sed 's|/|-|').so else clang -std=c99 -fPIC parser.c -c clang -shared parser.o -o /usr/lib/tree-sitter-$(echo ${language}|sed 's|/|-|').so fi mkdir -p /usr/share/tree-sitter/${language}/ cp grammar.json node-types.json /usr/share/tree-sitter/${language} cd - done |
On Arch Linux the
tree-sitter-languages-git aur
package may be used to install
tree-sitter support for many languages.
On MacOS the following shell script may be used to achieve similar results:
#!/bin/bash declare -a LANGUAGES LANGUAGES=agda bash c c-sharp cpp css go html java javascript jsdoc json julia ocaml/ocaml ocaml/interface php python ql regex ruby rust scala typescript/tsx typescript/typescript clone() { for language in ${LANGUAGES};do LANG="$(echo ${language}|sed 's|/|-|')" git clone https://github.com/tree-sitter/tree-sitter-${LANG} src/tree-sitter-${LANG} done } package() { for language in ${LANGUAGES};do echo $language LANG="$(echo ${language}|sed 's|/|-|')" BASE="tree-sitter-${LANG}" cd src/tree-sitter-${language}/src if test -f "scanner.cc"; then c++ -fPIC scanner.cc -c -lstdc++ cc -std=c99 -fPIC parser.c -c ar rcs ${BASE}.a scanner.o parser.o c++ -dynamiclib -Wl,-install_name,/usr/local/lib/${BASE}.0.dylib scanner.o parser.o -o ${BASE}.0.0.dylib ln -sf ${BASE}.0.0.dylib ${BASE}.dylib ln -sf ${BASE}.0.0.dylib ${BASE}.0.dylib sudo install -d "/usr/local/lib/tree-sitter/$LANG" sudo install -m755 ${BASE}.a "/usr/local/lib/tree-sitter/${BASE}".a sudo install -m755 ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.0.0.dylib ln -sf ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.0.dylib ln -sf ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.dylib elif test -f "scanner.c"; then cc -std=c99 -fPIC scanner.c -c cc -std=c99 -fPIC parser.c -c ar rcs ${BASE}.a scanner.o parser.o c++ -dynamiclib -Wl,-install_name,/usr/local/lib/${BASE}.0.dylib scanner.o parser.o -o ${BASE}.0.0.dylib ln -sf ${BASE}.0.0.dylib ${BASE}.dylib ln -sf ${BASE}.0.0.dylib ${BASE}.0.dylib sudo install -d "/usr/local/lib/tree-sitter/$LANG" sudo install -m755 ${BASE}.a "/usr/local/lib/tree-sitter/${BASE}".a sudo install -m755 ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.0.0.dylib ln -sf ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.0.dylib ln -sf ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.dylib else cc -std=c99 -fPIC parser.c -c ar rcs ${BASE}.a parser.o c++ -dynamiclib -Wl,-install_name,/usr/local/lib/${BASE}.0.dylib parser.o -o ${BASE}.0.0.dylib ln -sf ${BASE}.0.0.dylib ${BASE}.dylib ln -sf ${BASE}.0.0.dylib ${BASE}.0.dylib sudo install -d "/usr/local/lib/tree-sitter/$LANG" sudo install -m755 ${BASE}.a "/usr/local/lib/tree-sitter/${BASE}".a sudo install -m755 ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.0.0.dylib ln -sf ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.0.dylib ln -sf ${BASE}.0.0.dylib '/usr/local/lib'/${BASE}.dylib fi sudo install -d /usr/local/share/tree-sitter/${language}/ sudo install -m644 grammar.json node-types.json /usr/local/share/tree-sitter/${language}/ cd - >/dev/null done } mkdir -p src/ clone package |
Next: cl-tree-sitter Setup, Previous: Setting up libtree-sitter, Up: Source Code with tree-sitter
[Contents][Index]