@bablr/language-en-json 0.10.0 → 0.11.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 +34 -40
- package/lib/grammar.macro.js +38 -51
- package/package.json +7 -7
package/lib/grammar.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
1
|
/* @macrome
|
|
2
2
|
* @generatedby @bablr/macrome-generator-bablr
|
|
3
|
-
* @generatedfrom ./grammar.macro.js#
|
|
3
|
+
* @generatedfrom ./grammar.macro.js#dd06bed2bba53b9dde1ae7cf33f8696edb684bd6
|
|
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, _ExpressionDecs, _ArrayDecs, _ObjectDecs, _StringDecs, _NumberDecs, _InfinityDecs, _BooleanDecs, _NullDecs, _KeywordDecs, _PunctuatorDecs, _ListDecs, _AnyDecs, _AllDecs;
|
|
9
9
|
import { re, spam as m } from '@bablr/boot';
|
|
10
|
-
import {
|
|
10
|
+
import { basicTriviaEnhancer } from '@bablr/helpers/trivia';
|
|
11
11
|
import * as productions from '@bablr/helpers/productions';
|
|
12
|
-
import { o, eat, eatMatch, match, fail } from '@bablr/helpers/grammar';
|
|
13
|
-
import { buildString
|
|
12
|
+
import { o, eat, eatMatch, match, fail, defineAttribute } from '@bablr/helpers/grammar';
|
|
13
|
+
import { buildString } from '@bablr/helpers/builders';
|
|
14
14
|
import { Node, CoveredBy, AllowEmpty, InjectFrom, Literal } from '@bablr/helpers/decorators';
|
|
15
15
|
import * as Space from '@bablr/language-en-blank-space';
|
|
16
16
|
export const dependencies = {
|
|
@@ -30,32 +30,12 @@ const escapables = new Map(Object.entries({
|
|
|
30
30
|
function first(iter) {
|
|
31
31
|
for (let value of iter) return value;
|
|
32
32
|
}
|
|
33
|
-
export const
|
|
34
|
-
let cooked;
|
|
35
|
-
const codeNode = escapeNode.get('code');
|
|
36
|
-
if (first(codeNode.children)?.value.flags.token) {
|
|
37
|
-
const match_ = ctx.sourceTextFor(codeNode);
|
|
38
|
-
cooked = escapables.get(match_) || match_;
|
|
39
|
-
} else {
|
|
40
|
-
const type = ctx.sourceTextFor(codeNode.get('typeToken'));
|
|
41
|
-
const value = ctx.sourceTextFor(codeNode.get('value'));
|
|
42
|
-
if (!span.startsWith('String')) {
|
|
43
|
-
throw new Error('not implemented');
|
|
44
|
-
}
|
|
45
|
-
if (type === 'u') {
|
|
46
|
-
cooked = String.fromCharCode(parseInt(value, 16));
|
|
47
|
-
} else {
|
|
48
|
-
throw new Error();
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
return cooked.toString(10);
|
|
52
|
-
};
|
|
53
|
-
export const grammar = triviaEnhancer({
|
|
33
|
+
export const grammar = basicTriviaEnhancer({
|
|
54
34
|
triviaIsAllowed: s => s.span === 'Bare',
|
|
55
|
-
triviaMatcher: m`#:
|
|
35
|
+
triviaMatcher: m`#: :Space: <*Space /[ \n\r\t]/ />`
|
|
56
36
|
}, class JSONGrammar {
|
|
57
37
|
static {
|
|
58
|
-
[_initProto] = _applyDecs(this, [[_ExpressionDecs, 2, "Expression"], [_ArrayDecs, 2, "Array"], [_ObjectDecs, 2, "Object"], [Node, 2, "Property"], [
|
|
38
|
+
[_initProto] = _applyDecs(this, [[_ExpressionDecs, 2, "Expression"], [_ArrayDecs, 2, "Array"], [_ObjectDecs, 2, "Object"], [Node, 2, "Property"], [_StringDecs, 2, "String"], [[AllowEmpty, Node], 2, "StringContent"], [Node, 2, "EscapeSequence"], [Node, 2, "EscapeCode"], [_NumberDecs, 2, "Number"], [Node, 2, "Integer"], [Node, 2, "UnsignedInteger"], [Node, 2, "UnsignedHexInteger"], [_InfinityDecs, 2, "Infinity"], [_BooleanDecs, 2, "Boolean"], [_NullDecs, 2, "Null"], [_KeywordDecs, 2, "Keyword"], [_PunctuatorDecs, 2, "Punctuator"], [_ListDecs, 2, "List"], [_AnyDecs, 2, "Any"], [_AllDecs, 2, "All"]], []).e;
|
|
59
39
|
}
|
|
60
40
|
constructor() {
|
|
61
41
|
_initProto(this);
|
|
@@ -95,22 +75,14 @@ export const grammar = triviaEnhancer({
|
|
|
95
75
|
yield eat(m`closeToken: <*Punctuator '}' { balancer: true } />`);
|
|
96
76
|
}
|
|
97
77
|
*Property() {
|
|
98
|
-
yield eat(m`key$:
|
|
78
|
+
yield eat(m`key$: <String />`);
|
|
99
79
|
yield eat(m`sigilToken: <*Punctuator ':' />`);
|
|
100
80
|
yield eat(m`value+$: <__Expression />`);
|
|
101
81
|
}
|
|
102
|
-
*
|
|
103
|
-
yield eat(
|
|
104
|
-
}
|
|
105
|
-
*String({
|
|
106
|
-
ctx
|
|
107
|
-
}) {
|
|
108
|
-
let q = yield match(re`/['"]/`);
|
|
109
|
-
if (!q) yield fail();
|
|
110
|
-
const q_ = ctx.sourceTextFor(q);
|
|
111
|
-
yield q_ === "'" ? eat(m`openToken: <*Punctuator "'" { balanced: "'", balancedSpan: 'String:Single' } />`) : eat(m`openToken: <*Punctuator '"' { balanced: '"', balancedSpan: 'String:Double' } />`);
|
|
82
|
+
*String() {
|
|
83
|
+
yield eat(m`openToken: <*Punctuator '"' { balanced: '"', balancedSpan: 'String:Double' } />`);
|
|
112
84
|
yield eat(m`content$: <*StringContent />`);
|
|
113
|
-
yield
|
|
85
|
+
yield eat(m`closeToken: <*Punctuator '"' { balancer: true } />`);
|
|
114
86
|
}
|
|
115
87
|
*StringContent({
|
|
116
88
|
state: {
|
|
@@ -134,14 +106,36 @@ export const grammar = triviaEnhancer({
|
|
|
134
106
|
}
|
|
135
107
|
yield eat(m`sigilToken: <*Punctuator '\\' { openSpan: 'Escape' } />`);
|
|
136
108
|
let match_;
|
|
109
|
+
let cooked;
|
|
137
110
|
if (match_ = span === 'String:Single' ? yield match(re`/[\\/nrt0']/`) : yield match(re`/[\\/nrt0"]/`)) {
|
|
138
111
|
const matchText = ctx.sourceTextFor(match_);
|
|
139
112
|
yield eat(m`code: <*Keyword ${buildString(matchText)} { closeSpan: 'Escape' } />`);
|
|
113
|
+
cooked = escapables.get(matchText) || matchText;
|
|
140
114
|
} else if (yield match('u')) {
|
|
141
|
-
yield eat(m`code: <EscapeCode { closeSpan: 'Escape' } />`);
|
|
115
|
+
let codeNode = yield eat(m`code: <EscapeCode { closeSpan: 'Escape' } />`);
|
|
116
|
+
if (codeNode && first(codeNode.children)?.value.flags.token) {
|
|
117
|
+
const match_ = ctx.sourceTextFor(codeNode);
|
|
118
|
+
} else {
|
|
119
|
+
const type = ctx.sourceTextFor(codeNode.get('typeToken'));
|
|
120
|
+
if (type) {
|
|
121
|
+
const value = ctx.sourceTextFor(codeNode.get('value'));
|
|
122
|
+
if (!span.startsWith('String')) {
|
|
123
|
+
throw new Error('not implemented');
|
|
124
|
+
}
|
|
125
|
+
if (type === 'u') {
|
|
126
|
+
cooked = String.fromCharCode(parseInt(value, 16));
|
|
127
|
+
} else {
|
|
128
|
+
throw new Error();
|
|
129
|
+
}
|
|
130
|
+
} else {
|
|
131
|
+
let value = ctx.sourceTextFor(codeNode);
|
|
132
|
+
cooked = escapables.get(value) || value;
|
|
133
|
+
}
|
|
134
|
+
}
|
|
142
135
|
} else {
|
|
143
136
|
yield fail();
|
|
144
137
|
}
|
|
138
|
+
yield defineAttribute('cooked', cooked);
|
|
145
139
|
}
|
|
146
140
|
*EscapeCode() {
|
|
147
141
|
if (yield eatMatch(m`typeToken: <*Keyword 'u' />`)) {
|
package/lib/grammar.macro.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { re, spam as m } from '@bablr/boot';
|
|
2
|
-
import {
|
|
2
|
+
import { basicTriviaEnhancer } from '@bablr/helpers/trivia';
|
|
3
3
|
import * as productions from '@bablr/helpers/productions';
|
|
4
|
-
import { o, eat, eatMatch, match, fail } from '@bablr/helpers/grammar';
|
|
5
|
-
import { buildString
|
|
4
|
+
import { o, eat, eatMatch, match, fail, defineAttribute } from '@bablr/helpers/grammar';
|
|
5
|
+
import { buildString } from '@bablr/helpers/builders';
|
|
6
6
|
import { Node, CoveredBy, AllowEmpty, InjectFrom, Literal } from '@bablr/helpers/decorators';
|
|
7
7
|
import * as Space from '@bablr/language-en-blank-space';
|
|
8
8
|
|
|
@@ -25,36 +25,10 @@ function first(iter) {
|
|
|
25
25
|
for (let value of iter) return value;
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
export const
|
|
29
|
-
let cooked;
|
|
30
|
-
const codeNode = escapeNode.get('code');
|
|
31
|
-
|
|
32
|
-
if (first(codeNode.children)?.value.flags.token) {
|
|
33
|
-
const match_ = ctx.sourceTextFor(codeNode);
|
|
34
|
-
|
|
35
|
-
cooked = escapables.get(match_) || match_;
|
|
36
|
-
} else {
|
|
37
|
-
const type = ctx.sourceTextFor(codeNode.get('typeToken'));
|
|
38
|
-
const value = ctx.sourceTextFor(codeNode.get('value'));
|
|
39
|
-
|
|
40
|
-
if (!span.startsWith('String')) {
|
|
41
|
-
throw new Error('not implemented');
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
if (type === 'u') {
|
|
45
|
-
cooked = String.fromCharCode(parseInt(value, 16));
|
|
46
|
-
} else {
|
|
47
|
-
throw new Error();
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return cooked.toString(10);
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
export const grammar = triviaEnhancer(
|
|
28
|
+
export const grammar = basicTriviaEnhancer(
|
|
55
29
|
{
|
|
56
30
|
triviaIsAllowed: (s) => s.span === 'Bare',
|
|
57
|
-
triviaMatcher: m`#:
|
|
31
|
+
triviaMatcher: m`#: :Space: <*Space /[ \n\r\t]/ />`,
|
|
58
32
|
},
|
|
59
33
|
class JSONGrammar {
|
|
60
34
|
*[Symbol.for('@bablr/fragment')]({ props: { rootMatcher } }) {
|
|
@@ -112,34 +86,19 @@ export const grammar = triviaEnhancer(
|
|
|
112
86
|
|
|
113
87
|
@Node
|
|
114
88
|
*Property() {
|
|
115
|
-
yield eat(m`key$:
|
|
89
|
+
yield eat(m`key$: <String />`);
|
|
116
90
|
yield eat(m`sigilToken: <*Punctuator ':' />`);
|
|
117
91
|
yield eat(m`value+$: <__Expression />`);
|
|
118
92
|
}
|
|
119
93
|
|
|
120
|
-
@Node
|
|
121
|
-
*Identifier() {
|
|
122
|
-
yield eat(re`/[a-zA-Z][a-zA-Z_-]*/`);
|
|
123
|
-
}
|
|
124
|
-
|
|
125
94
|
@CoveredBy('Expression')
|
|
126
95
|
@Node
|
|
127
|
-
*String(
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
if (!q) yield fail();
|
|
131
|
-
|
|
132
|
-
const q_ = ctx.sourceTextFor(q);
|
|
133
|
-
|
|
134
|
-
yield q_ === "'"
|
|
135
|
-
? eat(m`openToken: <*Punctuator "'" { balanced: "'", balancedSpan: 'String:Single' } />`)
|
|
136
|
-
: eat(m`openToken: <*Punctuator '"' { balanced: '"', balancedSpan: 'String:Double' } />`);
|
|
96
|
+
*String() {
|
|
97
|
+
yield eat(m`openToken: <*Punctuator '"' { balanced: '"', balancedSpan: 'String:Double' } />`);
|
|
137
98
|
|
|
138
99
|
yield eat(m`content$: <*StringContent />`);
|
|
139
100
|
|
|
140
|
-
yield
|
|
141
|
-
? eat(m`closeToken: <*Punctuator "'" { balancer: true } />`)
|
|
142
|
-
: eat(m`closeToken: <*Punctuator '"' { balancer: true } />`);
|
|
101
|
+
yield eat(m`closeToken: <*Punctuator '"' { balancer: true } />`);
|
|
143
102
|
}
|
|
144
103
|
|
|
145
104
|
@AllowEmpty
|
|
@@ -164,6 +123,7 @@ export const grammar = triviaEnhancer(
|
|
|
164
123
|
yield eat(m`sigilToken: <*Punctuator '\\' { openSpan: 'Escape' } />`);
|
|
165
124
|
|
|
166
125
|
let match_;
|
|
126
|
+
let cooked;
|
|
167
127
|
|
|
168
128
|
if (
|
|
169
129
|
(match_ =
|
|
@@ -171,11 +131,38 @@ export const grammar = triviaEnhancer(
|
|
|
171
131
|
) {
|
|
172
132
|
const matchText = ctx.sourceTextFor(match_);
|
|
173
133
|
yield eat(m`code: <*Keyword ${buildString(matchText)} { closeSpan: 'Escape' } />`);
|
|
134
|
+
|
|
135
|
+
cooked = escapables.get(matchText) || matchText;
|
|
174
136
|
} else if (yield match('u')) {
|
|
175
|
-
yield eat(m`code: <EscapeCode { closeSpan: 'Escape' } />`);
|
|
137
|
+
let codeNode = yield eat(m`code: <EscapeCode { closeSpan: 'Escape' } />`);
|
|
138
|
+
|
|
139
|
+
if (codeNode && first(codeNode.children)?.value.flags.token) {
|
|
140
|
+
const match_ = ctx.sourceTextFor(codeNode);
|
|
141
|
+
} else {
|
|
142
|
+
const type = ctx.sourceTextFor(codeNode.get('typeToken'));
|
|
143
|
+
|
|
144
|
+
if (type) {
|
|
145
|
+
const value = ctx.sourceTextFor(codeNode.get('value'));
|
|
146
|
+
|
|
147
|
+
if (!span.startsWith('String')) {
|
|
148
|
+
throw new Error('not implemented');
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (type === 'u') {
|
|
152
|
+
cooked = String.fromCharCode(parseInt(value, 16));
|
|
153
|
+
} else {
|
|
154
|
+
throw new Error();
|
|
155
|
+
}
|
|
156
|
+
} else {
|
|
157
|
+
let value = ctx.sourceTextFor(codeNode);
|
|
158
|
+
cooked = escapables.get(value) || value;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
176
161
|
} else {
|
|
177
162
|
yield fail();
|
|
178
163
|
}
|
|
164
|
+
|
|
165
|
+
yield defineAttribute('cooked', cooked);
|
|
179
166
|
}
|
|
180
167
|
|
|
181
168
|
@Node
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bablr/language-en-json",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.11.0",
|
|
4
4
|
"description": "A BABLR language for JSON",
|
|
5
5
|
"engines": {
|
|
6
6
|
"node": ">=12.0.0"
|
|
@@ -21,15 +21,15 @@
|
|
|
21
21
|
},
|
|
22
22
|
"sideEffects": false,
|
|
23
23
|
"dependencies": {
|
|
24
|
-
"@bablr/agast-helpers": "0.
|
|
25
|
-
"@bablr/agast-vm-helpers": "0.
|
|
26
|
-
"@bablr/boot": "0.
|
|
27
|
-
"@bablr/helpers": "0.
|
|
28
|
-
"@bablr/language-en-blank-space": "0.
|
|
24
|
+
"@bablr/agast-helpers": "0.8.0",
|
|
25
|
+
"@bablr/agast-vm-helpers": "0.8.0",
|
|
26
|
+
"@bablr/boot": "0.9.0",
|
|
27
|
+
"@bablr/helpers": "0.23.0",
|
|
28
|
+
"@bablr/language-en-blank-space": "0.8.0",
|
|
29
29
|
"@babel/runtime": "^7.22.15"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
|
-
"@bablr/eslint-config-base": "github:bablr-lang/eslint-config-base#
|
|
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",
|