eyemind 0.2.3 → 0.2.4
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 +1 -1
- package/SPEC.md +63 -4
- package/package.json +1 -1
- package/src/builtins.js +1 -0
- package/src/engine.js +4 -2
- package/src/proof.js +5 -4
- package/src/reader.js +1 -2
- package/src/version.js +1 -1
- package/src/writer.js +3 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ JavaScript library, and a browser application, with no dependencies.
|
|
|
18
18
|
- **[Examples](https://eyereasoner.github.io/eyemind/examples/)**:
|
|
19
19
|
94 runnable programs, each with a card deck and saved conclusions, proofs
|
|
20
20
|
and check reports.
|
|
21
|
-
- **[Conformance suite](conformance/)**:
|
|
21
|
+
- **[Conformance suite](conformance/)**: 1201 cases that test any
|
|
22
22
|
implementation of the specification through its command line.
|
|
23
23
|
Run the suite [in your browser](https://eyereasoner.github.io/eyemind/playground/conformance).
|
|
24
24
|
|
package/SPEC.md
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
```text
|
|
4
4
|
Title: The eyemind Rule Language and Proof Format
|
|
5
|
-
Version: eyemind 0.2.
|
|
5
|
+
Version: eyemind 0.2.4
|
|
6
6
|
```
|
|
7
7
|
|
|
8
8
|
This document specifies the syntax and meaning of eyemind programs and data
|
|
@@ -81,6 +81,7 @@ proof.
|
|
|
81
81
|
- [13.1 Invocation and options](#131-invocation-and-options)
|
|
82
82
|
- [13.2 Unused clauses](#132-unused-clauses)
|
|
83
83
|
- [14. Conformance](#14-conformance)
|
|
84
|
+
- [14.1 Conformance test suite](#141-conformance-test-suite)
|
|
84
85
|
- [15. Security](#15-security)
|
|
85
86
|
- [Appendix A. Document Grammar](#appendix-a-document-grammar)
|
|
86
87
|
- [Appendix B. Example](#appendix-b-example)
|
|
@@ -999,8 +1000,8 @@ Object keys may also use these reserved names, since keys denote atom text.
|
|
|
999
1000
|
Otherwise use `e`, an explicit exponent sign and at least two exponent
|
|
1000
1001
|
digits, such as `1e+22` or `1e-05`.
|
|
1001
1002
|
- A variable is written as its name when the name is an ASCII identifier
|
|
1002
|
-
(letters, digits and `_`, not starting with a digit), not a reserved
|
|
1003
|
-
of
|
|
1003
|
+
(letters, digits and `_`, not starting with a digit), not a reserved name
|
|
1004
|
+
of Section 9.1, not `_` and does not begin with `VAR_`. Any other name is
|
|
1004
1005
|
written `VAR_` followed by the name with every ASCII letter and digit kept,
|
|
1005
1006
|
every `_` doubled and every other character `c` replaced by `_hex_` where
|
|
1006
1007
|
`hex` is the lowercase hexadecimal code point of `c`. The variable name `A-B`
|
|
@@ -1011,7 +1012,7 @@ Object keys may also use these reserved names, since keys denote atom text.
|
|
|
1011
1012
|
### 9.3 Canonical compounds
|
|
1012
1013
|
|
|
1013
1014
|
A compound is written `name(A1, A2, ...)` when its name is an ASCII
|
|
1014
|
-
identifier, not a reserved
|
|
1015
|
+
identifier, not a reserved name of Section 9.1 and not `struct`, and
|
|
1015
1016
|
`struct('name', A1, ...)` otherwise. Arguments are separated by `, `.
|
|
1016
1017
|
|
|
1017
1018
|
A chain of conjunctions or disjunctions built from the left,
|
|
@@ -1409,6 +1410,64 @@ and C5 accepts a result of such a function within 4 units (Section 11.6).
|
|
|
1409
1410
|
The conformance cases and saved example documents exercise these
|
|
1410
1411
|
requirements. They do not replace the definitions in this specification.
|
|
1411
1412
|
|
|
1413
|
+
### 14.1 Conformance test suite
|
|
1414
|
+
|
|
1415
|
+
The conformance test suite tests an implementation of the command line of
|
|
1416
|
+
Section 13.1 as a black box: each case creates files, runs the command and
|
|
1417
|
+
compares its exit code and output with what this specification requires.
|
|
1418
|
+
The suite is the `conformance` directory of the eyemind repository. Its
|
|
1419
|
+
expected outputs are derived from this specification; where a case and this
|
|
1420
|
+
specification disagree, the specification governs and the case is wrong.
|
|
1421
|
+
|
|
1422
|
+
**Manifest.** `manifest.json` is a JSON array that lists the case files in
|
|
1423
|
+
the order they run. Each element is an object with three string members:
|
|
1424
|
+
`file`, the name of a case file in the same directory; `spec`, the sections
|
|
1425
|
+
of this specification it tests, separated by commas; and `topic`, a
|
|
1426
|
+
description. The cases of a file run in the order they appear in it.
|
|
1427
|
+
|
|
1428
|
+
**Case files.** A case file is a document (Section 9.1), read as data and
|
|
1429
|
+
never executed, whatever its file name extension. Each of its terms is one
|
|
1430
|
+
case, `conformance(Name, Settings)`, where `Name` is an atom unique in the
|
|
1431
|
+
suite and `Settings` is a proper list of the settings below. A **block** is a
|
|
1432
|
+
proper list of atoms, each one line; its text is each line followed by a
|
|
1433
|
+
line feed, so `[]` is empty text. A file MUST NOT contain any other term,
|
|
1434
|
+
and a setting other than these is an error in the suite.
|
|
1435
|
+
|
|
1436
|
+
| Setting | Meaning | When absent |
|
|
1437
|
+
| --- | --- | --- |
|
|
1438
|
+
| `spec(S)` | `S`, an atom: the sections the case tests, separated by commas. | |
|
|
1439
|
+
| `args(A)` | `A`, an atom: the command's arguments, split into words as described below. | `'program.js'` |
|
|
1440
|
+
| `exit(N)` | `N`, an integer: the exit code required. | `0` |
|
|
1441
|
+
| `stderr(M)` | Standard error: `'empty'`, no text; `'nonempty'`, some text other than white space; `'json'`, one JSON value; `prefix(T)`, text that starts with the atom `T`. | Not compared |
|
|
1442
|
+
| `file(Name, Block)` | A file the case creates before running; `Name` is a relative path whose `/` separates directories. | |
|
|
1443
|
+
| `stdin(Block)` | Standard input. | Empty |
|
|
1444
|
+
| `stdout(Block)` | Standard output, compared line by line. | Not compared |
|
|
1445
|
+
| `stdout('nonempty')` | Standard output contains text other than white space. | |
|
|
1446
|
+
| `stdout_json(Block)` | Standard output, compared as JSON. | |
|
|
1447
|
+
| `stdout_text(T)` | Standard output given as the atom `T`, for text a block cannot show, such as text without a final line feed; compared as `stdout` compares. | |
|
|
1448
|
+
|
|
1449
|
+
Each setting appears at most once in a case, except `file`.
|
|
1450
|
+
|
|
1451
|
+
**Running a case.** A case runs in a new empty directory. Each `file`
|
|
1452
|
+
setting creates its file there, with any directories its path names. The
|
|
1453
|
+
command then runs in that directory, with the words of `args` after the
|
|
1454
|
+
command's own words and with the `stdin` text on standard input. `args` is
|
|
1455
|
+
split into words as a POSIX shell splits a command line without expansions:
|
|
1456
|
+
white space separates words; text between single quotes is taken as is;
|
|
1457
|
+
between double quotes a backslash escapes only `"`, `\`, `$`, `` ` `` and a
|
|
1458
|
+
line feed; elsewhere a backslash escapes the next character; and adjacent
|
|
1459
|
+
quoted and unquoted parts join into one word.
|
|
1460
|
+
|
|
1461
|
+
**Passing.** A case passes when the exit code equals `exit` and standard
|
|
1462
|
+
output and standard error meet the settings that compare them. Line by line,
|
|
1463
|
+
the expected and actual standard output MUST have the same number of lines,
|
|
1464
|
+
and each expected line MUST equal the actual one, except that each `…`
|
|
1465
|
+
(U+2026) in an expected line matches any sequence of characters within that
|
|
1466
|
+
line; this specification leaves such text, for example a failure detail, to
|
|
1467
|
+
the implementation (Section 14). As JSON, both outputs MUST parse, and they
|
|
1468
|
+
MUST be equal as JSON values: arrays element by element, objects with the
|
|
1469
|
+
same member names whatever their order, and numbers by their values.
|
|
1470
|
+
|
|
1412
1471
|
## 15. Security
|
|
1413
1472
|
|
|
1414
1473
|
Programs execute JavaScript and require the caller's trust. Documents,
|
package/package.json
CHANGED
package/src/builtins.js
CHANGED
|
@@ -60,6 +60,7 @@ function functor(args, resolved, env, bind) {
|
|
|
60
60
|
function arg(args, resolved, env, bind) {
|
|
61
61
|
const [position, term] = resolved;
|
|
62
62
|
const index = boundedInteger(position, 1, 1024);
|
|
63
|
+
if (term instanceof Var) throw new EyemindError('arg/3 needs a bound term');
|
|
63
64
|
return term instanceof Struct && index <= term.args.length && bind(args[2], term.args[index - 1]);
|
|
64
65
|
}
|
|
65
66
|
|
package/src/engine.js
CHANGED
|
@@ -1036,8 +1036,10 @@ function reason(program, goalInputs, options) {
|
|
|
1036
1036
|
}
|
|
1037
1037
|
let report = null;
|
|
1038
1038
|
if (document !== null) {
|
|
1039
|
-
// The generated proof is checked before it is returned
|
|
1040
|
-
|
|
1039
|
+
// The generated proof is checked before it is returned, against the goals
|
|
1040
|
+
// as they were given: an atom goal is a string, which read again as goal
|
|
1041
|
+
// text would be a variable or no term at all.
|
|
1042
|
+
report = checkRendered(program, rendered[1], goalInputs);
|
|
1041
1043
|
if (!report.valid) throw new EyemindError(`cannot certify this result: ${report.failures[0].detail}`);
|
|
1042
1044
|
}
|
|
1043
1045
|
let behind = null;
|
package/src/proof.js
CHANGED
|
@@ -339,7 +339,7 @@ function readDocument(program, document, fail, spellings) {
|
|
|
339
339
|
const [goal, by, bindingList, useList] = term.args;
|
|
340
340
|
const bindings = properListItems(bindingList, empty);
|
|
341
341
|
const uses = properListItems(useList, empty);
|
|
342
|
-
if (bindings === null || uses === null) {
|
|
342
|
+
if (bindings === null || uses === null || !bindings.every((pair) => isTerm(pair, '=', 2))) {
|
|
343
343
|
fail.add('C3', 'step bindings must be an object and uses an array', goal);
|
|
344
344
|
continue;
|
|
345
345
|
}
|
|
@@ -660,15 +660,16 @@ function checkBoundaries(program, steps, boundaries, fail) {
|
|
|
660
660
|
const solved = parts.every((part, i) => shown[i].some((item) => unify(freshTerm(part, `absent${nextSerial()}`), item, new Env())));
|
|
661
661
|
if (solved) fail.add('C6', `absence contradicted by evidence: ${text(boundary)}`, boundary);
|
|
662
662
|
} else {
|
|
663
|
+
const parts = flattenConjunction(boundary.args[1]);
|
|
664
|
+
const shown = parts.length === 1 ? evidence(parts[0]) : null;
|
|
665
|
+
// Whether the collection is decided does not depend on its result.
|
|
666
|
+
if (shown !== null) confronted++;
|
|
663
667
|
const items = properListItems(boundary.args[2], new Env());
|
|
664
668
|
if (items === null) {
|
|
665
669
|
fail.add('C6', `collected result is not a proper list: ${text(boundary)}`, boundary);
|
|
666
670
|
continue;
|
|
667
671
|
}
|
|
668
|
-
const parts = flattenConjunction(boundary.args[1]);
|
|
669
|
-
const shown = parts.length === 1 ? evidence(parts[0]) : null;
|
|
670
672
|
if (shown === null) continue;
|
|
671
|
-
confronted++;
|
|
672
673
|
for (const item of shown) {
|
|
673
674
|
const names = new Map();
|
|
674
675
|
const number = nextSerial();
|
package/src/reader.js
CHANGED
|
@@ -9,7 +9,6 @@ import { EMPTY, EyemindError, Struct, Var, nonfinite } from './terms.js';
|
|
|
9
9
|
import { CHAINED, RESERVED_WORDS, decodeName } from './writer.js';
|
|
10
10
|
|
|
11
11
|
// Names that a program reads as JavaScript values, so a document may not use them.
|
|
12
|
-
const JS_VALUES = new Set(['undefined', 'NaN', 'Infinity']);
|
|
13
12
|
|
|
14
13
|
// The name of the variable an identifier writes: names starting VAR_ are
|
|
15
14
|
// encoded (Section 9.2).
|
|
@@ -222,7 +221,7 @@ export class Reader {
|
|
|
222
221
|
else throw tokens.error('a minus sign applies only to a number', token.line);
|
|
223
222
|
state = 'after';
|
|
224
223
|
} else if (token.kind === 'name') {
|
|
225
|
-
if (RESERVED_WORDS.has(token.text) ||
|
|
224
|
+
if (RESERVED_WORDS.has(token.text) || token.text.includes('$')) {
|
|
226
225
|
throw tokens.error(`${token.text} is not a term`, token.line);
|
|
227
226
|
}
|
|
228
227
|
if (tokens.at('(')) {
|
package/src/version.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
// The release this checkout is; ./release keeps it in step with package.json.
|
|
2
|
-
export const VERSION = '0.2.
|
|
2
|
+
export const VERSION = '0.2.4';
|
package/src/writer.js
CHANGED
|
@@ -9,8 +9,10 @@
|
|
|
9
9
|
// plain identifier is written struct('name', Arg, ...).
|
|
10
10
|
import { Struct, Var, deref } from './terms.js';
|
|
11
11
|
|
|
12
|
-
// Words a
|
|
12
|
+
// Words a document cannot use as a plain name: JavaScript's reserved words,
|
|
13
|
+
// and the names of its values that are not terms (Section 9.1).
|
|
13
14
|
export const RESERVED_WORDS = new Set([
|
|
15
|
+
'undefined', 'NaN', 'Infinity',
|
|
14
16
|
'await', 'break', 'case', 'catch', 'class', 'const', 'continue', 'debugger', 'default', 'delete',
|
|
15
17
|
'do', 'else', 'enum', 'export', 'extends', 'false', 'finally', 'for', 'function', 'if',
|
|
16
18
|
'implements', 'import', 'in', 'instanceof', 'interface', 'let', 'new', 'null', 'package',
|