Skip to content

Commit

Permalink
dropped predefined_type ast and removed mutation from arrow_function …
Browse files Browse the repository at this point in the history
…parser
  • Loading branch information
azizghuloum committed Nov 26, 2024
1 parent d22b9ae commit b1ac102
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 16 deletions.
2 changes: 0 additions & 2 deletions src/AST.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ export type list_tag =
| "type_alias_declaration"
| "type_annotation"
| "property_signature"
| "predefined_type"
| "literal_type"
| "tuple_type"
| "pair"
Expand Down Expand Up @@ -78,7 +77,6 @@ export const list_tags: { [k in list_tag]: list_tag } = {
type_alias_declaration: "type_alias_declaration",
type_annotation: "type_annotation",
property_signature: "property_signature",
predefined_type: "predefined_type",
literal_type: "literal_type",
tuple_type: "tuple_type",
pair: "pair",
Expand Down
36 changes: 22 additions & 14 deletions src/parser-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,22 @@ function absurdly(node: Parser.SyntaxNode): AST {
return {
type: "list",
tag: "ERROR",
wrap: undefined,
content: array_to_ll(ls),
};
}
}
case "predefined_type": {
if (ls.length === 1) {
return ls[0];
} else {
throw new Error("predefined_type with more/less than one form");
}
}
case "required_parameter": {
if (ls.length === 1) {
return ls[0];
} else {
return { type: "list", tag: "required_parameter", content: array_to_ll(ls) };
return { type: "list", tag: node.type, content: array_to_ll(ls) };
}
}
case "union_type": {
Expand All @@ -83,18 +89,20 @@ function absurdly(node: Parser.SyntaxNode): AST {
}
case "arrow_function": {
if (ls.length === 3) {
const fmls = ls[0];
if (fmls.type === "atom" && fmls.tag === "identifier") {
// const lparen: AST = { type: "atom", tag: "other", content: "(" };
// const rparen: AST = { type: "atom", tag: "other", content: ")" };
const rfmls: AST = {
type: "list",
tag: "formal_parameters",
content: array_to_ll([fmls]),
};
ls[0] = rfmls;
}
assert(ls[0].type === "list");
const [fmls, arrow, body] = ls;
const new_fmls: AST =
fmls.type === "atom" && fmls.tag === "identifier"
? {
type: "list",
tag: "formal_parameters",
content: array_to_ll([fmls]),
}
: fmls;
return {
type: "list",
tag: "arrow_function",
content: [new_fmls, [arrow, [body, null]]],
};
} else {
return {
type: "list",
Expand Down

0 comments on commit b1ac102

Please sign in to comment.