@ldclabs/kip-lang 2.1.0 → 2.2.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/CHANGELOG.md +52 -0
- package/README.md +4 -4
- package/dist/ast.d.ts +58 -57
- package/dist/ast.d.ts.map +1 -1
- package/dist/exec-ast.d.ts +35 -51
- package/dist/exec-ast.d.ts.map +1 -1
- package/dist/formatter.d.ts.map +1 -1
- package/dist/formatter.js +41 -122
- package/dist/formatter.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lower.d.ts.map +1 -1
- package/dist/lower.js +91 -96
- package/dist/lower.js.map +1 -1
- package/dist/parser.d.ts.map +1 -1
- package/dist/parser.js +98 -223
- package/dist/parser.js.map +1 -1
- package/dist/semantics.js +63 -33
- package/dist/semantics.js.map +1 -1
- package/dist/token.d.ts +1 -11
- package/dist/token.d.ts.map +1 -1
- package/dist/token.js +2 -22
- package/dist/token.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +2 -2
- package/src/ast.ts +55 -71
- package/src/exec-ast.ts +38 -45
- package/src/formatter.ts +42 -140
- package/src/index.ts +5 -13
- package/src/lower.ts +108 -105
- package/src/parser.ts +103 -251
- package/src/semantics.ts +60 -35
- package/src/token.ts +2 -22
- package/src/version.ts +1 -1
package/src/parser.ts
CHANGED
|
@@ -63,16 +63,11 @@ import type {
|
|
|
63
63
|
UnsetStructuralClause,
|
|
64
64
|
StructuralRemoval,
|
|
65
65
|
ExpectVersionClause,
|
|
66
|
-
|
|
66
|
+
VersionPlane,
|
|
67
67
|
UpdateStatement,
|
|
68
68
|
UpdateAction,
|
|
69
|
-
|
|
70
|
-
SupersedeAssertionStatement,
|
|
71
|
-
CorrectEvidenceStatement,
|
|
72
|
-
TransitionActivityStatement,
|
|
69
|
+
TransitionStatement,
|
|
73
70
|
SetRetentionStatement,
|
|
74
|
-
ArchiveStatement,
|
|
75
|
-
TombstoneStatement,
|
|
76
71
|
PurgeStatement,
|
|
77
72
|
PurgePayloadStatement,
|
|
78
73
|
MergeConceptStatement,
|
|
@@ -89,7 +84,6 @@ import type {
|
|
|
89
84
|
PreviewStatement,
|
|
90
85
|
HistoryStatement,
|
|
91
86
|
ChangesStatement,
|
|
92
|
-
SnapshotStatement,
|
|
93
87
|
ExportCapsuleStatement,
|
|
94
88
|
Expression,
|
|
95
89
|
FunctionCallExpr,
|
|
@@ -200,13 +194,8 @@ class Parser {
|
|
|
200
194
|
case TokenType.Ensure:
|
|
201
195
|
case TokenType.Assert:
|
|
202
196
|
case TokenType.Update:
|
|
203
|
-
case TokenType.Retract:
|
|
204
|
-
case TokenType.Supersede:
|
|
205
|
-
case TokenType.Correct:
|
|
206
197
|
case TokenType.Transition:
|
|
207
198
|
case TokenType.Set:
|
|
208
|
-
case TokenType.Archive:
|
|
209
|
-
case TokenType.Tombstone:
|
|
210
199
|
case TokenType.Purge:
|
|
211
200
|
case TokenType.Merge:
|
|
212
201
|
return this.parseMutationClause()
|
|
@@ -228,8 +217,6 @@ class Parser {
|
|
|
228
217
|
return this.parseHistoryStatement()
|
|
229
218
|
case TokenType.Changes:
|
|
230
219
|
return this.parseChangesStatement()
|
|
231
|
-
case TokenType.Snapshot:
|
|
232
|
-
return this.parseSnapshotStatement()
|
|
233
220
|
case TokenType.Export:
|
|
234
221
|
return this.parseExportCapsuleStatement()
|
|
235
222
|
|
|
@@ -256,20 +243,10 @@ class Parser {
|
|
|
256
243
|
return this.parseAssertStatement()
|
|
257
244
|
case TokenType.Update:
|
|
258
245
|
return this.parseUpdateStatement()
|
|
259
|
-
case TokenType.Retract:
|
|
260
|
-
return this.parseRetractAssertion()
|
|
261
|
-
case TokenType.Supersede:
|
|
262
|
-
return this.parseSupersedeAssertion()
|
|
263
|
-
case TokenType.Correct:
|
|
264
|
-
return this.parseCorrectEvidence()
|
|
265
246
|
case TokenType.Transition:
|
|
266
|
-
return this.
|
|
247
|
+
return this.parseTransitionStatement()
|
|
267
248
|
case TokenType.Set:
|
|
268
249
|
return this.parseSetRetention()
|
|
269
|
-
case TokenType.Archive:
|
|
270
|
-
return this.parseArchiveStatement()
|
|
271
|
-
case TokenType.Tombstone:
|
|
272
|
-
return this.parseTombstoneStatement()
|
|
273
250
|
case TokenType.Purge:
|
|
274
251
|
return this.parsePurgeStatement()
|
|
275
252
|
case TokenType.Merge:
|
|
@@ -386,25 +363,18 @@ class Parser {
|
|
|
386
363
|
const start = this.currentPos()
|
|
387
364
|
const first = this.expect(TokenType.As)
|
|
388
365
|
this.expectSecondWord(TokenType.Of, first)
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
} else if (this.match(TokenType.Tx)) {
|
|
394
|
-
basis = 'TX'
|
|
395
|
-
} else if (this.match(TokenType.Time)) {
|
|
396
|
-
basis = 'TIME'
|
|
397
|
-
} else {
|
|
366
|
+
// Cognitive time is a sequence coordinate. A transaction id or an instant
|
|
367
|
+
// is resolved to one first (DESCRIBE TRANSACTION / DESCRIBE SNAPSHOT AT
|
|
368
|
+
// TIME), so the read names the sequence it actually ran against.
|
|
369
|
+
if (!this.match(TokenType.Seq)) {
|
|
398
370
|
this.error(
|
|
399
|
-
`Expected SEQ
|
|
371
|
+
`Expected SEQ after AS OF but got '${this.current().value}'`,
|
|
400
372
|
this.current()
|
|
401
373
|
)
|
|
402
|
-
basis = 'SEQ'
|
|
403
374
|
}
|
|
404
375
|
const value = this.parseScalarValue()
|
|
405
376
|
return {
|
|
406
377
|
kind: 'AsOfClause',
|
|
407
|
-
basis,
|
|
408
378
|
value,
|
|
409
379
|
range: { start, end: this.endPos() }
|
|
410
380
|
}
|
|
@@ -1264,6 +1234,7 @@ class Parser {
|
|
|
1264
1234
|
handle,
|
|
1265
1235
|
setFacets: [],
|
|
1266
1236
|
unsetFacets: [],
|
|
1237
|
+
expectVersions: [],
|
|
1267
1238
|
range: { start, end: start },
|
|
1268
1239
|
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
1269
1240
|
}
|
|
@@ -1278,10 +1249,6 @@ class Parser {
|
|
|
1278
1249
|
this.rejectRepeat(stmt.match, 'MATCH', tok)
|
|
1279
1250
|
stmt.match = this.parseMatchClause()
|
|
1280
1251
|
break
|
|
1281
|
-
case TokenType.Expect:
|
|
1282
|
-
this.rejectRepeat(stmt.expectVersion, 'EXPECT VERSION', tok)
|
|
1283
|
-
stmt.expectVersion = this.parseExpectVersionClause()
|
|
1284
|
-
break
|
|
1285
1252
|
case TokenType.Set: {
|
|
1286
1253
|
const clause = this.parseSetClause()
|
|
1287
1254
|
if (clause.kind === 'SetFieldsClause') {
|
|
@@ -1320,6 +1287,9 @@ class Parser {
|
|
|
1320
1287
|
if (this.pos === before) break
|
|
1321
1288
|
}
|
|
1322
1289
|
this.expect(TokenType.RBrace)
|
|
1290
|
+
// Preconditions trail the body, in the one tail order every mutation
|
|
1291
|
+
// shares: [WHERE] [LIMIT] {EXPECT VERSION} (Spec §52.8).
|
|
1292
|
+
stmt.expectVersions = this.parseExpectVersions()
|
|
1323
1293
|
stmt.range = { start, end: this.endPos() }
|
|
1324
1294
|
return stmt
|
|
1325
1295
|
}
|
|
@@ -1335,15 +1305,13 @@ class Parser {
|
|
|
1335
1305
|
: undefined
|
|
1336
1306
|
this.dialect = 'raw'
|
|
1337
1307
|
const tuple = this.parsePropositionTuple()
|
|
1338
|
-
const
|
|
1339
|
-
? this.parseExpectVersionClause()
|
|
1340
|
-
: undefined
|
|
1308
|
+
const expectVersions = this.parseExpectVersions()
|
|
1341
1309
|
|
|
1342
1310
|
return {
|
|
1343
1311
|
kind: 'EnsurePropositionStatement',
|
|
1344
1312
|
handle,
|
|
1345
1313
|
tuple,
|
|
1346
|
-
|
|
1314
|
+
expectVersions,
|
|
1347
1315
|
range: { start, end: this.endPos() },
|
|
1348
1316
|
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
1349
1317
|
}
|
|
@@ -1614,23 +1582,52 @@ class Parser {
|
|
|
1614
1582
|
const expect = this.expect(TokenType.Expect)
|
|
1615
1583
|
this.expectSecondWord(TokenType.Version, expect)
|
|
1616
1584
|
const value = this.parseScalarValue()
|
|
1585
|
+
|
|
1586
|
+
// `OF <plane>` guards one plane's own version instead of the element's
|
|
1587
|
+
// (Spec §35.1): a verdict guarded on ATTRIBUTES is not spoiled by a
|
|
1588
|
+
// metabolism sweep that touched a Facet.
|
|
1589
|
+
let plane: VersionPlane | undefined
|
|
1590
|
+
if (this.match(TokenType.Of)) {
|
|
1591
|
+
const tok = this.current()
|
|
1592
|
+
switch (tok.type) {
|
|
1593
|
+
case TokenType.Attributes:
|
|
1594
|
+
this.advance()
|
|
1595
|
+
plane = { kind: 'ATTRIBUTES' }
|
|
1596
|
+
break
|
|
1597
|
+
case TokenType.Structural:
|
|
1598
|
+
this.advance()
|
|
1599
|
+
plane = { kind: 'STRUCTURAL' }
|
|
1600
|
+
break
|
|
1601
|
+
case TokenType.Retention:
|
|
1602
|
+
this.advance()
|
|
1603
|
+
plane = { kind: 'RETENTION' }
|
|
1604
|
+
break
|
|
1605
|
+
case TokenType.Facet:
|
|
1606
|
+
this.advance()
|
|
1607
|
+
plane = { kind: 'FACET', facet: this.parseSchemaSymbol() }
|
|
1608
|
+
break
|
|
1609
|
+
default:
|
|
1610
|
+
this.error(
|
|
1611
|
+
`Expected ATTRIBUTES, STRUCTURAL, RETENTION or FACET after OF but got '${tok.value}'`,
|
|
1612
|
+
tok
|
|
1613
|
+
)
|
|
1614
|
+
}
|
|
1615
|
+
}
|
|
1617
1616
|
return {
|
|
1618
1617
|
kind: 'ExpectVersionClause',
|
|
1619
1618
|
value,
|
|
1619
|
+
plane,
|
|
1620
1620
|
range: { start, end: this.endPos() }
|
|
1621
1621
|
}
|
|
1622
1622
|
}
|
|
1623
1623
|
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
const
|
|
1627
|
-
this.
|
|
1628
|
-
|
|
1629
|
-
return {
|
|
1630
|
-
kind: 'ExpectStateClause',
|
|
1631
|
-
value,
|
|
1632
|
-
range: { start, end: this.endPos() }
|
|
1624
|
+
/** `{ expect_version_clause }` — the trailing precondition list. */
|
|
1625
|
+
private parseExpectVersions(): ExpectVersionClause[] {
|
|
1626
|
+
const clauses: ExpectVersionClause[] = []
|
|
1627
|
+
while (this.check(TokenType.Expect)) {
|
|
1628
|
+
clauses.push(this.parseExpectVersionClause())
|
|
1633
1629
|
}
|
|
1630
|
+
return clauses
|
|
1634
1631
|
}
|
|
1635
1632
|
|
|
1636
1633
|
// ────────────────────────────────────────────────────────────────────
|
|
@@ -1643,10 +1640,6 @@ class Parser {
|
|
|
1643
1640
|
this.expectKeywordWithSpace(TokenType.Update)
|
|
1644
1641
|
const target = this.parseTargetRef()
|
|
1645
1642
|
|
|
1646
|
-
const expectVersion = this.check(TokenType.Expect)
|
|
1647
|
-
? this.parseExpectVersionClause()
|
|
1648
|
-
: undefined
|
|
1649
|
-
|
|
1650
1643
|
const actions: UpdateAction[] = []
|
|
1651
1644
|
for (;;) {
|
|
1652
1645
|
if (this.check(TokenType.Set)) {
|
|
@@ -1670,9 +1663,9 @@ class Parser {
|
|
|
1670
1663
|
}
|
|
1671
1664
|
|
|
1672
1665
|
// WHERE binds a ?variable target; a direct :id / "id" target already names
|
|
1673
|
-
// the element and may omit it, exactly as
|
|
1674
|
-
// SET RETENTION
|
|
1675
|
-
//
|
|
1666
|
+
// the element and may omit it, exactly as TRANSITION / PURGE /
|
|
1667
|
+
// SET RETENTION do (Spec §58). Whether a bare ?variable is bound is
|
|
1668
|
+
// semantic — inside MUTATE it may be a local handle.
|
|
1676
1669
|
let where: WhereClause | undefined
|
|
1677
1670
|
if (this.check(TokenType.Where)) {
|
|
1678
1671
|
this.expectKeywordWithSpace(TokenType.Where)
|
|
@@ -1680,107 +1673,40 @@ class Parser {
|
|
|
1680
1673
|
where = this.parseWhereClause()
|
|
1681
1674
|
}
|
|
1682
1675
|
const limit = this.check(TokenType.Limit) ? this.parseLimitClause() : undefined
|
|
1676
|
+
const expectVersions = this.parseExpectVersions()
|
|
1683
1677
|
|
|
1684
1678
|
return {
|
|
1685
1679
|
kind: 'UpdateStatement',
|
|
1686
1680
|
target,
|
|
1687
|
-
expectVersion,
|
|
1688
1681
|
actions,
|
|
1689
1682
|
where,
|
|
1690
1683
|
limit,
|
|
1684
|
+
expectVersions,
|
|
1691
1685
|
range: { start, end: this.endPos() },
|
|
1692
1686
|
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
1693
1687
|
}
|
|
1694
1688
|
}
|
|
1695
1689
|
|
|
1696
1690
|
// ────────────────────────────────────────────────────────────────────
|
|
1697
|
-
// KML — lifecycle
|
|
1691
|
+
// KML — TRANSITION (the one lifecycle statement, Spec §52.5)
|
|
1698
1692
|
// ────────────────────────────────────────────────────────────────────
|
|
1699
1693
|
|
|
1700
|
-
private
|
|
1694
|
+
private parseTransitionStatement(): TransitionStatement {
|
|
1701
1695
|
const leadingComments = this.collectLeadingComments()
|
|
1702
1696
|
const start = this.currentPos()
|
|
1703
|
-
|
|
1704
|
-
this.expectSecondWord(TokenType.Assertion, retract)
|
|
1705
|
-
const target = this.parseTargetRef()
|
|
1706
|
-
|
|
1707
|
-
let where: WhereClause | undefined
|
|
1708
|
-
if (this.check(TokenType.Where)) {
|
|
1709
|
-
this.expectKeywordWithSpace(TokenType.Where)
|
|
1710
|
-
this.dialect = 'raw'
|
|
1711
|
-
where = this.parseWhereClause()
|
|
1712
|
-
}
|
|
1713
|
-
const limit = this.check(TokenType.Limit) ? this.parseLimitClause() : undefined
|
|
1714
|
-
const expectState = this.check(TokenType.Expect)
|
|
1715
|
-
? this.parseExpectStateClause()
|
|
1716
|
-
: undefined
|
|
1717
|
-
|
|
1718
|
-
return {
|
|
1719
|
-
kind: 'RetractAssertionStatement',
|
|
1720
|
-
target,
|
|
1721
|
-
where,
|
|
1722
|
-
limit,
|
|
1723
|
-
expectState,
|
|
1724
|
-
range: { start, end: this.endPos() },
|
|
1725
|
-
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
1726
|
-
}
|
|
1727
|
-
}
|
|
1728
|
-
|
|
1729
|
-
private parseSupersedeAssertion(): SupersedeAssertionStatement {
|
|
1730
|
-
const leadingComments = this.collectLeadingComments()
|
|
1731
|
-
const start = this.currentPos()
|
|
1732
|
-
const supersede = this.expectKeywordWithSpace(TokenType.Supersede)
|
|
1733
|
-
this.expectSecondWord(TokenType.Assertion, supersede)
|
|
1734
|
-
const target = this.parseTargetRef()
|
|
1735
|
-
this.expect(TokenType.By)
|
|
1736
|
-
const by = this.parseTargetRef()
|
|
1737
|
-
const expectState = this.check(TokenType.Expect)
|
|
1738
|
-
? this.parseExpectStateClause()
|
|
1739
|
-
: undefined
|
|
1740
|
-
|
|
1741
|
-
return {
|
|
1742
|
-
kind: 'SupersedeAssertionStatement',
|
|
1743
|
-
target,
|
|
1744
|
-
by,
|
|
1745
|
-
expectState,
|
|
1746
|
-
range: { start, end: this.endPos() },
|
|
1747
|
-
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
1748
|
-
}
|
|
1749
|
-
}
|
|
1750
|
-
|
|
1751
|
-
private parseCorrectEvidence(): CorrectEvidenceStatement {
|
|
1752
|
-
const leadingComments = this.collectLeadingComments()
|
|
1753
|
-
const start = this.currentPos()
|
|
1754
|
-
const correct = this.expectKeywordWithSpace(TokenType.Correct)
|
|
1755
|
-
this.expectSecondWord(TokenType.Evidence, correct)
|
|
1756
|
-
const target = this.parseTargetRef()
|
|
1757
|
-
this.expect(TokenType.By)
|
|
1758
|
-
const by = this.parseTargetRef()
|
|
1759
|
-
const expectState = this.check(TokenType.Expect)
|
|
1760
|
-
? this.parseExpectStateClause()
|
|
1761
|
-
: undefined
|
|
1762
|
-
|
|
1763
|
-
return {
|
|
1764
|
-
kind: 'CorrectEvidenceStatement',
|
|
1765
|
-
target,
|
|
1766
|
-
by,
|
|
1767
|
-
expectState,
|
|
1768
|
-
range: { start, end: this.endPos() },
|
|
1769
|
-
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
1770
|
-
}
|
|
1771
|
-
}
|
|
1772
|
-
|
|
1773
|
-
private parseTransitionActivity(): TransitionActivityStatement {
|
|
1774
|
-
const leadingComments = this.collectLeadingComments()
|
|
1775
|
-
const start = this.currentPos()
|
|
1776
|
-
const transition = this.expectKeywordWithSpace(TokenType.Transition)
|
|
1777
|
-
this.expectSecondWord(TokenType.Activity, transition)
|
|
1697
|
+
this.expectKeywordWithSpace(TokenType.Transition)
|
|
1778
1698
|
const target = this.parseTargetRef()
|
|
1779
1699
|
this.expect(TokenType.To)
|
|
1780
1700
|
const to = this.parseScalarValue()
|
|
1781
1701
|
|
|
1782
|
-
//
|
|
1783
|
-
|
|
1702
|
+
// `BY` names the replacing element for "superseded" / "corrected".
|
|
1703
|
+
let by: TargetRef | undefined
|
|
1704
|
+
if (this.match(TokenType.By)) {
|
|
1705
|
+
by = this.parseTargetRef()
|
|
1706
|
+
}
|
|
1707
|
+
|
|
1708
|
+
// A pending Activity finalizes terminal fields and topology in the same
|
|
1709
|
+
// statement that moves it (Spec §17.5, §52.5).
|
|
1784
1710
|
const finalize: (SetFieldsClause | SetStructuralClause)[] = []
|
|
1785
1711
|
while (this.check(TokenType.Set)) {
|
|
1786
1712
|
const clause = this.parseSetClause()
|
|
@@ -1788,23 +1714,31 @@ class Parser {
|
|
|
1788
1714
|
finalize.push(clause)
|
|
1789
1715
|
} else {
|
|
1790
1716
|
this.error(
|
|
1791
|
-
'TRANSITION
|
|
1717
|
+
'TRANSITION accepts only SET FIELDS and SET STRUCTURAL',
|
|
1792
1718
|
this.current()
|
|
1793
1719
|
)
|
|
1794
1720
|
break
|
|
1795
1721
|
}
|
|
1796
1722
|
}
|
|
1797
1723
|
|
|
1798
|
-
|
|
1799
|
-
|
|
1800
|
-
|
|
1724
|
+
let where: WhereClause | undefined
|
|
1725
|
+
if (this.check(TokenType.Where)) {
|
|
1726
|
+
this.expectKeywordWithSpace(TokenType.Where)
|
|
1727
|
+
this.dialect = 'raw'
|
|
1728
|
+
where = this.parseWhereClause()
|
|
1729
|
+
}
|
|
1730
|
+
const limit = this.check(TokenType.Limit) ? this.parseLimitClause() : undefined
|
|
1731
|
+
const expectVersions = this.parseExpectVersions()
|
|
1801
1732
|
|
|
1802
1733
|
return {
|
|
1803
|
-
kind: '
|
|
1734
|
+
kind: 'TransitionStatement',
|
|
1804
1735
|
target,
|
|
1805
1736
|
to,
|
|
1737
|
+
by,
|
|
1806
1738
|
finalize,
|
|
1807
|
-
|
|
1739
|
+
where,
|
|
1740
|
+
limit,
|
|
1741
|
+
expectVersions,
|
|
1808
1742
|
range: { start, end: this.endPos() },
|
|
1809
1743
|
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
1810
1744
|
}
|
|
@@ -1829,9 +1763,7 @@ class Parser {
|
|
|
1829
1763
|
where = this.parseWhereClause()
|
|
1830
1764
|
}
|
|
1831
1765
|
const limit = this.check(TokenType.Limit) ? this.parseLimitClause() : undefined
|
|
1832
|
-
const
|
|
1833
|
-
? this.parseExpectVersionClause()
|
|
1834
|
-
: undefined
|
|
1766
|
+
const expectVersions = this.parseExpectVersions()
|
|
1835
1767
|
|
|
1836
1768
|
return {
|
|
1837
1769
|
kind: 'SetRetentionStatement',
|
|
@@ -1839,75 +1771,12 @@ class Parser {
|
|
|
1839
1771
|
assignments,
|
|
1840
1772
|
where,
|
|
1841
1773
|
limit,
|
|
1842
|
-
|
|
1774
|
+
expectVersions,
|
|
1843
1775
|
range: { start, end: this.endPos() },
|
|
1844
1776
|
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
1845
1777
|
}
|
|
1846
1778
|
}
|
|
1847
1779
|
|
|
1848
|
-
private parseArchiveStatement(): ArchiveStatement {
|
|
1849
|
-
const { start, target, where, limit, expectState, leadingComments } =
|
|
1850
|
-
this.parseRemovalBody(TokenType.Archive)
|
|
1851
|
-
return {
|
|
1852
|
-
kind: 'ArchiveStatement',
|
|
1853
|
-
target,
|
|
1854
|
-
where,
|
|
1855
|
-
limit,
|
|
1856
|
-
expectState,
|
|
1857
|
-
range: { start, end: this.endPos() },
|
|
1858
|
-
leadingComments
|
|
1859
|
-
}
|
|
1860
|
-
}
|
|
1861
|
-
|
|
1862
|
-
private parseTombstoneStatement(): TombstoneStatement {
|
|
1863
|
-
const { start, target, where, limit, expectState, leadingComments } =
|
|
1864
|
-
this.parseRemovalBody(TokenType.Tombstone)
|
|
1865
|
-
return {
|
|
1866
|
-
kind: 'TombstoneStatement',
|
|
1867
|
-
target,
|
|
1868
|
-
where,
|
|
1869
|
-
limit,
|
|
1870
|
-
expectState,
|
|
1871
|
-
range: { start, end: this.endPos() },
|
|
1872
|
-
leadingComments
|
|
1873
|
-
}
|
|
1874
|
-
}
|
|
1875
|
-
|
|
1876
|
-
/** ARCHIVE and TOMBSTONE share one shape; PURGE adds its confirmation. */
|
|
1877
|
-
private parseRemovalBody(keyword: TokenType): {
|
|
1878
|
-
start: Position
|
|
1879
|
-
target: TargetRef
|
|
1880
|
-
where?: WhereClause
|
|
1881
|
-
limit?: LimitClause
|
|
1882
|
-
expectState?: ExpectStateClause
|
|
1883
|
-
leadingComments?: string[]
|
|
1884
|
-
} {
|
|
1885
|
-
const comments = this.collectLeadingComments()
|
|
1886
|
-
const start = this.currentPos()
|
|
1887
|
-
this.expectKeywordWithSpace(keyword)
|
|
1888
|
-
const target = this.parseTargetRef()
|
|
1889
|
-
|
|
1890
|
-
let where: WhereClause | undefined
|
|
1891
|
-
if (this.check(TokenType.Where)) {
|
|
1892
|
-
this.expectKeywordWithSpace(TokenType.Where)
|
|
1893
|
-
this.dialect = 'raw'
|
|
1894
|
-
where = this.parseWhereClause()
|
|
1895
|
-
}
|
|
1896
|
-
const limit = this.check(TokenType.Limit) ? this.parseLimitClause() : undefined
|
|
1897
|
-
const expectState = this.check(TokenType.Expect)
|
|
1898
|
-
? this.parseExpectStateClause()
|
|
1899
|
-
: undefined
|
|
1900
|
-
|
|
1901
|
-
return {
|
|
1902
|
-
start,
|
|
1903
|
-
target,
|
|
1904
|
-
where,
|
|
1905
|
-
limit,
|
|
1906
|
-
expectState,
|
|
1907
|
-
leadingComments: comments.length ? comments : undefined
|
|
1908
|
-
}
|
|
1909
|
-
}
|
|
1910
|
-
|
|
1911
1780
|
private parsePurgeStatement(): PurgeStatement | PurgePayloadStatement {
|
|
1912
1781
|
const leadingComments = this.collectLeadingComments()
|
|
1913
1782
|
const start = this.currentPos()
|
|
@@ -1925,6 +1794,7 @@ class Parser {
|
|
|
1925
1794
|
}
|
|
1926
1795
|
|
|
1927
1796
|
const limit = this.check(TokenType.Limit) ? this.parseLimitClause() : undefined
|
|
1797
|
+
const expectVersions = this.parseExpectVersions()
|
|
1928
1798
|
|
|
1929
1799
|
let referencePolicy: ScalarValue | undefined
|
|
1930
1800
|
if (this.check(TokenType.Reference)) {
|
|
@@ -1951,6 +1821,7 @@ class Parser {
|
|
|
1951
1821
|
target,
|
|
1952
1822
|
where,
|
|
1953
1823
|
limit,
|
|
1824
|
+
expectVersions,
|
|
1954
1825
|
referencePolicy,
|
|
1955
1826
|
confirm,
|
|
1956
1827
|
range: { start, end: this.endPos() },
|
|
@@ -1979,6 +1850,7 @@ class Parser {
|
|
|
1979
1850
|
}
|
|
1980
1851
|
|
|
1981
1852
|
const limit = this.check(TokenType.Limit) ? this.parseLimitClause() : undefined
|
|
1853
|
+
const expectVersions = this.parseExpectVersions()
|
|
1982
1854
|
|
|
1983
1855
|
this.expect(TokenType.Confirm)
|
|
1984
1856
|
const confirmTok = this.current()
|
|
@@ -1995,6 +1867,7 @@ class Parser {
|
|
|
1995
1867
|
target,
|
|
1996
1868
|
where,
|
|
1997
1869
|
limit,
|
|
1870
|
+
expectVersions,
|
|
1998
1871
|
confirm,
|
|
1999
1872
|
range: { start, end: this.endPos() },
|
|
2000
1873
|
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
@@ -2016,16 +1889,14 @@ class Parser {
|
|
|
2016
1889
|
this.dialect = 'raw'
|
|
2017
1890
|
where = this.parseWhereClause()
|
|
2018
1891
|
}
|
|
2019
|
-
const
|
|
2020
|
-
? this.parseExpectVersionClause()
|
|
2021
|
-
: undefined
|
|
1892
|
+
const expectVersions = this.parseExpectVersions()
|
|
2022
1893
|
|
|
2023
1894
|
return {
|
|
2024
1895
|
kind: 'MergeConceptStatement',
|
|
2025
1896
|
source,
|
|
2026
1897
|
into,
|
|
2027
1898
|
where,
|
|
2028
|
-
|
|
1899
|
+
expectVersions,
|
|
2029
1900
|
range: { start, end: this.endPos() },
|
|
2030
1901
|
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
2031
1902
|
}
|
|
@@ -2062,11 +1933,6 @@ class Parser {
|
|
|
2062
1933
|
case TokenType.Protocol:
|
|
2063
1934
|
this.expectSecondWord(TokenType.Protocol, describe)
|
|
2064
1935
|
return stmt('PROTOCOL')
|
|
2065
|
-
case TokenType.Execution: {
|
|
2066
|
-
const exec = this.expectSecondWord(TokenType.Execution, describe)
|
|
2067
|
-
this.expectSecondWord(TokenType.Context, exec)
|
|
2068
|
-
return stmt('EXECUTION_CONTEXT')
|
|
2069
|
-
}
|
|
2070
1936
|
case TokenType.Capabilities:
|
|
2071
1937
|
this.expectSecondWord(TokenType.Capabilities, describe)
|
|
2072
1938
|
return stmt('CAPABILITIES')
|
|
@@ -2123,8 +1989,18 @@ class Parser {
|
|
|
2123
1989
|
}
|
|
2124
1990
|
case TokenType.Snapshot: {
|
|
2125
1991
|
this.expectSecondWord(TokenType.Snapshot, describe)
|
|
2126
|
-
|
|
2127
|
-
|
|
1992
|
+
// A snapshot is addressed by sequence, or resolved from an instant:
|
|
1993
|
+
// the one place wall-clock time enters cognitive-time addressing.
|
|
1994
|
+
let asOf: AsOfClause | undefined
|
|
1995
|
+
let atTime: ScalarValue | undefined
|
|
1996
|
+
if (this.check(TokenType.As)) {
|
|
1997
|
+
asOf = this.parseAsOfClause()
|
|
1998
|
+
} else if (this.check(TokenType.At)) {
|
|
1999
|
+
const at = this.expect(TokenType.At)
|
|
2000
|
+
this.expectSecondWord(TokenType.Time, at)
|
|
2001
|
+
atTime = this.parseScalarValue()
|
|
2002
|
+
}
|
|
2003
|
+
return stmt('SNAPSHOT', { asOf, atTime })
|
|
2128
2004
|
}
|
|
2129
2005
|
case TokenType.Capsule:
|
|
2130
2006
|
this.expectSecondWord(TokenType.Capsule, describe)
|
|
@@ -2135,11 +2011,6 @@ class Parser {
|
|
|
2135
2011
|
const value = this.isMetaValueStart() ? this.parseScalarValue() : undefined
|
|
2136
2012
|
return stmt('EPISTEMIC_POLICY', { value })
|
|
2137
2013
|
}
|
|
2138
|
-
case TokenType.Projection: {
|
|
2139
|
-
const projection = this.expectSecondWord(TokenType.Projection, describe)
|
|
2140
|
-
this.expectSecondWord(TokenType.Capability, projection)
|
|
2141
|
-
return stmt('PROJECTION_CAPABILITY')
|
|
2142
|
-
}
|
|
2143
2014
|
case TokenType.Trust: {
|
|
2144
2015
|
this.expectSecondWord(TokenType.Trust, describe)
|
|
2145
2016
|
const value = this.isMetaValueStart() ? this.parseScalarValue() : undefined
|
|
@@ -2478,7 +2349,7 @@ class Parser {
|
|
|
2478
2349
|
}
|
|
2479
2350
|
|
|
2480
2351
|
// ────────────────────────────────────────────────────────────────────
|
|
2481
|
-
// META — HISTORY / CHANGES
|
|
2352
|
+
// META — HISTORY / CHANGES
|
|
2482
2353
|
// ────────────────────────────────────────────────────────────────────
|
|
2483
2354
|
|
|
2484
2355
|
private parseHistoryStatement(): HistoryStatement {
|
|
@@ -2569,19 +2440,6 @@ class Parser {
|
|
|
2569
2440
|
}
|
|
2570
2441
|
}
|
|
2571
2442
|
|
|
2572
|
-
private parseSnapshotStatement(): SnapshotStatement {
|
|
2573
|
-
const leadingComments = this.collectLeadingComments()
|
|
2574
|
-
const start = this.currentPos()
|
|
2575
|
-
this.expect(TokenType.Snapshot)
|
|
2576
|
-
const asOf = this.check(TokenType.As) ? this.parseAsOfClause() : undefined
|
|
2577
|
-
return {
|
|
2578
|
-
kind: 'SnapshotStatement',
|
|
2579
|
-
asOf,
|
|
2580
|
-
range: { start, end: this.endPos() },
|
|
2581
|
-
leadingComments: leadingComments.length ? leadingComments : undefined
|
|
2582
|
-
}
|
|
2583
|
-
}
|
|
2584
|
-
|
|
2585
2443
|
// ────────────────────────────────────────────────────────────────────
|
|
2586
2444
|
// META — EXPORT CAPSULE
|
|
2587
2445
|
// ────────────────────────────────────────────────────────────────────
|
|
@@ -3508,13 +3366,8 @@ class Parser {
|
|
|
3508
3366
|
TokenType.Ensure,
|
|
3509
3367
|
TokenType.Assert,
|
|
3510
3368
|
TokenType.Update,
|
|
3511
|
-
TokenType.Retract,
|
|
3512
|
-
TokenType.Supersede,
|
|
3513
|
-
TokenType.Correct,
|
|
3514
3369
|
TokenType.Transition,
|
|
3515
3370
|
TokenType.Set,
|
|
3516
|
-
TokenType.Archive,
|
|
3517
|
-
TokenType.Tombstone,
|
|
3518
3371
|
TokenType.Purge,
|
|
3519
3372
|
TokenType.Merge,
|
|
3520
3373
|
TokenType.Describe,
|
|
@@ -3525,7 +3378,6 @@ class Parser {
|
|
|
3525
3378
|
TokenType.Preview,
|
|
3526
3379
|
TokenType.History,
|
|
3527
3380
|
TokenType.Changes,
|
|
3528
|
-
TokenType.Snapshot,
|
|
3529
3381
|
TokenType.Export,
|
|
3530
3382
|
TokenType.EOF
|
|
3531
3383
|
])
|