@bablr/helpers 0.15.3 → 0.16.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/lib/enhancers.js CHANGED
@@ -1,4 +1,3 @@
1
- import { Coroutine } from '@bablr/coroutine';
2
1
  import {
3
2
  enhanceStrategyBuilderWithDebugLogging as logStrategy,
4
3
  enhanceStrategyBuilderWithEmittedLogging as logEmitted,
@@ -60,16 +59,12 @@ export const mapProductions = (fn, Grammar) => {
60
59
  return MappedGrammar;
61
60
  };
62
61
 
63
- export const buildDebugEnhancers = (log) => {
64
- return {
65
- agastStrategy: (strategy) => logEmitted(strategy, '>>> ', log),
66
- bablrStrategy: (strategy) => logStrategy(strategy, ' ', log),
67
- bablrProduction: createProductionLogger(' ', log),
68
- };
62
+ export const debugEnhancers = {
63
+ agast: (strategy) => logEmitted(strategy, '<<< '),
64
+ createBablrStrategy: (strategy) => logStrategy(strategy, ' >>> '),
65
+ bablrProduction: createProductionLogger('>>> '),
69
66
  };
70
67
 
71
- export const debugEnhancers = buildDebugEnhancers();
72
-
73
68
  export const stateEnhancer = (hooks, grammar) => {
74
69
  let state;
75
70
  return mapProductions((production) => {
@@ -1,6 +1,6 @@
1
1
  /* @macrome
2
2
  * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./productions.macro.js#f1d7575719a2690bc530f7c4dd1607fd8a4bdc7d
3
+ * @generatedfrom ./productions.macro.js#f76280b033fb91e9fb8362cc2c1caa8988b5beb4
4
4
  * This file is autogenerated. Please do not edit it directly.
5
5
  * When editing run `npx macrome watch` then change the file this is generated from.
6
6
  */
@@ -19,32 +19,51 @@ export function* List({
19
19
  allowHoles = false,
20
20
  allowTrailingSeparator = true
21
21
  } = ctx.unbox(props);
22
- let sep, it;
22
+ let sep,
23
+ it,
24
+ anySep = false;
23
25
  for (;;) {
24
26
  it = yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
25
27
  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
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, ..._interpolateArrayChildren(element, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`closeToken`], {
29
+ openToken: _t.s_i_node(_l.Instruction, "Punctuator", "("),
28
30
  values: [..._interpolateArray(element)],
29
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
31
+ closeToken: _t.s_i_node(_l.Instruction, "Punctuator", ")")
30
32
  }, {})
31
33
  }, {});
32
34
  if (it || allowTrailingSeparator) {
33
35
  sep = yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
34
36
  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", "'"),
37
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, ..._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`closeToken`], {
38
+ openToken: _t.s_i_node(_l.Instruction, "Punctuator", "("),
39
+ values: [..._interpolateArray(separator), _t.node(_l.CSTML, "String", [_t.ref`openToken`, _t.ref`content`, _t.ref`closeToken`], {
40
+ openToken: _t.s_i_node(_l.CSTML, "Punctuator", "'"),
39
41
  content: _t.node(_l.CSTML, "Content", [_t.lit("separators[]")], {}, {}),
40
- close: _t.s_i_node(_l.CSTML, "Punctuator", "'")
42
+ closeToken: _t.s_i_node(_l.CSTML, "Punctuator", "'")
41
43
  }, {})],
42
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
44
+ closeToken: _t.s_i_node(_l.Instruction, "Punctuator", ")")
43
45
  }, {})
44
46
  }, {});
47
+ anySep ||= sep;
45
48
  }
46
49
  if (!(sep || allowHoles)) break;
47
50
  }
51
+ if (!anySep) {
52
+ yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
53
+ verb: _t.s_node(_l.Instruction, "Identifier", "eat"),
54
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, _t.ref`values[]`, _t.embedded(_t.s_t_node(_l.Space, "Space", [_t.lit(" ")], {}, {})), _t.ref`values[]`, _t.ref`closeToken`], {
55
+ openToken: _t.s_i_node(_l.Instruction, "Punctuator", "("),
56
+ values: [_t.node(_l.Instruction, "Null", [_t.ref`sigilToken`], {
57
+ sigilToken: _t.s_i_node(_l.Instruction, "Keyword", "null")
58
+ }, {}), _t.node(_l.CSTML, "String", [_t.ref`openToken`, _t.ref`content`, _t.ref`closeToken`], {
59
+ openToken: _t.s_i_node(_l.CSTML, "Punctuator", "'"),
60
+ content: _t.node(_l.CSTML, "Content", [_t.lit("separators[]")], {}, {}),
61
+ closeToken: _t.s_i_node(_l.CSTML, "Punctuator", "'")
62
+ }, {})],
63
+ closeToken: _t.s_i_node(_l.Instruction, "Punctuator", ")")
64
+ }, {})
65
+ }, {});
66
+ }
48
67
  }
49
68
  export function* Any({
50
69
  value: matchers,
@@ -53,10 +72,10 @@ export function* Any({
53
72
  for (const matcher of ctx.unbox(matchers)) {
54
73
  if (yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
55
74
  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", "("),
75
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, ..._interpolateArrayChildren(matcher, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`closeToken`], {
76
+ openToken: _t.s_i_node(_l.Instruction, "Punctuator", "("),
58
77
  values: [..._interpolateArray(matcher)],
59
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
78
+ closeToken: _t.s_i_node(_l.Instruction, "Punctuator", ")")
60
79
  }, {})
61
80
  }, {})) break;
62
81
  }
@@ -68,10 +87,10 @@ export function* All({
68
87
  for (const matcher of ctx.unbox(matchers)) {
69
88
  yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
70
89
  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", "("),
90
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, ..._interpolateArrayChildren(matcher, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`closeToken`], {
91
+ openToken: _t.s_i_node(_l.Instruction, "Punctuator", "("),
73
92
  values: [..._interpolateArray(matcher)],
74
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
93
+ closeToken: _t.s_i_node(_l.Instruction, "Punctuator", ")")
75
94
  }, {})
76
95
  }, {});
77
96
  }
@@ -82,10 +101,10 @@ export function* Punctuator({
82
101
  if (!intrinsicValue) throw new Error('Intrinsic productions must have value');
83
102
  yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
84
103
  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", "("),
104
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, ..._interpolateArrayChildren(intrinsicValue, _t.ref`values[]`, _t.embedded(_t.t_node(_l.Comment, null, [_t.embedded(_t.t_node('Space', 'Space', [_t.lit(' ')]))]))), _t.ref`closeToken`], {
105
+ openToken: _t.s_i_node(_l.Instruction, "Punctuator", "("),
87
106
  values: [..._interpolateArray(intrinsicValue)],
88
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
107
+ closeToken: _t.s_i_node(_l.Instruction, "Punctuator", ")")
89
108
  }, {})
90
109
  }, {});
91
110
  }
@@ -100,10 +119,10 @@ export function* Optional({
100
119
  }
101
120
  yield _t.node(_l.Instruction, "Call", [_t.ref`verb`, _t.ref`arguments`], {
102
121
  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", "("),
122
+ arguments: _t.node(_l.Instruction, "Tuple", [_t.ref`openToken`, ..._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`closeToken`], {
123
+ openToken: _t.s_i_node(_l.Instruction, "Punctuator", "("),
105
124
  values: [..._interpolateArray(matchers_[0])],
106
- close: _t.s_i_node(_l.Instruction, "Punctuator", ")")
125
+ closeToken: _t.s_i_node(_l.Instruction, "Punctuator", ")")
107
126
  }, {})
108
127
  }, {});
109
128
  }
@@ -8,14 +8,21 @@ export function* List({ value: props, ctx }) {
8
8
  allowTrailingSeparator = true,
9
9
  } = ctx.unbox(props);
10
10
 
11
- let sep, it;
11
+ let sep,
12
+ it,
13
+ anySep = false;
12
14
  for (;;) {
13
15
  it = yield i`eatMatch(${element})`;
14
16
  if (it || allowTrailingSeparator) {
15
17
  sep = yield i`eatMatch(${separator} 'separators[]')`;
18
+ anySep ||= sep;
16
19
  }
17
20
  if (!(sep || allowHoles)) break;
18
21
  }
22
+
23
+ if (!anySep) {
24
+ yield i`eat(null 'separators[]')`;
25
+ }
19
26
  }
20
27
 
21
28
  export function* Any({ value: matchers, ctx }) {
package/lib/source.js CHANGED
@@ -145,7 +145,7 @@ export const sourceFromQuasis = (quasis) => new StreamIterable(__sourceFromQuasi
145
145
  export function* fillGapsWith(expressions, stream) {
146
146
  let exprIdx = 0;
147
147
  let iter = getStreamIterator(stream);
148
- let step;
148
+ let holding = false;
149
149
 
150
150
  for (;;) {
151
151
  let step = iter.next();
@@ -158,10 +158,19 @@ export function* fillGapsWith(expressions, stream) {
158
158
 
159
159
  const token = step.value;
160
160
 
161
+ if (token.type === 'Shift') {
162
+ holding = true;
163
+ }
164
+
161
165
  if (token.type === 'Gap') {
162
- if (exprIdx >= expressions.length) throw new Error('not enough gaps for expressions');
163
- yield* slice(2, -1, streamFromTree(expressions[exprIdx]));
164
- exprIdx++;
166
+ if (holding) {
167
+ holding = false;
168
+ yield token;
169
+ } else {
170
+ if (exprIdx >= expressions.length) throw new Error('not enough gaps for expressions');
171
+ yield* slice(2, -1, streamFromTree(expressions[exprIdx]));
172
+ exprIdx++;
173
+ }
165
174
  } else {
166
175
  yield token;
167
176
  }
package/lib/trivia.js CHANGED
@@ -6,7 +6,7 @@ const lookbehind = (context, s) => {
6
6
  let token = s.result;
7
7
  while (
8
8
  token &&
9
- ['OpenNodeTag', 'CloseNodeTag', 'OpenFragmentTag', 'Reference'].includes(token.type) &&
9
+ ['OpenNodeTag', 'CloseNodeTag', 'Reference'].includes(token.type) &&
10
10
  (token.type !== 'OpenNodeTag' || !token.value.intrinsicValue)
11
11
  ) {
12
12
  const prevToken = context.getPreviousTerminal(token);
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.3",
4
+ "version": "0.16.0",
5
5
  "author": "Conrad Buck<conartist6@gmail.com>",
6
6
  "type": "module",
7
7
  "files": [
@@ -26,25 +26,18 @@
26
26
  "clean": "macrome clean"
27
27
  },
28
28
  "dependencies": {
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",
29
+ "@bablr/language_enhancer-debug-log": "0.3.0",
30
+ "@bablr/strategy_enhancer-debug-log": "0.2.0",
31
+ "@bablr/agast-helpers": "0.1.6",
32
+ "@bablr/agast-vm-helpers": "0.1.5",
33
33
  "@bablr/coroutine": "0.1.0",
34
34
  "iter-tools-es": "^7.5.3"
35
35
  },
36
36
  "devDependencies": {
37
- "@babel/cli": "7.22.15",
38
- "@babel/core": "7.22.20",
39
- "@babel/plugin-proposal-decorators": "7.22.15",
40
- "@babel/plugin-transform-modules-commonjs": "^7.23.0",
41
- "@babel/plugin-transform-runtime": "^7.22.15",
42
- "@babel/runtime": "^7.23.2",
43
- "@bablr/boot": "0.2.1",
37
+ "@bablr/boot": "0.2.4",
44
38
  "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#d834ccc52795d6c3b96ecc6c419960fceed221a6",
45
39
  "@bablr/macrome": "0.1.1",
46
- "@bablr/macrome-generator-bablr": "0.2.0",
47
- "babel-plugin-macros": "3.1.0",
40
+ "@bablr/macrome-generator-bablr": "0.3.1",
48
41
  "enhanced-resolve": "^5.12.0",
49
42
  "eslint": "^7.32.0",
50
43
  "eslint-import-resolver-enhanced-resolve": "^1.0.5",
package/lib/.babelrc.json DELETED
@@ -1,7 +0,0 @@
1
- {
2
- "plugins": [
3
- "babel-plugin-macros",
4
- ["@babel/plugin-proposal-decorators", { "version": "2023-05" }],
5
- ["@babel/plugin-transform-runtime", { "helpers": true, "version": "^7.22.15" }]
6
- ]
7
- }