-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add full-parser, like full-lexer #100
Comments
That will be a good feature if you need one. |
I tried looking into ways to add comments but could not quickly figure out how to best add it to the grammar. Then I looked at ruff cause they do formatting now as well and use this parser (although it seems they vendor/ fork it) and here is some code which does it for them https://github.com/astral-sh/ruff/tree/9cb5ce750e9dead53eb8235e8cfb7cff653a1cd2/crates/ruff_python_formatter/src/comments
Yes that would be enough for me, it does not have to be a perfect reproduction, but I'd want to preserve the meaning/ content of the comments. |
Fitting comments into the grammar will be difficult because comments can appear in almost all positions. Ruff's comment handling is specific to the formatter and not a general purpose solution. I recommend taking a look at how oxc handles comments https://github.com/web-infra-dev/oxc/blob/main/crates/oxc_ast/src/trivia.rs An entirely different approach is to use a cst similar to rome/biome/Roslyn/swift https://boshen.github.io/javascript-parser-in-rust/blog/rome/ |
Currently it does not seem to be possible to get an AST with comments attached?
The text was updated successfully, but these errors were encountered: