Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
atheist9793116dI'm writing a docstring linter for python which required parsing python into an AST, extracting the docstrings and they use reStructuredText markup so I'm now trying to parse *that* into another AST. The tools for both are mixed quality...
-
Demolishun34492116dWtf with downvoting this? The guy is venting. Must be getting a lot of redditors in here.
-
lorentz15200116dAh, the *python AST* is the bane of your existence. If it's any consolation, I'm pretty sure everyone who's parsing Python is suffering from it just as much. Utterly deranged grammar. There are natural languages that are easier to parse with a program than Python.
-
atheist9793116d@lorentz I have to say, astro (pylint's custom AST parser) is insanely good for my purpose. I gave up trying to use python's built in AST library, just a headache. I've got all docstrings extracted and now trying to parse restructured text. Which, honestly... Is worse...
There's the docstring_parser library which is insanely noncompliant with the standard.
There's docutils, which probably _is_ standards compliant but has zero type annotations and at best mediocre documentation for parsing.
There's sphinx which basically defines the standard. But I looked at the code, it's ugly as hell and it's overly complicated. But the standard can fit on a page or 2. So... I'm currently just writing a simple AST parser for it myself. Or at least parse the structural mark up.
This whole project started because I wanted something that would lint class attribute docstrings that are declared as string literals on the line after and couldn't find anything. "How hard could that be?!" Ahhh... So naive... -
retoor11393116dHow are docstrings nodes. My lexer skips all that. Or maybe they filter it on parser level. You don't want a comment trough your interpreter is guess
-
retoor11393116dI would've used regex to find function names and just from there copy docstring. Maybe you can even match group
-
lorentz15200116d@retoor I lex comments, then in the parsing stage keep them if they're on item level and discard them if they're inside expressions. That way you can look up the docstrings associated with a constant or namespace, but they don't complicate the expression level
-
lorentz15200116d@retoor in the built-in test runner, a test is a constant with the comment --[| test |]--
Abstract Syntax Trees are the bane of my existence.
rant