(code: string)
| 1077 | } |
| 1078 | |
| 1079 | export function parseBasic2(code: string): TermForBasic2 { |
| 1080 | function conv(node: Term): Term { |
| 1081 | switch (node.tag) { |
| 1082 | case "if": |
| 1083 | return { tag: "if", cond: conv(node.cond), thn: conv(node.thn), els: conv(node.els), loc: node.loc }; |
| 1084 | case "add": |
| 1085 | return { tag: "add", left: conv(node.left), right: conv(node.right), loc: node.loc }; |
| 1086 | case "func": |
| 1087 | return { tag: "func", params: node.params, body: conv(node.body), loc: node.loc }; |
| 1088 | case "call": |
| 1089 | return { tag: "call", func: conv(node.func), args: node.args.map(conv), loc: node.loc }; |
| 1090 | case "seq": |
| 1091 | case "const": { |
| 1092 | const body: Term[] = []; |
| 1093 | while (true) { |
| 1094 | switch (node.tag) { |
| 1095 | case "seq": { |
| 1096 | body.push(conv(node.body)); |
| 1097 | node = node.rest; |
| 1098 | break; |
| 1099 | } |
| 1100 | case "const": { |
| 1101 | body.push({ tag: "const2", name: node.name, init: conv(node.init), loc: node.loc }); |
| 1102 | node = node.rest; |
| 1103 | break; |
| 1104 | } |
| 1105 | default: { |
| 1106 | body.push(conv(node)); |
| 1107 | return { tag: "seq2", body, loc: node.loc }; |
| 1108 | } |
| 1109 | } |
| 1110 | } |
| 1111 | } |
| 1112 | default: |
| 1113 | return node; |
| 1114 | } |
| 1115 | } |
| 1116 | return subsetSystem( |
| 1117 | conv(parse(code)), |
| 1118 | ["Boolean", "Number", "Func"], |
| 1119 | ["true", "false", "if", "number", "add", "var", "func", "call", "seq2", "const2"], |
| 1120 | ); |
| 1121 | } |
| 1122 | |
| 1123 | export function parseObj(code: string): TermForObj { |
| 1124 | return subsetSystem( |
no test coverage detected