Skip to content

Commit 031b7e6

Browse files
committed
format the entire "rest of the program" into a single "rest element"
1 parent dcd5f06 commit 031b7e6

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

src/transpiler/parser/scheme-parser.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1462,6 +1462,23 @@ export class SchemeParser implements Parser {
14621462
const sexprElements = this.parse(true);
14631463
// then take the rest of the top level elements (total - n) from the restElements.
14641464
const restElements = sexprElements.slice(numImports);
1465+
1466+
// It would be convenient to map the entire restElements to a single sequence, using begin.
1467+
// We should accomodate for an empty restElements array (leave as is),
1468+
// a single element (leave as is),
1469+
// and multiple elements (wrap in begin, represented as a list).
1470+
const finalRestElements =
1471+
restElements.length === 0
1472+
? restElements
1473+
: restElements.length === 1
1474+
? restElements
1475+
: [
1476+
new Extended.List(restElements[0].location, [
1477+
new Atomic.Symbol(restElements[0].location, "begin"),
1478+
...restElements,
1479+
]),
1480+
];
1481+
14651482
// add the imports to the restElements
14661483
const finalElements = importElements.concat(restElements);
14671484

0 commit comments

Comments
 (0)