All Projects → afnanenayet → Diffsitter

afnanenayet / Diffsitter

Licence: mit
A tree-sitter based AST difftool to get meaningful semantic diffs

Programming Languages

rust
11053 projects

Projects that are alternatives of or similar to Diffsitter

Tolerant Php Parser
An early-stage PHP parser designed for IDE usage scenarios.
Stars: ✭ 717 (+705.62%)
Mutual labels:  ast, parser
Metric Parser
📜 AST-based advanced mathematical parser written by Typescript.
Stars: ✭ 26 (-70.79%)
Mutual labels:  ast, parser
Esprima
ECMAScript parsing infrastructure for multipurpose analysis
Stars: ✭ 6,391 (+7080.9%)
Mutual labels:  ast, parser
Webassemblyjs
Toolchain for WebAssembly
Stars: ✭ 566 (+535.96%)
Mutual labels:  ast, parser
Charly Vm
Fibers, Closures, C-Module System | NaN-boxing, bytecode-VM written in C++
Stars: ✭ 66 (-25.84%)
Mutual labels:  ast, parser
Meriyah
A 100% compliant, self-hosted javascript parser - https://meriyah.github.io/meriyah
Stars: ✭ 690 (+675.28%)
Mutual labels:  ast, parser
Proposal Binary Ast
Binary AST proposal for ECMAScript
Stars: ✭ 831 (+833.71%)
Mutual labels:  ast, parser
Astexplorer
A web tool to explore the ASTs generated by various parsers.
Stars: ✭ 4,330 (+4765.17%)
Mutual labels:  ast, parser
Astexplorer.app
https://astexplorer.net with ES Modules support and Hot Reloading
Stars: ✭ 65 (-26.97%)
Mutual labels:  ast, parser
Csstree
A tool set for CSS including fast detailed parser, walker, generator and lexer based on W3C specs and browser implementations
Stars: ✭ 1,121 (+1159.55%)
Mutual labels:  ast, parser
Tenko
An 100% spec compliant ES2021 JavaScript parser written in JS
Stars: ✭ 490 (+450.56%)
Mutual labels:  ast, parser
Lang C
Lightweight C parser for Rust
Stars: ✭ 77 (-13.48%)
Mutual labels:  ast, parser
Tiny Compiler
A tiny compiler for a language featuring LL(2) with Lexer, Parser, ASM-like codegen and VM. Complex enough to give you a flavour of how the "real" thing works whilst not being a mere toy example
Stars: ✭ 425 (+377.53%)
Mutual labels:  ast, parser
Postcss
Transforming styles with JS plugins
Stars: ✭ 25,612 (+28677.53%)
Mutual labels:  ast, parser
Php Parser
🌿 NodeJS PHP Parser - extract AST or tokens (PHP5 and PHP7)
Stars: ✭ 400 (+349.44%)
Mutual labels:  ast, parser
Php Parser
PHP parser written in Go
Stars: ✭ 787 (+784.27%)
Mutual labels:  ast, parser
Ratel Core
High performance JavaScript to JavaScript compiler with a Rust core
Stars: ✭ 367 (+312.36%)
Mutual labels:  ast, parser
Javaparser
Java 1-15 Parser and Abstract Syntax Tree for Java, including preview features to Java 13
Stars: ✭ 3,972 (+4362.92%)
Mutual labels:  ast, parser
Spoon
Spoon is a metaprogramming library to analyze and transform Java source code (up to Java 15). 🥄 is made with ❤️, 🍻 and ✨. It parses source files to build a well-designed AST with powerful analysis and transformation API.
Stars: ✭ 1,078 (+1111.24%)
Mutual labels:  ast, parser
Method log
Trace the history of an individual method in a git repository (experimental)
Stars: ✭ 73 (-17.98%)
Mutual labels:  ast, parser

diffsitter

CI release crates version latest tag downloads license

asciicast

Summary

diffsitter performs diffs on text files using the AST to compute the diff instead of using a naive text-based diff. This can give you more semantically meaningful diff information, which will prevent diffs from getting polluted by formatting differences, for example.

diffstter uses the parsers from the tree-sitter project to parse source code. As such, the languages supported by this tool are limited by the languages supported by the tree-sitter project.

Examples

Take the following files:

a.rs:

fn main() {
    let x = 1;
}

b.rs

fn



main

()

{
}

fn addition() {
}

fn add_two() {
}

The standard output from diff will get you:

1,2c1,12
< fn main() {
<     let x = 1;
---
> fn
>
>
>
> main
>
> ()
>
> {
> }
>
> fn addition() {
5c15
< fn add_one {
---
> fn add_two() {

You can see that it picks up the formatting differences for the main function, even though they aren't semantically different.

Check out the output from diffsitter:

-     let x = 1;
- fn add_one {
+ }
+ fn addition() {
+ fn add_two() {

Since it uses the AST to calculate the difference, it knows that the formatting differences in main between the two files isn't a meaningful difference, so it doesn't show up in the diff.

diffsitter has some nice (terminal aware) formatting too:

screenshot of rust diff

Installation

Published binaries

This project uses Github actions to build and publish binaries for each tagged release. You can download binaries from there if your platform is listed.

Cargo

You can install using cargo the standard way with cargo install diffsitter.

Homebrew

You can use my tap to install diffsitter:

brew tap afnanenayet/tap
brew install diffsitter
# brew install afnanenayet/tap/diffsitter

Usage

For detailed help you can run diffsitter --help (diffsitter -h provides brief help messages).

You can configure file associations and formatting options for diffsitter using a config file. If a config is not supplied, the app will use the default config, which you can see with diffsitter --cmd dump_default_config. It will look for a config at $XDG_HOME/.config on macOS and Linux, and the standard directory for Windows. You can also refer to the sample config.

Note: the tests for this crate check to make sure the provided sample config is a valid config.

Development

In order to develop for this project, you need to clone the project and initialize all submodules (each tree-sitter grammar is added as a subdirectory).

git clone
git submodule --init --recursive

This uses cargo with the cc crate, so you need to install rust and have a working C and C++ compiler.

This project targets the latest stable version of rustc, it may work on older versions, but I only guarantee support for the latest stable release.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].