diff --git a/src/index.ts b/src/index.ts index 0a9e1967..c99bfdc4 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,4 +1,5 @@ export * from "./fetcher" +export * from "./lang/definition" export * from "./lang/errors" export * from "./lang/mod" export * from "./lang/net" diff --git a/src/lang/mod/Mod.ts b/src/lang/mod/Mod.ts index 89a52d81..f0ad00f7 100644 --- a/src/lang/mod/Mod.ts +++ b/src/lang/mod/Mod.ts @@ -2,8 +2,8 @@ import { Loader } from "../../loader" import { Checking } from "../checking" import { Definition } from "../definition" import { Env } from "../env/Env.js" -import { Rule } from "../rule" import { Stmt } from "../stmt/Stmt.js" +import { RuleEntry } from "./RuleEntry" export type Mod = { loader: Loader @@ -13,6 +13,6 @@ export type Mod = { text: string stmts: Array definitions: Map - rules: Map + ruleEntries: Map requiredMods: Map } diff --git a/src/lang/mod/RuleEntry.ts b/src/lang/mod/RuleEntry.ts new file mode 100644 index 00000000..3a0a0c6b --- /dev/null +++ b/src/lang/mod/RuleEntry.ts @@ -0,0 +1,8 @@ +import { Word } from "../word" +import { Mod } from "./Mod" + +export type RuleEntry = { + name: string + mod: Mod + words: Array +} diff --git a/src/lang/mod/createMod.ts b/src/lang/mod/createMod.ts index e8153792..11bff470 100644 --- a/src/lang/mod/createMod.ts +++ b/src/lang/mod/createMod.ts @@ -17,7 +17,7 @@ export function createMod(options: { text: options.text, stmts: options.stmts, definitions: new Map(), - rules: new Map(), + ruleEntries: new Map(), requiredMods: new Map(), } as Mod diff --git a/src/lang/mod/defineRule.ts b/src/lang/mod/defineRule.ts index 8973391c..82aa2799 100644 --- a/src/lang/mod/defineRule.ts +++ b/src/lang/mod/defineRule.ts @@ -23,6 +23,7 @@ export function defineRule( }) const key = `${firstKey} ${secondKey}` + const name = `${firstName} ${secondName}` - mod.rules.set(key, { mod, words }) + mod.ruleEntries.set(key, { name, mod, words }) } diff --git a/src/lang/mod/findNodeRules.ts b/src/lang/mod/findNodeRuleEntries.ts similarity index 54% rename from src/lang/mod/findNodeRules.ts rename to src/lang/mod/findNodeRuleEntries.ts index fe4e9853..95097045 100644 --- a/src/lang/mod/findNodeRules.ts +++ b/src/lang/mod/findNodeRuleEntries.ts @@ -1,17 +1,20 @@ import { NodeWithoutId } from "../node" import { nodeKeyWithoutId } from "../node/nodeKeyWithoutId" -import { Rule } from "../rule" import { Mod } from "./Mod" +import { RuleEntry } from "./RuleEntry" -export function findNodeRules(mod: Mod, node: NodeWithoutId): Array { +export function findNodeRuleEntries( + mod: Mod, + node: NodeWithoutId, +): Array { const nodeKey = nodeKeyWithoutId(node) - const rules = [] - for (const [key, rule] of mod.rules) { + const entries = [] + for (const [key, entry] of mod.ruleEntries) { const [firstKey, secondKey] = key.split(" ") if (firstKey === nodeKey || secondKey === nodeKey) { - rules.push(rule) + entries.push(entry) } } - return rules + return entries } diff --git a/src/lang/mod/index.ts b/src/lang/mod/index.ts index c11181da..f8ffcd90 100644 --- a/src/lang/mod/index.ts +++ b/src/lang/mod/index.ts @@ -2,7 +2,7 @@ export * from "./Mod" export * from "./createMod" export * from "./define" export * from "./defineRule" -export * from "./findNodeRules" +export * from "./findNodeRuleEntries" export * from "./lookupDefinition" export * from "./lookupDefinitionOrFail" export * from "./lookupRule" diff --git a/src/lang/mod/lookupRule.ts b/src/lang/mod/lookupRule.ts index 3dbed601..0577e2ac 100644 --- a/src/lang/mod/lookupRule.ts +++ b/src/lang/mod/lookupRule.ts @@ -26,5 +26,5 @@ export function lookupRule( ? mod : mod.loader.loaded.get(secondNode.url.href) - return firstMod?.rules.get(key) || secondMod?.rules.get(key) + return firstMod?.ruleEntries.get(key) || secondMod?.ruleEntries.get(key) }