@plurnk/plurnk-parser 1.18.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.
Files changed (37) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +71 -0
  3. package/SPEC.md +35 -0
  4. package/bin/plurnk-parser.js +43 -0
  5. package/dist/AstBuilder.d.ts +21 -0
  6. package/dist/AstBuilder.d.ts.map +1 -0
  7. package/dist/AstBuilder.js +871 -0
  8. package/dist/AstBuilder.js.map +1 -0
  9. package/dist/PlurnkErrorStrategy.d.ts +11 -0
  10. package/dist/PlurnkErrorStrategy.d.ts.map +1 -0
  11. package/dist/PlurnkErrorStrategy.js +288 -0
  12. package/dist/PlurnkErrorStrategy.js.map +1 -0
  13. package/dist/PlurnkParser.d.ts +15 -0
  14. package/dist/PlurnkParser.d.ts.map +1 -0
  15. package/dist/PlurnkParser.js +324 -0
  16. package/dist/PlurnkParser.js.map +1 -0
  17. package/dist/RecordingListener.d.ts +9 -0
  18. package/dist/RecordingListener.d.ts.map +1 -0
  19. package/dist/RecordingListener.js +37 -0
  20. package/dist/RecordingListener.js.map +1 -0
  21. package/dist/generated/plurnkLexer.d.ts +172 -0
  22. package/dist/generated/plurnkLexer.d.ts.map +1 -0
  23. package/dist/generated/plurnkLexer.js +1168 -0
  24. package/dist/generated/plurnkLexer.js.map +1 -0
  25. package/dist/generated/plurnkParser.d.ts +437 -0
  26. package/dist/generated/plurnkParser.d.ts.map +1 -0
  27. package/dist/generated/plurnkParser.js +2974 -0
  28. package/dist/generated/plurnkParser.js.map +1 -0
  29. package/dist/generated/plurnkParserVisitor.d.ts +263 -0
  30. package/dist/generated/plurnkParserVisitor.d.ts.map +1 -0
  31. package/dist/generated/plurnkParserVisitor.js +227 -0
  32. package/dist/generated/plurnkParserVisitor.js.map +1 -0
  33. package/dist/index.d.ts +4 -0
  34. package/dist/index.d.ts.map +1 -0
  35. package/dist/index.js +5 -0
  36. package/dist/index.js.map +1 -0
  37. package/package.json +73 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 PossumTech Laboratories, LLC
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,71 @@
1
+ # @plurnk/plurnk-parser
2
+
3
+ The parser for the PLURNK model language: the ANTLR grammars, the generated
4
+ lexer and parser, the AST builder, and path decomposition. It implements the
5
+ language that [`@plurnk/plurnk-contracts`](../plurnk-contracts) specifies and
6
+ teaches; the AST and wire types it produces are the contracts package's.
7
+
8
+ ## Install
9
+
10
+ ```sh
11
+ npm install @plurnk/plurnk-parser
12
+ ```
13
+
14
+ The service's execution path is the consumer. A client that validates or
15
+ presents the wire needs only `@plurnk/plurnk-contracts`, which carries no parser
16
+ runtime.
17
+
18
+ ## Parser
19
+
20
+ ```ts
21
+ import { PlurnkParser } from "@plurnk/plurnk-parser";
22
+
23
+ const result = PlurnkParser.parse(input);
24
+
25
+ for (const item of result.items) {
26
+ if (item.kind === "statement") {
27
+ console.log(item.statement.op);
28
+ }
29
+ }
30
+ ```
31
+
32
+ Parse items are ordered and discriminate as `statement` or `error`.
33
+ Outside-block text is ignored in every tier; literal bodies remain exact.
34
+ The parser entry points deliberately accept different document tiers:
35
+
36
+ | Entry point | Accepted input |
37
+ |--------------------------------|-------------------------------------------------------|
38
+ | `PlurnkParser.parse` | One operation-bearing model turn; omitted TASK continues silently |
39
+ | `PlurnkParser.parseStatements` | A sequence of protocol statements |
40
+ | `PlurnkParser.parseLog` | Consecutive disposition-ended turns |
41
+ | `PlurnkParser.parseClient` | Protocol statements plus the client-only LOOK |
42
+ | `parsePath` | One path or URI using parser-equivalent decomposition |
43
+
44
+ See the contracts SPEC {§turn-shape} and {§tier-entrypoints} for the tier
45
+ boundaries. The AST, parse-result, and wire types come from
46
+ `@plurnk/plurnk-contracts`.
47
+
48
+ ## CLI
49
+
50
+ ```text
51
+ plurnk-parser [file] parse a file, or standard input when omitted
52
+ plurnk-parser --help show usage
53
+ ```
54
+
55
+ The CLI prints the parse result as JSON and exits `0` for a clean parse or `1`
56
+ when the result contains an error or unparsed tail.
57
+
58
+ ## Development
59
+
60
+ ```sh
61
+ npm run build
62
+ npm test
63
+ npm run test:installation
64
+ ```
65
+
66
+ `npm run build:grammar` regenerates the parser from `plurnkLexer.g4` and
67
+ `plurnkParser.g4`. Change the grammar rather than editing generated output.
68
+
69
+ ## License
70
+
71
+ MIT
package/SPEC.md ADDED
@@ -0,0 +1,35 @@
1
+ # @plurnk/plurnk-parser — SPEC
2
+
3
+ ## §parser-package 1. What this package is
4
+
5
+ `@plurnk/plurnk-parser` implements the PLURNK language that
6
+ `@plurnk/plurnk-contracts` specifies. It owns the ANTLR grammars
7
+ (`plurnkLexer.g4`, `plurnkParser.g4`), the generated lexer, parser and visitor,
8
+ `AstBuilder`, the error strategy and the recording listener, the `PlurnkParser`
9
+ tier entry points, `parsePath`, and the `plurnk-parser` command line. It depends
10
+ on contracts for the AST and wire types, the schemas, `PathSyntax`,
11
+ `PlurnkParseError`, `PlanValue`, `TurnDisposition`, and the constants. Contracts
12
+ depends on nothing here.
13
+
14
+ §parser-boundary **The contract lives in contracts; the implementation lives here.**
15
+ Accepted syntax, document tiers, recovery, whitespace, framing, and diagnostics
16
+ are specified by `plurnk-contracts/SPEC.md` ({§contract-layers},
17
+ {§path-syntax}, {§parser-architecture}, {§turn-shape}, {§tier-entrypoints}) and
18
+ taught by `plurnk-contracts/plurnk.md`. This package's tests are the evidence for
19
+ those anchors and cite them. Nothing that only validates, presents, or transports
20
+ the wire needs this package.
21
+
22
+ §parser-consumers **Who imports the parser.** The service's execution path (core,
23
+ agui, execs) imports `PlurnkParser` and `parsePath` from this package.
24
+ `@plurnk/plurnk-contracts` exports neither and declares no parser dependency, so a
25
+ client that installs contracts installs no `antlr4ng`, `xpath`, or `json-p3`.
26
+
27
+ ## §parser-build 2. Build and artifacts
28
+
29
+ `npm run build:grammar` regenerates `src/generated` from the grammars with
30
+ antlr-ng; generated files are artifacts, never edited, and are not tracked.
31
+ `npm run build` emits `dist`. `npm run test:installation` packs the built parser
32
+ and contracts candidates, installs both into a clean consumer, verifies their
33
+ installed versions, and exercises every tier entry point, `parsePath`, the CLI,
34
+ and a browser-Worker bundle. Prepublication checks must not resolve the candidate
35
+ contracts version from the registry.
@@ -0,0 +1,43 @@
1
+ #!/usr/bin/env node
2
+ import { readFileSync } from "node:fs";
3
+ import { parseArgs } from "node:util";
4
+ import { PlurnkParser } from "../dist/index.js";
5
+
6
+ const USAGE = `Usage:
7
+ plurnk-parser [file] Parse plurnk source from a file (or stdin if omitted or '-')
8
+ and print the result as JSON.
9
+ plurnk-parser --help Show this message.
10
+
11
+ Exit codes:
12
+ 0 parse succeeded with no errors and no unparsed tail
13
+ 1 parse produced one or more errors, or left an unparsed tail`;
14
+
15
+ const { values, positionals } = parseArgs({
16
+ args: process.argv.slice(2),
17
+ options: {
18
+ help: { type: "boolean", short: "h" },
19
+ },
20
+ allowPositionals: true,
21
+ });
22
+
23
+ if (values.help) {
24
+ process.stdout.write(`${USAGE}\n`);
25
+ process.exit(0);
26
+ }
27
+
28
+ const target = positionals[0];
29
+ const input = !target || target === "-"
30
+ ? readFileSync(0, "utf8")
31
+ : readFileSync(target, "utf8");
32
+
33
+ const result = PlurnkParser.parse(input);
34
+
35
+ const serialized = JSON.stringify(
36
+ result,
37
+ (_key, value) => (value instanceof RegExp ? value.toString() : value),
38
+ 2,
39
+ );
40
+ process.stdout.write(`${serialized}\n`);
41
+
42
+ const hasIssues = result.items.some((i) => i.kind === "error") || result.unparsedTail !== undefined;
43
+ process.exit(hasIssues ? 1 : 0);
@@ -0,0 +1,21 @@
1
+ import type { ClientStatement, ParsedPath, PlurnkStatement, Position } from "@plurnk/plurnk-contracts";
2
+ import type { ClientStatementContext, StatementContext, MidStatementContext } from "./generated/plurnkParser.ts";
3
+ import { DispositionStatementContext, SendStatementContext } from "./generated/plurnkParser.ts";
4
+ import { PlurnkParseError } from "@plurnk/plurnk-contracts";
5
+ declare module "xpath" {
6
+ function parse(expression: string): unknown;
7
+ }
8
+ export default class AstBuilder {
9
+ #private;
10
+ static takeAdvisories(): PlurnkParseError[];
11
+ static build(ctx: StatementContext | MidStatementContext | DispositionStatementContext | SendStatementContext): PlurnkStatement;
12
+ static buildClient(ctx: ClientStatementContext): ClientStatement;
13
+ static executorSpellings: ReadonlyMap<string, string>;
14
+ /**
15
+ * Apply target-slot decomposition without round-tripping through a statement.
16
+ * Returns null for empty input and throws PlurnkParseError when a scheme URL
17
+ * fails WHATWG admission. {§path-syntax}
18
+ */
19
+ static parsePath(raw: string, pos?: Position): ParsedPath | null;
20
+ }
21
+ //# sourceMappingURL=AstBuilder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AstBuilder.d.ts","sourceRoot":"","sources":["../src/AstBuilder.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAER,eAAe,EAcf,UAAU,EACV,eAAe,EACf,QAAQ,EAOX,MAAM,0BAA0B,CAAC;AAClC,OAAO,KAAK,EAER,sBAAsB,EActB,gBAAgB,EAChB,mBAAmB,EACtB,MAAM,6BAA6B,CAAC;AACrC,OAAO,EAIH,2BAA2B,EAC3B,oBAAoB,EAGvB,MAAM,6BAA6B,CAAC;AAErC,OAAO,EAAyB,gBAAgB,EAAmB,MAAM,0BAA0B,CAAC;AAGpG,OAAO,QAAQ,OAAO,CAAC;IACnB,SAAgB,KAAK,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO,CAAC;CACtD;AAQD,MAAM,CAAC,OAAO,OAAO,UAAU;;IAK3B,MAAM,CAAC,cAAc,IAAI,gBAAgB,EAAE,CAI1C;IAwJD,MAAM,CAAC,KAAK,CAAC,GAAG,EAAE,gBAAgB,GAAG,mBAAmB,GAAG,2BAA2B,GAAG,oBAAoB,GAAG,eAAe,CAmB9H;IA8BD,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,sBAAsB,GAAG,eAAe,CAI/D;IA4ID,MAAM,CAAC,iBAAiB,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAa;IA+RlE;;;;OAIG;IACH,MAAM,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,GAAG,GAAE,QAAiC,GAAG,UAAU,GAAG,IAAI,CAmCvF;CAiLJ"}