@bablr/language-en-regex-vm-pattern 0.8.0 → 0.9.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/grammar.js CHANGED
@@ -1,16 +1,16 @@
1
1
  /* @macrome
2
2
  * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./grammar.macro.js#0f254bf8ccce6de1ebde89020c7430dc4259e311
3
+ * @generatedfrom ./grammar.macro.js#668869863dcbbe5d7e42f8cae9451aa4d70fbf6e
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
  */
7
7
  import _applyDecs from "@babel/runtime/helpers/applyDecs2305";
8
8
  let _initProto, _FlagsDecs, _GroupDecs, _AssertionDecs, _StartOfInputAssertionDecs, _EndOfInputAssertionDecs, _WordBoundaryAssertionDecs, _GapDecs, _CharacterDecs, _CharacterClassDecs, _CharacterClassRangeDecs, _CharacterSetDecs, _AnyCharacterSetDecs, _DigitCharacterSetDecs, _SpaceCharacterSetDecs, _WordCharacterSetDecs, _QuantifierDecs, _AnyDecs, _KeywordDecs, _PunctuatorDecs;
9
9
  import { re, spam as m } from '@bablr/boot';
10
- import { Node, CoveredBy, InjectFrom, UnboundAttributes, AllowEmpty } from '@bablr/helpers/decorators';
10
+ import { Node, CoveredBy, InjectFrom, UndefinedAttributes, AllowEmpty, Literal } from '@bablr/helpers/decorators';
11
11
  import objectEntries from 'iter-tools-es/methods/object-entries';
12
12
  import * as Shared from '@bablr/helpers/productions';
13
- import { eat, eatMatch, match, holdForMatch, guard, bindAttribute, fail } from '@bablr/helpers/grammar';
13
+ import { eat, eatMatch, match, holdForMatch, guard, defineAttribute, fail, o } from '@bablr/helpers/grammar';
14
14
  import { buildString, buildBoolean } from '@bablr/helpers/builders';
15
15
  export const canonicalURL = 'https://bablr.org/languages/core/en/bablr-regex-pattern';
16
16
  export const dependencies = {};
@@ -55,14 +55,14 @@ const getSpecialPattern = span => {
55
55
  };
56
56
  export const grammar = class RegexGrammar {
57
57
  static {
58
- [_initProto] = _applyDecs(this, [[Node, 2, "Pattern"], [_FlagsDecs, 2, "Flags"], [AllowEmpty, 2, "Alternatives"], [[AllowEmpty, Node], 2, "Alternative"], [AllowEmpty, 2, "Elements"], [_GroupDecs, 2, "Group"], [Node, 2, "CapturingGroup"], [_AssertionDecs, 2, "Assertion"], [_StartOfInputAssertionDecs, 2, "StartOfInputAssertion"], [_EndOfInputAssertionDecs, 2, "EndOfInputAssertion"], [_WordBoundaryAssertionDecs, 2, "WordBoundaryAssertion"], [_GapDecs, 2, "Gap"], [_CharacterDecs, 2, "Character"], [_CharacterClassDecs, 2, "CharacterClass"], [_CharacterClassRangeDecs, 2, "CharacterClassRange"], [_CharacterSetDecs, 2, "CharacterSet"], [_AnyCharacterSetDecs, 2, "AnyCharacterSet"], [_DigitCharacterSetDecs, 2, "DigitCharacterSet"], [_SpaceCharacterSetDecs, 2, "SpaceCharacterSet"], [_WordCharacterSetDecs, 2, "WordCharacterSet"], [_QuantifierDecs, 2, "Quantifier"], [Node, 2, "UnsignedInteger"], [Node, 2, "EscapeSequence"], [Node, 2, "EscapeCode"], [Node, 2, "Digit"], [_AnyDecs, 2, "Any"], [_KeywordDecs, 2, "Keyword"], [_PunctuatorDecs, 2, "Punctuator"]], []).e;
58
+ [_initProto] = _applyDecs(this, [[Node, 2, "Pattern"], [_FlagsDecs, 2, "Flags"], [AllowEmpty, 2, "Alternatives"], [[AllowEmpty, Node], 2, "Alternative"], [AllowEmpty, 2, "Elements"], [_GroupDecs, 2, "Group"], [Node, 2, "CapturingGroup"], [_AssertionDecs, 2, "Assertion"], [_StartOfInputAssertionDecs, 2, "StartOfInputAssertion"], [_EndOfInputAssertionDecs, 2, "EndOfInputAssertion"], [_WordBoundaryAssertionDecs, 2, "WordBoundaryAssertion"], [_GapDecs, 2, "Gap"], [_CharacterDecs, 2, "Character"], [_CharacterClassDecs, 2, "CharacterClass"], [_CharacterClassRangeDecs, 2, "CharacterClassRange"], [_CharacterSetDecs, 2, "CharacterSet"], [_AnyCharacterSetDecs, 2, "AnyCharacterSet"], [_DigitCharacterSetDecs, 2, "DigitCharacterSet"], [_SpaceCharacterSetDecs, 2, "SpaceCharacterSet"], [_WordCharacterSetDecs, 2, "WordCharacterSet"], [_QuantifierDecs, 2, "Quantifier"], [Node, 2, "UnsignedInteger"], [Node, 2, "UnsignedHexInteger"], [Node, 2, "EscapeSequence"], [Node, 2, "EscapeCode"], [Node, 2, "Digit"], [_AnyDecs, 2, "Any"], [_KeywordDecs, 2, "Keyword"], [_PunctuatorDecs, 2, "Punctuator"]], []).e;
59
59
  }
60
60
  constructor() {
61
61
  _initProto(this);
62
62
  }
63
- *[(_FlagsDecs = [UnboundAttributes(Object.keys(flagCharacters)), AllowEmpty, Node], _GroupDecs = [CoveredBy('Element'), Node], _AssertionDecs = CoveredBy('Element'), _StartOfInputAssertionDecs = [CoveredBy('Assertion'), Node], _EndOfInputAssertionDecs = [CoveredBy('Assertion'), Node], _WordBoundaryAssertionDecs = [UnboundAttributes(['negate']), CoveredBy('Assertion'), Node], _GapDecs = [CoveredBy('Assertion'), Node], _CharacterDecs = [CoveredBy('Element'), CoveredBy('CharacterClassElement'), Node], _CharacterClassDecs = [UnboundAttributes(['negate']), CoveredBy('Element'), Node], _CharacterClassRangeDecs = [CoveredBy('CharacterClassElement'), Node], _CharacterSetDecs = CoveredBy('Element'), _AnyCharacterSetDecs = [CoveredBy('CharacterSet'), Node], _DigitCharacterSetDecs = [UnboundAttributes(['negate']), CoveredBy('CharacterSet'), Node], _SpaceCharacterSetDecs = [UnboundAttributes(['negate']), CoveredBy('CharacterSet'), Node], _WordCharacterSetDecs = [UnboundAttributes(['negate']), CoveredBy('CharacterSet'), Node], _QuantifierDecs = [UnboundAttributes(['min', 'max']), Node], _AnyDecs = InjectFrom(Shared), _KeywordDecs = [Node, InjectFrom(Shared)], _PunctuatorDecs = [Node, InjectFrom(Shared)], "Pattern")]() {
63
+ *[(_FlagsDecs = [UndefinedAttributes(Object.keys(flagCharacters)), AllowEmpty, Node], _GroupDecs = [CoveredBy('Element'), Node], _AssertionDecs = CoveredBy('Element'), _StartOfInputAssertionDecs = [CoveredBy('Assertion'), Node], _EndOfInputAssertionDecs = [CoveredBy('Assertion'), Node], _WordBoundaryAssertionDecs = [UndefinedAttributes(['negate']), CoveredBy('Assertion'), Node], _GapDecs = [CoveredBy('Assertion'), Node], _CharacterDecs = [CoveredBy('Element'), CoveredBy('CharacterClassElement'), Node], _CharacterClassDecs = [UndefinedAttributes(['negate']), CoveredBy('Element'), Node], _CharacterClassRangeDecs = [CoveredBy('CharacterClassElement'), Node], _CharacterSetDecs = CoveredBy('Element'), _AnyCharacterSetDecs = [CoveredBy('Element'), CoveredBy('CharacterSet'), Node], _DigitCharacterSetDecs = [UndefinedAttributes(['negate']), CoveredBy('Element'), CoveredBy('CharacterSet'), Node], _SpaceCharacterSetDecs = [UndefinedAttributes(['negate']), CoveredBy('Element'), CoveredBy('CharacterSet'), Node], _WordCharacterSetDecs = [UndefinedAttributes(['negate']), CoveredBy('Element'), CoveredBy('CharacterSet'), Node], _QuantifierDecs = [UndefinedAttributes(['min', 'max']), Node], _AnyDecs = InjectFrom(Shared), _KeywordDecs = [Literal, Node, InjectFrom(Shared)], _PunctuatorDecs = [Literal, Node, InjectFrom(Shared)], "Pattern")]() {
64
64
  yield eat(m`openToken: <*Punctuator '/' { balanced: '/', balancedSpan: 'Pattern' } />`);
65
- yield eat(m`<Alternatives />`);
65
+ yield eat(m`<_Alternatives />`);
66
66
  yield eat(m`closeToken: <*Punctuator '/' { balancer: true } />`);
67
67
  yield eat(m`flags$: <Flags />`);
68
68
  }
@@ -77,9 +77,9 @@ export const grammar = class RegexGrammar {
77
77
  1: chr
78
78
  } of Object.entries(flagCharacters)) {
79
79
  if (flagsStr.includes(chr)) {
80
- yield bindAttribute(name, true);
80
+ yield defineAttribute(name, true);
81
81
  } else {
82
- yield bindAttribute(name, false);
82
+ yield defineAttribute(name, false);
83
83
  }
84
84
  }
85
85
  for (const flagChr of flagsStr) {
@@ -92,33 +92,33 @@ export const grammar = class RegexGrammar {
92
92
  } while (yield eatMatch(m`separatorTokens[]: <*Punctuator '|' />`));
93
93
  }
94
94
  *Alternative() {
95
- yield eat(m`elements[]$: <Elements />`);
95
+ yield eat(m`elements[]+$: <_Elements />`);
96
96
  }
97
97
  *Elements() {
98
98
  yield eat(m`.[]: []`);
99
99
  while (yield match(re`/[^|]/`)) {
100
- yield eat(m`.[]+: <Element />`);
100
+ yield eat(m`.[]+: <__Element />`);
101
101
  }
102
102
  }
103
103
  *Element() {
104
104
  yield guard(m`<*Keyword /[*+?]/ />`);
105
- yield eat(m`<Any />`, [m`<CharacterClass '[' />`, m`<Group '(?:' />`, m`<Assertion /[$^]|\\b/i />`, m`<Gap '\\g' />`, m`<CharacterSet /\.|\\[dswp]/i />`, m`<*Character />`]);
105
+ yield eat(m`<_Any />`, [m`<CharacterClass '[' />`, m`<Group '(?:' />`, m`<__Assertion /[$^]|\\b/i />`, m`<Gap '\\g' />`, m`<__CharacterSet /\.|\\[dswp]/i />`, m`<*Character />`]);
106
106
  if (yield match(re`/[*+?{]/`)) {
107
107
  return holdForMatch(m`<Quantifier />`);
108
108
  }
109
109
  }
110
110
  *Group() {
111
111
  yield eat(m`openToken: <*Punctuator '(?:' { balanced: ')' } />`);
112
- yield eat(m`<Alternatives />`);
112
+ yield eat(m`<_Alternatives />`);
113
113
  yield eat(m`closeToken: <*Punctuator ')' { balancer: true } />`);
114
114
  }
115
115
  *CapturingGroup() {
116
116
  yield eat(m`openToken: <*Punctuator '(' { balanced: ')' } />`);
117
- yield eat(m`<Alternatives />`);
117
+ yield eat(m`<_Alternatives />`);
118
118
  yield eat(m`closeToken: <*Punctuator ')' { balancer: true } />`);
119
119
  }
120
120
  *Assertion() {
121
- yield eat(m`<Any />`, [m`<*StartOfInputAssertion '^' />`, m`<*EndOfInputAssertion '$' />`, m`<*WordBoundaryAssertion /\\b/i />`]);
121
+ yield eat(m`<_Any />`, [m`<*StartOfInputAssertion '^' />`, m`<*EndOfInputAssertion '$' />`, m`<*WordBoundaryAssertion /\\b/i />`]);
122
122
  }
123
123
  *StartOfInputAssertion() {
124
124
  yield eat(m`sigilToken: <*Keyword '^' />`);
@@ -131,7 +131,7 @@ export const grammar = class RegexGrammar {
131
131
  }) {
132
132
  yield eatMatch(m`escapeToken: <*Punctuator '\\' />`);
133
133
  const m_ = yield eat(m`value: <*Keyword /b/i />`);
134
- yield bindAttribute('negate', buildBoolean(ctx.sourceTextFor(m_) === 'B'));
134
+ yield defineAttribute('negate', buildBoolean(ctx.sourceTextFor(m_) === 'B'));
135
135
  }
136
136
  *Gap() {
137
137
  yield eatMatch(m`escapeToken: <*Punctuator '\\' />`);
@@ -146,15 +146,17 @@ export const grammar = class RegexGrammar {
146
146
  }
147
147
  *CharacterClass() {
148
148
  yield eat(m`openToken: <*Punctuator '[' { balancedSpan: 'CharacterClass', balanced: ']' } />`);
149
- let negate = yield eatMatch(m`negateToken: <*Keyword '^' />`);
150
- yield bindAttribute('negate', !!negate);
149
+ let negate = yield eatMatch(m`negateToken: <*Keyword '^' />`, null, o({
150
+ bind: true
151
+ }));
152
+ yield defineAttribute('negate', !!negate);
151
153
  while (yield match(re`/./s`)) {
152
- yield eat(m`elements[]+$: <CharacterClassElement />`);
154
+ yield eat(m`elements[]+$: <__CharacterClassElement />`);
153
155
  }
154
156
  yield eat(m`closeToken: <*Punctuator ']' { balancer: true } />`);
155
157
  }
156
158
  *CharacterClassElement() {
157
- yield eat(m`<Any />`, [m`<CharacterSet /\\[dswp]/i />`, m`<Gap '\\g' />`, m`<*Character />`]);
159
+ yield eat(m`<_Any />`, [m`<__CharacterSet /\\[dswp]/i />`, m`<Gap '\\g' />`, m`<*Character />`]);
158
160
  if (yield match('-')) {
159
161
  return holdForMatch(m`<CharacterClassRange />`);
160
162
  }
@@ -165,7 +167,7 @@ export const grammar = class RegexGrammar {
165
167
  yield eat(m`max+$: <*Character />`);
166
168
  }
167
169
  *CharacterSet() {
168
- yield eat(m`<Any />`, [m`<AnyCharacterSet '.' />`, m`<DigitCharacterSet /\\[dD]/ />`, m`<SpaceCharacterSet /\\[sS]/ />`, m`<WordCharacterSet /\\[wW]/ />`]);
170
+ yield eat(m`<_Any />`, [m`<AnyCharacterSet '.' />`, m`<DigitCharacterSet /\\[dD]/ />`, m`<SpaceCharacterSet /\\[sS]/ />`, m`<WordCharacterSet /\\[wW]/ />`]);
169
171
  }
170
172
  *AnyCharacterSet() {
171
173
  yield eat(m`sigilToken: <*Keyword '.' />`);
@@ -175,26 +177,26 @@ export const grammar = class RegexGrammar {
175
177
  }) {
176
178
  yield eat(m`escapeToken: <*Punctuator '\\' />`);
177
179
  let code = yield eat(m`value: <*Keyword /[dD]/ />`);
178
- yield bindAttribute('negate', buildBoolean(ctx.sourceTextFor(code) === 'D'));
180
+ yield defineAttribute('negate', ctx.sourceTextFor(code) === 'D');
179
181
  }
180
182
  *SpaceCharacterSet({
181
183
  ctx
182
184
  }) {
183
185
  yield eat(m`escapeToken: <*Punctuator '\\' />`);
184
186
  let code = yield eat(m`value: <*Keyword /[sS]/ />`);
185
- yield bindAttribute('negate', buildBoolean(ctx.sourceTextFor(code) === 'S'));
187
+ yield defineAttribute('negate', ctx.sourceTextFor(code) === 'S');
186
188
  }
187
189
  *WordCharacterSet({
188
190
  ctx
189
191
  }) {
190
192
  yield eat(m`escapeToken: <*Punctuator '\\' />`);
191
193
  let code = yield eat(m`value: <*Keyword /[wW]/ />`);
192
- yield bindAttribute('negate', ctx.sourceTextFor(code) === 'W');
194
+ yield defineAttribute('negate', ctx.sourceTextFor(code) === 'W');
193
195
  }
194
196
  *Quantifier({
195
197
  ctx
196
198
  }) {
197
- yield eat(m`element+$: <Element />`);
199
+ yield eat(m`element+$: <__Element />`);
198
200
  let attrs, sigil;
199
201
  if (sigil = yield eatMatch(m`sigilToken: <*Keyword /[*+?]/ />`)) {
200
202
  switch (ctx.sourceTextFor(sigil)) {
@@ -233,16 +235,18 @@ export const grammar = class RegexGrammar {
233
235
  };
234
236
  yield eat(m`closeToken: <*Punctuator '}' { balancer: true } />`);
235
237
  }
236
- yield bindAttribute('min', attrs.min);
237
- yield bindAttribute('max', attrs.max);
238
+ yield defineAttribute('min', attrs.min);
239
+ yield defineAttribute('max', attrs.max);
238
240
  }
239
241
  *UnsignedInteger() {
240
242
  yield eat(re`/\d+/`);
241
243
  }
244
+ *UnsignedHexInteger() {
245
+ yield eat(re`/[\da-fA-F]+/`);
246
+ }
242
247
  *EscapeSequence({
243
248
  state,
244
- ctx,
245
- value: props
249
+ ctx
246
250
  }) {
247
251
  const parentSpan = state.span;
248
252
  yield eat(m`escape: <*Punctuator '\\' { openSpan: 'Escape' } />`);
@@ -262,15 +266,15 @@ export const grammar = class RegexGrammar {
262
266
  *EscapeCode() {
263
267
  if (yield eatMatch(m`type: <*Keyword 'u' />`)) {
264
268
  if (yield eatMatch(m`openToken: <*Punctuator '{' />`)) {
265
- yield eatMatch(m`value$: <*UnsignedInteger />`);
269
+ yield eatMatch(m`value$: <*UnsignedHexInteger />`);
266
270
  yield eat(m`closeToken: <*Punctuator '}' />`);
267
271
  } else {
268
- yield eat(m`value$: <*UnsignedInteger /\d{4}/ />`);
272
+ yield eat(m`value$: <*UnsignedHexInteger /[\da-fA-F]{4}/ />`);
269
273
  yield eat(m`closeToken: null`);
270
274
  }
271
275
  } else if (yield eatMatch(m`type: <*Keyword 'x' />`)) {
272
276
  yield eat(m`openToken: null`);
273
- yield eat(m`value$: <*UnsignedInteger /\d{2}/ />`);
277
+ yield eat(m`value$: <*UnsignedHexInteger /[\da-fA-F]{2}/ />`);
274
278
  yield eat(m`closeToken: null`);
275
279
  }
276
280
  }
@@ -3,8 +3,9 @@ import {
3
3
  Node,
4
4
  CoveredBy,
5
5
  InjectFrom,
6
- UnboundAttributes,
6
+ UndefinedAttributes,
7
7
  AllowEmpty,
8
+ Literal,
8
9
  } from '@bablr/helpers/decorators';
9
10
  import objectEntries from 'iter-tools-es/methods/object-entries';
10
11
  import * as Shared from '@bablr/helpers/productions';
@@ -14,8 +15,9 @@ import {
14
15
  match,
15
16
  holdForMatch,
16
17
  guard,
17
- bindAttribute,
18
+ defineAttribute,
18
19
  fail,
20
+ o,
19
21
  } from '@bablr/helpers/grammar';
20
22
  import { buildString, buildBoolean } from '@bablr/helpers/builders';
21
23
 
@@ -76,12 +78,12 @@ export const grammar = class RegexGrammar {
76
78
  @Node
77
79
  *Pattern() {
78
80
  yield eat(m`openToken: <*Punctuator '/' { balanced: '/', balancedSpan: 'Pattern' } />`);
79
- yield eat(m`<Alternatives />`);
81
+ yield eat(m`<_Alternatives />`);
80
82
  yield eat(m`closeToken: <*Punctuator '/' { balancer: true } />`);
81
83
  yield eat(m`flags$: <Flags />`);
82
84
  }
83
85
 
84
- @UnboundAttributes(Object.keys(flagCharacters))
86
+ @UndefinedAttributes(Object.keys(flagCharacters))
85
87
  @AllowEmpty
86
88
  @Node
87
89
  *Flags({ ctx }) {
@@ -93,9 +95,9 @@ export const grammar = class RegexGrammar {
93
95
 
94
96
  for (const { 0: name, 1: chr } of Object.entries(flagCharacters)) {
95
97
  if (flagsStr.includes(chr)) {
96
- yield bindAttribute(name, true);
98
+ yield defineAttribute(name, true);
97
99
  } else {
98
- yield bindAttribute(name, false);
100
+ yield defineAttribute(name, false);
99
101
  }
100
102
  }
101
103
 
@@ -114,26 +116,26 @@ export const grammar = class RegexGrammar {
114
116
  @AllowEmpty
115
117
  @Node
116
118
  *Alternative() {
117
- yield eat(m`elements[]$: <Elements />`);
119
+ yield eat(m`elements[]+$: <_Elements />`);
118
120
  }
119
121
 
120
122
  @AllowEmpty
121
123
  *Elements() {
122
124
  yield eat(m`.[]: []`);
123
125
  while (yield match(re`/[^|]/`)) {
124
- yield eat(m`.[]+: <Element />`);
126
+ yield eat(m`.[]+: <__Element />`);
125
127
  }
126
128
  }
127
129
 
128
130
  *Element() {
129
131
  yield guard(m`<*Keyword /[*+?]/ />`);
130
132
 
131
- yield eat(m`<Any />`, [
133
+ yield eat(m`<_Any />`, [
132
134
  m`<CharacterClass '[' />`,
133
135
  m`<Group '(?:' />`,
134
- m`<Assertion /[$^]|\\b/i />`,
136
+ m`<__Assertion /[$^]|\\b/i />`,
135
137
  m`<Gap '\\g' />`,
136
- m`<CharacterSet /\.|\\[dswp]/i />`,
138
+ m`<__CharacterSet /\.|\\[dswp]/i />`,
137
139
  m`<*Character />`,
138
140
  ]);
139
141
 
@@ -146,20 +148,20 @@ export const grammar = class RegexGrammar {
146
148
  @Node
147
149
  *Group() {
148
150
  yield eat(m`openToken: <*Punctuator '(?:' { balanced: ')' } />`);
149
- yield eat(m`<Alternatives />`);
151
+ yield eat(m`<_Alternatives />`);
150
152
  yield eat(m`closeToken: <*Punctuator ')' { balancer: true } />`);
151
153
  }
152
154
 
153
155
  @Node
154
156
  *CapturingGroup() {
155
157
  yield eat(m`openToken: <*Punctuator '(' { balanced: ')' } />`);
156
- yield eat(m`<Alternatives />`);
158
+ yield eat(m`<_Alternatives />`);
157
159
  yield eat(m`closeToken: <*Punctuator ')' { balancer: true } />`);
158
160
  }
159
161
 
160
162
  @CoveredBy('Element')
161
163
  *Assertion() {
162
- yield eat(m`<Any />`, [
164
+ yield eat(m`<_Any />`, [
163
165
  m`<*StartOfInputAssertion '^' />`,
164
166
  m`<*EndOfInputAssertion '$' />`,
165
167
  m`<*WordBoundaryAssertion /\\b/i />`,
@@ -178,13 +180,13 @@ export const grammar = class RegexGrammar {
178
180
  yield eatMatch(m`sigilToken: <*Keyword '$' />`);
179
181
  }
180
182
 
181
- @UnboundAttributes(['negate'])
183
+ @UndefinedAttributes(['negate'])
182
184
  @CoveredBy('Assertion')
183
185
  @Node
184
186
  *WordBoundaryAssertion({ ctx }) {
185
187
  yield eatMatch(m`escapeToken: <*Punctuator '\\' />`);
186
188
  const m_ = yield eat(m`value: <*Keyword /b/i />`);
187
- yield bindAttribute('negate', buildBoolean(ctx.sourceTextFor(m_) === 'B'));
189
+ yield defineAttribute('negate', buildBoolean(ctx.sourceTextFor(m_) === 'B'));
188
190
  }
189
191
 
190
192
  @CoveredBy('Assertion')
@@ -205,25 +207,29 @@ export const grammar = class RegexGrammar {
205
207
  }
206
208
  }
207
209
 
208
- @UnboundAttributes(['negate'])
210
+ @UndefinedAttributes(['negate'])
209
211
  @CoveredBy('Element')
210
212
  @Node
211
213
  *CharacterClass() {
212
214
  yield eat(m`openToken: <*Punctuator '[' { balancedSpan: 'CharacterClass', balanced: ']' } />`);
213
215
 
214
- let negate = yield eatMatch(m`negateToken: <*Keyword '^' />`);
216
+ let negate = yield eatMatch(m`negateToken: <*Keyword '^' />`, null, o({ bind: true }));
215
217
 
216
- yield bindAttribute('negate', !!negate);
218
+ yield defineAttribute('negate', !!negate);
217
219
 
218
220
  while (yield match(re`/./s`)) {
219
- yield eat(m`elements[]+$: <CharacterClassElement />`);
221
+ yield eat(m`elements[]+$: <__CharacterClassElement />`);
220
222
  }
221
223
 
222
224
  yield eat(m`closeToken: <*Punctuator ']' { balancer: true } />`);
223
225
  }
224
226
 
225
227
  *CharacterClassElement() {
226
- yield eat(m`<Any />`, [m`<CharacterSet /\\[dswp]/i />`, m`<Gap '\\g' />`, m`<*Character />`]);
228
+ yield eat(m`<_Any />`, [
229
+ m`<__CharacterSet /\\[dswp]/i />`,
230
+ m`<Gap '\\g' />`,
231
+ m`<*Character />`,
232
+ ]);
227
233
 
228
234
  if (yield match('-')) {
229
235
  return holdForMatch(m`<CharacterClassRange />`);
@@ -240,7 +246,7 @@ export const grammar = class RegexGrammar {
240
246
 
241
247
  @CoveredBy('Element')
242
248
  *CharacterSet() {
243
- yield eat(m`<Any />`, [
249
+ yield eat(m`<_Any />`, [
244
250
  m`<AnyCharacterSet '.' />`,
245
251
  m`<DigitCharacterSet /\\[dD]/ />`,
246
252
  m`<SpaceCharacterSet /\\[sS]/ />`,
@@ -248,13 +254,15 @@ export const grammar = class RegexGrammar {
248
254
  ]);
249
255
  }
250
256
 
257
+ @CoveredBy('Element')
251
258
  @CoveredBy('CharacterSet')
252
259
  @Node
253
260
  *AnyCharacterSet() {
254
261
  yield eat(m`sigilToken: <*Keyword '.' />`);
255
262
  }
256
263
 
257
- @UnboundAttributes(['negate'])
264
+ @UndefinedAttributes(['negate'])
265
+ @CoveredBy('Element')
258
266
  @CoveredBy('CharacterSet')
259
267
  @Node
260
268
  *DigitCharacterSet({ ctx }) {
@@ -262,10 +270,11 @@ export const grammar = class RegexGrammar {
262
270
 
263
271
  let code = yield eat(m`value: <*Keyword /[dD]/ />`);
264
272
 
265
- yield bindAttribute('negate', buildBoolean(ctx.sourceTextFor(code) === 'D'));
273
+ yield defineAttribute('negate', ctx.sourceTextFor(code) === 'D');
266
274
  }
267
275
 
268
- @UnboundAttributes(['negate'])
276
+ @UndefinedAttributes(['negate'])
277
+ @CoveredBy('Element')
269
278
  @CoveredBy('CharacterSet')
270
279
  @Node
271
280
  *SpaceCharacterSet({ ctx }) {
@@ -273,10 +282,11 @@ export const grammar = class RegexGrammar {
273
282
 
274
283
  let code = yield eat(m`value: <*Keyword /[sS]/ />`);
275
284
 
276
- yield bindAttribute('negate', buildBoolean(ctx.sourceTextFor(code) === 'S'));
285
+ yield defineAttribute('negate', ctx.sourceTextFor(code) === 'S');
277
286
  }
278
287
 
279
- @UnboundAttributes(['negate'])
288
+ @UndefinedAttributes(['negate'])
289
+ @CoveredBy('Element')
280
290
  @CoveredBy('CharacterSet')
281
291
  @Node
282
292
  *WordCharacterSet({ ctx }) {
@@ -284,13 +294,13 @@ export const grammar = class RegexGrammar {
284
294
 
285
295
  let code = yield eat(m`value: <*Keyword /[wW]/ />`);
286
296
 
287
- yield bindAttribute('negate', ctx.sourceTextFor(code) === 'W');
297
+ yield defineAttribute('negate', ctx.sourceTextFor(code) === 'W');
288
298
  }
289
299
 
290
- @UnboundAttributes(['min', 'max'])
300
+ @UndefinedAttributes(['min', 'max'])
291
301
  @Node
292
302
  *Quantifier({ ctx }) {
293
- yield eat(m`element+$: <Element />`);
303
+ yield eat(m`element+$: <__Element />`);
294
304
 
295
305
  let attrs, sigil;
296
306
 
@@ -325,8 +335,8 @@ export const grammar = class RegexGrammar {
325
335
  yield eat(m`closeToken: <*Punctuator '}' { balancer: true } />`);
326
336
  }
327
337
 
328
- yield bindAttribute('min', attrs.min);
329
- yield bindAttribute('max', attrs.max);
338
+ yield defineAttribute('min', attrs.min);
339
+ yield defineAttribute('max', attrs.max);
330
340
  }
331
341
 
332
342
  @Node
@@ -335,7 +345,12 @@ export const grammar = class RegexGrammar {
335
345
  }
336
346
 
337
347
  @Node
338
- *EscapeSequence({ state, ctx, value: props }) {
348
+ *UnsignedHexInteger() {
349
+ yield eat(re`/[\da-fA-F]+/`);
350
+ }
351
+
352
+ @Node
353
+ *EscapeSequence({ state, ctx }) {
339
354
  const parentSpan = state.span;
340
355
 
341
356
  yield eat(m`escape: <*Punctuator '\\' { openSpan: 'Escape' } />`);
@@ -359,15 +374,15 @@ export const grammar = class RegexGrammar {
359
374
  *EscapeCode() {
360
375
  if (yield eatMatch(m`type: <*Keyword 'u' />`)) {
361
376
  if (yield eatMatch(m`openToken: <*Punctuator '{' />`)) {
362
- yield eatMatch(m`value$: <*UnsignedInteger />`);
377
+ yield eatMatch(m`value$: <*UnsignedHexInteger />`);
363
378
  yield eat(m`closeToken: <*Punctuator '}' />`);
364
379
  } else {
365
- yield eat(m`value$: <*UnsignedInteger /\d{4}/ />`);
380
+ yield eat(m`value$: <*UnsignedHexInteger /[\da-fA-F]{4}/ />`);
366
381
  yield eat(m`closeToken: null`);
367
382
  }
368
383
  } else if (yield eatMatch(m`type: <*Keyword 'x' />`)) {
369
384
  yield eat(m`openToken: null`);
370
- yield eat(m`value$: <*UnsignedInteger /\d{2}/ />`);
385
+ yield eat(m`value$: <*UnsignedHexInteger /[\da-fA-F]{2}/ />`);
371
386
  yield eat(m`closeToken: null`);
372
387
  }
373
388
  }
@@ -384,10 +399,12 @@ export const grammar = class RegexGrammar {
384
399
  @InjectFrom(Shared)
385
400
  *Any() {}
386
401
 
402
+ @Literal
387
403
  @Node
388
404
  @InjectFrom(Shared)
389
405
  *Keyword() {}
390
406
 
407
+ @Literal
391
408
  @Node
392
409
  @InjectFrom(Shared)
393
410
  *Punctuator() {}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-regex-vm-pattern",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "A BABLR language for nonbacktracking JS-style regexes",
5
5
  "engines": {
6
6
  "node": ">=12.0.0"
@@ -22,18 +22,18 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@babel/runtime": "^7.23.2",
25
- "@bablr/helpers": "0.21.1",
26
- "@bablr/agast-helpers": "0.6.0",
27
- "@bablr/agast-vm-helpers": "0.6.0",
25
+ "@bablr/boot": "0.8.1",
26
+ "@bablr/helpers": "0.22.1",
27
+ "@bablr/agast-helpers": "0.7.1",
28
+ "@bablr/agast-vm-helpers": "0.7.1",
28
29
  "iter-tools-es": "7.5.3"
29
30
  },
30
31
  "devDependencies": {
31
- "@bablr/boot": "^0.7.0",
32
32
  "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
33
33
  "@bablr/macrome": "^0.1.3",
34
34
  "@bablr/macrome-generator-bablr": "^0.3.2",
35
35
  "@qnighy/dedent": "0.1.1",
36
- "bablr": "^0.6.0",
36
+ "bablr": "^0.7.0",
37
37
  "enhanced-resolve": "^5.12.0",
38
38
  "eslint": "^8.47.0",
39
39
  "eslint-import-resolver-enhanced-resolve": "^1.0.5",