eyeprolog 1.1.3 → 1.1.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/package.json +1 -1
- package/src/cli.js +3 -3
- package/test/run-regression.mjs +26 -0
- package/the-art-of-eyeprolog.md +5 -5
package/package.json
CHANGED
package/src/cli.js
CHANGED
|
@@ -48,9 +48,9 @@ export async function main(argv) {
|
|
|
48
48
|
options.version = true;
|
|
49
49
|
} else if (!endOptions && (arg === '--warnings' || arg === '-w')) {
|
|
50
50
|
options.warnings = true;
|
|
51
|
-
} else if (!endOptions && arg === '--goal') {
|
|
51
|
+
} else if (!endOptions && (arg === '--goal' || arg === '-g')) {
|
|
52
52
|
const goal = argv[++i];
|
|
53
|
-
if (goal == null) throw new Error(
|
|
53
|
+
if (goal == null) throw new Error(`option ${arg} requires a goal`);
|
|
54
54
|
options.goals.push(goal);
|
|
55
55
|
} else if (!endOptions && arg.startsWith('-') && !arg.startsWith('--') && arg.length > 2) {
|
|
56
56
|
const flags = arg.slice(1);
|
|
@@ -210,7 +210,7 @@ Options:
|
|
|
210
210
|
-s, --stats Print solver statistics to stderr after execution.
|
|
211
211
|
-v, --version Show the package version and exit.
|
|
212
212
|
-w, --warnings Print non-fatal portability warnings to stderr.
|
|
213
|
-
--goal goal
|
|
213
|
+
-g, --goal goal Solve goal and print its ground answers; may be repeated.
|
|
214
214
|
If omitted, use %% goal: comments from the inputs.
|
|
215
215
|
-- Stop option parsing; following arguments are treated as files.
|
|
216
216
|
`);
|
package/test/run-regression.mjs
CHANGED
|
@@ -210,6 +210,7 @@ why(
|
|
|
210
210
|
assertEqual(result.status, 0, 'exit status');
|
|
211
211
|
assertIncludes(result.stdout, 'Usage:\n eyeprolog\n eyeprolog [options] [file-or-url.pl|- ...]', 'stdout');
|
|
212
212
|
assertIncludes(result.stdout, 'With no arguments, start a Prolog REPL.', 'stdout');
|
|
213
|
+
assertIncludes(result.stdout, '-g, --goal goal', 'stdout');
|
|
213
214
|
assertIncludes(result.stdout, '-p, --proof', 'stdout');
|
|
214
215
|
assertIncludes(result.stdout, '-s, --stats', 'stdout');
|
|
215
216
|
assertIncludes(result.stdout, '-v, --version', 'stdout');
|
|
@@ -366,6 +367,31 @@ why(
|
|
|
366
367
|
assertEqual(result.stderr, '', 'stderr');
|
|
367
368
|
},
|
|
368
369
|
},
|
|
370
|
+
{
|
|
371
|
+
name: '-g supplies an explicit CLI goal',
|
|
372
|
+
run: () => {
|
|
373
|
+
const input = [
|
|
374
|
+
'%% goal: answer(metadata, X)',
|
|
375
|
+
'value(metadata, ignored).',
|
|
376
|
+
'value(explicit, selected).',
|
|
377
|
+
'answer(Kind, Value) :- value(Kind, Value).',
|
|
378
|
+
'',
|
|
379
|
+
].join('\n');
|
|
380
|
+
const result = runCli(['-g', 'answer(explicit, X)', '-'], { input });
|
|
381
|
+
assertEqual(result.status, 0, 'exit status');
|
|
382
|
+
assertEqual(result.stdout, 'answer(explicit, selected).\n', 'stdout');
|
|
383
|
+
assertEqual(result.stderr, '', 'stderr');
|
|
384
|
+
},
|
|
385
|
+
},
|
|
386
|
+
{
|
|
387
|
+
name: '-g requires a goal argument',
|
|
388
|
+
run: () => {
|
|
389
|
+
const result = runCli(['-g']);
|
|
390
|
+
assertEqual(result.status, 1, 'exit status');
|
|
391
|
+
assertEqual(result.stdout, '', 'stdout');
|
|
392
|
+
assertEqual(result.stderr, 'eyeprolog: option -g requires a goal\n', 'stderr');
|
|
393
|
+
},
|
|
394
|
+
},
|
|
369
395
|
|
|
370
396
|
{
|
|
371
397
|
name: '--proof enables query explanations',
|
package/the-art-of-eyeprolog.md
CHANGED
|
@@ -6046,13 +6046,13 @@ displays command-line help.
|
|
|
6046
6046
|
### Selecting goals
|
|
6047
6047
|
|
|
6048
6048
|
A Prolog source file states facts, rules, and ISO directives; the command line
|
|
6049
|
-
selects what to solve. Supply `--goal` followed by a callable Prolog goal:
|
|
6049
|
+
selects what to solve. Supply `-g` or `--goal` followed by a callable Prolog goal:
|
|
6050
6050
|
|
|
6051
6051
|
```sh
|
|
6052
6052
|
eyeprolog --goal 'ancestor(ada, Who)' examples/ancestor.pl
|
|
6053
6053
|
```
|
|
6054
6054
|
|
|
6055
|
-
Repeat `--goal` to request several result relations in one run. EyeProlog prints
|
|
6055
|
+
Repeat `-g` or `--goal` to request several result relations in one run. EyeProlog prints
|
|
6056
6056
|
their ground answers in the order the goals were supplied.
|
|
6057
6057
|
|
|
6058
6058
|
For a self-running example, place the host goal in an ordinary comment:
|
|
@@ -6061,8 +6061,8 @@ For a self-running example, place the host goal in an ordinary comment:
|
|
|
6061
6061
|
%% goal: ancestor(ada, Who)
|
|
6062
6062
|
```
|
|
6063
6063
|
|
|
6064
|
-
When no `--goal` option is present, the CLI reads these comments from all
|
|
6065
|
-
sources and runs them in source order. An explicit
|
|
6064
|
+
When no `-g` or `--goal` option is present, the CLI reads these comments from all
|
|
6065
|
+
input sources and runs them in source order. An explicit goal option overrides them.
|
|
6066
6066
|
Because `%% goal:` is a comment rather than a Prolog directive, another ISO
|
|
6067
6067
|
processor may ignore it and the program remains portable Prolog text. External
|
|
6068
6068
|
goals are still preferable when a script, shell history, or API call should
|
|
@@ -6075,7 +6075,7 @@ make the observed question explicit.
|
|
|
6075
6075
|
| `-s`, `--stats` | Print solver counters to stderr |
|
|
6076
6076
|
| `-v`, `--version` | Print the package version |
|
|
6077
6077
|
| `-w`, `--warnings` | Print non-fatal portability warnings |
|
|
6078
|
-
| `--goal Goal` | Solve a callable goal; may be repeated; overrides `%% goal:` comments |
|
|
6078
|
+
| `-g`, `--goal Goal` | Solve a callable goal; may be repeated; overrides `%% goal:` comments |
|
|
6079
6079
|
| `--` | Treat following arguments as inputs |
|
|
6080
6080
|
|
|
6081
6081
|
Short flags may be combined, so `-pw` is equivalent to `-p -w`.
|