Skip to content

Commit

Permalink
loosen parser verification for macro chapter
Browse files Browse the repository at this point in the history
  • Loading branch information
s-kybound committed Nov 3, 2024
1 parent 9c0f35d commit 3e7580a
Showing 1 changed file with 46 additions and 2 deletions.
48 changes: 46 additions & 2 deletions src/transpiler/parser/scheme-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,11 @@ export class SchemeParser implements Parser {
private parseNormalGroup(group: Group): Expression {
// it is an error if the group is empty in a normal context
if (group.length() === 0) {
if (this.chapter >= MACRO_CHAPTER) {
// disable any verification for the empty group
// the CSEP machine will verify its validity
return new Atomic.Nil(group.location);
}
throw new ParserError.ExpectedFormError(
this.source,
group.location.start,
Expand Down Expand Up @@ -887,6 +892,19 @@ export class SchemeParser implements Parser {
* @returns
*/
private parseLet(group: Group): Extended.Let {
if (this.chapter >= MACRO_CHAPTER) {
// disable any verification for the let expression
const groupItems = group.unwrap().slice(1);
groupItems.forEach(item => {
this.parseExpression(item);
});
return new Extended.Let(
group.location,
[],
[],
new Atomic.Identifier(group.location, "undefined")
);
}
// Form: (let ((<identifier> <value>)*) <body>+)
// ensure that the group has at least 3 elements
if (group.length() < 3) {
Expand Down Expand Up @@ -1003,6 +1021,19 @@ export class SchemeParser implements Parser {
* @returns
*/
private parseExtendedCond(group: Group): Extended.Cond {
if (this.chapter >= MACRO_CHAPTER) {
// disable any verification for the cond expression
const groupItems = group.unwrap().slice(1);
groupItems.forEach(item => {
this.parseExpression(item);
});
return new Extended.Cond(
group.location,
[],
[],
new Atomic.Identifier(group.location, "undefined")
);
}
// Form: (cond (<pred> <body>)*)
// | (cond (<pred> <body>)* (else <val>))
// ensure that the group has at least 2 elements
Expand Down Expand Up @@ -1248,6 +1279,17 @@ export class SchemeParser implements Parser {
* @returns
*/
private parseDelay(group: Group): Extended.Delay {
if (this.chapter >= MACRO_CHAPTER) {
// disable any verification for the delay expression
const groupItems = group.unwrap().slice(1);
groupItems.forEach(item => {
this.parseExpression(item);
});
return new Extended.Delay(
group.location,
new Atomic.Identifier(group.location, "undefined")
);
}
// Form: (delay <expr>)
// ensure that the group has 2 elements
if (group.length() !== 2) {
Expand Down Expand Up @@ -1439,7 +1481,8 @@ export class SchemeParser implements Parser {
pattern instanceof Atomic.Symbol ||
pattern instanceof Atomic.BooleanLiteral ||
pattern instanceof Atomic.NumericLiteral ||
pattern instanceof Atomic.StringLiteral
pattern instanceof Atomic.StringLiteral ||
pattern instanceof Atomic.Nil
) {
return true;
} else {
Expand Down Expand Up @@ -1524,7 +1567,8 @@ export class SchemeParser implements Parser {
template instanceof Atomic.Symbol ||
template instanceof Atomic.BooleanLiteral ||
template instanceof Atomic.NumericLiteral ||
template instanceof Atomic.StringLiteral
template instanceof Atomic.StringLiteral ||
template instanceof Atomic.Nil
) {
return true;
} else {
Expand Down

0 comments on commit 3e7580a

Please sign in to comment.