Skip to content

Commit

Permalink
fix: formatting should allow statements between proc python and submit (
Browse files Browse the repository at this point in the history
  • Loading branch information
scnwwu authored Oct 11, 2024
1 parent 4e61203 commit febab0a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
8 changes: 8 additions & 0 deletions client/testFixture/formatter/expected.sas
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,11 @@ submit;
end
endsubmit;
run;

proc python;
/* comment */
i;
print('hello')
endinteractive;
/* comment */
run;
8 changes: 8 additions & 0 deletions client/testFixture/formatter/unformatted.sas
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,12 @@ submit;
end
end
endsubmit;
run;

proc python;
/* comment */
i;
print('hello')
endinteractive;
/* comment */
run;
11 changes: 7 additions & 4 deletions server/src/sas/formatter/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,19 @@ const preserveProcs = (
model: Model,
) => {
// should not format python/lua, treat it as raw data
const lastStatement =
region.children.length >= 2 &&
region.children[region.children.length - 1].children;
if (
current === -1 &&
region.block?.name === "PROC" &&
region.children.length === 2 &&
lastStatement &&
region.children[0].children.length > 0 &&
region.children[1].children.length > 1 &&
lastStatement.length > 1 &&
"text" in region.children[0].children[1] &&
/^(python|lua)$/i.test(region.children[0].children[1].text) &&
"text" in region.children[1].children[0] &&
/^(submit|interactive)$/i.test(region.children[1].children[0].text)
"text" in lastStatement[0] &&
/^(submit|interactive|i)$/i.test(lastStatement[0].text)
) {
current = 0;
}
Expand Down

0 comments on commit febab0a

Please sign in to comment.