@bablr/helpers 0.15.0 → 0.15.2

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/lib/enhancers.js CHANGED
@@ -1,8 +1,10 @@
1
+ import { Coroutine } from '@bablr/coroutine';
1
2
  import {
2
3
  enhanceStrategyBuilderWithDebugLogging as logStrategy,
3
4
  enhanceStrategyBuilderWithEmittedLogging as logEmitted,
4
5
  } from '@bablr/strategy_enhancer-debug-log';
5
6
  import { enhanceProductionWithDebugLogging as createProductionLogger } from '@bablr/language_enhancer-debug-log';
7
+ import { getPrototypeOf } from './object.js';
6
8
 
7
9
  const { getOwnPropertyNames, hasOwn } = Object;
8
10
 
@@ -52,7 +54,7 @@ export const mapProductions = (fn, Grammar) => {
52
54
  mapped[key] = fn(prototype[key], key);
53
55
  }
54
56
  }
55
- ({ prototype } = prototype);
57
+ prototype = getPrototypeOf(prototype);
56
58
  }
57
59
 
58
60
  return MappedGrammar;
@@ -67,3 +69,30 @@ export const buildDebugEnhancers = (log) => {
67
69
  };
68
70
 
69
71
  export const debugEnhancers = buildDebugEnhancers();
72
+
73
+ export const stateEnhancer = (hooks, grammar) => {
74
+ let state;
75
+ return mapProductions((production) => {
76
+ return function* (props) {
77
+ let prevState = props.state;
78
+
79
+ if (!state) {
80
+ hooks.buildState?.(props.state);
81
+ } else if (props.state !== state) {
82
+ hooks.branchState?.(state, props.state);
83
+ }
84
+
85
+ state = props.state;
86
+
87
+ try {
88
+ yield* production(props);
89
+
90
+ hooks.acceptState?.(props.state, state);
91
+ } catch (e) {
92
+ hooks.rejectState?.(props.state);
93
+ }
94
+
95
+ state = prevState;
96
+ };
97
+ }, grammar);
98
+ };
@@ -1,57 +1,109 @@
1
- import { i } from '@bablr/boot/shorthand.macro';
2
-
3
- export function* List({ value: props, ctx }) {
1
+ /* @macrome
2
+ * @generatedby @bablr/macrome-generator-bablr
3
+ * @generatedfrom ./productions.macro.js#f1d7575719a2690bc530f7c4dd1607fd8a4bdc7d
4
+ * This file is autogenerated. Please do not edit it directly.
5
+ * When editing run `npx macrome watch` then change the file this is generated from.
6
+ */
7
+ import { interpolateString as _interpolateString } from "@bablr/agast-helpers/template";
8
+ import { interpolateArrayChildren as _interpolateArrayChildren } from "@bablr/agast-helpers/template";
9
+ import { interpolateArray as _interpolateArray } from "@bablr/agast-helpers/template";
10
+ import * as _l from "@bablr/agast-vm-helpers/languages";
11
+ import * as _t from "@bablr/agast-helpers/shorthand";
12
+ export function* List({
13
+ value: props,
14
+ ctx
15
+ }) {
4
16
  const {
5
17
  element,
6
18
  separator,
7
19
  allowHoles = false,
8
- allowTrailingSeparator = true,
20
+ allowTrailingSeparator = true
9
21
  } = ctx.unbox(props);
10
-
11
22
  let sep, it;
12
23
  for (;;) {
13
- it = yield i`eatMatch(${element})`;
24
+ it = yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
25
+ verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
26
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(element, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
27
+ open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
28
+ values: [..._interpolateArray(element)],
29
+ close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
30
+ }, {})
31
+ }, {});
14
32
  if (it || allowTrailingSeparator) {
15
- sep = yield i`eatMatch(${separator} 'separators[]')`;
33
+ sep = yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
34
+ verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
35
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(separator, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.embedded(_t.s_t_node(_l.Space, "Space", [_t.lit(" ")], {}, {})), _t.ref`values[]`, _t.ref`close`], {
36
+ open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
37
+ values: [..._interpolateArray(separator), _t.node(_l.CSTML, "String", [_t.ref`open`, _t.ref`content`, _t.ref`close`], {
38
+ open: _t.s_i_node(_l.CSTML, "Punctuator", "'"),
39
+ content: _t.node(_l.CSTML, "Content", [_t.lit("separators[]")], {}, {}),
40
+ close: _t.s_i_node(_l.CSTML, "Punctuator", "'")
41
+ }, {})],
42
+ close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
43
+ }, {})
44
+ }, {});
16
45
  }
17
46
  if (!(sep || allowHoles)) break;
18
47
  }
19
48
  }
20
-
21
- export function* Any({ value: matchers, ctx }) {
49
+ export function* Any({
50
+ value: matchers,
51
+ ctx
52
+ }) {
22
53
  for (const matcher of ctx.unbox(matchers)) {
23
- if (yield i`eatMatch(${matcher})`) break;
54
+ if (yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
55
+ verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
56
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(matcher, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
57
+ open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
58
+ values: [..._interpolateArray(matcher)],
59
+ close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
60
+ }, {})
61
+ }, {})) break;
24
62
  }
25
63
  }
26
-
27
- export function* All({ value: matchers, ctx }) {
64
+ export function* All({
65
+ value: matchers,
66
+ ctx
67
+ }) {
28
68
  for (const matcher of ctx.unbox(matchers)) {
29
- yield i`eat(${matcher})`;
69
+ yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
70
+ verb: _t.s_node(_l.Instruction, "Identifier", "eat"),
71
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(matcher, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
72
+ open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
73
+ values: [..._interpolateArray(matcher)],
74
+ close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
75
+ }, {})
76
+ }, {});
30
77
  }
31
78
  }
32
-
33
- export function* Match({ value: cases, ctx }) {
34
- for (const case_ of ctx.unbox(cases)) {
35
- const { 0: matcher, 1: guard, 2: props = i.Expression`null` } = ctx.unbox(case_);
36
- if (yield i`match(${guard})`) {
37
- yield i`eat(${matcher} null ${props})`;
38
- break;
39
- }
40
- }
41
- }
42
-
43
- export function* Punctuator({ intrinsicValue }) {
79
+ export function* Punctuator({
80
+ intrinsicValue
81
+ }) {
44
82
  if (!intrinsicValue) throw new Error('Intrinsic productions must have value');
45
-
46
- yield i`eat(${intrinsicValue})`;
83
+ yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
84
+ verb: _t.s_node(_l.Instruction, "Identifier", "eat"),
85
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(intrinsicValue, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
86
+ open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
87
+ values: [..._interpolateArray(intrinsicValue)],
88
+ close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
89
+ }, {})
90
+ }, {});
47
91
  }
48
-
49
92
  export const Keyword = Punctuator;
50
-
51
- export function* Optional({ value: matchers, ctx }) {
93
+ export function* Optional({
94
+ value: matchers,
95
+ ctx
96
+ }) {
52
97
  const matchers_ = ctx.unbox(matchers);
53
98
  if (matchers_.length > 1) {
54
99
  throw new Error('Optional only allows one matcher');
55
100
  }
56
- yield i`eatMatch(${matchers_[0]})`;
57
- }
101
+ yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
102
+ verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
103
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(matchers_[0], _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
104
+ open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
105
+ values: [..._interpolateArray(matchers_[0])],
106
+ close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
107
+ }, {})
108
+ }, {});
109
+ }
@@ -0,0 +1,47 @@
1
+ import { i } from '@bablr/boot/shorthand.macro';
2
+
3
+ export function* List({ value: props, ctx }) {
4
+ const {
5
+ element,
6
+ separator,
7
+ allowHoles = false,
8
+ allowTrailingSeparator = true,
9
+ } = ctx.unbox(props);
10
+
11
+ let sep, it;
12
+ for (;;) {
13
+ it = yield i`eatMatch(${element})`;
14
+ if (it || allowTrailingSeparator) {
15
+ sep = yield i`eatMatch(${separator} 'separators[]')`;
16
+ }
17
+ if (!(sep || allowHoles)) break;
18
+ }
19
+ }
20
+
21
+ export function* Any({ value: matchers, ctx }) {
22
+ for (const matcher of ctx.unbox(matchers)) {
23
+ if (yield i`eatMatch(${matcher})`) break;
24
+ }
25
+ }
26
+
27
+ export function* All({ value: matchers, ctx }) {
28
+ for (const matcher of ctx.unbox(matchers)) {
29
+ yield i`eat(${matcher})`;
30
+ }
31
+ }
32
+
33
+ export function* Punctuator({ intrinsicValue }) {
34
+ if (!intrinsicValue) throw new Error('Intrinsic productions must have value');
35
+
36
+ yield i`eat(${intrinsicValue})`;
37
+ }
38
+
39
+ export const Keyword = Punctuator;
40
+
41
+ export function* Optional({ value: matchers, ctx }) {
42
+ const matchers_ = ctx.unbox(matchers);
43
+ if (matchers_.length > 1) {
44
+ throw new Error('Optional only allows one matcher');
45
+ }
46
+ yield i`eatMatch(${matchers_[0]})`;
47
+ }
package/lib/source.js CHANGED
@@ -9,7 +9,7 @@ const escapables = {
9
9
  0: '\0',
10
10
  };
11
11
 
12
- function* __readStreamAsStreamIterator(stream) {
12
+ function* __sourceFromReadStream(stream) {
13
13
  let iter = stream[Symbol.asyncIterator]();
14
14
  let step;
15
15
 
@@ -26,13 +26,12 @@ function* __readStreamAsStreamIterator(stream) {
26
26
  }
27
27
  }
28
28
 
29
- const readStreamAsStreamIterator = (stream) =>
30
- new StreamIterable(__readStreamAsStreamIterator(stream));
29
+ export const sourceFromReadStream = (stream) => new StreamIterable(__sourceFromReadStream(stream));
31
30
 
32
31
  const gapStr = '<//>';
33
32
 
34
- function* __sourceFromReadStream(stream) {
35
- let iter = getStreamIterator(readStreamAsStreamIterator(stream));
33
+ function* __embeddedSourceFromReadStream(stream) {
34
+ let iter = getStreamIterator(sourceFromReadStream(stream));
36
35
  let step;
37
36
  let escape = false;
38
37
  let gapMatchIdx = 0;
@@ -90,7 +89,8 @@ function* __sourceFromReadStream(stream) {
90
89
  }
91
90
  }
92
91
 
93
- export const sourceFromReadStream = (stream) => new StreamIterable(__sourceFromReadStream(stream));
92
+ export const embeddedSourceFromReadStream = (stream) =>
93
+ new StreamIterable(__embeddedSourceFromReadStream(stream));
94
94
 
95
95
  function* __sourceFromTokenStream(terminals) {
96
96
  let iter = getStreamIterator(terminals);
package/lib/trivia.js CHANGED
@@ -25,10 +25,6 @@ export const triviaEnhancer = ({ triviaIsAllowed, eatMatchTrivia }, grammar) =>
25
25
  const co = new Coroutine(production(props));
26
26
  const { s, ctx } = props;
27
27
 
28
- if (!co.generator) {
29
- throw new Error('Production was not a generator');
30
- }
31
-
32
28
  co.advance();
33
29
 
34
30
  try {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bablr/helpers",
3
3
  "description": "Command helpers for use in writing BABLR grammars",
4
- "version": "0.15.0",
4
+ "version": "0.15.2",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -13,7 +13,7 @@
13
13
  "./grammar": "./lib/grammar.js",
14
14
  "./object": "./lib/object.js",
15
15
  "./path": "./lib/path.js",
16
- "./productions": "./lib/productions.generated.js",
16
+ "./productions": "./lib/productions.js",
17
17
  "./shorthand": "./lib/shorthand.js",
18
18
  "./source": "./lib/source.js",
19
19
  "./symbols": "./lib/symbols.js",
@@ -21,14 +21,15 @@
21
21
  },
22
22
  "sideEffects": false,
23
23
  "scripts": {
24
- "generate": "babel lib/productions.js --out-file lib/productions.generated.js",
25
- "clean": "rm lib/productions.generated.js"
24
+ "build": "macrome build",
25
+ "watch": "macrome watch",
26
+ "clean": "macrome clean"
26
27
  },
27
28
  "dependencies": {
28
- "@bablr/language_enhancer-debug-log": "0.2.0",
29
- "@bablr/strategy_enhancer-debug-log": "0.1.0",
30
- "@bablr/agast-helpers": "0.1.0",
31
- "@bablr/agast-vm-helpers": "0.1.0",
29
+ "@bablr/language_enhancer-debug-log": "0.2.1",
30
+ "@bablr/strategy_enhancer-debug-log": "0.1.1",
31
+ "@bablr/agast-helpers": "0.1.1",
32
+ "@bablr/agast-vm-helpers": "0.1.1",
32
33
  "@bablr/coroutine": "0.1.0",
33
34
  "iter-tools-es": "^7.5.3"
34
35
  },
@@ -39,8 +40,10 @@
39
40
  "@babel/plugin-transform-modules-commonjs": "^7.23.0",
40
41
  "@babel/plugin-transform-runtime": "^7.22.15",
41
42
  "@babel/runtime": "^7.23.2",
42
- "@bablr/boot": "0.2.0",
43
+ "@bablr/boot": "0.2.1",
43
44
  "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#d834ccc52795d6c3b96ecc6c419960fceed221a6",
45
+ "@bablr/macrome": "0.1.1",
46
+ "@bablr/macrome-generator-bablr": "0.2.0",
44
47
  "babel-plugin-macros": "3.1.0",
45
48
  "enhanced-resolve": "^5.12.0",
46
49
  "eslint": "^7.32.0",
@@ -1,137 +0,0 @@
1
- import { interpolateString as _interpolateString } from "@bablr/agast-helpers/template";
2
- import { interpolateArrayChildren as _interpolateArrayChildren } from "@bablr/agast-helpers/template";
3
- import { interpolateArray as _interpolateArray } from "@bablr/agast-helpers/template";
4
- import * as _l from "@bablr/agast-vm-helpers/languages";
5
- import * as _t from "@bablr/agast-helpers/shorthand";
6
- export function* List({
7
- value: props,
8
- ctx
9
- }) {
10
- const {
11
- element,
12
- separator,
13
- allowHoles = false,
14
- allowTrailingSeparator = true
15
- } = ctx.unbox(props);
16
- let sep, it;
17
- for (;;) {
18
- it = yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
19
- verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
20
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(element, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
21
- open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
22
- values: [..._interpolateArray(element)],
23
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
24
- }, {})
25
- }, {});
26
- if (it || allowTrailingSeparator) {
27
- sep = yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
28
- verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
29
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(separator, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.embedded(_t.s_t_node(_l.Space, "Space", [_t.lit(" ")], {}, {})), _t.ref`values[]`, _t.ref`close`], {
30
- open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
31
- values: [..._interpolateArray(separator), _t.node(_l.CSTML, "String", [_t.ref`open`, _t.ref`content`, _t.ref`close`], {
32
- open: _t.s_i_node(_l.CSTML, "Punctuator", "'"),
33
- content: _t.node(_l.CSTML, "Content", [_t.lit("separators[]")], {}, {}),
34
- close: _t.s_i_node(_l.CSTML, "Punctuator", "'")
35
- }, {})],
36
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
37
- }, {})
38
- }, {});
39
- }
40
- if (!(sep || allowHoles)) break;
41
- }
42
- }
43
- export function* Any({
44
- value: matchers,
45
- ctx
46
- }) {
47
- for (const matcher of ctx.unbox(matchers)) {
48
- if (yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
49
- verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
50
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(matcher, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
51
- open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
52
- values: [..._interpolateArray(matcher)],
53
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
54
- }, {})
55
- }, {})) break;
56
- }
57
- }
58
- export function* All({
59
- value: matchers,
60
- ctx
61
- }) {
62
- for (const matcher of ctx.unbox(matchers)) {
63
- yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
64
- verb: _t.s_node(_l.Instruction, "Identifier", "eat"),
65
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(matcher, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
66
- open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
67
- values: [..._interpolateArray(matcher)],
68
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
69
- }, {})
70
- }, {});
71
- }
72
- }
73
- export function* Match({
74
- value: cases,
75
- ctx
76
- }) {
77
- for (const case_ of ctx.unbox(cases)) {
78
- const {
79
- 0: matcher,
80
- 1: guard,
81
- 2: props = _t.node(_l.Instruction, "Null", [_t.ref`value`], {
82
- value: _t.s_i_node(_l.Instruction, "Keyword", "null")
83
- }, {})
84
- } = ctx.unbox(case_);
85
- if (yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
86
- verb: _t.s_node(_l.Instruction, "Identifier", "match"),
87
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(guard, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
88
- open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
89
- values: [..._interpolateArray(guard)],
90
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
91
- }, {})
92
- }, {})) {
93
- yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
94
- verb: _t.s_node(_l.Instruction, "Identifier", "eat"),
95
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(matcher, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.embedded(_t.s_t_node(_l.Space, "Space", [_t.lit(" ")], {}, {})), _t.ref`values[]`, _t.embedded(_t.s_t_node(_l.Space, "Space", [_t.lit(" ")], {}, {})), ..._interpolateArrayChildren(props, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
96
- open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
97
- values: [..._interpolateArray(matcher), _t.node(_l.Instruction, "Null", [_t.ref`value`], {
98
- value: _t.s_i_node(_l.Instruction, "Keyword", "null")
99
- }, {}), ..._interpolateArray(props)],
100
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
101
- }, {})
102
- }, {});
103
- break;
104
- }
105
- }
106
- }
107
- export function* Punctuator({
108
- intrinsicValue
109
- }) {
110
- if (!intrinsicValue) throw new Error('Intrinsic productions must have value');
111
- yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
112
- verb: _t.s_node(_l.Instruction, "Identifier", "eat"),
113
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(intrinsicValue, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
114
- open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
115
- values: [..._interpolateArray(intrinsicValue)],
116
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
117
- }, {})
118
- }, {});
119
- }
120
- export const Keyword = Punctuator;
121
- export function* Optional({
122
- value: matchers,
123
- ctx
124
- }) {
125
- const matchers_ = ctx.unbox(matchers);
126
- if (matchers_.length > 1) {
127
- throw new Error('Optional only allows one matcher');
128
- }
129
- yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
130
- verb: _t.s_node(_l.Instruction, "Identifier", "eatMatch"),
131
- arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`open`, ..._interpolateArrayChildren(matchers_[0], _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`close`], {
132
- open: _t.s_i_node(_l.Instruction, "Punctuator", "("),
133
- values: [..._interpolateArray(matchers_[0])],
134
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
135
- }, {})
136
- }, {});
137
- }