@bablr/language-en-cstml-json 0.5.5 → 0.6.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 +27 -20
- package/package.json +7 -9
package/lib/grammar.js
CHANGED
|
@@ -1,26 +1,23 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
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(
|
|
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
|
|
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(
|
|
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(
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
|
@@ -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
|
-
|
|
107
|
+
freezeClass(CSTMLJSON);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/language-en-cstml-json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
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.
|
|
22
|
-
"@bablr/agast-vm-helpers": "0.
|
|
23
|
-
"@bablr/
|
|
24
|
-
"@bablr/
|
|
25
|
-
"@bablr/language-en-json": "0.13.4"
|
|
21
|
+
"@bablr/agast-helpers": "0.11.3",
|
|
22
|
+
"@bablr/agast-vm-helpers": "0.11.3",
|
|
23
|
+
"@bablr/helpers": "0.26.4",
|
|
24
|
+
"@bablr/language-en-json": "0.14.0"
|
|
26
25
|
},
|
|
27
26
|
"devDependencies": {
|
|
28
|
-
"bablr": "^0.
|
|
29
|
-
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#
|
|
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"
|