update the rest of the translation

pull/370/head
Yeegsing 2022-09-12 08:04:36 +07:00
parent 013a4ecdb7
commit c380ecff48
5 changed files with 80 additions and 78 deletions

@ -96,7 +96,7 @@ favourite tool, and I will link it in the README!
## Translation ## Translation
+ [Chinese](./translation/README-zh-CN.md) + [Chinese](./translation/zh-CN/README-zh-CN.md)
## License ## License

@ -1,28 +1,28 @@
# Adding A Parser # Adding A Parser添加解析器
## Finding a parser ## Finding a parser寻找解析器
New parsers for difftastic must be reasonably complete and maintained. New parsers for difftastic must be reasonably complete and maintained.Difftastic的新解析器必须完整且合理地维护。
There are many tree-sitter parsers available, and the tree-sitter There are many tree-sitter parsers available, and the tree-sitter
website includes [a list of some well-known website includes [a list of some well-known
parsers](https://tree-sitter.github.io/tree-sitter/#available-parsers). parsers](https://tree-sitter.github.io/tree-sitter/#available-parsers).有许多解析器可用,网站包括[一些著名的解析器列表](https://tree-sitter.github.io/tree-sitter/#available-parsers)。
## Add the source code ## Add the source code添加源码
Once you've found a parser, add it as a git subtree to Once you've found a parser, add it as a git subtree to
`vendor/`. We'll use `vendor/`. We'll use
[tree-sitter-json](https://github.com/tree-sitter/tree-sitter-json) as [tree-sitter-json](https://github.com/tree-sitter/tree-sitter-json) as
an example. an example.一旦你找到一个解析器需要将其作为git的subtree添加到`vendor/`中。我们会使用[tree-sitter-json](https://github.com/tree-sitter/tree-sitter-json)作为例子。
``` ```
$ git subtree add --prefix=vendor/tree-sitter-json git@github.com:tree-sitter/tree-sitter-json.git master $ git subtree add --prefix=vendor/tree-sitter-json git@github.com:tree-sitter/tree-sitter-json.git master
``` ```
## Configure the build ## Configure the build配置编译过程
Cargo does not allow packages to include subdirectories that contain a Cargo does not allow packages to include subdirectories that contain a
`Cargo.toml`. Add a symlink to the `src/` parser subdirectory. `Cargo.toml`. Add a symlink to the `src/` parser subdirectory.Cargo不允许软件包包含`Cargo.toml`。需要在`src/`解析器子目录中添加一个符号链接。
``` ```
$ cd vendor $ cd vendor
@ -30,7 +30,7 @@ $ ln -s tree-sitter-json/src tree-sitter-json-src
``` ```
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
language. language.更新`guess_language.rs`中的`from_extension`以检测新的语言。
``` ```
"json" => Some(Json), "json" => Some(Json),
@ -103,32 +103,33 @@ language.
There may also file names or shebangs associated with your There may also file names or shebangs associated with your
language. [GitHub's linguist language. [GitHub's linguist
definitions](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml) definitions](https://github.com/github/linguist/blob/master/lib/linguist/languages.yml)
is a useful source of common file extensions. 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`文件一个符号链接。
``` ```
$ cd vendor/highlights $ cd vendor/highlights
$ ln -s ../tree-sitter-json/queries/highlights.scm json.scm $ ln -s ../tree-sitter-json/queries/highlights.scm json.scm
``` ```
## Add a regression test ## Add a regression test添加一个回归测试
Finally, add a regression test for your language. This ensures that Finally, add a regression test for your language. This ensures that
the output for your test file doesn't change unexpectedly. the output for your test file doesn't change unexpectedly.最后,为你的语言添加一个回归测试,这样可以确保你的测试文件的输出不会意外改变。
Regression test files live in `sample_files/` and have the form Regression test files live in `sample_files/` and have the form
`foo_before.abc` and `foo_after.abc`. `foo_before.abc` and `foo_after.abc`.回归测试文件存在于`sample_files/`中,其形式为
`foo_before.abc`和`foo_after.abc`。
``` ```
$ nano simple_before.json $ nano simple_before.json
$ nano simple_after.json $ nano simple_after.json
``` ```
Run the regression test script and update the `.expected` file. Run the regression test script and update the `.expected` file.运行回归测试脚本并更新`.expect`文件。
``` ```
$ ./sample_files/compare_all.sh $ ./sample_files/compare_all.sh

@ -1,8 +1,8 @@
# Contributing # Contributing贡献
## Building ## Building构建
Install Rust with [rustup](https://rustup.rs/), then clone the code. Install Rust with [rustup](https://rustup.rs/), then clone the code.用[rustup](https://rustup.rs/)安装Rust然后克隆代码。
``` ```
$ git clone git@github.com:Wilfred/difftastic.git $ git clone git@github.com:Wilfred/difftastic.git
@ -10,7 +10,7 @@ $ cd difftastic
``` ```
Difftastic uses [Cargo](https://doc.rust-lang.org/cargo/) for Difftastic uses [Cargo](https://doc.rust-lang.org/cargo/) for
building. building.Difftastic使用[Cargo](https://doc.rust-lang.org/cargo/)进行构建。
``` ```
$ cargo build $ cargo build
@ -18,51 +18,50 @@ $ cargo build
Debug builds are significantly slower than release builds. For files Debug builds are significantly slower than release builds. For files
with more than fifty lines, it's usually worth using an optimised with more than fifty lines, it's usually worth using an optimised
build. build.调试构建的速度明显比发布构建的速度慢。对于超过50行的文件通常建议使用一个优化的构建。
``` ```
$ cargo build --release $ cargo build --release
``` ```
## Manual ## Manual说明书
This website is generated with This website is generated with
[mdbook](https://github.com/rust-lang/mdBook/). mdbook can be [mdbook](https://github.com/rust-lang/mdBook/). mdbook can be
installed with Cargo. installed with Cargo.这个网站是用[mdbook](https://github.com/rust-lang/mdBook/)。mdbook可以用Cargo安装。
``` ```
$ cargo install mdbook $ cargo install mdbook
``` ```
You can then use the `mdbook` binary to build and serve the site You can then use the `mdbook` binary to build and serve the site
locally. locally.然后你可以使用`mdbook`二进制文件来建立和在本地运行网站。
``` ```
$ cd manual $ cd manual
$ mdbook serve $ mdbook serve
``` ```
## API Documentation ## API DocumentationAPI文档
You can browse the internal API documentation generated by rustdoc You can browse the internal API documentation generated by rustdoc
[here](https://difftastic.wilfred.me.uk/rustdoc/difft/). [here](https://difftastic.wilfred.me.uk/rustdoc/difft/).你可以浏览由rustdoc生成的内部API文档[在这里](https://difftastic.wilfred.me.uk/rustdoc/difft/)。
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。
``` ```
$ GIT_EXTERNAL_DIFF=./target/release/difft git log -p --ext-diff -- src $ GIT_EXTERNAL_DIFF=./target/release/difft git log -p --ext-diff -- src
``` ```
@ -70,34 +69,34 @@ $ GIT_EXTERNAL_DIFF=./target/release/difft git log -p --ext-diff -- src
## Logging ## Logging
Difftastic uses the `pretty_env_logger` library to log some additional Difftastic uses the `pretty_env_logger` library to log some additional
debug information. debug information.Difftastic使用`pretty_env_logger`库来记录一些额外的调试信息。
``` ```
$ RUST_LOG=debug cargo run sample_files/old.jsx sample_files/new.jsx $ RUST_LOG=debug cargo run sample_files/old.jsx sample_files/new.jsx
``` ```
See the [`env_logger` See the [`env_logger`
documentation](https://docs.rs/env_logger/0.9.0/env_logger/) for full details. documentation](https://docs.rs/env_logger/0.9.0/env_logger/) for full details.请参阅[`env_logger`](https://docs.rs/env_logger/0.9.0/env_logger/)以获得完整的细节。
## Profiling ## Profiling
If you have a file that's particularly slow, you can use If you have a file that's particularly slow, you can use
[cargo-flamegraph](https://github.com/flamegraph-rs/flamegraph) to see [cargo-flamegraph](https://github.com/flamegraph-rs/flamegraph) to see
which functions are slow. which functions are slow.如果你有一个特别慢的文件,你可以使用 [cargo-flamegraph](https://github.com/flamegraph-rs/flamegraph) 来查看是哪些函数慢的。
``` ```
$ CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin difft sample_files/slow_before.rs sample_files/slow_after.rs $ CARGO_PROFILE_RELEASE_DEBUG=true cargo flamegraph --bin difft sample_files/slow_before.rs sample_files/slow_after.rs
``` ```
It's also worth looking at memory usage, as graph traversal bugs can It's also worth looking at memory usage, as graph traversal bugs can
lead to huge memory consumption. lead to huge memory consumption.内存的使用情况也是值得关注,因为图的遍历错误会导致巨大的内存消耗。
``` ```
$ /usr/bin/time -v ./target/release/difft sample_files/slow_before.rs sample_files/slow_after.rs $ /usr/bin/time -v ./target/release/difft sample_files/slow_before.rs sample_files/slow_after.rs
``` ```
If timing measurement are noisy, Linux's `perf` tool will report If timing measurement are noisy, Linux's `perf` tool will report
instructions executed, which is more stable. instructions executed, which is more stable.如果定时测量有噪音Linux的`perf`工具将报告 执行的指令,这也是更加稳定的。
``` ```
$ perf stat ./target/release/difft sample_files/slow_before.rs sample_files/slow_after.rs $ perf stat ./target/release/difft sample_files/slow_before.rs sample_files/slow_after.rs
@ -105,16 +104,17 @@ $ perf stat ./target/release/difft sample_files/typing_old.ml sample_files/typin
``` ```
Many more profiling techniques are discussed in the [The Rust Many more profiling techniques are discussed in the [The Rust
Performance Book](https://nnethercote.github.io/perf-book/). Performance Book](https://nnethercote.github.io/perf-book/).还有很多剖析技术在[The Rust性能手册](https://nnethercote.github.io/perf-book/)中讨论了。
## Releasing ## Releasing发布
Use Cargo to create a new release, and tag it in git. Difftastic has a Use Cargo to create a new release, and tag it in git. Difftastic has a
helper script for this: helper script for this:使用Cargo创建一个新的版本并在git中标记它。Difftastic有一个帮助脚本。
``` ```
$ ./scripts/release.sh $ ./scripts/release.sh
``` ```
You can now increment the version in Cargo.toml and add a new entry to You can now increment the version in Cargo.toml and add a new entry to
CHANGELOG.md. CHANGELOG.md.现在你可以增加Cargo.toml中的版本并在
CHANGELOG.md加一个新的条目。

@ -1,17 +1,17 @@
# Diffing # Diffing差异分析
Difftastic treats diff calculations as a route finding problem on a Difftastic treats diff calculations as a route finding problem on a
directed acyclic graph. directed acyclic graph.Difftastic将diff计算视作为有向无环图上的寻路问题。
## Graph Representation ## Graph Representation图表示
A vertex in the graph represents a position in two syntax trees. A vertex in the graph represents a position in two syntax trees.图中的一个顶点代表两个语法树中的一个位置。
The start vertex has both positions pointing to the first syntax node The start vertex has both positions pointing to the first syntax node
in both trees. The end vertex has both positions just in both trees. The end vertex has both positions just
after the last syntax node in both trees. after the last syntax node in both trees.开始顶点的两个位置都指向两个树的第一个语法节点。结束顶点的两个位置都正好在两棵语法树的最后一个节点之后。
Consider comparing `A` with `X A`. Consider comparing `A` with `X A`.以`A`和`X A`比较为例:
``` ```
START START
@ -27,12 +27,12 @@ END
+---------------------+ +---------------------+
``` ```
From the start vertex, we have two options: From the start vertex, we have two options:从起始顶点开始,我们有两个选择:
* we can mark the first syntax node on the left as novel, and advance * we can mark the first syntax node on the left as novel, and advance
to the next syntax node on the left (vertex 1 above), or to the next syntax node on the left (vertex 1 above), or我们可以将左边的第一个语法节点标记为注意项并推进到左边的下一个语法节点即上面的顶点1
* we can mark the first syntax node on the right as novel, and advance * we can mark the first syntax node on the right as novel, and advance
to the next syntax node on the right (vertex 2 above). to the next syntax node on the right (vertex 2 above).我们可以将右边的第一个语法节点标记为注意项并推进到右边的下一个语法节点上即上面的顶点2
``` ```
START START
@ -51,7 +51,7 @@ From the start vertex, we have two options:
Choosing "novel atom R" to vertex 2 will turn out to be the best Choosing "novel atom R" to vertex 2 will turn out to be the best
choice. From vertex 2, we can see three routes to the end vertex. choice. From vertex 2, we can see three routes to the end vertex.选择"新原子R"到顶点2将是最佳选择。从顶点2我们可以看到有三条路线通往终点。
``` ```
2 2
@ -76,25 +76,26 @@ choice. From vertex 2, we can see three routes to the end vertex.
+---------------------+ +---------------------+
``` ```
## Comparing Routes ## Comparing Routes比较路线
We assign a cost to each edge. Marking a syntax node as novel is worse We assign a cost to each edge. Marking a syntax node as novel is worse
than finding a matching syntax node, so the "novel atom" edge has a than finding a matching syntax node, so the "novel atom" edge has a
higher cost than the "syntax nodes match" edge. higher cost than the "syntax nodes match" edge.我们给每条边分配一个成本。将一个语法节点标记为新奇,比找到一个匹配的语法节点更糟糕,因此"新奇原子"边的成本比"语法节点匹配"边更高。
The best route is the lowest cost route from the start vertex to the The best route is the lowest cost route from the start vertex to the
end vertex. end vertex.最佳路线是指从起始顶点到终端顶点成本最低的路线。
## Finding The Best Route ## Finding The Best Route寻找最佳路线
Difftastic uses Dijkstra's algorithm to find the best (i.e. lowest cost) Difftastic uses Dijkstra's algorithm to find the best (i.e. lowest cost)
route. route.Difftastic使用Dijkstra算法来寻找最佳或称最低成本的路线。
One big advantage of this algorithm is that we don't need to construct One big advantage of this algorithm is that we don't need to construct
the graph in advance. Constructing the whole graph would require the graph in advance. Constructing the whole graph would require
exponential memory relative to the number of syntax nodes. Instead, exponential memory relative to the number of syntax nodes. Instead,
vertex neighbours are constructed as the graph is explored. vertex neighbours are constructed as the graph is explored.这种算法的一大优势是,我们不需要事先构建图。相对于语法节点的数量,构建整个图需要指数级的内存。相反顶点的邻居是在探索图的过程中构建的。
There are lots of resources explaining Dijkstra's algorithm online, There are lots of resources explaining Dijkstra's algorithm online,
but I particularly recommend the [graph search section of Red Blob but I particularly recommend the [graph search section of Red Blob
Games](https://www.redblobgames.com/pathfinding/a-star/introduction.html#dijkstra). Games](https://www.redblobgames.com/pathfinding/a-star/introduction.html#dijkstra).网上有很多解释Dijkstra的算法但我特别推荐[Red
Blod Games的图搜索部分](https://www.redblobgames.com/pathfinding/a-star/introduction.html#dijkstra)。

@ -1,11 +1,11 @@
# Tricky Cases # Tricky Cases棘手的例子
Tree diffing is challenging in some situations. This page demonstrates Tree diffing is challenging in some situations. This page demonstrates
difficult cases observed during development. difficult cases observed during development.在某些情况下,树状图的差异分析是具有挑战性的。本页展示了在开发过程中所观察到的困难情况。
Not all of these cases work well in difftastic yet. Not all of these cases work well in difftastic yet.并非所有这些情况在Difftastic中都能很好地工作。
## Adding Delimiters ## Adding Delimiters添加定界符
``` ```
;; Before ;; Before
@ -15,7 +15,7 @@ x
(x) (x)
``` ```
Desired result: <code><span style="background-color: PaleGreen">(</span>x<span style="background-color: PaleGreen">)</span></code> Desired result: <code><span style="background-color: PaleGreen">(</span>x<span style="background-color: PaleGreen">)</span></code>理想输出: <code><span style="background-color: PaleGreen">(</span>x<span style="background-color: PaleGreen">)</span></code>
This is tricky because `x` has changed its depth in the tree, but `x` This is tricky because `x` has changed its depth in the tree, but `x`
itself is unchanged. itself is unchanged.