Where can I find a super simple rust parser?

My requirement is simply to know the file path and line number that each "thing" (function, type. etc) is defined at.
I would like to write a small utility just for myself that helps to enforce my own brand of code layout and to do this, I need to know where things are defined.

I am hoping there is some crate I can use by providing a project path and it outputs something I can use to derive the above information.

You can get this from the syn crate. Alternatively there's also tree-sitter, but it's a wrapper around a C project.

I don't have code to share yet. I have been wanting something similar. I think the options are (1) syn, (2) rust-analyzer, (3) rustc, and (4) .. possibly clippy.

With syn, I do not think there is type info. I have not explored rust-analyzer much. With rustc, I could not get IntelliJ intellisense to work with HIR / THIR. I am currently wondering if Clippy might be the right approach -- since the linter already has logic to traverse the cargo workspace / find all the files / parse/typecheck everything, so it seems to have all the requisite machinery.

1 Like

You may be interested in GitHub - rust-marker/marker: An experimental linting interface for Rust. Let's make custom lints a reality

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.