lark icon indicating copy to clipboard operation
lark copied to clipboard

A fix for black formatter breaking standalone parser generation.

Open marsninja opened this issue 2 years ago • 6 comments

Here lies a fix for Lark's standalone parser generation breaking when Lark is run through the black formatter. The fix simply entails stripping lines as they are iterated through in the extract_sections function in standlone.py.

marsninja avatar Nov 12 '23 14:11 marsninja

Closes #1362

marsninja avatar Nov 12 '23 14:11 marsninja

Or... You don't run black on this codebase, which in this case destroys information. I presume the problem is that black indents the comments, which is just wrong behavior since the comments do act on a global scope.

MegaIng avatar Nov 12 '23 14:11 MegaIng

@MegaIng Thats correct, the comments get tabbed in with black, however the strip fix appears to correct the issue for both Lark proper and standalone. Doesn't hurt to make the implementation more black friendly.

marsninja avatar Nov 13 '23 02:11 marsninja

@marsninja Why not just run black after the standalone has been generated?

erezsh avatar Nov 13 '23 04:11 erezsh

@MegaIng Thats correct, the comments get tabbed in with black, however the strip fix appears to correct the issue for both Lark proper and standalone. Doesn't hurt to make the implementation more black friendly.

Sure, it technically doesn't hurt. But it is extra code, and it allows something that currently isn't allowed, with good reasons. Having those comments be indented is confusing for human parsers, so it shouldn't be allowed. Considering the alternative solution to this "issue" is "just don't do the thing that breaks it, there is no reason to do it", I don't see why we should add this.

MegaIng avatar Nov 13 '23 15:11 MegaIng

@marsninja Please address the concerns of the maintainers, or I will close this PR. Thanks.

erezsh avatar Mar 29 '24 11:03 erezsh

Here is something

m42e avatar Jun 20 '24 05:06 m42e