Make tree-sitter the default parser

ida_star
Wilfred Hughes 2021-08-29 15:17:40 +07:00
parent 1dfedc6534
commit c662181cd6
3 changed files with 16 additions and 21 deletions

@ -6,6 +6,9 @@ Fixed a crash on removing whole files.
### Parsing
Tree-sitter parsing is now the default, unless the environment
variable DFT_RX is set.
Tree-sitter parser: Improved handling of string literals. Improved
matching of delimiters.

@ -11,16 +11,12 @@ It currently supports the following languages:
* CSS
* Emacs Lisp
* Go
* JavaScript
* JavaScript (including JSX)
* JSON
* OCaml
* Rust
* Scheme
The parsing logic is based on matched delimiters, so difftastic tends
to give best results on heavily parenthesised code (e.g. Lisps or
JSON).
If a file has an unrecognised extension, difftastic uses a
line-oriented diff.
@ -28,20 +24,14 @@ line-oriented diff.
(1) Parsing.
Difftastic treats source code as a sequence of atoms or (possibly
nested) lists.
Language syntax is defined in `src/regex_parser.rs`: you provide regular
expressions for atoms (including comments), open delimiters, and close
delimiters.
This is heavily inspired by
[Comby](https://github.com/comby-tools/comby), which handles a large
number of languages by using a similar approach.
Difftastic uses
[tree-sitter](https://tree-sitter.github.io/tree-sitter/) for
parsing. The concrete syntax tree is then converted to a sequence of
atoms or (possibly nested) lists.
(A [tree-sitter](https://tree-sitter.github.io/tree-sitter/) parsing
backend is also available by setting `DFT_TS=y`. It is not yet
recommended.)
The command line flags `--dump-ts` and `--dump-syntax` will display
the syntax trees for a given file. Difftastic also has a simple regex-based
parser which can be enabled with `DFT_RX=1`.
(2) Diffing.

@ -198,10 +198,12 @@ fn main() {
let extension = Path::new(&display_path).extension();
let extension = extension.unwrap_or_else(|| OsStr::new(""));
let ts_lang = if env::var("DFT_TS").is_ok() {
tsp::from_extension(extension)
} else {
// Try tree-sitter parser first unless DFT_RX (difftastic regex)
// environment variable is set.
let ts_lang = if env::var("DFT_RX").is_ok() {
None
} else {
tsp::from_extension(extension)
};
let (lang_name, lhs, rhs) = match ts_lang {