@hotdocx/endash-kernel 0.1.0-preview.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +9 -1
- package/README.md +24 -2
- package/bin/endash-cli.cjs +4 -0
- package/bin/endash-mcp.cjs +7 -0
- package/browser.d.ts +44 -0
- package/endash-browser.js +698 -0
- package/index.cjs +704 -14
- package/index.d.ts +19 -11
- package/index.mjs +704 -14
- package/node.cjs +116606 -0
- package/node.d.ts +8 -0
- package/node.mjs +53 -0
- package/package.json +51 -7
- package/types/ast.d.ts +964 -0
- package/types/book/book_compiler.d.ts +57 -0
- package/types/book/html_renderer.d.ts +27 -0
- package/types/book/literate_en.d.ts +40 -0
- package/types/book/schema.d.ts +279 -0
- package/types/browser.d.ts +44 -0
- package/types/builders.d.ts +191 -0
- package/types/cache/core_snapshot.d.ts +259 -0
- package/types/cas/bar_hochschild.d.ts +106 -0
- package/types/cas/cotangent_deformation.d.ts +100 -0
- package/types/cas/cyclic_homology.d.ts +100 -0
- package/types/cas/derham_hkr.d.ts +117 -0
- package/types/cas/ext_algebra.d.ts +112 -0
- package/types/cas/groebner_syzygy.d.ts +43 -0
- package/types/cas/hilbert_proj_ag.d.ts +97 -0
- package/types/cas/hnf_snf.d.ts +49 -0
- package/types/cas/lefschetz_weil.d.ts +114 -0
- package/types/cas/localization_cech.d.ts +201 -0
- package/types/cas/matrix.d.ts +45 -0
- package/types/cas/modules_complexes.d.ts +141 -0
- package/types/cas/perm_coset_cgt.d.ts +166 -0
- package/types/cas/poly.d.ts +66 -0
- package/types/cas/reify_proofs.d.ts +104 -0
- package/types/cas/resolutions_spectral_seq.d.ts +193 -0
- package/types/cas/rings.d.ts +70 -0
- package/types/cas/smith_resultant_gauss.d.ts +164 -0
- package/types/cas/theta_stepanov.d.ts +182 -0
- package/types/check.d.ts +65 -0
- package/types/cli/endash_cli.d.ts +19 -0
- package/types/context.d.ts +110 -0
- package/types/duality.d.ts +76 -0
- package/types/elab/elab_ast.d.ts +274 -0
- package/types/elab/elaborate.d.ts +106 -0
- package/types/elab/env.d.ts +170 -0
- package/types/elab/match.d.ts +123 -0
- package/types/elab/pretty.d.ts +14 -0
- package/types/elab/structure.d.ts +46 -0
- package/types/elab/tactics.d.ts +238 -0
- package/types/elab/typeclass.d.ts +31 -0
- package/types/elab/unify.d.ts +166 -0
- package/types/eval.d.ts +28 -0
- package/types/index.d.ts +98 -0
- package/types/kernel_ops.d.ts +196 -0
- package/types/mcp/endash_mcp_server.d.ts +63 -0
- package/types/module/comparator.d.ts +86 -0
- package/types/module/desugar.d.ts +94 -0
- package/types/module/goal_inspector.d.ts +104 -0
- package/types/module/loader.d.ts +105 -0
- package/types/module/node_fs_provider.d.ts +26 -0
- package/types/module/package_builder.d.ts +83 -0
- package/types/module/proof_graph.d.ts +80 -0
- package/types/module/quasiquote.d.ts +37 -0
- package/types/module/stdlib_fresh_builders.d.ts +10 -0
- package/types/module/stdlib_tactic_hooks.d.ts +20 -0
- package/types/parser/lexer.d.ts +12 -0
- package/types/parser/parser.d.ts +78 -0
- package/types/parser/pratt.d.ts +17 -0
- package/types/parser/span.d.ts +26 -0
- package/types/parser/surface_ast.d.ts +501 -0
- package/types/stdlib_types.d.ts +113 -0
- package/types/value.d.ts +942 -0
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Node.js Filesystem `.en` Module Resolver, Disk Core-Snapshot Hook, &
|
|
3
|
+
* Zero-Trust Persistent Disk `.encache` Provider (`endash/src/module/node_fs_provider.ts`).
|
|
4
|
+
*
|
|
5
|
+
* Kept in its own module so browser bundles (`src/browser.ts` -> `dist/endash-browser.js`)
|
|
6
|
+
* contain ZERO `node:*`, `fs`, `path`, or `process` references (`NC-12b` Part 3).
|
|
7
|
+
*/
|
|
8
|
+
import { ModuleSourceEntry, ModuleSourceProvider } from './loader';
|
|
9
|
+
export declare class NodeFsModuleProvider implements ModuleSourceProvider {
|
|
10
|
+
private readonly _roots;
|
|
11
|
+
constructor(roots: readonly string[]);
|
|
12
|
+
resolve(moduleId: string): ModuleSourceEntry | undefined;
|
|
13
|
+
}
|
|
14
|
+
export declare function resolveBundledOrSourcePath(...candidatesRelativeToDirname: string[]): string | undefined;
|
|
15
|
+
export interface NodeEnDiskCacheStats {
|
|
16
|
+
readonly hits: number;
|
|
17
|
+
readonly misses: number;
|
|
18
|
+
readonly writes: number;
|
|
19
|
+
}
|
|
20
|
+
export declare function getNodeEnDiskCacheDir(): string | null;
|
|
21
|
+
export declare function setNodeEnDiskCacheDir(dir: string | null | undefined, opts?: {
|
|
22
|
+
readonly allowVirtualFiles?: boolean;
|
|
23
|
+
}): void;
|
|
24
|
+
export declare function getNodeEnDiskCacheStats(): NodeEnDiskCacheStats;
|
|
25
|
+
export declare function clearNodeEnDiskCacheStats(): void;
|
|
26
|
+
export declare function clearNodeEnDiskCache(): void;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lake-Style Content-Addressed Incremental `.en` Package Builder & Zero-Trust `.ensnap` Cache
|
|
3
|
+
* (`endash/src/module/package_builder.ts`, Phase B1 & `NC-14a` Part 1).
|
|
4
|
+
*
|
|
5
|
+
* Computes transitive SHA-256 content & dependency hashes:
|
|
6
|
+
* `cacheKeySha256 = sha256({ format, kernelPinSha256, moduleId, sourceSha256, imports })`
|
|
7
|
+
*
|
|
8
|
+
* Soundness (`NC-14a` Part 1):
|
|
9
|
+
* 1. Modifying any upstream `.en` module changes its `sourceSha256` -> changes its
|
|
10
|
+
* `cacheKeySha256` -> automatically invalidates all downstream `.ensnap.json` caches,
|
|
11
|
+
* while leaving independent sibling modules cached!
|
|
12
|
+
* 2. Every cached `.ensnap.json` hit is re-verified through the trusted kernel
|
|
13
|
+
* (`declareDef` / `declareTheorem` in `src/check.ts` via `loadVerifiedElabDeltaSnapshot`).
|
|
14
|
+
* If an `.ensnap.json` file with a matching header has a tampered `valueTerm`, mutated
|
|
15
|
+
* `typeTerm`, or smuggled `sorry` / `axiom`, loading fails closed immediately!
|
|
16
|
+
*/
|
|
17
|
+
import { AstGraphInterner, SerializedModuleDeltaSnapshot } from '../cache/core_snapshot';
|
|
18
|
+
import { CompiledModuleSnapshot } from './loader';
|
|
19
|
+
export declare function sha256Hex(content: string): string;
|
|
20
|
+
export declare function computeKernelPinSha256(customSrcDir?: string): string;
|
|
21
|
+
export interface PackageModuleBuildEntry {
|
|
22
|
+
readonly moduleId: string;
|
|
23
|
+
readonly filePath: string;
|
|
24
|
+
readonly ensnapPath: string;
|
|
25
|
+
readonly status: 'elaborated' | 'cached-verified';
|
|
26
|
+
readonly cacheKeySha256: string;
|
|
27
|
+
readonly sourceSha256: string;
|
|
28
|
+
readonly declaredCount: number;
|
|
29
|
+
readonly elapsedMs: number;
|
|
30
|
+
}
|
|
31
|
+
export interface PackageBuildOptions {
|
|
32
|
+
/** Root directory (or directories) containing `.en` package modules. */
|
|
33
|
+
readonly sourceDirs: readonly string[];
|
|
34
|
+
/** Output directory for `<Module/Path>.ensnap.json` artifacts (`skipDiskWrite` skips writing individual files). */
|
|
35
|
+
readonly outDir: string;
|
|
36
|
+
/** Optional explicit module IDs to build (defaults to all `.en` files under `sourceDirs[0]`). */
|
|
37
|
+
readonly targetModules?: readonly string[];
|
|
38
|
+
/** Reject `axiom` / `sorry`-tainted modules (`default: true`). */
|
|
39
|
+
readonly requireAxiomFree?: boolean;
|
|
40
|
+
/** Optional override for TCB pin testing. */
|
|
41
|
+
readonly kernelPinOverride?: string;
|
|
42
|
+
/** Keep `SerializedModuleDeltaSnapshot` objects in memory without writing individual `.ensnap.json` files. */
|
|
43
|
+
readonly collectDeltasInMemoryOnly?: boolean;
|
|
44
|
+
/** Optional shared `AstGraphInterner` for incremental streaming deduplication across modules. */
|
|
45
|
+
readonly astInterner?: AstGraphInterner;
|
|
46
|
+
/** Evict `compiled` `ElabEnv` snapshots once no remaining downstream module imports them. */
|
|
47
|
+
readonly evictUnneededCompiledEnvs?: boolean;
|
|
48
|
+
/** Optional zero-trust reuse of persistent host `.encache` entries (verified via `src/check.ts`). */
|
|
49
|
+
readonly reuseHostDiskCache?: boolean;
|
|
50
|
+
/** Optional previous `.ensnap` bundle map for zero-trust incremental rebuilds (verified via `src/check.ts`). */
|
|
51
|
+
readonly previousDeltas?: Map<string, SerializedModuleDeltaSnapshot>;
|
|
52
|
+
}
|
|
53
|
+
export interface PackageBuildResult {
|
|
54
|
+
readonly kernelPinSha256: string;
|
|
55
|
+
readonly outDir: string;
|
|
56
|
+
readonly modules: readonly PackageModuleBuildEntry[];
|
|
57
|
+
readonly elaboratedCount: number;
|
|
58
|
+
readonly cachedCount: number;
|
|
59
|
+
readonly totalDeclaredCount: number;
|
|
60
|
+
readonly totalElapsedMs: number;
|
|
61
|
+
readonly compiledSnapshots: ReadonlyMap<string, CompiledModuleSnapshot>;
|
|
62
|
+
readonly deltaSnapshots?: ReadonlyMap<string, SerializedModuleDeltaSnapshot>;
|
|
63
|
+
}
|
|
64
|
+
export declare function buildEnPackage(opts: PackageBuildOptions): PackageBuildResult;
|
|
65
|
+
/**
|
|
66
|
+
* Elaborate all `.en` library submodules under subdirectories of `stdlibEnDir`
|
|
67
|
+
* (`CategoryTheory.*`, `Combinatorics.*`, `GroupTheory.*`, `HigherAlgebra.*`, etc.,
|
|
68
|
+
* excluding top-level `*Showcase.en` files) from scratch against the verified built-in
|
|
69
|
+
* stdlib snapshot and serialize a single structurally hash-consed shared-DAG
|
|
70
|
+
* `endash-en-ensnap-bundle-v1` JSON artifact (`dist/stdlib-en-ensnaps.json`).
|
|
71
|
+
*/
|
|
72
|
+
export declare function buildEnLibraryEnsnapBundle(opts: {
|
|
73
|
+
readonly stdlibEnDir: string;
|
|
74
|
+
readonly kernelPinSha256?: string;
|
|
75
|
+
readonly requireAxiomFree?: boolean;
|
|
76
|
+
readonly previousBundleJson?: string;
|
|
77
|
+
}): {
|
|
78
|
+
readonly rawBundleJson: string;
|
|
79
|
+
readonly kernelPinSha256: string;
|
|
80
|
+
readonly moduleCount: number;
|
|
81
|
+
readonly declCount: number;
|
|
82
|
+
readonly elapsedMs: number;
|
|
83
|
+
};
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Browser-Safe Proof-Graph, Transitive Closure, & Anti-Goodhart Unused-Proof-Binder
|
|
3
|
+
* Auditor (`endash/src/module/proof_graph.ts`).
|
|
4
|
+
*
|
|
5
|
+
* Extracts the complete acyclic declaration dependency graph (`collectGlobalRefsInTerm`),
|
|
6
|
+
* module summary DAG, `0`-axiom status, `@[tag]`/`@[book]`/`@[ha]`/`@[ega]`/`@[rh]`
|
|
7
|
+
* cross-reference index, and mechanical `DISCARDED_PROOF_ARGUMENT` findings (`termMentionsVar`).
|
|
8
|
+
*
|
|
9
|
+
* 100% browser-safe (zero `node:*` built-in imports), `0` `any` casts, and `0 LOC` TCB delta.
|
|
10
|
+
*/
|
|
11
|
+
import { CrossRefTagEntry, ElabDeclKind, ElabEnv } from '../elab/env';
|
|
12
|
+
export interface ProofGraphNode {
|
|
13
|
+
readonly id: string;
|
|
14
|
+
readonly moduleId: string;
|
|
15
|
+
readonly kind: ElabDeclKind;
|
|
16
|
+
readonly axiomFree: boolean;
|
|
17
|
+
readonly deps: readonly string[];
|
|
18
|
+
readonly tags: readonly CrossRefTagEntry[];
|
|
19
|
+
}
|
|
20
|
+
export interface ProofGraphModuleSummary {
|
|
21
|
+
readonly moduleId: string;
|
|
22
|
+
readonly declCount: number;
|
|
23
|
+
readonly theoremCount: number;
|
|
24
|
+
readonly defCount: number;
|
|
25
|
+
readonly tagCount: number;
|
|
26
|
+
readonly dependsOnModules: readonly string[];
|
|
27
|
+
}
|
|
28
|
+
export interface ProofGraphAtlas {
|
|
29
|
+
readonly format: 'endash-proof-graph-v1';
|
|
30
|
+
readonly modules: readonly ProofGraphModuleSummary[];
|
|
31
|
+
readonly nodes: readonly ProofGraphNode[];
|
|
32
|
+
readonly tags: readonly CrossRefTagEntry[];
|
|
33
|
+
readonly stats: {
|
|
34
|
+
readonly moduleCount: number;
|
|
35
|
+
readonly totalDecls: number;
|
|
36
|
+
readonly axiomFreeDecls: number;
|
|
37
|
+
readonly totalEdges: number;
|
|
38
|
+
readonly totalTags: number;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Build a deduplicated `ProofGraphAtlas` across an ordered list of `(moduleId, env)` snapshots.
|
|
43
|
+
* Each declaration is owned by the first module in topological order that introduces it.
|
|
44
|
+
*/
|
|
45
|
+
export declare function buildProofGraphAtlas(modulesInOrder: readonly {
|
|
46
|
+
readonly moduleId: string;
|
|
47
|
+
readonly env: ElabEnv;
|
|
48
|
+
}[]): ProofGraphAtlas;
|
|
49
|
+
/**
|
|
50
|
+
* Compute the transitive Core `global-ref` dependency closure of `rootDeclFullName`
|
|
51
|
+
* across either a `ProofGraphAtlas` or an `ElabEnv` (walking both `typeTerm` and `valueTerm`).
|
|
52
|
+
*
|
|
53
|
+
* Cycle-safe, deterministic, 100% browser-safe (`0` Node built-ins), and `0 LOC` TCB delta.
|
|
54
|
+
*/
|
|
55
|
+
export declare function computeTransitiveDeclClosure(source: ProofGraphAtlas | ElabEnv, rootDeclFullName: string): ReadonlySet<string>;
|
|
56
|
+
export interface DiscardedProofArgFinding {
|
|
57
|
+
readonly declName: string;
|
|
58
|
+
readonly binderName: string;
|
|
59
|
+
readonly binderTypeHead: string;
|
|
60
|
+
readonly message: string;
|
|
61
|
+
}
|
|
62
|
+
export interface TheoremDataProjectionFinding {
|
|
63
|
+
readonly declName: string;
|
|
64
|
+
readonly theoremName: string;
|
|
65
|
+
readonly projectionTag: 'fst-grpd' | 'snd-grpd';
|
|
66
|
+
readonly message: string;
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Audit elaborated kernel `valueTerm` bodies for proof-discarding lambdas (`NC-24c` Part 2a):
|
|
70
|
+
* flags any `lam-grpd` whose binder domain is a relational/proof predicate (`RatLe`, `Rle1`,
|
|
71
|
+
* `RealLe`, `sintLe`, `ExactPadicValNat`, `NatDvd1`, `IsValidDyadicPageFn`, `HeightLe`, `Eq`,
|
|
72
|
+
* `-> Empty`, non-zero `Nat.leProp`, etc.) where `!termMentionsVar(body, sym.id)`.
|
|
73
|
+
*/
|
|
74
|
+
export declare function auditDiscardedProofArguments(env: ElabEnv, declNames?: readonly string[]): readonly DiscardedProofArgFinding[];
|
|
75
|
+
/**
|
|
76
|
+
* OCaml Proof/Data Extraction Separation Lint (`THEOREM_DATA_PROJECTION`, `NC-25a` Part 2):
|
|
77
|
+
* rejects any computational `def` (`info.kind === 'def'`) whose `typeTerm` or `valueTerm`
|
|
78
|
+
* projects non-proof computational data (`.fst` / `.snd`) out of a `theorem` declaration.
|
|
79
|
+
*/
|
|
80
|
+
export declare function auditTheoremDataProjections(env: ElabEnv, declNames?: readonly string[]): readonly TheoremDataProjectionFinding[];
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AI-Native TypeScript Quasiquotes (`en\`...\``) & Metaprogramming Helpers
|
|
3
|
+
* (`endash/src/module/quasiquote.ts`).
|
|
4
|
+
*
|
|
5
|
+
* Bridges Lean-compatible `.en` surface syntax directly with TypeScript metaprograms:
|
|
6
|
+
* - `en\`∀ {α : Type} (xs : List α), (${prefix} ++ xs).length = ...\``
|
|
7
|
+
* splices `ElabTerm`, kernel `Term`, `number`, `boolean`, or identifier strings
|
|
8
|
+
* hygienically into parsed `.en` expressions!
|
|
9
|
+
* - `enExpr(env, src)` parses an expression using `env`'s active operator table.
|
|
10
|
+
* - `enProve(env, goalTy, tacticSrc)` runs a `.en` tactic script and returns the
|
|
11
|
+
* verified kernel `Term`.
|
|
12
|
+
* - `assertAxiomFree(env, declName)` mechanically certifies in O(1) that zero
|
|
13
|
+
* `axiom` or `sorry` assumptions entered a theorem's dependency cone (`NC-9`).
|
|
14
|
+
*/
|
|
15
|
+
import { Term } from '../ast';
|
|
16
|
+
import { ElabTerm } from '../elab/elab_ast';
|
|
17
|
+
import { ElabEnv } from '../elab/env';
|
|
18
|
+
export type EnSpliceValue = ElabTerm | Term | number | boolean;
|
|
19
|
+
/**
|
|
20
|
+
* Tagged template literal parsing `.en` expression syntax with hygienic `${...}`
|
|
21
|
+
* splices of `ElabTerm`, kernel `Term`, `number`, or `boolean` values.
|
|
22
|
+
*/
|
|
23
|
+
export declare function en(strings: TemplateStringsArray, ...values: readonly EnSpliceValue[]): ElabTerm;
|
|
24
|
+
/**
|
|
25
|
+
* Parse a `.en` expression string in the context of `env` (respecting `env`'s
|
|
26
|
+
* custom infix/prefix operators and global namespace resolution).
|
|
27
|
+
*/
|
|
28
|
+
export declare function enExpr(env: ElabEnv, source: string, file?: string): ElabTerm;
|
|
29
|
+
/**
|
|
30
|
+
* Prove `goalSurface` (either a `.en` string or `ElabTerm`) using `.en` tactic syntax
|
|
31
|
+
* and return the verified, metavariable-free kernel `Term`.
|
|
32
|
+
*/
|
|
33
|
+
export declare function enProve(env: ElabEnv, goal: string | ElabTerm, tacticSource: string): Term;
|
|
34
|
+
/**
|
|
35
|
+
* Mechanically assert in O(1) that `declName` has an empty `axiomsUsed` footprint (`NC-9`).
|
|
36
|
+
*/
|
|
37
|
+
export declare function assertAxiomFree(env: ElabEnv, declName: string): void;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Fresh Uncached Built-in Stdlib Module Builders (`endash/src/module/stdlib_fresh_builders.ts`).
|
|
3
|
+
*
|
|
4
|
+
* Used during `scripts/build.mjs` snapshot generation and uncached Node tests (`ENDASH_DISABLE_SNAPSHOT_CACHE=1`),
|
|
5
|
+
* while replaced in `dist/endash-browser.js` with a lightweight `Init.Prelude` + `endash-stdlib-pack.js`
|
|
6
|
+
* stub so the browser engine stays `< 190 KiB` gzipped regardless of library growth!
|
|
7
|
+
*/
|
|
8
|
+
import { ElabEnv } from '../elab/env';
|
|
9
|
+
export declare function installWalkingEndSurfaceDecls(env: ElabEnv): ElabEnv;
|
|
10
|
+
export declare function buildFreshBuiltinStdlibModule(moduleId: string, getDep: (depId: string) => ElabEnv | undefined, existingHydrated?: ElabEnv): ElabEnv | undefined;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-Stdlib-Import Runtime Tactic & Cross-Reference Hook Registrar
|
|
3
|
+
* (`endash/src/module/stdlib_tactic_hooks.ts`).
|
|
4
|
+
*
|
|
5
|
+
* Keeps `dist/endash-browser.js` decoupled from `src/stdlib/*.ts` proof builders (`< 190 KiB` gz)
|
|
6
|
+
* while attaching all custom `.en` tactics (`dosen_cut`, `cas_snf`, `cas_les_lift`,
|
|
7
|
+
* `cas_cech_p1`, `cas_ext`, `cas_spectral_seq`) when hydrating modules from
|
|
8
|
+
* `VerifiedStdlibBundleCache`.
|
|
9
|
+
*/
|
|
10
|
+
import { CrossRefNamespace, ElabEnv } from '../elab/env';
|
|
11
|
+
export declare function attachDosenCutTacticLightweight(env: ElabEnv): ElabEnv;
|
|
12
|
+
export declare function attachGeometryTacticsLightweight(env: ElabEnv): ElabEnv;
|
|
13
|
+
export declare const BUILTIN_STDLIB_CROSS_REF_TAGS: readonly {
|
|
14
|
+
readonly decl: string;
|
|
15
|
+
readonly namespace: CrossRefNamespace;
|
|
16
|
+
readonly code: string;
|
|
17
|
+
readonly title: string;
|
|
18
|
+
}[];
|
|
19
|
+
export declare function attachBuiltinStdlibCrossRefTags(env: ElabEnv): void;
|
|
20
|
+
export declare function attachBuiltinStdlibRuntimeHooks(_moduleId: string, env: ElabEnv): void;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-Dependency Unicode & Layout-Aware Lexer for `.en` Surface Syntax
|
|
3
|
+
* (`endash/src/parser/lexer.ts`).
|
|
4
|
+
*/
|
|
5
|
+
import { SourceSpan } from './span';
|
|
6
|
+
export type TokenKind = 'ident' | 'nat' | 'string' | 'hole' | 'splice' | 'keyword' | 'command' | 'punct' | 'op' | 'eof';
|
|
7
|
+
export interface Token {
|
|
8
|
+
readonly kind: TokenKind;
|
|
9
|
+
readonly text: string;
|
|
10
|
+
readonly span: SourceSpan;
|
|
11
|
+
}
|
|
12
|
+
export declare function tokenize(source: string, file?: string): readonly Token[];
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-Dependency Lean 4-Compatible + Functorial Recursive-Descent & Pratt Parser
|
|
3
|
+
* for `.en` Modules, Expressions, Patterns & Tactics (`endash/src/parser/parser.ts`).
|
|
4
|
+
*/
|
|
5
|
+
import { OperatorTable } from './pratt';
|
|
6
|
+
import { SurfaceExpr, SurfaceModule, SurfaceTactic } from './surface_ast';
|
|
7
|
+
interface ParseContextOpts {
|
|
8
|
+
/** Minimum column strictly greater than enclosing block/field indentation when inside `where`/`by`/`match`. */
|
|
9
|
+
readonly minLineCol?: number;
|
|
10
|
+
/** Disallow consuming `|` at top level (inside `match` or `cases`/`induction` arms). */
|
|
11
|
+
readonly stopAtPipe?: boolean;
|
|
12
|
+
}
|
|
13
|
+
export declare class EndashParser {
|
|
14
|
+
private readonly tokens;
|
|
15
|
+
private readonly source;
|
|
16
|
+
private readonly file;
|
|
17
|
+
private pos;
|
|
18
|
+
private _instCounter;
|
|
19
|
+
private readonly _universeVars;
|
|
20
|
+
readonly operators: OperatorTable;
|
|
21
|
+
constructor(source: string, file?: string, operators?: OperatorTable);
|
|
22
|
+
private peek;
|
|
23
|
+
private prev;
|
|
24
|
+
private atEof;
|
|
25
|
+
private advance;
|
|
26
|
+
private fail;
|
|
27
|
+
private isKeyword;
|
|
28
|
+
private isPunct;
|
|
29
|
+
private isOp;
|
|
30
|
+
private matchKeyword;
|
|
31
|
+
private matchPunct;
|
|
32
|
+
private expectKeyword;
|
|
33
|
+
private expectPunct;
|
|
34
|
+
private expectIdent;
|
|
35
|
+
private parseDottedName;
|
|
36
|
+
parseModule(): SurfaceModule;
|
|
37
|
+
parseStandaloneExpr(): SurfaceExpr;
|
|
38
|
+
parseStandaloneTactics(): readonly SurfaceTactic[];
|
|
39
|
+
private parseCommandList;
|
|
40
|
+
private parseAttributes;
|
|
41
|
+
private parseCommand;
|
|
42
|
+
private parseTypeBeforeWhere;
|
|
43
|
+
private parseTypeBeforeWhereOrAssign;
|
|
44
|
+
private isTopCommandStart;
|
|
45
|
+
private parseStructureFields;
|
|
46
|
+
private parseInstanceFields;
|
|
47
|
+
private parseBinderList;
|
|
48
|
+
private looksLikeParenBinderGroup;
|
|
49
|
+
private parseParenBinderGroup;
|
|
50
|
+
private parseBraceBinderGroup;
|
|
51
|
+
private parseBracketInstanceBinder;
|
|
52
|
+
private parseBunchedStages;
|
|
53
|
+
parseExpr(opts: ParseContextOpts): SurfaceExpr;
|
|
54
|
+
private shouldStopAtLineBoundary;
|
|
55
|
+
private parsePrattExpr;
|
|
56
|
+
private parseLeadExpr;
|
|
57
|
+
private looksLikeBarePiTelescope;
|
|
58
|
+
private parseLevelAtom;
|
|
59
|
+
private parseLevelExpr;
|
|
60
|
+
private looksLikeParenLevelExpr;
|
|
61
|
+
private parseCalcChain;
|
|
62
|
+
private parseAppTail;
|
|
63
|
+
private canStartArg;
|
|
64
|
+
private parsePostfixAtom;
|
|
65
|
+
private parsePrimaryAtom;
|
|
66
|
+
private parseMatchExpr;
|
|
67
|
+
private parsePattern;
|
|
68
|
+
private parseLeadPattern;
|
|
69
|
+
private canStartAtomPattern;
|
|
70
|
+
private parseAtomPattern;
|
|
71
|
+
private parseTacticSeq;
|
|
72
|
+
private parseSingleTactic;
|
|
73
|
+
private parseTacticArms;
|
|
74
|
+
}
|
|
75
|
+
export declare function parseEnModule(source: string, file?: string, operators?: OperatorTable): SurfaceModule;
|
|
76
|
+
export declare function parseEnExpr(source: string, file?: string, operators?: OperatorTable): SurfaceExpr;
|
|
77
|
+
export declare function parseEnTactics(source: string, file?: string, operators?: OperatorTable): readonly SurfaceTactic[];
|
|
78
|
+
export {};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Extensible Pratt Operator-Precedence Table for `.en` Surface Syntax
|
|
3
|
+
* (`endash/src/parser/pratt.ts`).
|
|
4
|
+
*/
|
|
5
|
+
import { OperatorSpec, SurfaceFixity } from './surface_ast';
|
|
6
|
+
export declare class OperatorTable {
|
|
7
|
+
private readonly _infix;
|
|
8
|
+
private readonly _prefix;
|
|
9
|
+
constructor(copyFrom?: OperatorTable);
|
|
10
|
+
static standard(): OperatorTable;
|
|
11
|
+
clone(): OperatorTable;
|
|
12
|
+
register(spec: OperatorSpec): void;
|
|
13
|
+
getInfix(symbol: string): OperatorSpec | undefined;
|
|
14
|
+
getPrefix(symbol: string): OperatorSpec | undefined;
|
|
15
|
+
allSpecs(): readonly OperatorSpec[];
|
|
16
|
+
}
|
|
17
|
+
export declare function infixBindingPowers(fixity: SurfaceFixity, prec: number): readonly [number, number];
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Zero-Dependency Source Locations & Parse Diagnostics (`endash/src/parser/span.ts`).
|
|
3
|
+
*/
|
|
4
|
+
export interface SourcePos {
|
|
5
|
+
/** 0-based UTF-16 code-unit offset into `source`. */
|
|
6
|
+
readonly offset: number;
|
|
7
|
+
/** 1-based line number. */
|
|
8
|
+
readonly line: number;
|
|
9
|
+
/** 1-based column number. */
|
|
10
|
+
readonly column: number;
|
|
11
|
+
}
|
|
12
|
+
export interface SourceSpan {
|
|
13
|
+
readonly file: string;
|
|
14
|
+
readonly start: SourcePos;
|
|
15
|
+
readonly end: SourcePos;
|
|
16
|
+
}
|
|
17
|
+
export declare function mkPos(offset: number, line: number, column: number): SourcePos;
|
|
18
|
+
export declare function mkSpan(file: string, start: SourcePos, end: SourcePos): SourceSpan;
|
|
19
|
+
export declare function mergeSpans(a: SourceSpan, b: SourceSpan): SourceSpan;
|
|
20
|
+
export declare function formatSpan(span: SourceSpan): string;
|
|
21
|
+
export type EndashParseErrorCode = 'LEX_ERROR' | 'UNCLOSED_COMMENT' | 'UNEXPECTED_TOKEN' | 'UNEXPECTED_EOF' | 'INVALID_BINDER' | 'INVALID_PATTERN' | 'INVALID_TACTIC' | 'INVALID_COMMAND' | 'INVALID_PRECEDENCE';
|
|
22
|
+
export declare class EndashParseError extends Error {
|
|
23
|
+
readonly code: EndashParseErrorCode;
|
|
24
|
+
readonly span: SourceSpan;
|
|
25
|
+
constructor(code: EndashParseErrorCode, span: SourceSpan, message: string, sourceText?: string);
|
|
26
|
+
}
|