dimitarvp

dimitarvp

To @jonatanklosko and @the-mikedavis:

I see that there is a Rust crate at crates.io: Rust Package Registry but it is pointing at https://github.com/tree-sitter/tree-sitter-elixir – and that no longer exists.

Can this be fixed to correctly point to GitHub - elixir-lang/tree-sitter-elixir: Elixir grammar for tree-sitter · GitHub, please? Assuming they are even the same which they might not be.

I am looking into making a PR to GitHub - ast-grep/ast-grep: ⚡A CLI tool for code structural search, lint and rewriting. Written in Rust · GitHub so Elixir can be included in the semantic / structural code search that this tool provides.

I am asking for this because the project’s Cargo.toml needs a valid crate to point at a language grammar before the small boilerplate required to add a language can work: ast-grep/crates/language/Cargo.toml at 782b175dacaf161cd567538f01929c5e78074e9f · ast-grep/ast-grep · GitHub

/CC @josevalim

Showing Posts 1 to 10

dimitarvp

dimitarvp OP

To clarify further: I can and have started a PR to add Elixir to the ast-grep tool because Cargo allows GIT dependencies just fine. But I thought it would be more… hygienic might be the word… for us to have a proper Rust crate hosted on crates.io.

shanesveller

shanesveller

Notably you cannot publish a release to crates.io if it contains any git dependencies, so many packages that are actually CLIs or other end-user applications may forbid introducing such changes. On the projects’ side the stance is mainly motivated to protect the ability to cargo install the package by name.

I knew this from past friction; and Specifying Dependencies - The Cargo Book mentions that near the bottom of that section, but I couldn’t trivially find a page directly on crate.io to cite.

dimitarvp

dimitarvp OP

Thanks for pointing this out, I overlooked it.

And yikes, I guess in that case repairing the crate is indeed a blocker if I am to contribute to ast-grep.

dimitarvp

dimitarvp OP

OK, I have forked the repo and made a bunch of changes that plug in the Elixir TreeSitter implementation – it seems that the moved repo is indeed doing the same things that the old (the one that no longer exists) was doing.

The only thing that is missing is replacing this line in Cargo.toml:

tree-sitter-elixir = { git = "https://github.com/elixir-lang/tree-sitter-elixir", optional = true }

with:

tree-sitter-elixir = { version = "0.1.0", optional = true }

(or whatever the version gets bumped to)


There’s a problem though, searching for $A != nil yields an error:

Multiple AST nodes are detected. Please check the pattern source $A != nil.

Looking for e.g. is_nil($A) works fine.

I have zero clue as to how TreeSitter works so this is still a mystery. Hopefully I can find some more time to experiment and see how this can be solved (if it can at all).

Here’s the forked repo. Running cargo test elixir is easy enough, and so is finding elixir.rs inside the project, if anybody wants to tinker.

F.ex. test_match("$A = 0", "a = 0"); also breaks with the “multiple nodes” error. Try and put it inside elixir.rs’s function test_elixir_pattern() and re-run cargo test elixir.

Finally, tinkering would be done like so:

cd /where/you/cloned/the/forked/repo
cargo b --release
export ASTGREP=$(pwd)/target/release/sg
cd /path/to/elixir/repo
$ASTGREP -p '$A != nil' --lang elixir
$ASTGREP -p 'is_nil($A)' --lang elixir
# etc.
dimitarvp

dimitarvp OP

I’ve also opened a pull request in the original repo.

dimitarvp

dimitarvp OP

It seems that replacing one Rust macro incantation with another fixed the strange “multiple AST nodes” error. I’ll work on adding better and more convincing tests and will then ask the tool authors to merge the PR, after which we’ll be able to use ast-grep to search and replace Elixir code from the CLI. :partying_face:

…if the owners of the tree-sitter-elixir re-publish the Rust crate with the right GitHub repo URL that is.

dimitarvp

dimitarvp OP

tree-sitter-elixir has been fixed to have its correct GIT URL on crates.io.

I’ll proceed to enrich the tests in my PR and we’ll have Elixir support for ast-grep very soon.

dimitarvp

dimitarvp OP

My PR has been merged.

We’ll have Elixir support in ast-grep come next release (so a matter of days).

dimitarvp

dimitarvp OP

ast-grep version 0.14.3 has been released and is now supporting Elixir.

Example usage:

# or "ex" for a shorthand name for Elixir.
$ sg -l elixir -p '$A != nil'

Where Next? Top

Trending in Proposals: Ideas Top

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
New
mhanberg
Hi everyone! The first release candidate for the Expert language server project is now available! We’ve published a press release detai...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews