@mark1russell7/coeval 0.7.0 → 0.8.0
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/README.md +31 -0
- package/build/index.d.ts +399 -100
- package/build/index.d.ts.map +1 -1
- package/build/index.js +1818 -172
- package/build/index.js.map +1 -1
- package/package.json +2 -2
- package/src/agree.ts +26 -5
- package/src/codec.ts +185 -0
- package/src/conform.ts +2 -3
- package/src/doc.ts +2 -2
- package/src/evaluate.ts +281 -9
- package/src/formula.ts +19 -8
- package/src/index.ts +36 -2
- package/src/parts.ts +70 -1
- package/src/reference.ts +143 -18
- package/src/static.ts +54 -74
- package/src/stdlib.ts +220 -18
- package/src/syntax.ts +846 -0
- package/src/types.ts +28 -1
- package/src/world.ts +50 -0
package/README.md
CHANGED
|
@@ -39,6 +39,8 @@ A plan evaluates many times without a trace. `evaluate(machine, doc)` gives the
|
|
|
39
39
|
| The static facts | `factsOf`, `DocFacts`, `StaticRead`, `FactsOptions`, `KindFacts`, `LazyRule` | The reads of a document with a mark for each read under a lazy part, its side, its effects and the marks `pure` and `volatile`. The contracts and the hook `facts` of a machine declare them (D24). The option `verb` names the verb |
|
|
40
40
|
| Trees | `STD_WORLD` (`panel`, `box`), `nearestWalker` | The decorated tree: each field of a node is an attribute that evaluates on demand, one time in an evaluation. A sibling is a path through the parent, and a cycle gives `#CYCLE!` with its chain |
|
|
41
41
|
| The formula kit | `formulaMachine`, `FormulaProfile`, `formulaKnown`, `formulaFacts` | The shared constructs `lit`, `ref`, `record`, `list`, `let`, `fn`, `call`, `if`, `and`, `or`, and the namespaces `ops` and `ext`. A profile gives the rules of a language, for example how the errors of two parts combine. A language extends the kit through the merge. An address gives a thing, not its value |
|
|
42
|
+
| The codec of values | `encodeValue`, `decodeValue`, `decodeDomain`, `DomainCodec`, `STD_EXT` | A host value as one term document. JSON stays as it is. `ext.number`, `ext.undefined` and `ext.domain` hold the other values. A domain gives its codec (D40) |
|
|
43
|
+
| The syntax kit | `parse`, `print`, `syntaxFormat`, `SyntaxProfile`, `SyntaxOperator`, `SyntaxIssue`, `STD_SYNTAX` | One parser and one printer for the text of a language. A profile gives the operators, the literals, the references and the calls. `parse` gives documents or issues with spans, and `print` gives text that `parse` reads back (D41) |
|
|
42
44
|
| One meaning | `agree`, `reference`, `formulaDefinitions`, `STD_DEFINITIONS`, `generate`, `TierInput` | A reference interpreter that compiles nothing, and `agree`, which compares a plan with it and with the second tier of a language. Each tier gets the mock `perform` and the `verb` of `agree`. `generate` builds random documents from the kind contracts |
|
|
43
45
|
| Conformance | `conforms`, `ConformOptions`, `Finding`, `Obligation`, `ConformProbe` | The obligations of host code, examined for one evaluator or runner with probe parts and a probe runtime. Each finding names the obligation, the reason and a probe that shows it (D36) |
|
|
44
46
|
| Early cutoff | `sameResult` | A safe equality of two results for a schedule. Plain JSON compares by structure, and each other object only as itself. Two errors need the same code, reason and place |
|
|
@@ -52,6 +54,35 @@ A plan evaluates many times without a trace. `evaluate(machine, doc)` gives the
|
|
|
52
54
|
|
|
53
55
|
Each rule has an ID in [`docs/SPEC.md`](https://github.com/mark1russell7/coeval/blob/main/docs/SPEC.md), and each ID has a test. [The site](https://mark1russell7.github.io/coeval/) explains each idea with a live diagram.
|
|
54
56
|
|
|
57
|
+
## Give your language a text syntax
|
|
58
|
+
|
|
59
|
+
A language with a text form writes a `SyntaxProfile`, not a parser. The profile is data: an operator table, literal rules, reference syntax and call syntax.
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
import { type SyntaxProfile, formulaMachine, mergeMachines, parse, print, syntaxFormat } from "@mark1russell7/coeval";
|
|
63
|
+
|
|
64
|
+
const algebra: SyntaxProfile = {
|
|
65
|
+
operators: [
|
|
66
|
+
{ symbol: "+", fixity: "infix", prec: 1, kind: "ops.add" },
|
|
67
|
+
{ symbol: "*", fixity: "infix", prec: 2, kind: "ops.mul" },
|
|
68
|
+
{ symbol: "-", fixity: "prefix", prec: 3, kind: "ops.neg" },
|
|
69
|
+
],
|
|
70
|
+
literals: { strings: false, words: {} },
|
|
71
|
+
refs: { bare: "world", roots: [], fields: false },
|
|
72
|
+
calls: { ops: ["min", "max", "floor"] },
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const parsed = parse(algebra, "min(gap, 2) * 3"); // { ok: true, doc: { type: ["ops", "mul"], value: [...] } }
|
|
76
|
+
if (parsed.ok) print(algebra, parsed.doc); // { ok: true, value: "min(gap, 2) * 3" }
|
|
77
|
+
const machine = mergeMachines(formulaMachine(profile), syntaxFormat(algebra)); // the verb format
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
- A larger `prec` binds more tightly. `assoc` is `left` (the default), `right`, `none` or `flat`. A `flat` chain gives one document with each term.
|
|
81
|
+
- `kind` is the type of the document, with dots between the keys. A call `name(args)` applies `ops.name`, and a call form in `calls.forms` makes a construct.
|
|
82
|
+
- A bare name is a path from `refs.bare`. A name in `refs.roots` starts a path. `refs.patterns` add other references, for example `A1`, with `read` and `write`.
|
|
83
|
+
- An issue of `parse` has `offset`, `length` and `message`. Show it at its span in an editor.
|
|
84
|
+
- Test your profile with a round trip: `parse(print(doc))` gives `doc` again. `STD_SYNTAX` is the standard profile of the formula kit.
|
|
85
|
+
|
|
55
86
|
## Check the code of a language
|
|
56
87
|
|
|
57
88
|
`conforms` examines the code of an evaluator or a runner against the obligations of host code, C1 to C8 of [`docs/SEMANTICS.md`](https://github.com/mark1russell7/coeval/blob/main/docs/SEMANTICS.md). Start it in a test for each name of your machine. An empty list means that the code conforms.
|