Replies: 1 comment 2 replies
-
Hi @mbhall88
I'm always impressed by what people build. Nice that this works :)
Forking Ruff's parser and extending it to support the snakefile syntax shouldn't be too much work. You probably want to add a few custom statement types in ruff/crates/ruff_python_parser/src/parser/statement.rs Lines 112 to 146 in 5109b50 I don't think the Ruff parser uses any error recovery today that would be incompatible or cause problems with the syntax I see above but there's a risk that we might add error recovery that would result in skipping valid snakemake syntax (but only if there was some invalid syntax before it). Forking a parser comes with its own challenge if you want to stay up to date with new Python syntax, and we don't make any stability guarantees regarding our parser/AST API. I suspect what you would want most is for Ruff to add a snakemake dialect to its parser. That's something we would have to consider thoroughly because I used to maintain an error-recoverable JavaScript/TypeScript parser and supporting multiple dialects adds a lot of complexity. The main issue I see with snakemake is that Python could introduce new syntax that leads to ambiguity with snakemake in the future and that would put Ruff in a rough spot ;) This problem did not exist with TypeScript/JavaScript because the JS standard committee agreed not to introduce any new syntax that would break TypeScript. I don't think snakemake has enough community today to warrant the added complexity on our side. |
Beta Was this translation helpful? Give feedback.
-
Snakemake is a workflow management system used very heavily in the biology research community, among others. It is essentially an extension of Python, with some Snakemake-specific syntax. For example
I am a co-dev and co-maintainer of a tool to format Snakefiles, which essentially just passed the code to black, converting snakemake-specific syntax into python analogs, and then converting back after the formatting.
However, this parsing is getting harder and harder to maintain as we just have a hacky parser. What I would ultimately like to do is extend and existing python parser to include the snakemake syntax keywords such as
rule
,include
, etc. This would allow for much easier parsing and bug fixing. We currently have lots of hacky fixes which are building up into a headache.I noticed that ruff has essentially implemented a python parser from scratch and was wondering how simple you think it would be for me to create a snakemake parser that extends this? Any direction/advice you could provide would be so helpful. I have played around with lark but had a hard time trying to get it to work.
If it were possible to extend ruff's parser, would that then make it easy to plug into ruff's formatting and we could then just pass the snakemake code through to ruff for formatting instead of black?
Sorry I know this has been a bit rambling, I hope it is somewhat clear what I am asking...
Beta Was this translation helpful? Give feedback.
All reactions