Closed bcr closed 1 year ago
I agree, it's very pedantic, but that's okay! If you want to submit this as a PR, I'm fine with it.
OK, my plan is to fix both. I'll try out an rstrip
also and see if you like that.
diff --git a/lark/tools/standalone.py b/lark/tools/standalone.py
index 87e9031..9684350 100644
--- a/lark/tools/standalone.py
+++ b/lark/tools/standalone.py
@@ -85,7 +85,7 @@ def extract_sections(lines):
else:
raise ValueError(line)
elif section:
- text.append(line)
+ text.append(line.rstrip())
return {name: ''.join(text) for name, text in sections.items()}
I'll make sure to at least try it first :)
Describe the bug
Using the standalone generator tool generates a module with trailing line whitespace that comes from trailing line whitespace in the Lark source code.
One suggestion is to trim trailing whitespace when emitting the module (handles the case where it may happen again.) Another is to change it in the source (but it might happen again.)
I can appreciate that this is a bit pedantic, I am prepared to post-process the output to remove whitespace.
To Reproduce
If you make the simplest grammar possible (
start:
) and generate a standalone module from it, there are lines that have trailing whitespace. These are included from various files. I have removed the whitespace and the generated module no longer has it.I can fork and open a PR if you want to make this change, but the diffs are straightforward and included below. I have tested this in my local environment and it worked.