diff --git a/TODO.md b/TODO.md index 9fa193dc..63e93d8a 100644 --- a/TODO.md +++ b/TODO.md @@ -1,5 +1,3 @@ -remove rule support - update to esmodule remove partech -- use hand write parser diff --git a/src/lang/evaluate/evaluate.ts b/src/lang/evaluate/evaluate.ts index 77c33840..47bc4b12 100644 --- a/src/lang/evaluate/evaluate.ts +++ b/src/lang/evaluate/evaluate.ts @@ -2,14 +2,13 @@ import * as Actions from "../actions" import { Caze } from "../caze" import type { Env } from "../env" import * as Errors from "../errors" -import { evaluateGoalExp, evaluateRuleExp } from "../evaluate" +import { evaluateGoalExp } from "../evaluate" import type { Exp } from "../exp" import { find } from "../find" import { freshen } from "../freshen" import type { Mod } from "../mod" import { quote } from "../quote" import { refresh, refreshGoals } from "../refresh" -import * as Rules from "../rule" import type { Value } from "../value" import * as Values from "../value" import { @@ -117,13 +116,6 @@ export function evaluate(mod: Mod, env: Env, exp: Exp): Value { return Values.fromArray(find(exp.limit, pattern, goals)) } - case "RuleList": { - return Values.Rule( - exp.name, - Rules.List(exp.rules.map((rule) => evaluateRuleExp(mod, env, rule))), - ) - } - case "And": { for (const arg of exp.exps) { const value = evaluate(mod, env, arg) diff --git a/src/lang/evaluate/evaluateRuleExp.ts b/src/lang/evaluate/evaluateRuleExp.ts deleted file mode 100644 index 0f0cf8fe..00000000 --- a/src/lang/evaluate/evaluateRuleExp.ts +++ /dev/null @@ -1,27 +0,0 @@ -import type { Env } from "../env" -import type { Mod } from "../mod" -import type { Rule } from "../rule" -import * as Rules from "../rule" -import type { RuleExp } from "../rule-exp" -import * as Values from "../value" -import { evaluate } from "./evaluate" - -export function evaluateRuleExp(mod: Mod, env: Env, rule: RuleExp): Rule { - switch (rule["@kind"]) { - case "Case": { - return Rules.Case(mod, env, rule.pattern, rule.stmts) - } - - case "List": { - return Rules.List( - rule.rules.map((rule) => evaluateRuleExp(mod, env, rule)), - ) - } - - case "Include": { - const value = evaluate(mod, env, rule.exp) - Values.assertValue(value, "Rule", { who: "evaluateRuleExp Use" }) - return Rules.List([value.rule]) - } - } -} diff --git a/src/lang/evaluate/index.ts b/src/lang/evaluate/index.ts index 8d655bc6..b3c46318 100644 --- a/src/lang/evaluate/index.ts +++ b/src/lang/evaluate/index.ts @@ -1,3 +1,2 @@ export * from "./evaluate" export * from "./evaluateGoalExp" -export * from "./evaluateRuleExp" diff --git a/src/lang/execute/execute.ts b/src/lang/execute/execute.ts index a3c28e81..a2f07062 100644 --- a/src/lang/execute/execute.ts +++ b/src/lang/execute/execute.ts @@ -1,11 +1,10 @@ import * as Errors from "../errors" -import { evaluate, evaluateRuleExp } from "../evaluate" +import { evaluate } from "../evaluate" import * as Exps from "../exp" import { formatExp, formatValue } from "../format" import { match } from "../match" import type { Mod } from "../mod" import { quote } from "../quote" -import * as Rules from "../rule" import type { Stmt } from "../stmt" import { ReturnValue } from "../stmt" import { @@ -68,20 +67,6 @@ export function execute(mod: Mod, stmt: Stmt): undefined | string { return } - case "Rule": { - mod.define( - stmt.name, - Values.Rule( - stmt.name, - Rules.List( - stmt.rules.map((rule) => evaluateRuleExp(mod, mod.env, rule)), - ), - ), - ) - - return - } - case "Import": { const importedMod = importMod(mod, stmt.path) for (const { name, alias } of stmt.bindings) { diff --git a/src/lang/exp/Exp.ts b/src/lang/exp/Exp.ts index 5a007049..68bf4304 100644 --- a/src/lang/exp/Exp.ts +++ b/src/lang/exp/Exp.ts @@ -1,5 +1,4 @@ import type { GoalExp } from "../goal-exp" -import type { RuleExp } from "../rule-exp" import type { Span } from "../span" import type { Stmt } from "../stmt" @@ -18,7 +17,6 @@ export type Exp = | Quote | Eval | Find - | RuleList | And | Or | Not @@ -262,28 +260,6 @@ export function Find( } } -export type RuleList = { - "@type": "Exp" - "@kind": "RuleList" - name: string | undefined - rules: Array - span: Span -} - -export function RuleList( - name: string | undefined, - rules: Array, - span: Span, -): RuleList { - return { - "@type": "Exp", - "@kind": "RuleList", - name, - rules, - span, - } -} - export type And = { "@type": "Exp" "@kind": "And" diff --git a/src/lang/format/formatExp.ts b/src/lang/format/formatExp.ts index d74ffe02..c3da9531 100644 --- a/src/lang/format/formatExp.ts +++ b/src/lang/format/formatExp.ts @@ -1,6 +1,6 @@ import { indent } from "../../utils/indent" import type { Exp } from "../exp" -import { formatGoalExp, formatRuleExp, formatStmt } from "../format" +import { formatGoalExp, formatStmt } from "../format" export function formatExp(exp: Exp): string { switch (exp["@kind"]) { @@ -88,11 +88,6 @@ export function formatExp(exp: Exp): string { )}\n}` } - case "RuleList": { - const rules = exp.rules.map(formatRuleExp) - return `rule {\n${indent(rules.join("\n"))}\n}` - } - case "And": { const exps = exp.exps.map((arg) => formatExp(arg)) return `and [${exps.join(", ")}]` diff --git a/src/lang/format/formatRule.ts b/src/lang/format/formatRule.ts deleted file mode 100644 index 1d9a1064..00000000 --- a/src/lang/format/formatRule.ts +++ /dev/null @@ -1,28 +0,0 @@ -import { indent } from "../../utils/indent" -import { formatExp, formatStmt } from "../format" -import type { Rule } from "../rule" - -export function formatRule(rule: Rule): string { - switch (rule["@kind"]) { - case "Case": { - const pattern = formatExp(rule.pattern) - - if (rule.stmts.length === 1 && rule.stmts[0]["@kind"] === "Return") { - const exp = formatExp(rule.stmts[0].exp) - return `${pattern} => ${exp}` - } - - const stmts = rule.stmts.map(formatStmt) - return `${pattern} => {\n${indent(stmts.join("\n"))}\n}` - } - - case "List": { - if (rule.rules.length === 0) { - return formatRule(rule.rules[0]) - } - - const rules = rule.rules.map(formatRule) - return `rule {\n${indent(rules.join("\n"))}\n}` - } - } -} diff --git a/src/lang/format/formatRuleExp.ts b/src/lang/format/formatRuleExp.ts deleted file mode 100644 index 755f98d7..00000000 --- a/src/lang/format/formatRuleExp.ts +++ /dev/null @@ -1,33 +0,0 @@ -import { indent } from "../../utils/indent" -import { formatExp, formatStmt } from "../format" -import type { RuleExp } from "../rule-exp" - -export function formatRuleExp(rule: RuleExp): string { - switch (rule["@kind"]) { - case "Case": { - const pattern = formatExp(rule.pattern) - - if (rule.stmts.length === 1 && rule.stmts[0]["@kind"] === "Return") { - const exp = formatExp(rule.stmts[0].exp) - return `${pattern} => ${exp}` - } - - const stmts = rule.stmts.map(formatStmt) - return `${pattern} => {\n${indent(stmts.join("\n"))}\n}` - } - - case "List": { - if (rule.rules.length === 0) { - return formatRuleExp(rule.rules[0]) - } - - const rules = rule.rules.map(formatRuleExp) - return `rule {\n${indent(rules.join("\n"))}\n}` - } - - case "Include": { - const exp = formatExp(rule.exp) - return `include ${exp}` - } - } -} diff --git a/src/lang/format/formatStmt.ts b/src/lang/format/formatStmt.ts index 76d10066..f98754b8 100644 --- a/src/lang/format/formatStmt.ts +++ b/src/lang/format/formatStmt.ts @@ -1,5 +1,5 @@ import { indent } from "../../utils/indent" -import { formatArgs, formatExp, formatGoalExp, formatRuleExp } from "../format" +import { formatArgs, formatExp, formatGoalExp } from "../format" import type { ImportBinding, Stmt } from "../stmt" export function formatStmt(stmt: Stmt): string { @@ -31,11 +31,6 @@ export function formatStmt(stmt: Stmt): string { )}\n}` } - case "Rule": { - const rules = stmt.rules.map(formatRuleExp) - return `rule ${stmt.name} {\n${indent(rules.join("\n"))}\n}` - } - case "Import": { const bindings = stmt.bindings.map(formatImportBinding) return `import { ${bindings.join(", ")} } from "${stmt.path}"` diff --git a/src/lang/format/formatValue.ts b/src/lang/format/formatValue.ts index 20c6b798..7bc69cfa 100644 --- a/src/lang/format/formatValue.ts +++ b/src/lang/format/formatValue.ts @@ -1,5 +1,5 @@ import { indent } from "../../utils/indent" -import { formatGoal, formatRule, formatStmt } from "../format" +import { formatGoal, formatStmt } from "../format" import type { Value } from "../value" export function formatValue(value: Value): string { @@ -69,10 +69,6 @@ export function formatValue(value: Value): string { return `$TypeConstraint(${value.name})` } - case "Rule": { - return `$Rule(${formatRule(value.rule)})` - } - case "Fn": { /** A function should be opaque (like in scheme), diff --git a/src/lang/format/index.ts b/src/lang/format/index.ts index 57afb73b..14559fff 100644 --- a/src/lang/format/index.ts +++ b/src/lang/format/index.ts @@ -1,7 +1,5 @@ export * from "./formatExp" export * from "./formatGoal" export * from "./formatGoalExp" -export * from "./formatRule" -export * from "./formatRuleExp" export * from "./formatStmt" export * from "./formatValue" diff --git a/src/lang/globals/aboutRule.ts b/src/lang/globals/aboutRule.ts deleted file mode 100644 index 8b6c048f..00000000 --- a/src/lang/globals/aboutRule.ts +++ /dev/null @@ -1,19 +0,0 @@ -import { rewrite, rewriteManySteps } from "../rewrite" -import * as Values from "../value" - -import type { GlobalStore } from "./GlobalStore" - -export function aboutRule(globals: GlobalStore): void { - globals.primitive("rewrite", 2, ([rule, target]) => { - Values.assertValue(rule, "Rule", { who: "rewrite" }) - return rewrite(rule.rule, target) - }) - - globals.primitive("rewriteManySteps", 3, ([limit, rule, target]) => { - Values.assertValue(limit, "Number", { who: "rewriteManySteps" }) - Values.assertValue(rule, "Rule", { who: "rewriteManySteps" }) - return Values.fromArray( - rewriteManySteps(rule.rule, target, { limit: limit.data }), - ) - }) -} diff --git a/src/lang/globals/useGlobals.ts b/src/lang/globals/useGlobals.ts index c8728e62..017bdd6a 100644 --- a/src/lang/globals/useGlobals.ts +++ b/src/lang/globals/useGlobals.ts @@ -6,7 +6,6 @@ import { aboutNull } from "./aboutNull" import { aboutNumber } from "./aboutNumber" import { aboutObject } from "./aboutObject" import { aboutRelation } from "./aboutRelation" -import { aboutRule } from "./aboutRule" import { aboutString } from "./aboutString" import { aboutTerm } from "./aboutTerm" import { GlobalStore } from "./GlobalStore" @@ -22,7 +21,6 @@ export function useGlobals(): GlobalStore { aboutGoal(globals) aboutRelation(globals) - aboutRule(globals) aboutNull(globals) aboutBoolean(globals) diff --git a/src/lang/quote/quote.ts b/src/lang/quote/quote.ts index df6175b6..e4471fc8 100644 --- a/src/lang/quote/quote.ts +++ b/src/lang/quote/quote.ts @@ -97,12 +97,6 @@ export function quote(mod: Mod, env: Env, exp: Exp): Value { }) } - case "RuleList": { - throw new Errors.LangError(`[quote] can not handle Exps.RuleList`, { - span: exp.span, - }) - } - case "And": { throw new Errors.LangError(`[quote] can not handle Exps.And`, { span: exp.span, diff --git a/src/lang/refresh/refresh.ts b/src/lang/refresh/refresh.ts index 51ebef70..038bccd8 100644 --- a/src/lang/refresh/refresh.ts +++ b/src/lang/refresh/refresh.ts @@ -68,7 +68,6 @@ export function refresh( case "Relation": case "TypeConstraint": - case "Rule": case "Fn": case "WithConstraints": case "Primitive": diff --git a/src/lang/rewrite/index.ts b/src/lang/rewrite/index.ts deleted file mode 100644 index 6dbae8ea..00000000 --- a/src/lang/rewrite/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from "./rewrite" -export * from "./rewriteManySteps" diff --git a/src/lang/rewrite/rewrite.ts b/src/lang/rewrite/rewrite.ts deleted file mode 100644 index 9a7bbaa2..00000000 --- a/src/lang/rewrite/rewrite.ts +++ /dev/null @@ -1,14 +0,0 @@ -import type { Rule } from "../rule" -import type { Value } from "../value" -import { rewriteOneStep } from "./rewriteOneStep" - -export function rewrite(rule: Rule, value: Value): Value { - while (true) { - const result = rewriteOneStep(rule, value) - if (result === undefined) { - return value - } - - value = result - } -} diff --git a/src/lang/rewrite/rewriteManySteps.ts b/src/lang/rewrite/rewriteManySteps.ts deleted file mode 100644 index b03dcf61..00000000 --- a/src/lang/rewrite/rewriteManySteps.ts +++ /dev/null @@ -1,22 +0,0 @@ -import type { Rule } from "../rule" -import type { Value } from "../value" -import { rewriteOneStep } from "./rewriteOneStep" - -export function rewriteManySteps( - rule: Rule, - value: Value, - options: { limit: number }, -): Array { - const results = [value] - while (results.length < options.limit) { - const result = rewriteOneStep(rule, value) - if (result === undefined) { - return results - } - - results.push(result) - value = result - } - - return results -} diff --git a/src/lang/rewrite/rewriteOnePlace.ts b/src/lang/rewrite/rewriteOnePlace.ts deleted file mode 100644 index 1a40a154..00000000 --- a/src/lang/rewrite/rewriteOnePlace.ts +++ /dev/null @@ -1,46 +0,0 @@ -import { catchReturnValue } from "../actions/catchReturnValue" -import { defineRenames } from "../actions/defineRenames" -import { envMerge } from "../env" -import { match } from "../match" -import { quote } from "../quote" -import { refresh } from "../refresh" -import type { Rule } from "../rule" -import { substitutionDeepWalk, substitutionEmpty } from "../substitution" -import type { Value } from "../value" - -export function rewriteOnePlace(rule: Rule, value: Value): Value | undefined { - switch (rule["@kind"]) { - case "Case": { - const mod = rule.mod.copy() - mod.env = envMerge(mod.env, rule.env) - - const renames = new Map() - const pattern = refresh(renames, quote(mod, mod.env, rule.pattern)) - const substitution = match(substitutionEmpty(), pattern, value) - - if (substitution === undefined) { - return undefined - } - - defineRenames(mod, renames, substitution) - const returnValue = catchReturnValue(mod, rule.stmts) - - if (returnValue["@kind"] === "Null") { - return undefined - } - - return substitutionDeepWalk(substitution, refresh(renames, returnValue)) - } - - case "List": { - for (const subRule of rule.rules) { - const result = rewriteOnePlace(subRule, value) - if (result !== undefined) { - return result - } - } - - return undefined - } - } -} diff --git a/src/lang/rewrite/rewriteOneStep.ts b/src/lang/rewrite/rewriteOneStep.ts deleted file mode 100644 index b5879d08..00000000 --- a/src/lang/rewrite/rewriteOneStep.ts +++ /dev/null @@ -1,82 +0,0 @@ -import type { Rule } from "../rule" -import type { Value } from "../value" -import * as Values from "../value" -import { rewriteOnePlace } from "./rewriteOnePlace" - -export function rewriteOneStep(rule: Rule, value: Value): Value | undefined { - const result = rewriteOnePlace(rule, value) - if (result !== undefined) { - return result - } - - switch (value["@kind"]) { - case "PatternVar": - case "ReifiedVar": - case "String": - case "Number": - case "Boolean": - case "Null": { - return undefined - } - - case "ArrayCons": { - const car = rewriteOneStep(rule, value.car) - if (car !== undefined) { - return Values.ArrayCons(car, value.cdr) - } - - const cdr = rewriteOneStep(rule, value.cdr) - if (cdr !== undefined) { - return Values.ArrayCons(value.car, cdr) - } - - return undefined - } - - case "ArrayNull": { - return undefined - } - - case "Objekt": { - for (const [name, property] of Object.entries(value.properties)) { - const result = rewriteOneStep(rule, property) - if (result !== undefined) { - return Values.Objekt( - { ...value.properties, [name]: result }, - value.etc, - ) - } - } - - if (value.etc !== undefined) { - const etc = rewriteOneStep(rule, value.etc) - if (etc !== undefined) { - return Values.Objekt(value.properties, etc) - } - } - - return undefined - } - - case "Term": { - for (const [index, arg] of value.args.entries()) { - const result = rewriteOneStep(rule, arg) - if (result !== undefined) { - return Values.Term(value.name, [ - ...value.args.slice(0, index), - result, - ...value.args.slice(index + 1), - ]) - } - } - - return undefined - } - - case "Relation": - case "TypeConstraint": - case "Rule": { - return undefined - } - } -} diff --git a/src/lang/rule-exp/RuleExp.ts b/src/lang/rule-exp/RuleExp.ts deleted file mode 100644 index 3b8d5458..00000000 --- a/src/lang/rule-exp/RuleExp.ts +++ /dev/null @@ -1,55 +0,0 @@ -import type { Exp } from "../exp" -import type { Span } from "../span" -import type { Stmt } from "../stmt" - -export type RuleExp = Case | List | Include - -export type Case = { - "@type": "RuleExp" - "@kind": "Case" - pattern: Exp - stmts: Array - span: Span -} - -export function Case(pattern: Exp, stmts: Array, span: Span): Case { - return { - "@type": "RuleExp", - "@kind": "Case", - pattern, - stmts, - span, - } -} - -export type List = { - "@type": "RuleExp" - "@kind": "List" - rules: Array - span: Span -} - -export function List(rules: Array, span: Span): List { - return { - "@type": "RuleExp", - "@kind": "List", - rules, - span, - } -} - -export type Include = { - "@type": "RuleExp" - "@kind": "Include" - exp: Exp - span: Span -} - -export function Include(exp: Exp, span: Span): Include { - return { - "@type": "RuleExp", - "@kind": "Include", - exp, - span, - } -} diff --git a/src/lang/rule-exp/index.ts b/src/lang/rule-exp/index.ts deleted file mode 100644 index 82bcf58e..00000000 --- a/src/lang/rule-exp/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./RuleExp" diff --git a/src/lang/rule/Rule.ts b/src/lang/rule/Rule.ts deleted file mode 100644 index 272edce1..00000000 --- a/src/lang/rule/Rule.ts +++ /dev/null @@ -1,45 +0,0 @@ -import type { Env } from "../env" -import type { Exp } from "../exp" -import type { Mod } from "../mod" -import type { Stmt } from "../stmt" - -export type Rule = Case | List - -export type Case = { - "@type": "Rule" - "@kind": "Case" - mod: Mod - env: Env - pattern: Exp - stmts: Array -} - -export function Case( - mod: Mod, - env: Env, - pattern: Exp, - stmts: Array, -): Case { - return { - "@type": "Rule", - "@kind": "Case", - mod, - env, - pattern, - stmts, - } -} - -export type List = { - "@type": "Rule" - "@kind": "List" - rules: Array -} - -export function List(rules: Array): List { - return { - "@type": "Rule", - "@kind": "List", - rules, - } -} diff --git a/src/lang/rule/index.ts b/src/lang/rule/index.ts deleted file mode 100644 index 8aeeb72c..00000000 --- a/src/lang/rule/index.ts +++ /dev/null @@ -1 +0,0 @@ -export * from "./Rule" diff --git a/src/lang/stmt/Stmt.ts b/src/lang/stmt/Stmt.ts index 570006e2..19d95d09 100644 --- a/src/lang/stmt/Stmt.ts +++ b/src/lang/stmt/Stmt.ts @@ -2,7 +2,6 @@ import * as Errors from "../errors" import type { Exp } from "../exp" import { formatValue } from "../format" import type { GoalExp } from "../goal-exp" -import type { RuleExp } from "../rule-exp" import type { Span } from "../span" import type { Value } from "../value" @@ -10,7 +9,6 @@ export type Stmt = | Clause | Let | Fn - | Rule | Import | ImportAll | ImportAllAs @@ -93,24 +91,6 @@ export function Fn( } } -export type Rule = { - "@type": "Stmt" - "@kind": "Rule" - name: string - rules: Array - span: Span -} - -export function Rule(name: string, rules: Array, span: Span): Rule { - return { - "@type": "Stmt", - "@kind": "Rule", - name, - rules, - span, - } -} - export type ImportBinding = { name: string alias?: string diff --git a/src/lang/substitution/substitutionContainsPatternVarInValue.ts b/src/lang/substitution/substitutionContainsPatternVarInValue.ts index 0e86b35d..ccbda090 100644 --- a/src/lang/substitution/substitutionContainsPatternVarInValue.ts +++ b/src/lang/substitution/substitutionContainsPatternVarInValue.ts @@ -60,10 +60,6 @@ export function substitutionContainsPatternVarInValue( return false } - case "Rule": { - return false - } - case "Fn": { return false } diff --git a/src/lang/syntax/grammars/exp.ts b/src/lang/syntax/grammars/exp.ts index 9773bf5f..249c1cec 100644 --- a/src/lang/syntax/grammars/exp.ts +++ b/src/lang/syntax/grammars/exp.ts @@ -68,14 +68,6 @@ export const operand = { { goals: "goals" }, '"}"', ], - "operand:rule_list": [ - '"rule"', - { name: "variable_name" }, - '"{"', - { rules: "rules" }, - '"}"', - ], - "operand:rule_list_nameless": ['"rule"', '"{"', { rules: "rules" }, '"}"'], "operand:and": [ '"and"', '"["', diff --git a/src/lang/syntax/grammars/index.ts b/src/lang/syntax/grammars/index.ts index 5cb98a50..bc48554f 100644 --- a/src/lang/syntax/grammars/index.ts +++ b/src/lang/syntax/grammars/index.ts @@ -14,5 +14,4 @@ export * from "./import_binding" export * from "./key" export * from "./name" export * from "./property" -export * from "./rule" export * from "./stmt" diff --git a/src/lang/syntax/grammars/rule.ts b/src/lang/syntax/grammars/rule.ts deleted file mode 100644 index a9d3b88d..00000000 --- a/src/lang/syntax/grammars/rule.ts +++ /dev/null @@ -1,20 +0,0 @@ -export const rule = { - $grammar: { - "rule:case": [ - { pattern: "exp" }, - '"="', - '">"', - '"{"', - { stmts: "stmts" }, - '"}"', - ], - "rule:case_with_exp": [{ pattern: "exp" }, '"="', '">"', { exp: "exp" }], - "rule:include": ['"include"', { exp: "exp" }], - }, -} - -export const rules = { - $grammar: { - "rules:rules": [{ rules: { $ap: ["zero_or_more", "rule"] } }], - }, -} diff --git a/src/lang/syntax/grammars/stmt.ts b/src/lang/syntax/grammars/stmt.ts index 126fb237..984e1635 100644 --- a/src/lang/syntax/grammars/stmt.ts +++ b/src/lang/syntax/grammars/stmt.ts @@ -60,13 +60,6 @@ export const stmt = { { names: "variable_names" }, '"}"', ], - "stmt:rule": [ - '"rule"', - { name: "variable_name" }, - '"{"', - { rules: "rules" }, - '"}"', - ], "stmt:let": ['"let"', { pattern: "exp" }, '"="', { exp: "exp" }], "stmt:print": ['"print"', { exp: "exp" }], "stmt:compute": ['"compute"', { exp: "exp" }], diff --git a/src/lang/syntax/matchers/exp_matcher.ts b/src/lang/syntax/matchers/exp_matcher.ts index 3e995b42..ed7a756f 100644 --- a/src/lang/syntax/matchers/exp_matcher.ts +++ b/src/lang/syntax/matchers/exp_matcher.ts @@ -98,10 +98,6 @@ export function operand_matcher(tree: pt.Tree): Exp { span, ) }, - "operand:rule_list": ({ name, rules }, { span }) => - Exps.RuleList(pt.str(name), matchers.rules_matcher(rules), span), - "operand:rule_list_nameless": ({ rules }, { span }) => - Exps.RuleList(undefined, matchers.rules_matcher(rules), span), "operand:and": ({ elements, last_element }, { span }) => Exps.And( [ diff --git a/src/lang/syntax/matchers/index.ts b/src/lang/syntax/matchers/index.ts index 6135a6d1..a3174a2a 100644 --- a/src/lang/syntax/matchers/index.ts +++ b/src/lang/syntax/matchers/index.ts @@ -7,5 +7,4 @@ export * from "./import_binding_matcher" export * from "./key_matcher" export * from "./name_matcher" export * from "./property_matcher" -export * from "./rule_matcher" export * from "./stmt_matcher" diff --git a/src/lang/syntax/matchers/rule_matcher.ts b/src/lang/syntax/matchers/rule_matcher.ts deleted file mode 100644 index 5f5581ba..00000000 --- a/src/lang/syntax/matchers/rule_matcher.ts +++ /dev/null @@ -1,31 +0,0 @@ -import * as pt from "@cicada-lang/partech" -import type { RuleExp } from "../../rule-exp" -import * as RuleExps from "../../rule-exp" -import * as Stmts from "../../stmt" -import * as matchers from "./index" - -export function rule_matcher(tree: pt.Tree): RuleExp { - return pt.matcher({ - "rule:case": ({ pattern, stmts }, { span }) => - RuleExps.Case( - matchers.exp_matcher(pattern), - matchers.stmts_matcher(stmts), - span, - ), - "rule:case_with_exp": ({ pattern, exp }, { span }) => - RuleExps.Case( - matchers.exp_matcher(pattern), - [Stmts.Return(matchers.exp_matcher(exp), span)], - span, - ), - "rule:include": ({ exp }, { span }) => - RuleExps.Include(matchers.exp_matcher(exp), span), - })(tree) -} - -export function rules_matcher(tree: pt.Tree): Array { - return pt.matcher({ - "rules:rules": ({ rules }) => - pt.matchers.zero_or_more_matcher(rules).map(rule_matcher), - })(tree) -} diff --git a/src/lang/syntax/matchers/stmt_matcher.ts b/src/lang/syntax/matchers/stmt_matcher.ts index 7f8e0375..df4474e9 100644 --- a/src/lang/syntax/matchers/stmt_matcher.ts +++ b/src/lang/syntax/matchers/stmt_matcher.ts @@ -54,8 +54,6 @@ export function stmt_matcher(tree: pt.Tree): Stmt { Stmts.Export(matchers.stmt_matcher(stmt), span), "stmt:export_names": ({ names }, { span }) => Stmts.ExportNames(matchers.variable_names_matcher(names), span), - "stmt:rule": ({ name, rules }, { span }) => - Stmts.Rule(pt.str(name), matchers.rules_matcher(rules), span), "stmt:let": ({ pattern, exp }, { span }) => Stmts.Let(matchers.exp_matcher(pattern), matchers.exp_matcher(exp), span), "stmt:print": ({ exp }, { span }) => diff --git a/src/lang/value/Value.ts b/src/lang/value/Value.ts index ad9a53af..7764de16 100644 --- a/src/lang/value/Value.ts +++ b/src/lang/value/Value.ts @@ -2,7 +2,6 @@ import type { Clause } from "../clause" import type { Env } from "../env" import type { Goal as EmbeddedGoal } from "../goal" import type { Mod } from "../mod" -import type { Rule as EmbeddedRule } from "../rule" import type { Solution as EmbeddedSolution } from "../solution" import type { Stmt } from "../stmt" @@ -19,7 +18,6 @@ export type Value = | Term | Relation | TypeConstraint - | Rule | Fn | WithConstraints | Primitive @@ -213,22 +211,6 @@ export function TypeConstraint( } } -export type Rule = { - "@type": "Value" - "@kind": "Rule" - name: string | undefined - rule: EmbeddedRule -} - -export function Rule(name: string | undefined, rule: EmbeddedRule): Rule { - return { - "@type": "Value", - "@kind": "Rule", - name, - rule, - } -} - /** `Values.Fn` has both `env` and `mod` diff --git a/src/lang/var-collection/varCollectionFromExp.ts b/src/lang/var-collection/varCollectionFromExp.ts index d44da830..c619663b 100644 --- a/src/lang/var-collection/varCollectionFromExp.ts +++ b/src/lang/var-collection/varCollectionFromExp.ts @@ -60,10 +60,6 @@ export function varCollectionFromExp(exp: Exp): VarCollection { return createVarCollection() } - case "RuleList": { - return createVarCollection() - } - case "And": { return createVarCollection() }