Skip to content

Commit edcb0f6

Browse files
committed
implicit-map-top-level-pk0
1 parent cd23e5d commit edcb0f6

File tree

5 files changed

+35
-33
lines changed

5 files changed

+35
-33
lines changed

dist/grammar.js

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/grammar.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,13 @@
5252
"./debug": "./dist/debug.js"
5353
},
5454
"devDependencies": {
55-
"@jsonic/directive": "^0.12.0",
55+
"@jsonic/directive": "^1.0.1",
5656
"@types/jest": "^29.5.14",
5757
"es-jest": "^2.1.0",
58-
"esbuild": "^0.24.0",
58+
"esbuild": "^0.24.2",
5959
"jest": "^29.7.0",
60-
"prettier": "^3.3.3",
61-
"typescript": "^5.6.3",
62-
"@jsonic/csv": "^0.5.0"
60+
"prettier": "^3.4.2",
61+
"typescript": "^5.7.3",
62+
"@jsonic/csv": "^0.7.0"
6363
}
6464
}

src/grammar.ts

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,13 @@ function grammar(jsonic: Jsonic) {
8888
// If there's no node,
8989
undefined === r.node
9090
? // ... or no child node (child map or list),
91-
undefined === r.child.node
91+
undefined === r.child.node
9292
? // ... or no matched tokens,
93-
0 === r.os
93+
0 === r.os
9494
? // ... then the node has no value
95-
undefined
95+
undefined
9696
: // .. otherwise use the token value
97-
r.o0.resolveVal(r, ctx)
97+
r.o0.resolveVal(r, ctx)
9898
: r.child.node
9999
: r.node
100100
})
@@ -220,7 +220,18 @@ function grammar(jsonic: Jsonic) {
220220
rs.open(
221221
[
222222
// A pair key: `a: ...`
223-
// Increment counter n.pk to indicate pair-key state (for extensions).
223+
// Implicit map at top level.
224+
{
225+
s: [KEY, CL],
226+
c: (r) => 0 == r.d,
227+
p: 'map',
228+
b: 2,
229+
g: 'pair,jsonic,top',
230+
},
231+
232+
// A pair dive: `a:b: ...`
233+
// Increment counter n.pk to indicate pair-key depth (for extensions).
234+
// a:9 -> pk=undef, a:b:9 -> pk=1, a:b:c:9 -> pk=2, etc
224235
{
225236
s: [KEY, CL],
226237
p: 'map',
@@ -244,7 +255,6 @@ function grammar(jsonic: Jsonic) {
244255
{
245256
s: [CA],
246257
c: (r) => 0 === r.d,
247-
// c: { n: { dlist: 0 } },
248258
p: 'list',
249259
b: 1,
250260
g: 'list,imp,jsonic',
@@ -256,6 +266,7 @@ function grammar(jsonic: Jsonic) {
256266
{ s: [ZZ], g: 'jsonic' },
257267
],
258268
{ append: true, delete: [2] },
269+
259270
).close(
260271
[
261272
// Explicitly close map or list: `}`, `]`
@@ -269,7 +280,6 @@ function grammar(jsonic: Jsonic) {
269280
// Implicit list (comma sep) only allowed at top level: `1,2`.
270281
{
271282
s: [CA],
272-
// c: { n: { dlist: 0, dmap: 0 } },
273283
c: (r) => r.lte('dlist') && r.lte('dmap'),
274284
r: 'list',
275285
u: { implist: true },
@@ -278,7 +288,6 @@ function grammar(jsonic: Jsonic) {
278288

279289
// Implicit list (space sep) only allowed at top level: `1 2`.
280290
{
281-
// c: { n: { dlist: 0, dmap: 0 } },
282291
c: (r) => r.lte('dlist') && r.lte('dmap'),
283292
r: 'list',
284293
u: { implist: true },
@@ -318,7 +327,6 @@ function grammar(jsonic: Jsonic) {
318327
// Normal end of map, no path dive.
319328
{
320329
s: [CB],
321-
// c: { n: { pk: 0 } },
322330
c: (r) => r.lte('pk'),
323331
g: 'end,json',
324332
},
@@ -391,7 +399,6 @@ function grammar(jsonic: Jsonic) {
391399
// a:b:c:1,d:2 -> {a:{b:{c:1}},d:2}
392400
{
393401
s: [CB],
394-
// c: { n: { pk: 0 } },
395402
c: (r) => r.lte('pk'),
396403
b: 1,
397404
g: 'map,pair,json',
@@ -400,7 +407,6 @@ function grammar(jsonic: Jsonic) {
400407
// Ignore trailing comma at end of map.
401408
{
402409
s: [CA, CB],
403-
// c: { n: { pk: 0 } },
404410
c: (r) => r.lte('pk'),
405411
b: 1,
406412
g: 'map,pair,comma,jsonic',
@@ -411,7 +417,6 @@ function grammar(jsonic: Jsonic) {
411417
// Comma means a new pair at same pair-key level.
412418
{
413419
s: [CA],
414-
// c: { n: { pk: 0 } },
415420
c: (r) => r.lte('pk'),
416421
r: 'pair',
417422
g: 'map,pair,json',
@@ -421,7 +426,6 @@ function grammar(jsonic: Jsonic) {
421426
// Comma means a new pair if implicit top level map.
422427
{
423428
s: [CA],
424-
// c: { n: { dmap: 1 } },
425429
c: (r) => r.lte('dmap', 1),
426430
r: 'pair',
427431
g: 'map,pair,jsonic',
@@ -430,9 +434,7 @@ function grammar(jsonic: Jsonic) {
430434
// TODO: try VAL CL ? works anywhere?
431435
// Value means a new pair if implicit top level map.
432436
{
433-
// s: [VAL],
434437
s: [KEY],
435-
// c: { n: { dmap: 1 } },
436438
c: (r) => r.lte('dmap', 1),
437439
r: 'pair',
438440
b: 1,

test/jsonic.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ describe('jsonic', function () {
8888
})
8989
})
9090
// console.log(k1.rule().val.def.open)
91-
expect(k1.rule().val.def.open.length).toEqual(5)
91+
expect(k1.rule().val.def.open.length).toEqual(6)
9292
})
9393

9494
it('token-gen', () => {

0 commit comments

Comments
 (0)