You can now add the parser to build by including the directory in
You can now add the parser to build by including the directory in
`build.rs`.
`build.rs`. 现在你可以通过在`build.rs`中加入目录,并将解析器添加到构建中。
```
```
TreeSitterParser {
TreeSitterParser {
@ -41,11 +41,11 @@ TreeSitterParser {
```
```
If your parser includes custom C or C++ files for lexing (e.g. a
If your parser includes custom C or C++ files for lexing (e.g. a
`scanner.cc`), add them to `extra_files`.
`scanner.cc`), add them to `extra_files`.如果你的解析器包括用于语法的自定义C或C++文件(例如,一个`scanner.cc`),请将它添加到`extra_files`中。
## Configure parsing
## Configure parsing配置解析器
Add an entry to `tree_sitter_parser.rs` for your language.
Add an entry to `tree_sitter_parser.rs` for your language.为你的语言在`tree_sitter_parser.rs`中增加一个条目。
```
```
Json => {
Json => {
@ -64,37 +64,37 @@ Json => {
}
}
```
```
`name` is the human-readable name shown in the UI.
`name` is the human-readable name shown in the UI.`name`是用户节目中显示的可读名称。
`atom_nodes` is a list of tree-sitter node names that should be
`atom_nodes` is a list of tree-sitter node names that should be
treated as atoms even though the nodes have children. This is common
treated as atoms even though the nodes have children. This is common
for things like string literals or interpolated strings, where the
for things like string literals or interpolated strings, where the
node might have children for the opening and closing quote.
node might have children for the opening and closing quote.`atom_nodes`是一个树形节点名称的列表,这些节点应被视为原子。即使这些节点有子节点,也应被视为原子。这对于字符串表面之或插值字符串非常常见的,因为在这种情况下,节点可能有用来表示开头和结尾的引用号。
If you don't set `atom_nodes`, you may notice added/removed content
If you don't set `atom_nodes`, you may notice added/removed content
shown in white. This is usually a sign that child node should have its
shown in white. This is usually a sign that child node should have its
parent treated as an atom.
parent treated as an atom.如果你没有设置`atom_nodes`,你可能会主要添加/删除的内容显示为白色。这通常表面了子节点的父节点应该被当作原子。
`delimiter_tokens` are delimiters that difftastic stores on
`delimiter_tokens` are delimiters that difftastic stores on
the enclosing list node. This allows difftastic to distinguish
the enclosing list node. This allows difftastic to distinguish
delimiter tokens from other punctuation in the language.
delimiter tokens from other punctuation in the language.`delimiter_tokens`是Difftastic存储在闭包节点上的定界符。这使得Difftastic能够区分划线符号和语言中的其它标点符号。
If you don't set `delimiter_tokens`, difftastic will consider the
If you don't set `delimiter_tokens`, difftastic will consider the
tokens in isolation, and may think that a `(` was added but the `)`
tokens in isolation, and may think that a `(` was added but the `)`
was unchanged.
was unchanged.如果你不设置`delimiter_tokens`,Difftastic会单独考虑这些标记,并会认为是添加了`(`,但是`)`没有发生变化。
You can use `difft --dump-ts foo.json` to see the results of the
You can use `difft --dump-ts foo.json` to see the results of the
tree-sitter parser, and `difft --dump-syntax foo.json` to confirm that
tree-sitter parser, and `difft --dump-syntax foo.json` to confirm that
you've set atoms and delimiters correctly.
you've set atoms and delimiters correctly.你可以使用`difft --dump-ts foo.json`来查看树状解析器的结果,并使用`difft --dump-syntax foo.json`来确认你已经正确设置了原子和定界符。
## Configure sliders
## Configure sliders配置滑动
Add an entry to `sliders.rs` for your language.
Add an entry to `sliders.rs` for your language.请为你的语言在`sliders.rs`中添加入口。
## Configure language detection
## Configure language detection配置语言检测
Update `from_extension` in `guess_language.rs` to detect your new
Update `from_extension` in `guess_language.rs` to detect your new
is a useful source of common file extensions.也可能有与你的语言相关的文件名或shebangs。[GitHub的语言定义](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml)是针对常见文件扩展名的一个有用来源。
## Syntax highlighting (Optional)
## Syntax highlighting (Optional)语法高亮(可选)
To add syntax highlighting for your language, you'll also need a symlink
To add syntax highlighting for your language, you'll also need a symlink
to the `queries/highlights.scm` file, if available.
to the `queries/highlights.scm` file, if available.要为你的语言添加语法高亮,如果有的话,你还需要在`queries/highlights.scm`文件一个符号链接。
Difftastic's internal docs are not available on docs.rs, as it [does
Difftastic's internal docs are not available on docs.rs, as it [does
not support binary crates today](https://difftastic.wilfred.me.uk/rustdoc/difft/).
not support binary crates today](https://difftastic.wilfred.me.uk/rustdoc/difft/).Difftastic的内部文档在docs.rs上没有提供,因为它[不支持二进制工具箱](https://difftastic.wilfred.me.uk/rustdoc/difft/)。
## Testing
## Testing测试
```
```
$ cargo test
$ cargo test
```
```
There are also several files in `sample_files/` that you can use.
There are also several files in `sample_files/` that you can use.在`sample_files/`中也有几个文件你可以使用。
The best way to test difftastic is to look at history from a real
The best way to test difftastic is to look at history from a real
project. Set `GIT_EXTERNAL_DIFF` to point to your current build.
project. Set `GIT_EXTERNAL_DIFF` to point to your current build.测试difftastic的最好方法是在真实项目查看历史。设置`GIT_EXTERNAL_DIFF`指向你当前的构建。
For example, you can run difftastic on its own source code.
For example, you can run difftastic on its own source code.例如,你可以在自己的源代码上运行Difftastic。