8000 Fixed unhandled trailing comment in multiline list for OpenSCAD by mkatychev · Pull Request #972 · tweag/topiary · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Fixed unhandled trailing comment in multiline list for OpenSCAD #972

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 9 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ This name should be decided amongst the team before the release.
- [#908](https://github.com/tweag/topiary/pull/908) [#907](https://github.com/tweag/topiary/pull/907) [#939](https://github.com/tweag/topiary/pull/939) [#955](https://github.com/tweag/topiary/pull/955) [#964](https://github.com/tweag/topiary/pull/964) [#967](https://github.com/tweag/to 10000 piary/pull/967) [#975](https://github.com/tweag/topiary/pull/975) Various OCaml issues and improvements
- [#953](https://github.com/tweag/topiary/pull/953) Coverage output when there are zero queries
- [#974](https://github.com/tweag/topiary/pull/974) No longer remove trailing spaces after pretty-printing
- [#867](https://github.com/tweag/topiary/pull/972) Fixed [#969](https://github.com/tweag/topiary/issues/969) unhandled trailing comment in multiline list for OpenSCAD, thanks to @mkatychev

<!-- ### Security -->
<!-- - <Vulnerabilities> -->
Expand Down
18 changes: 18 additions & 0 deletions topiary-cli/tests/samples/expected/openscad.scad
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,24 @@ module my_cylinder() {
cube();
}

list1 = [
1,
2, // comment
];

list2 = [
1,
2, /* block comment */
];
arguments1 = foo(
1,
(point2[1] - point1[1]) / (point2[0] - point1[0]), // comment
);
arguments2 = foo(
1,
2, // comment
);

// ================================================================================
// Modifiers
// ================================================================================
Expand Down
15 changes: 15 additions & 0 deletions topiary-cli/tests/samples/input/openscad.scad
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,20 @@ module my_cylinder() {
cube();
}

list1 = [
1,
2 // comment
];

list2 = [
1, 2 /* block comment */ ];
arguments1= foo(1,
(point2[1] - point1[1]) / (point2[0] - point1[0]) // comment
);
arguments2= foo(1,
2 , // comment
);

// ================================================================================
// Modifiers
// ================================================================================
8000 Expand Down Expand Up @@ -130,6 +144,7 @@ fn = function(x) echo("this is x") x;
echo(fn ? "truthy" : "falsey");
echo(function(y) y ? "first" : "second");


// ================================================================================
// Lists/Ternaries
// ================================================================================
Expand Down
22 changes: 13 additions & 9 deletions topiary-queries/queries/openscad.scm
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"="
"?"
":"
(parenthesized_expression)
(assignments)
((parenthesized_expression) . _)
] @prepend_space @append_space

; Colon should have whitespace trimmed in a range delimiter
Expand Down Expand Up @@ -94,6 +94,7 @@
"else"
(block_comment)
(line_comment)
";"
]* @do_nothing
)

Expand Down Expand Up @@ -135,14 +136,15 @@
"[" @append_antispace
"]" @prepend_antispace
)
(list "," @append_spaced_softline . [(block_comment) (line_comment)]* @do_nothing)
(assignments "," @append_spaced_softline . [(block_comment) (line_comment)]* @do_nothing)
(parameters "," @append_spaced_softline . [(block_comment) (line_comment)]* @do_nothing)
(";" @append_spaced_softline . [(block_comment) (line_comment)]* @do_nothing)

; Never put a space before a comma
("," @prepend_antispace)
(";" @prepend_antispace)
[
","
";"
] @prepend_antispace

; Don't insert spaces between the operator and their expression operand
; '-x' v.s. '- x'
Expand Down Expand Up @@ -210,7 +212,7 @@
.
","? @do_nothing
.
(line_comment)*
[(block_comment) (line_comment)]*
.
")"
.
Expand All @@ -223,7 +225,6 @@
.
)
(assignments "," @delete . ")" . (#single_line_only!))
(assignments "," @append_spaced_softline)

(arguments "," @append_input_softline)
(arguments "," @delete . ")" . (#single_line_only!))
Expand All @@ -235,11 +236,11 @@
)
(arguments
(#delimiter! ",")
(_) @append_delimiter
(expression) @append_delimiter
.
","? @do_nothing
.
(line_comment)*
[(block_comment) (line_comment)]*
.
")"
.
Expand All @@ -264,14 +265,17 @@
(list "," @delete . "]" . (#single_line_only!))
(list
(#delimiter! ",")
(_) @append_delimiter
[(expression) (list_comprehension)] @append_delimiter
.
","? @do_nothing
.
[(block_comment) (line_comment)]*
.
"]"
.
(#multi_line_only!)
)
(list "," @append_spaced_softline . [(block_comment) (line_comment)]* @do_nothing)

; differentiate parameter definitions from parameter invocation,
; module/function definitions have param separation while
Expand Down
0