@bablr/language-en-cstml-json 0.5.5 → 0.6.1

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 (2) hide show
  1. package/lib/grammar.js +28 -21
  2. package/package.json +7 -9
package/lib/grammar.js CHANGED
@@ -1,26 +1,23 @@
1
- import { spam as m, re } from '@bablr/boot';
2
- import { o, eat, eatMatch, match, fail, startSpan, endSpan } from '@bablr/helpers/grammar';
3
- import { default as JSON, dependencies } from '@bablr/language-en-json';
4
- import { buildString } from '@bablr/helpers/builders';
1
+ import { m, eat, eatMatch, match, fail, startSpan, endSpan, o } from '@bablr/helpers/grammar';
2
+ import { default as JSON } from '@bablr/language-en-json';
5
3
  import { printSource } from '@bablr/agast-helpers/tree';
6
-
7
- export const canonicalURL = 'https://bablr.org/languages/core/en/cstml-json';
8
-
9
- export const defaultMatcher = m`<_Expression />`;
4
+ import { freezeClass } from '@bablr/agast-helpers/object';
10
5
 
11
6
  export function* eatMatchTrivia() {
12
7
  let trivia = null;
13
- while (yield match(re`/[ \t\r\n]/`)) {
8
+ while (yield match(m`/[ \t\r\n]/`)) {
14
9
  trivia = yield eat(m`#: :Space: <_Blank />`);
15
10
  }
16
11
  return trivia;
17
12
  }
18
13
 
19
- export const grammar = class CSTMLJSONGrammar extends JSON.grammar {
14
+ export default class CSTMLJSON extends JSON {
15
+ static canonicalURL = 'https://bablr.org/languages/core/en/cstml-json';
16
+
20
17
  *Expression(props) {
21
- if (yield match('NaN')) {
18
+ if (yield match(m`'NaN'`)) {
22
19
  yield eat(m`<NotANumber />`);
23
- } else if (yield match('undefined')) {
20
+ } else if (yield match(m`'undefined'`)) {
24
21
  yield eat(m`<Undefined />`);
25
22
  } else if (yield eatMatch(m`<Infinity /[+-]?Infinity/ />`)) {
26
23
  } else {
@@ -29,7 +26,7 @@ export const grammar = class CSTMLJSONGrammar extends JSON.grammar {
29
26
  }
30
27
 
31
28
  *String() {
32
- let q = yield match(re`/['"]/`);
29
+ let q = yield match(m`/['"]/`);
33
30
 
34
31
  if (!q) yield fail();
35
32
 
@@ -44,7 +41,7 @@ export const grammar = class CSTMLJSONGrammar extends JSON.grammar {
44
41
  }
45
42
 
46
43
  *Property() {
47
- if (yield match(re`/['"]/`)) {
44
+ if (yield match(m`/['"]/`)) {
48
45
  yield eatMatch(m`key$: <String />`);
49
46
  } else {
50
47
  yield eatMatch(m`key$: <Identifier />`);
@@ -57,16 +54,26 @@ export const grammar = class CSTMLJSONGrammar extends JSON.grammar {
57
54
  }
58
55
 
59
56
  *Identifier() {
60
- yield eat(m`content*: <*IdentifierContent />`);
57
+ let q;
58
+ q = yield eatMatch(m`openToken*: <* '\u0060' />`);
59
+
60
+ yield eat(m`content*: <*IdentifierContent />`, o({ quoted: !!q }));
61
+ if (q) {
62
+ yield eat(m`closeToken*: <* '\u0060' />`);
63
+ }
61
64
  }
62
65
 
63
- *IdentifierContent() {
66
+ *IdentifierContent({ props: { quoted = false } }) {
64
67
  let lit, esc;
65
68
  do {
66
- if ((esc = yield match('\\'))) {
69
+ if ((esc = yield match(m`'\\'`))) {
67
70
  esc = yield eatMatch(m`@: <EscapeSequence />`);
68
71
  } else {
69
- lit = yield eatMatch(re`/[a-zA-Z\u{80}-\u{10ffff}][a-zA-Z0-9_\u{80}-\u{10ffff}-]*/`);
72
+ if (!quoted) {
73
+ lit = yield eatMatch(m`/[a-zA-Z\u{80}-\u{10ffff}][a-zA-Z0-9_\u{80}-\u{10ffff}-]*/`);
74
+ } else {
75
+ lit = yield eatMatch(m`/[^\u0060\\\r\n]+/`);
76
+ }
70
77
  }
71
78
  } while (lit || esc);
72
79
  }
@@ -84,7 +91,7 @@ export const grammar = class CSTMLJSONGrammar extends JSON.grammar {
84
91
 
85
92
  let s = args.getState();
86
93
 
87
- let { cooked } = s.node.value.attributes;
94
+ let { cooked } = s.getNode().value.attributes;
88
95
 
89
96
  if (cooked >= '\uD800' && cooked <= '\uDFFF') {
90
97
  throw new Error('unpaired surrogates are invalid in CSTML JSON');
@@ -95,6 +102,6 @@ export const grammar = class CSTMLJSONGrammar extends JSON.grammar {
95
102
  yield eatMatch(m`signToken*: <* /[+-]/ />`);
96
103
  yield eat(m`sigilToken*: <*Keyword 'Infinity' />`);
97
104
  }
98
- };
105
+ }
99
106
 
100
- export default { canonicalURL, dependencies, grammar, defaultMatcher };
107
+ freezeClass(CSTMLJSON);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bablr/language-en-cstml-json",
3
- "version": "0.5.5",
3
+ "version": "0.6.1",
4
4
  "description": "A BABLR language for CSTML-style JSON",
5
5
  "engines": {
6
6
  "node": ">=12.0.0"
@@ -18,21 +18,19 @@
18
18
  "test": "mocha"
19
19
  },
20
20
  "dependencies": {
21
- "@bablr/agast-helpers": "0.10.10",
22
- "@bablr/agast-vm-helpers": "0.10.5",
23
- "@bablr/boot": "0.11.4",
24
- "@bablr/helpers": "0.25.5",
25
- "@bablr/language-en-json": "0.13.4"
21
+ "@bablr/agast-helpers": "0.11.4",
22
+ "@bablr/agast-vm-helpers": "0.11.4",
23
+ "@bablr/helpers": "0.26.5",
24
+ "@bablr/language-en-json": "0.14.1"
26
25
  },
27
26
  "devDependencies": {
28
- "bablr": "^0.11.11",
29
- "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#49f5952efed27f94ee9b94340eb1563c440bf64e",
27
+ "bablr": "^0.12.3",
28
+ "@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#23b94fb3bdfdbc3ac7ed9cb58d7979d8f07dce2b",
30
29
  "@qnighy/dedent": "0.1.1",
31
30
  "enhanced-resolve": "^5.12.0",
32
31
  "eslint": "^8.47.0",
33
32
  "eslint-import-resolver-enhanced-resolve": "^1.0.5",
34
33
  "eslint-plugin-import": "^2.27.5",
35
- "iter-tools-es": "^7.5.3",
36
34
  "mocha": "10.4.0",
37
35
  "expect": "29.7.0",
38
36
  "prettier": "^2.0.5"