/tree-sitter-torque

TypeScript grammar for tree-sitter

Primary LanguagePythonMIT LicenseMIT

tree-sitter-typescript

Build Status Build status

TypeScript and TSX grammars for tree-sitter.

Because TSX and TypeScript are actually two different dialects, this module defines two grammars. Require them as follows:

require('tree-sitter-typescript').typescript; // TypeScript grammar
require('tree-sitter-typescript').tsx; // TSX grammar

For Javascript files with flow type annotations you can use the the tsx parser.

References

开始

centos下

yum install nodejs
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
source "$HOME/.cargo/env"
cargo install tree-sitter-cli

然后去掉package.json中关于tree-sitter-cli的安装。

npm install
npm run build
npm run test
npm run test-load

Linux下安装(舍弃,tree-sitter 提示 glibc版本过低)

若报错error lto1: fatal error: bytecode stream in file ‘Release/obj.target/tree_sitter_javascript_binding/src/parser.o’ generated with LTO version 2.2 instead of the expected 7.3,则将binding.gyp中的编译指令更改如下:

# 添加"-fno-lto"
      "cflags_c": [
        "-std=c99",
        "-fno-lto",
      ]

可能tree-sitter-typescript以及tree-sitter-javascript都需要对应的更改。

windows下安装(舍弃,npm run奇怪错误)

先安装vs2022,并确保选上了Desktop development with C++

然后设置如下:

npm config set msvs_version 2022

若Python也需要设置,可以使用npm config set python python3.10.

然后遇到报错VCINSTALLDIR not set, not running in VS Command Prompt, 可以参考 https://github.com/nodejs/node-gyp/blob/main/docs/Updating-npm-bundled-node-gyp.md#windows

tree-sitter学习

  1. 有关precedences

  2. 有关dynamic precedence