@bablr/language-en-regex-vm-pattern 0.9.0 → 0.10.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,6 +1,6 @@
1
1
  /* @macrome
2
2
  * @generatedby @bablr/macrome-generator-bablr
3
- * @generatedfrom ./grammar.macro.js#668869863dcbbe5d7e42f8cae9451aa4d70fbf6e
3
+ * @generatedfrom ./grammar.macro.js#44cd5c6d803ea69c494531d65db6b33a5faa09cb
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
  */
@@ -10,7 +10,7 @@ import { re, spam as m } from '@bablr/boot';
10
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, defineAttribute, fail, o } from '@bablr/helpers/grammar';
13
+ import { eat, eatMatch, match, shiftMatch, 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 = {};
@@ -20,21 +20,6 @@ const escapables = new Map(objectEntries({
20
20
  t: '\t',
21
21
  0: '\0'
22
22
  }));
23
- export const getCooked = (escapeNode, span, ctx) => {
24
- let cooked;
25
- const codeNode = escapeNode.get('code');
26
- const type = ctx.sourceTextFor(codeNode.get('typeToken'));
27
- const value = ctx.sourceTextFor(codeNode.get('value'));
28
- if (!type) {
29
- const match_ = ctx.sourceTextFor(codeNode);
30
- cooked = escapables.get(match_) || match_;
31
- } else if (type === 'u' || type === 'x') {
32
- cooked = parseInt(value, 16);
33
- } else {
34
- throw new Error();
35
- }
36
- return cooked.toString(10);
37
- };
38
23
  const flagCharacters = {
39
24
  global: 'g',
40
25
  ignoreCase: 'i',
@@ -46,7 +31,7 @@ const flagCharacters = {
46
31
  const unique = flags => flags.length === new Set(flags).size;
47
32
  const getSpecialPattern = span => {
48
33
  if (span === 'Pattern') {
49
- return re`/[*+{}[\]().^$|\n\\<>]/`;
34
+ return re`/[*+?{}[\]().^$|\n\\<>]/`;
50
35
  } else if (span === 'CharacterClass') {
51
36
  return re`/[\]\\]/`;
52
37
  } else {
@@ -102,9 +87,9 @@ export const grammar = class RegexGrammar {
102
87
  }
103
88
  *Element() {
104
89
  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 />`]);
90
+ yield eat(m`<_Any />`, [m`<CharacterClass '[' />`, m`<Group '(?:' />`, m`<_Assertion /[$^]|\\b/i />`, m`<Gap '\\g' />`, m`<_CharacterSet /\.|\\[dswp]/i />`, m`<*Character />`]);
106
91
  if (yield match(re`/[*+?{]/`)) {
107
- return holdForMatch(m`<Quantifier />`);
92
+ return shiftMatch(m`<Quantifier />`);
108
93
  }
109
94
  }
110
95
  *Group() {
@@ -156,9 +141,9 @@ export const grammar = class RegexGrammar {
156
141
  yield eat(m`closeToken: <*Punctuator ']' { balancer: true } />`);
157
142
  }
158
143
  *CharacterClassElement() {
159
- yield eat(m`<_Any />`, [m`<__CharacterSet /\\[dswp]/i />`, m`<Gap '\\g' />`, m`<*Character />`]);
144
+ yield eat(m`<_Any />`, [m`<_CharacterSet /\\[dswp]/i />`, m`<Gap '\\g' />`, m`<*Character />`]);
160
145
  if (yield match('-')) {
161
- return holdForMatch(m`<CharacterClassRange />`);
146
+ return shiftMatch(m`<CharacterClassRange />`);
162
147
  }
163
148
  }
164
149
  *CharacterClassRange() {
@@ -218,6 +203,8 @@ export const grammar = class RegexGrammar {
218
203
  max: 1
219
204
  };
220
205
  break;
206
+ default:
207
+ yield fail();
221
208
  }
222
209
  } else if (yield eat(m`openToken: <*Punctuator '{' { balanced: '}' } />`)) {
223
210
  let max;
@@ -251,17 +238,22 @@ export const grammar = class RegexGrammar {
251
238
  const parentSpan = state.span;
252
239
  yield eat(m`escape: <*Punctuator '\\' { openSpan: 'Escape' } />`);
253
240
  let m_;
241
+ let cooked;
254
242
  if (m_ = yield match(re`/[\\/nrt0]/`)) {
255
243
  const match_ = ctx.sourceTextFor(m_);
256
244
  yield eat(m`code: <*Keyword ${buildString(match_)} { closeSpan: 'Escape' } />`);
245
+ cooked = escapables.get(match_) || match_;
257
246
  } else if (m_ = yield match(getSpecialPattern(parentSpan))) {
258
- const match_ = ctx.sourceTextFor(m_);
259
- yield eat(m`code: <*Keyword ${buildString(match_)} { closeSpan: 'Escape' } />`);
247
+ cooked = ctx.sourceTextFor(m_);
248
+ yield eat(m`code: <*Keyword ${buildString(cooked)} { closeSpan: 'Escape' } />`);
260
249
  } else if (yield match(re`/[ux]/`)) {
261
- yield eat(m`code: <EscapeCode { closeSpan: 'Escape' } />`);
250
+ let code = yield eat(m`code: <EscapeCode { closeSpan: 'Escape' } />`);
251
+ let value = code.get('value');
252
+ cooked = String.fromCodePoint(parseInt(ctx.sourceTextFor(value), 16));
262
253
  } else {
263
254
  yield fail();
264
255
  }
256
+ yield defineAttribute('cooked', cooked);
265
257
  }
266
258
  *EscapeCode() {
267
259
  if (yield eatMatch(m`type: <*Keyword 'u' />`)) {
@@ -13,7 +13,7 @@ import {
13
13
  eat,
14
14
  eatMatch,
15
15
  match,
16
- holdForMatch,
16
+ shiftMatch,
17
17
  guard,
18
18
  defineAttribute,
19
19
  fail,
@@ -34,25 +34,6 @@ const escapables = new Map(
34
34
  }),
35
35
  );
36
36
 
37
- export const getCooked = (escapeNode, span, ctx) => {
38
- let cooked;
39
- const codeNode = escapeNode.get('code');
40
- const type = ctx.sourceTextFor(codeNode.get('typeToken'));
41
- const value = ctx.sourceTextFor(codeNode.get('value'));
42
-
43
- if (!type) {
44
- const match_ = ctx.sourceTextFor(codeNode);
45
-
46
- cooked = escapables.get(match_) || match_;
47
- } else if (type === 'u' || type === 'x') {
48
- cooked = parseInt(value, 16);
49
- } else {
50
- throw new Error();
51
- }
52
-
53
- return cooked.toString(10);
54
- };
55
-
56
37
  const flagCharacters = {
57
38
  global: 'g',
58
39
  ignoreCase: 'i',
@@ -66,7 +47,7 @@ const unique = (flags) => flags.length === new Set(flags).size;
66
47
 
67
48
  const getSpecialPattern = (span) => {
68
49
  if (span === 'Pattern') {
69
- return re`/[*+{}[\]().^$|\n\\<>]/`;
50
+ return re`/[*+?{}[\]().^$|\n\\<>]/`;
70
51
  } else if (span === 'CharacterClass') {
71
52
  return re`/[\]\\]/`;
72
53
  } else {
@@ -133,14 +114,14 @@ export const grammar = class RegexGrammar {
133
114
  yield eat(m`<_Any />`, [
134
115
  m`<CharacterClass '[' />`,
135
116
  m`<Group '(?:' />`,
136
- m`<__Assertion /[$^]|\\b/i />`,
117
+ m`<_Assertion /[$^]|\\b/i />`,
137
118
  m`<Gap '\\g' />`,
138
- m`<__CharacterSet /\.|\\[dswp]/i />`,
119
+ m`<_CharacterSet /\.|\\[dswp]/i />`,
139
120
  m`<*Character />`,
140
121
  ]);
141
122
 
142
123
  if (yield match(re`/[*+?{]/`)) {
143
- return holdForMatch(m`<Quantifier />`);
124
+ return shiftMatch(m`<Quantifier />`);
144
125
  }
145
126
  }
146
127
 
@@ -225,14 +206,10 @@ export const grammar = class RegexGrammar {
225
206
  }
226
207
 
227
208
  *CharacterClassElement() {
228
- yield eat(m`<_Any />`, [
229
- m`<__CharacterSet /\\[dswp]/i />`,
230
- m`<Gap '\\g' />`,
231
- m`<*Character />`,
232
- ]);
209
+ yield eat(m`<_Any />`, [m`<_CharacterSet /\\[dswp]/i />`, m`<Gap '\\g' />`, m`<*Character />`]);
233
210
 
234
211
  if (yield match('-')) {
235
- return holdForMatch(m`<CharacterClassRange />`);
212
+ return shiftMatch(m`<CharacterClassRange />`);
236
213
  }
237
214
  }
238
215
 
@@ -315,6 +292,8 @@ export const grammar = class RegexGrammar {
315
292
  case '?':
316
293
  attrs = { min: 0, max: 1 };
317
294
  break;
295
+ default:
296
+ yield fail();
318
297
  }
319
298
  } else if (yield eat(m`openToken: <*Punctuator '{' { balanced: '}' } />`)) {
320
299
  let max;
@@ -356,18 +335,27 @@ export const grammar = class RegexGrammar {
356
335
  yield eat(m`escape: <*Punctuator '\\' { openSpan: 'Escape' } />`);
357
336
 
358
337
  let m_;
338
+ let cooked;
359
339
 
360
340
  if ((m_ = yield match(re`/[\\/nrt0]/`))) {
361
341
  const match_ = ctx.sourceTextFor(m_);
362
342
  yield eat(m`code: <*Keyword ${buildString(match_)} { closeSpan: 'Escape' } />`);
343
+
344
+ cooked = escapables.get(match_) || match_;
363
345
  } else if ((m_ = yield match(getSpecialPattern(parentSpan)))) {
364
- const match_ = ctx.sourceTextFor(m_);
365
- yield eat(m`code: <*Keyword ${buildString(match_)} { closeSpan: 'Escape' } />`);
346
+ cooked = ctx.sourceTextFor(m_);
347
+ yield eat(m`code: <*Keyword ${buildString(cooked)} { closeSpan: 'Escape' } />`);
366
348
  } else if (yield match(re`/[ux]/`)) {
367
- yield eat(m`code: <EscapeCode { closeSpan: 'Escape' } />`);
349
+ let code = yield eat(m`code: <EscapeCode { closeSpan: 'Escape' } />`);
350
+
351
+ let value = code.get('value');
352
+
353
+ cooked = String.fromCodePoint(parseInt(ctx.sourceTextFor(value), 16));
368
354
  } else {
369
355
  yield fail();
370
356
  }
357
+
358
+ yield defineAttribute('cooked', cooked);
371
359
  }
372
360
 
373
361
  @Node
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-regex-vm-pattern",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "description": "A BABLR language for nonbacktracking JS-style regexes",
5
5
  "engines": {
6
6
  "node": ">=12.0.0"
@@ -22,14 +22,14 @@
22
22
  },
23
23
  "dependencies": {
24
24
  "@babel/runtime": "^7.23.2",
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",
25
+ "@bablr/boot": "0.9.0",
26
+ "@bablr/helpers": "0.23.0",
27
+ "@bablr/agast-helpers": "0.8.0",
28
+ "@bablr/agast-vm-helpers": "0.8.0",
29
29
  "iter-tools-es": "7.5.3"
30
30
  },
31
31
  "devDependencies": {
32
- "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
32
+ "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#c97bfa4b3663f8378e9b3e42bb5a41e685406cf9",
33
33
  "@bablr/macrome": "^0.1.3",
34
34
  "@bablr/macrome-generator-bablr": "^0.3.2",
35
35
  "@qnighy/dedent": "0.1.1",