Skip to content

Commit

Permalink
remove rule support
Browse files Browse the repository at this point in the history
  • Loading branch information
xieyuheng committed Apr 21, 2024
1 parent 1800be7 commit 7114505
Show file tree
Hide file tree
Showing 37 changed files with 5 additions and 575 deletions.
2 changes: 0 additions & 2 deletions TODO.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
remove rule support

update to esmodule

remove partech -- use hand write parser
Expand Down
10 changes: 1 addition & 9 deletions src/lang/evaluate/evaluate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
27 changes: 0 additions & 27 deletions src/lang/evaluate/evaluateRuleExp.ts

This file was deleted.

1 change: 0 additions & 1 deletion src/lang/evaluate/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export * from "./evaluate"
export * from "./evaluateGoalExp"
export * from "./evaluateRuleExp"
17 changes: 1 addition & 16 deletions src/lang/execute/execute.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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) {
Expand Down
24 changes: 0 additions & 24 deletions src/lang/exp/Exp.ts
Original file line number Diff line number Diff line change
@@ -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"

Expand All @@ -18,7 +17,6 @@ export type Exp =
| Quote
| Eval
| Find
| RuleList
| And
| Or
| Not
Expand Down Expand Up @@ -262,28 +260,6 @@ export function Find(
}
}

export type RuleList = {
"@type": "Exp"
"@kind": "RuleList"
name: string | undefined
rules: Array<RuleExp>
span: Span
}

export function RuleList(
name: string | undefined,
rules: Array<RuleExp>,
span: Span,
): RuleList {
return {
"@type": "Exp",
"@kind": "RuleList",
name,
rules,
span,
}
}

export type And = {
"@type": "Exp"
"@kind": "And"
Expand Down
7 changes: 1 addition & 6 deletions src/lang/format/formatExp.ts
Original file line number Diff line number Diff line change
@@ -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"]) {
Expand Down Expand Up @@ -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(", ")}]`
Expand Down
28 changes: 0 additions & 28 deletions src/lang/format/formatRule.ts

This file was deleted.

33 changes: 0 additions & 33 deletions src/lang/format/formatRuleExp.ts

This file was deleted.

7 changes: 1 addition & 6 deletions src/lang/format/formatStmt.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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}"`
Expand Down
6 changes: 1 addition & 5 deletions src/lang/format/formatValue.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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),
Expand Down
2 changes: 0 additions & 2 deletions src/lang/format/index.ts
Original file line number Diff line number Diff line change
@@ -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"
19 changes: 0 additions & 19 deletions src/lang/globals/aboutRule.ts

This file was deleted.

2 changes: 0 additions & 2 deletions src/lang/globals/useGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -22,7 +21,6 @@ export function useGlobals(): GlobalStore {

aboutGoal(globals)
aboutRelation(globals)
aboutRule(globals)

aboutNull(globals)
aboutBoolean(globals)
Expand Down
6 changes: 0 additions & 6 deletions src/lang/quote/quote.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
1 change: 0 additions & 1 deletion src/lang/refresh/refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,6 @@ export function refresh(

case "Relation":
case "TypeConstraint":
case "Rule":
case "Fn":
case "WithConstraints":
case "Primitive":
Expand Down
2 changes: 0 additions & 2 deletions src/lang/rewrite/index.ts

This file was deleted.

14 changes: 0 additions & 14 deletions src/lang/rewrite/rewrite.ts

This file was deleted.

22 changes: 0 additions & 22 deletions src/lang/rewrite/rewriteManySteps.ts

This file was deleted.

Loading

0 comments on commit 7114505

Please sign in to comment.