openscad-parser 2.4.7__tar.gz → 2.4.8__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: openscad_parser
3
- Version: 2.4.7
3
+ Version: 2.4.8
4
4
  Summary: A PEG parser to read OpenSCAD language source code, with optional AST tree generation.
5
5
  Keywords: openscad,openscad parser,parser
6
6
  Author: Revar Desmera
@@ -4,7 +4,7 @@ build-backend = "uv_build"
4
4
 
5
5
  [project]
6
6
  name = "openscad_parser"
7
- version = "2.4.7"
7
+ version = "2.4.8"
8
8
  description = "A PEG parser to read OpenSCAD language source code, with optional AST tree generation."
9
9
  readme = "README.rst"
10
10
  authors = [
@@ -47,7 +47,27 @@ def to_openscad(nodes: list[ASTNode], indent_width: int = 4) -> str:
47
47
  parts.append("")
48
48
  parts.append(_fmt_node(node, 0, indent_width))
49
49
  prev_complex = is_complex
50
- return "\n".join(parts)
50
+ return _coalesce_paren_bracket("\n".join(parts))
51
+
52
+
53
+ def _coalesce_paren_bracket(text: str) -> str:
54
+ """Join consecutive lines where one is a bare ')' and the next starts with '['."""
55
+ lines = text.split("\n")
56
+ result = []
57
+ i = 0
58
+ while i < len(lines):
59
+ if (
60
+ i + 1 < len(lines)
61
+ and lines[i].strip() == ")"
62
+ and lines[i + 1].lstrip().startswith("[")
63
+ ):
64
+ indent = len(lines[i]) - len(lines[i].lstrip())
65
+ result.append(" " * indent + ") " + lines[i + 1].lstrip())
66
+ i += 2
67
+ else:
68
+ result.append(lines[i])
69
+ i += 1
70
+ return "\n".join(result)
51
71
 
52
72
 
53
73
  # Line length beyond which call arguments are formatted one-per-line.