@altopelago/sansa 0.11.1 → 0.12.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 +71 -0
- package/README.md +23 -2
- package/conformance/cts-claims.json +9 -2
- package/docs/api-contract.md +101 -13
- package/docs/capabilities.json +3 -1
- package/docs/query-tool.md +42 -2
- package/docs/releasing.md +11 -8
- package/fixtures/query-inventory.aeon +7 -0
- package/fixtures/query-inventory.telex.aes +5 -0
- package/package.json +1 -1
- package/scripts/cts-value-semantics.mjs +1 -1
- package/scripts/query.mjs +17 -0
- package/src/index.d.ts +79 -4
- package/src/index.js +942 -53
- package/tools/mutate-web/runtime.mjs +30 -1
- package/tools/query-web/examples.mjs +44 -1
- package/tools/query-web/index.html +2 -0
- package/tools/query-web/runtime.mjs +97 -3
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export const SANSA_MAX_QUERY_INTEGER = Number.MAX_SAFE_INTEGER;
|
|
|
5
5
|
|
|
6
6
|
const QUERY_VALUE_METADATA_PROPERTY = '__sansaQueryValueMetadata';
|
|
7
7
|
const QUERY_OBJECT_FIELD_METADATA_PROPERTY = '__sansaObjectFieldMetadata';
|
|
8
|
+
const COMPARABLE_SCALAR_DESCRIPTOR_PROPERTY = Symbol('sansaComparableScalarDescriptor');
|
|
8
9
|
const TRANSFORM_EXTENSION_FUNCTIONS = new Map([
|
|
9
10
|
['objectFrom', 'sansa.transform.objectFrom'],
|
|
10
11
|
['fieldsFrom', 'sansa.transform.fieldsFrom'],
|
|
@@ -13,7 +14,10 @@ const DEFAULT_VALUE_SEMANTICS_PROFILE_ID = 'aeon.value.default.v1';
|
|
|
13
14
|
const CODEPOINT_STRING_PROFILE_ID = 'aeon.value.string.codepoint.v1';
|
|
14
15
|
const FRENCH_STRING_PROFILE_ID = 'aeon.value.string.locale.fr.v1';
|
|
15
16
|
const NATURAL_ASCII_STRING_PROFILE_ID = 'aeon.value.string.natural.ascii.v1';
|
|
16
|
-
const
|
|
17
|
+
const TEMPORAL_CANONICAL_PROFILE_ID = 'aeon.value.temporal.canonical.v1';
|
|
18
|
+
const RADIX_NUMERIC_SAME_BASE_PROFILE_ID = 'aeon.value.radix.numeric.same-base.v1';
|
|
19
|
+
const RADIX_NUMERIC_CROSS_BASE_PROFILE_ID = 'aeon.value.radix.numeric.cross-base.v1';
|
|
20
|
+
const MAX_EXACT_NUMERIC_CHARACTERS = 65_536;
|
|
17
21
|
const MUTATION_REQUEST_ENVELOPE_FIELDS = new Set(['operations', 'preconditions', 'provenance']);
|
|
18
22
|
const MUTATION_OPERATION_FIELDS = new Map([
|
|
19
23
|
['create', new Set(['op', 'parent', 'name', 'value', 'datatype', 'kind', 'provenance'])],
|
|
@@ -28,6 +32,7 @@ const VALUE_SEMANTICS_METADATA_CATEGORIES = [
|
|
|
28
32
|
'radix',
|
|
29
33
|
'encoding',
|
|
30
34
|
'separator',
|
|
35
|
+
'symbol',
|
|
31
36
|
'sansa',
|
|
32
37
|
'sansaAddress',
|
|
33
38
|
'cloneReference',
|
|
@@ -285,7 +290,7 @@ export function validateMutationPlanTarget(plan, targetSurface = 'aeon') {
|
|
|
285
290
|
export const aeonValueSemanticsDefaultProfile = Object.freeze({
|
|
286
291
|
id: DEFAULT_VALUE_SEMANTICS_PROFILE_ID,
|
|
287
292
|
stringOrder: CODEPOINT_STRING_PROFILE_ID,
|
|
288
|
-
temporalOrder:
|
|
293
|
+
temporalOrder: TEMPORAL_CANONICAL_PROFILE_ID,
|
|
289
294
|
caseMapping: 'unicode-default',
|
|
290
295
|
compareStrings: compareStringsByUnicodeScalarValue,
|
|
291
296
|
compareTemporal: compareTemporalByCanonicalValue,
|
|
@@ -306,10 +311,11 @@ export function createIntlValueSemanticsProfile(options = {}) {
|
|
|
306
311
|
id: options.id ?? `aeon.value.string.intl.${Array.isArray(locale) ? locale.join('-') : locale}.v1`,
|
|
307
312
|
locale,
|
|
308
313
|
stringOrder: 'intl-collator',
|
|
309
|
-
temporalOrder:
|
|
314
|
+
temporalOrder: TEMPORAL_CANONICAL_PROFILE_ID,
|
|
310
315
|
caseMapping: 'intl-locale',
|
|
311
316
|
compareStrings: (left, right) => normalizeComparison(collator.compare(left, right)),
|
|
312
317
|
compareTemporal: options.compareTemporal ?? compareTemporalByCanonicalValue,
|
|
318
|
+
...(typeof options.compareRadix === 'function' ? { compareRadix: options.compareRadix } : {}),
|
|
313
319
|
lowerString: (value) => value.toLocaleLowerCase(locale),
|
|
314
320
|
upperString: (value) => value.toLocaleUpperCase(locale),
|
|
315
321
|
});
|
|
@@ -327,7 +333,7 @@ export function createNaturalAsciiValueSemanticsProfile(options = {}) {
|
|
|
327
333
|
return Object.freeze({
|
|
328
334
|
id: NATURAL_ASCII_STRING_PROFILE_ID,
|
|
329
335
|
stringOrder: NATURAL_ASCII_STRING_PROFILE_ID,
|
|
330
|
-
temporalOrder:
|
|
336
|
+
temporalOrder: TEMPORAL_CANONICAL_PROFILE_ID,
|
|
331
337
|
caseMapping: 'unicode-default',
|
|
332
338
|
...options,
|
|
333
339
|
compareStrings: compareStringsByNaturalAsciiOrder,
|
|
@@ -337,6 +343,73 @@ export function createNaturalAsciiValueSemanticsProfile(options = {}) {
|
|
|
337
343
|
});
|
|
338
344
|
}
|
|
339
345
|
|
|
346
|
+
export function createRadixNumericValueSemanticsProfile(options = {}) {
|
|
347
|
+
return Object.freeze({
|
|
348
|
+
...aeonValueSemanticsDefaultProfile,
|
|
349
|
+
id: options.id ?? RADIX_NUMERIC_SAME_BASE_PROFILE_ID,
|
|
350
|
+
radixComparison: 'same-base-exact',
|
|
351
|
+
compareRadix: compareExactRadixSemanticValues,
|
|
352
|
+
});
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
export function createCrossBaseRadixNumericValueSemanticsProfile(options = {}) {
|
|
356
|
+
return Object.freeze({
|
|
357
|
+
...aeonValueSemanticsDefaultProfile,
|
|
358
|
+
id: options.id ?? RADIX_NUMERIC_CROSS_BASE_PROFILE_ID,
|
|
359
|
+
radixComparison: 'cross-base-exact',
|
|
360
|
+
compareRadix: compareExactCrossBaseRadixSemanticValues,
|
|
361
|
+
});
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
/** Compare two exact radix payloads in the same declared base. */
|
|
365
|
+
export function compareExactRadixValues(left, right, base) {
|
|
366
|
+
const leftValue = parseExactRadixValue(String(left), base);
|
|
367
|
+
const rightValue = parseExactRadixValue(String(right), base);
|
|
368
|
+
if (leftValue === null || rightValue === null) return null;
|
|
369
|
+
return compareParsedRadixValues(leftValue, rightValue);
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
/** Compare two exact radix payloads with independently declared bases. */
|
|
373
|
+
export function compareExactCrossBaseRadixValues(left, leftBase, right, rightBase) {
|
|
374
|
+
const leftValue = parseExactRadixValue(String(left), leftBase);
|
|
375
|
+
const rightValue = parseExactRadixValue(String(right), rightBase);
|
|
376
|
+
if (leftValue === null || rightValue === null) return null;
|
|
377
|
+
if (leftBase === rightBase) return compareParsedRadixValues(leftValue, rightValue);
|
|
378
|
+
return compareParsedCrossBaseRadixValues(leftValue, leftBase, rightValue, rightBase);
|
|
379
|
+
}
|
|
380
|
+
|
|
381
|
+
/** Return the number of represented fractional radix digits, excluding visual separators. */
|
|
382
|
+
export function radixScaleOf(value, base) {
|
|
383
|
+
const payload = String(value);
|
|
384
|
+
if (payload.length === 0 || payload.length > MAX_EXACT_NUMERIC_CHARACTERS) return null;
|
|
385
|
+
if (base !== undefined && (!Number.isInteger(base) || base < 2 || base > 64)) return null;
|
|
386
|
+
|
|
387
|
+
let index = payload[0] === '+' || payload[0] === '-' ? 1 : 0;
|
|
388
|
+
if (index === payload.length) return null;
|
|
389
|
+
let sawDigit = false;
|
|
390
|
+
let sawPoint = false;
|
|
391
|
+
let scale = 0;
|
|
392
|
+
for (; index < payload.length; index += 1) {
|
|
393
|
+
const character = payload[index];
|
|
394
|
+
if (character === '.') {
|
|
395
|
+
if (sawPoint) return null;
|
|
396
|
+
sawPoint = true;
|
|
397
|
+
continue;
|
|
398
|
+
}
|
|
399
|
+
if (character === '_') {
|
|
400
|
+
const previous = payload[index - 1];
|
|
401
|
+
const next = payload[index + 1];
|
|
402
|
+
if (radixDigitValue(previous) === null || radixDigitValue(next) === null) return null;
|
|
403
|
+
continue;
|
|
404
|
+
}
|
|
405
|
+
const digit = radixDigitValue(character);
|
|
406
|
+
if (digit === null || base !== undefined && digit >= base) return null;
|
|
407
|
+
sawDigit = true;
|
|
408
|
+
if (sawPoint) scale += 1;
|
|
409
|
+
}
|
|
410
|
+
return !sawDigit || sawPoint && scale === 0 ? null : scale;
|
|
411
|
+
}
|
|
412
|
+
|
|
340
413
|
export function evaluateQuery(input, namespace, options = {}) {
|
|
341
414
|
let valueSemanticsProfile;
|
|
342
415
|
try {
|
|
@@ -1739,6 +1812,7 @@ const TELEX_SCALAR_KINDS = new Set([
|
|
|
1739
1812
|
'RadixLiteral',
|
|
1740
1813
|
'EncodingLiteral',
|
|
1741
1814
|
'SeparatorLiteral',
|
|
1815
|
+
'SymbolicLiteral',
|
|
1742
1816
|
'SansaAddressLiteral',
|
|
1743
1817
|
'DateLiteral',
|
|
1744
1818
|
'TimeLiteral',
|
|
@@ -1754,6 +1828,7 @@ const TELEX_KIND_ALIASES = new Map([
|
|
|
1754
1828
|
['hex', 'HexLiteral'], ['radix', 'RadixLiteral'], ['encoding', 'EncodingLiteral'],
|
|
1755
1829
|
['base64', 'EncodingLiteral'], ['embed', 'EncodingLiteral'], ['inline', 'EncodingLiteral'],
|
|
1756
1830
|
['separator', 'SeparatorLiteral'], ['sep', 'SeparatorLiteral'], ['csv', 'SeparatorLiteral'],
|
|
1831
|
+
['symbol', 'SymbolicLiteral'], ['symbolicliteral', 'SymbolicLiteral'],
|
|
1757
1832
|
['sansa', 'SansaAddressLiteral'], ['sansaaddress', 'SansaAddressLiteral'],
|
|
1758
1833
|
['date', 'DateLiteral'], ['time', 'TimeLiteral'], ['datetime', 'DateTimeLiteral'], ['wtc', 'WTCDateTimeLiteral'],
|
|
1759
1834
|
]);
|
|
@@ -2033,6 +2108,10 @@ function validateAeonTargetScalarValue(value, representation, path, operationInd
|
|
|
2033
2108
|
return typeof value === 'string'
|
|
2034
2109
|
? { ok: true }
|
|
2035
2110
|
: invalidAeonTargetValue('String literals must use string payloads', path, operationIndex);
|
|
2111
|
+
case 'symbol':
|
|
2112
|
+
return typeof value === 'string' && value.length > 0
|
|
2113
|
+
? { ok: true }
|
|
2114
|
+
: invalidAeonTargetValue('Symbol literals must use non-empty string payloads', path, operationIndex);
|
|
2036
2115
|
case 'number':
|
|
2037
2116
|
return typeof value === 'number' && Number.isFinite(value)
|
|
2038
2117
|
? { ok: true }
|
|
@@ -2275,6 +2354,7 @@ function isReservedAeonDatatypeBase(base) {
|
|
|
2275
2354
|
'sep',
|
|
2276
2355
|
'separator',
|
|
2277
2356
|
'kadot',
|
|
2357
|
+
'symbol',
|
|
2278
2358
|
'sansa',
|
|
2279
2359
|
'object',
|
|
2280
2360
|
'obj',
|
|
@@ -2488,6 +2568,7 @@ function representationKindFromMutationName(name, { allowUnknown = false } = {})
|
|
|
2488
2568
|
if (base === 'infinity') return 'infinity';
|
|
2489
2569
|
if (base === 'null') return 'null';
|
|
2490
2570
|
if (base === 'sep' || base === 'separator' || base === 'kadot') return 'separator';
|
|
2571
|
+
if (base === 'symbol' || lowered === 'symbolicliteral') return 'symbol';
|
|
2491
2572
|
if (base === 'sansa') return 'sansa';
|
|
2492
2573
|
if (base === 'encoding' || ['base64', 'embed', 'inline'].includes(base)) return 'encoding';
|
|
2493
2574
|
if (['date', 'time', 'datetime', 'wtc'].includes(base)) return base;
|
|
@@ -3528,7 +3609,7 @@ function evaluateQueryExpressionValue(expression, currentBinding, namespace, opt
|
|
|
3528
3609
|
return {
|
|
3529
3610
|
ok: true,
|
|
3530
3611
|
value: scalarQueryValue(
|
|
3531
|
-
expression.value,
|
|
3612
|
+
expression.kind === 'number' ? expression.canonical : expression.value,
|
|
3532
3613
|
queryLiteralMetadata(expression),
|
|
3533
3614
|
).value,
|
|
3534
3615
|
};
|
|
@@ -3609,6 +3690,15 @@ function evaluateBinaryExpression(expression, currentBinding, namespace, options
|
|
|
3609
3690
|
return evaluateMembershipExpression(left.value, right.value, namespace, options);
|
|
3610
3691
|
}
|
|
3611
3692
|
|
|
3693
|
+
const nativeStructuralEquality = evaluateNativeStructuralEquality(
|
|
3694
|
+
expression.operator,
|
|
3695
|
+
left.value,
|
|
3696
|
+
right.value,
|
|
3697
|
+
namespace,
|
|
3698
|
+
options,
|
|
3699
|
+
);
|
|
3700
|
+
if (nativeStructuralEquality !== undefined) return nativeStructuralEquality;
|
|
3701
|
+
|
|
3612
3702
|
const leftScalar = expectComparableQueryValue(left.value, namespace);
|
|
3613
3703
|
if (!leftScalar.ok) return leftScalar;
|
|
3614
3704
|
const rightScalar = expectComparableQueryValue(right.value, namespace);
|
|
@@ -3616,6 +3706,33 @@ function evaluateBinaryExpression(expression, currentBinding, namespace, options
|
|
|
3616
3706
|
return compareQueryScalars(expression.operator, leftScalar, rightScalar, options);
|
|
3617
3707
|
}
|
|
3618
3708
|
|
|
3709
|
+
function evaluateNativeStructuralEquality(operator, left, right, namespace, options) {
|
|
3710
|
+
if (!['==', '!='].includes(operator) || typeof namespace.structurallyEqual !== 'function') {
|
|
3711
|
+
return undefined;
|
|
3712
|
+
}
|
|
3713
|
+
if (left.type !== 'bindingSet' || right.type !== 'bindingSet') return undefined;
|
|
3714
|
+
if (left.bindings.length !== 1 || right.bindings.length !== 1) return undefined;
|
|
3715
|
+
|
|
3716
|
+
const leftBinding = left.bindings[0];
|
|
3717
|
+
const rightBinding = right.bindings[0];
|
|
3718
|
+
const leftKind = explicitContainerKindFromBinding(namespace, leftBinding);
|
|
3719
|
+
const rightKind = explicitContainerKindFromBinding(namespace, rightBinding);
|
|
3720
|
+
if (leftKind === undefined || rightKind === undefined || leftKind !== rightKind) return undefined;
|
|
3721
|
+
|
|
3722
|
+
const equal = namespace.structurallyEqual(leftBinding, rightBinding, {
|
|
3723
|
+
operator,
|
|
3724
|
+
valueSemantics: options.valueSemantics,
|
|
3725
|
+
});
|
|
3726
|
+
if (typeof equal !== 'boolean') return undefined;
|
|
3727
|
+
return {
|
|
3728
|
+
ok: true,
|
|
3729
|
+
value: {
|
|
3730
|
+
type: 'scalar',
|
|
3731
|
+
value: operator === '==' ? equal : !equal,
|
|
3732
|
+
},
|
|
3733
|
+
};
|
|
3734
|
+
}
|
|
3735
|
+
|
|
3619
3736
|
function evaluateMembershipExpression(leftValue, rightValue, namespace, options) {
|
|
3620
3737
|
const leftScalar = expectScalarQueryValue(leftValue, namespace);
|
|
3621
3738
|
if (!leftScalar.ok) return leftScalar;
|
|
@@ -3746,7 +3863,7 @@ function evaluateFunctionCallExpression(expression, currentBinding, namespace, o
|
|
|
3746
3863
|
if (!evaluated.ok) return evaluated;
|
|
3747
3864
|
const scalar = expectScalarQueryValue(evaluated.value, namespace);
|
|
3748
3865
|
if (!scalar.ok) return scalar;
|
|
3749
|
-
evaluatedArgs.push(scalar
|
|
3866
|
+
evaluatedArgs.push(scalar);
|
|
3750
3867
|
}
|
|
3751
3868
|
|
|
3752
3869
|
return evaluateOrdinaryFunction(expression.name, evaluatedArgs, options);
|
|
@@ -3779,7 +3896,7 @@ function isExtensionEnabled(extensionId, options) {
|
|
|
3779
3896
|
}
|
|
3780
3897
|
|
|
3781
3898
|
function isOrdinaryFunctionName(name) {
|
|
3782
|
-
return ['contains', 'startsWith', 'endsWith', 'lower', 'upper', 'concat'].includes(name);
|
|
3899
|
+
return ['contains', 'startsWith', 'endsWith', 'lower', 'upper', 'concat', 'radixScale', 'temporalRelation'].includes(name);
|
|
3783
3900
|
}
|
|
3784
3901
|
|
|
3785
3902
|
function evaluateOrdinaryFunction(name, evaluatedArgs, options = {}) {
|
|
@@ -3803,6 +3920,10 @@ function evaluateOrdinaryFunction(name, evaluatedArgs, options = {}) {
|
|
|
3803
3920
|
};
|
|
3804
3921
|
}
|
|
3805
3922
|
return evaluateStringFunction(name, evaluatedArgs, evaluatedArgs.length, (args) => args.join(''));
|
|
3923
|
+
case 'radixScale':
|
|
3924
|
+
return evaluateRadixScaleFunction(evaluatedArgs);
|
|
3925
|
+
case 'temporalRelation':
|
|
3926
|
+
return evaluateTemporalRelationFunction(evaluatedArgs);
|
|
3806
3927
|
default:
|
|
3807
3928
|
return {
|
|
3808
3929
|
ok: false,
|
|
@@ -3811,6 +3932,62 @@ function evaluateOrdinaryFunction(name, evaluatedArgs, options = {}) {
|
|
|
3811
3932
|
}
|
|
3812
3933
|
}
|
|
3813
3934
|
|
|
3935
|
+
function evaluateTemporalRelationFunction(args) {
|
|
3936
|
+
if (args.length !== 2) {
|
|
3937
|
+
return {
|
|
3938
|
+
ok: false,
|
|
3939
|
+
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'temporalRelation' expects 2 arguments"),
|
|
3940
|
+
};
|
|
3941
|
+
}
|
|
3942
|
+
|
|
3943
|
+
const claims = args.map((argument) => {
|
|
3944
|
+
const info = queryScalarToInfo(argument);
|
|
3945
|
+
const category = normalizeValueSemanticsCategory(info.category ?? info.kind);
|
|
3946
|
+
if (category !== 'temporal' || typeof info.value !== 'string') return null;
|
|
3947
|
+
return {
|
|
3948
|
+
payload: info.value,
|
|
3949
|
+
semanticType: temporalSemanticType(info),
|
|
3950
|
+
};
|
|
3951
|
+
});
|
|
3952
|
+
|
|
3953
|
+
if (claims.some((claim) => claim === null)) {
|
|
3954
|
+
return {
|
|
3955
|
+
ok: false,
|
|
3956
|
+
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'temporalRelation' expects temporal arguments"),
|
|
3957
|
+
};
|
|
3958
|
+
}
|
|
3959
|
+
|
|
3960
|
+
return scalarQueryValue(compareTemporalClaims(claims[0], claims[1]), {
|
|
3961
|
+
kind: 'string',
|
|
3962
|
+
category: 'string',
|
|
3963
|
+
});
|
|
3964
|
+
}
|
|
3965
|
+
|
|
3966
|
+
function evaluateRadixScaleFunction(args) {
|
|
3967
|
+
if (args.length !== 1) {
|
|
3968
|
+
return {
|
|
3969
|
+
ok: false,
|
|
3970
|
+
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'radixScale' expects 1 argument"),
|
|
3971
|
+
};
|
|
3972
|
+
}
|
|
3973
|
+
const info = queryScalarToInfo(args[0]);
|
|
3974
|
+
const category = normalizeValueSemanticsCategory(info.category ?? info.kind);
|
|
3975
|
+
if (category !== 'radix') {
|
|
3976
|
+
return {
|
|
3977
|
+
ok: false,
|
|
3978
|
+
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'radixScale' expects a radix value"),
|
|
3979
|
+
};
|
|
3980
|
+
}
|
|
3981
|
+
const scale = radixScaleOf(info.value, info.radixBase);
|
|
3982
|
+
if (scale === null || info.radixScale !== undefined && info.radixScale !== scale) {
|
|
3983
|
+
return {
|
|
3984
|
+
ok: false,
|
|
3985
|
+
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'radixScale' received an invalid radix value"),
|
|
3986
|
+
};
|
|
3987
|
+
}
|
|
3988
|
+
return scalarQueryValue(scale, { kind: 'number', category: 'finiteNumber', numericLexeme: String(scale) });
|
|
3989
|
+
}
|
|
3990
|
+
|
|
3814
3991
|
function evaluatePathExpression(expression, currentBinding, namespace, options) {
|
|
3815
3992
|
if (expression.arguments.length !== 1) {
|
|
3816
3993
|
return {
|
|
@@ -3823,6 +4000,12 @@ function evaluatePathExpression(expression, currentBinding, namespace, options)
|
|
|
3823
4000
|
if (!evaluated.ok) return evaluated;
|
|
3824
4001
|
const scalar = expectScalarQueryValue(evaluated.value, namespace);
|
|
3825
4002
|
if (!scalar.ok) return scalar;
|
|
4003
|
+
if (scalar.metadata?.numericLexeme !== undefined) {
|
|
4004
|
+
return {
|
|
4005
|
+
ok: false,
|
|
4006
|
+
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'path' expects a string or SANSA address literal"),
|
|
4007
|
+
};
|
|
4008
|
+
}
|
|
3826
4009
|
|
|
3827
4010
|
const activated = activateAddressLiteral(scalar.value, options.parse?.address);
|
|
3828
4011
|
if (!activated.ok) return activated;
|
|
@@ -4213,10 +4396,11 @@ function evaluateResolveChildExpression(expression, currentBinding, namespace, o
|
|
|
4213
4396
|
if (!keyScalar.ok) return keyScalar;
|
|
4214
4397
|
|
|
4215
4398
|
let bindings;
|
|
4216
|
-
|
|
4399
|
+
const numericPosition = queryScalarPosition(keyScalar);
|
|
4400
|
+
if (numericPosition !== null) {
|
|
4401
|
+
bindings = selectPosition(namespace, base.value.bindings[0], numericPosition);
|
|
4402
|
+
} else if (isStringQueryScalar(keyScalar)) {
|
|
4217
4403
|
bindings = selectMember(namespace, base.value.bindings[0], keyScalar.value);
|
|
4218
|
-
} else if (Number.isInteger(keyScalar.value) && keyScalar.value >= 0) {
|
|
4219
|
-
bindings = selectPosition(namespace, base.value.bindings[0], keyScalar.value);
|
|
4220
4404
|
} else {
|
|
4221
4405
|
return {
|
|
4222
4406
|
ok: false,
|
|
@@ -4389,7 +4573,7 @@ function evaluateFieldsFromExpression(expression, currentBinding, namespace, opt
|
|
|
4389
4573
|
if (!evaluated.ok) return evaluated;
|
|
4390
4574
|
const scalar = expectScalarQueryValue(evaluated.value, namespace);
|
|
4391
4575
|
if (!scalar.ok) return scalar;
|
|
4392
|
-
if (
|
|
4576
|
+
if (!isStringQueryScalar(scalar)) {
|
|
4393
4577
|
return {
|
|
4394
4578
|
ok: false,
|
|
4395
4579
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'fieldsFrom' expects string field names"),
|
|
@@ -4426,7 +4610,7 @@ function objectFromBindingSets(keyBindings, valueBindings, namespace, functionNa
|
|
|
4426
4610
|
for (let index = 0; index < keyBindings.length; index += 1) {
|
|
4427
4611
|
const keyScalar = getBindingScalarValue(namespace, keyBindings[index]);
|
|
4428
4612
|
if (!keyScalar.ok) return keyScalar;
|
|
4429
|
-
if (
|
|
4613
|
+
if (!isStringQueryScalar(keyScalar)) {
|
|
4430
4614
|
return {
|
|
4431
4615
|
ok: false,
|
|
4432
4616
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', `Function '${functionName}' expects string key bindings`),
|
|
@@ -4500,7 +4684,7 @@ function evaluateSpecialValuePredicate(expression, currentBinding, namespace, op
|
|
|
4500
4684
|
if (!reason.ok) return reason;
|
|
4501
4685
|
const scalarReason = expectScalarQueryValue(reason.value, namespace);
|
|
4502
4686
|
if (!scalarReason.ok) return scalarReason;
|
|
4503
|
-
if (
|
|
4687
|
+
if (!isStringQueryScalar(scalarReason)) {
|
|
4504
4688
|
return {
|
|
4505
4689
|
ok: false,
|
|
4506
4690
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'isNullReason' expects a string reason"),
|
|
@@ -4614,6 +4798,8 @@ function scalarBoolean(value) {
|
|
|
4614
4798
|
|
|
4615
4799
|
function queryLiteralMetadata(expression) {
|
|
4616
4800
|
switch (expression.kind) {
|
|
4801
|
+
case 'number':
|
|
4802
|
+
return { kind: 'number', category: 'finiteNumber', numericLexeme: expression.canonical };
|
|
4617
4803
|
case 'toggle':
|
|
4618
4804
|
return { kind: 'toggle', category: 'toggle' };
|
|
4619
4805
|
case 'hex':
|
|
@@ -4624,6 +4810,8 @@ function queryLiteralMetadata(expression) {
|
|
|
4624
4810
|
return { kind: 'encoding', category: 'encoding' };
|
|
4625
4811
|
case 'separator':
|
|
4626
4812
|
return { kind: 'separator', category: 'separator' };
|
|
4813
|
+
case 'symbol':
|
|
4814
|
+
return { kind: 'symbol', category: 'symbol' };
|
|
4627
4815
|
case 'date':
|
|
4628
4816
|
case 'time':
|
|
4629
4817
|
case 'datetime':
|
|
@@ -4660,7 +4848,7 @@ function evaluateStringFunction(name, args, arity, operation) {
|
|
|
4660
4848
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', `Function '${name}' expects ${arity} argument${arity === 1 ? '' : 's'}`),
|
|
4661
4849
|
};
|
|
4662
4850
|
}
|
|
4663
|
-
if (args.some((arg) =>
|
|
4851
|
+
if (args.some((arg) => !isStringQueryScalar(arg))) {
|
|
4664
4852
|
return {
|
|
4665
4853
|
ok: false,
|
|
4666
4854
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', `Function '${name}' expects string arguments`),
|
|
@@ -4670,11 +4858,43 @@ function evaluateStringFunction(name, args, arity, operation) {
|
|
|
4670
4858
|
ok: true,
|
|
4671
4859
|
value: {
|
|
4672
4860
|
type: 'scalar',
|
|
4673
|
-
value: operation(args),
|
|
4861
|
+
value: operation(args.map((arg) => arg.value)),
|
|
4674
4862
|
},
|
|
4675
4863
|
};
|
|
4676
4864
|
}
|
|
4677
4865
|
|
|
4866
|
+
function isStringQueryScalar(scalar) {
|
|
4867
|
+
if (typeof scalar.value !== 'string' || scalar.metadata?.numericLexeme !== undefined) return false;
|
|
4868
|
+
const info = queryScalarToInfo(scalar);
|
|
4869
|
+
const category = normalizeValueSemanticsCategory(info.category ?? info.kind);
|
|
4870
|
+
return category === undefined || category === 'string' || category === 'stringLiteral';
|
|
4871
|
+
}
|
|
4872
|
+
|
|
4873
|
+
function queryScalarPosition(scalar) {
|
|
4874
|
+
const numericLexeme = scalar.metadata?.numericLexeme;
|
|
4875
|
+
if (typeof numericLexeme === 'string') {
|
|
4876
|
+
const parsed = parseExactFiniteNumber(numericLexeme);
|
|
4877
|
+
if (parsed === null || parsed.sign < 0) return null;
|
|
4878
|
+
if (parsed.sign === 0) return 0;
|
|
4879
|
+
|
|
4880
|
+
let integerDigits = parsed.digits;
|
|
4881
|
+
if (parsed.scale < 0n) {
|
|
4882
|
+
const fractionalWidth = -parsed.scale;
|
|
4883
|
+
if (fractionalWidth > BigInt(integerDigits.length)) return null;
|
|
4884
|
+
const split = integerDigits.length - Number(fractionalWidth);
|
|
4885
|
+
if (!/^0*$/u.test(integerDigits.slice(split))) return null;
|
|
4886
|
+
integerDigits = integerDigits.slice(0, split) || '0';
|
|
4887
|
+
} else {
|
|
4888
|
+
if (BigInt(integerDigits.length) + parsed.scale > 16n) return null;
|
|
4889
|
+
integerDigits += '0'.repeat(Number(parsed.scale));
|
|
4890
|
+
}
|
|
4891
|
+
|
|
4892
|
+
const value = Number(integerDigits);
|
|
4893
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
4894
|
+
}
|
|
4895
|
+
return Number.isSafeInteger(scalar.value) && scalar.value >= 0 ? scalar.value : null;
|
|
4896
|
+
}
|
|
4897
|
+
|
|
4678
4898
|
function evaluateExistenceExpression(expression, currentBinding, namespace, options) {
|
|
4679
4899
|
const resolution = unwrapResolutionExpression(expression.argument);
|
|
4680
4900
|
if (!resolution) {
|
|
@@ -4822,7 +5042,7 @@ function evaluateCardinalityFunctionBooleans(expression, currentBinding, namespa
|
|
|
4822
5042
|
}
|
|
4823
5043
|
const scalar = expectScalarQueryValue(evaluatedArgs[index], namespace);
|
|
4824
5044
|
if (!scalar.ok) return scalar;
|
|
4825
|
-
scalarArgs.push(scalar
|
|
5045
|
+
scalarArgs.push(scalar);
|
|
4826
5046
|
}
|
|
4827
5047
|
|
|
4828
5048
|
const values = [];
|
|
@@ -4830,7 +5050,7 @@ function evaluateCardinalityFunctionBooleans(expression, currentBinding, namespa
|
|
|
4830
5050
|
const bindingScalar = getBindingScalarValue(namespace, binding);
|
|
4831
5051
|
if (!bindingScalar.ok) return bindingScalar;
|
|
4832
5052
|
const args = scalarArgs.slice();
|
|
4833
|
-
args[bindingSetArgs[0].index] = bindingScalar
|
|
5053
|
+
args[bindingSetArgs[0].index] = bindingScalar;
|
|
4834
5054
|
const evaluated = evaluateOrdinaryFunction(expression.name, args);
|
|
4835
5055
|
if (!evaluated.ok) return evaluated;
|
|
4836
5056
|
if (evaluated.value.type !== 'scalar' || typeof evaluated.value.value !== 'boolean') {
|
|
@@ -4981,6 +5201,12 @@ function getValueSemanticsProfile(valueSemantics) {
|
|
|
4981
5201
|
if (valueSemantics === NATURAL_ASCII_STRING_PROFILE_ID || valueSemantics === 'natural-ascii') {
|
|
4982
5202
|
return createNaturalAsciiValueSemanticsProfile();
|
|
4983
5203
|
}
|
|
5204
|
+
if (valueSemantics === RADIX_NUMERIC_SAME_BASE_PROFILE_ID || valueSemantics === 'radix-numeric') {
|
|
5205
|
+
return createRadixNumericValueSemanticsProfile();
|
|
5206
|
+
}
|
|
5207
|
+
if (valueSemantics === RADIX_NUMERIC_CROSS_BASE_PROFILE_ID || valueSemantics === 'radix-numeric-cross-base') {
|
|
5208
|
+
return createCrossBaseRadixNumericValueSemanticsProfile();
|
|
5209
|
+
}
|
|
4984
5210
|
if (valueSemantics === 'fr' || valueSemantics === 'fr-FR') {
|
|
4985
5211
|
return createFrenchValueSemanticsProfile({ locale: valueSemantics });
|
|
4986
5212
|
}
|
|
@@ -4992,6 +5218,7 @@ function getValueSemanticsProfile(valueSemantics) {
|
|
|
4992
5218
|
const hasLowerString = typeof valueSemantics.lowerString === 'function';
|
|
4993
5219
|
const hasUpperString = typeof valueSemantics.upperString === 'function';
|
|
4994
5220
|
const hasCompareTemporal = typeof valueSemantics.compareTemporal === 'function';
|
|
5221
|
+
const hasCompareRadix = typeof valueSemantics.compareRadix === 'function';
|
|
4995
5222
|
if (hasCompareStrings && hasLowerString && hasUpperString) {
|
|
4996
5223
|
return {
|
|
4997
5224
|
...aeonValueSemanticsDefaultProfile,
|
|
@@ -5000,16 +5227,24 @@ function getValueSemanticsProfile(valueSemantics) {
|
|
|
5000
5227
|
compareTemporal: typeof valueSemantics.compareTemporal === 'function'
|
|
5001
5228
|
? (left, right) => normalizeComparison(valueSemantics.compareTemporal(left, right))
|
|
5002
5229
|
: aeonValueSemanticsDefaultProfile.compareTemporal,
|
|
5230
|
+
...(hasCompareRadix ? {
|
|
5231
|
+
compareRadix: (left, right) => normalizeOptionalComparison(valueSemantics.compareRadix(left, right)),
|
|
5232
|
+
} : {}),
|
|
5003
5233
|
};
|
|
5004
5234
|
}
|
|
5005
5235
|
if (hasCompareStrings || hasLowerString || hasUpperString) {
|
|
5006
5236
|
throw new Error('Custom value-semantics profiles must define compareStrings, lowerString, and upperString together.');
|
|
5007
5237
|
}
|
|
5008
|
-
if (hasCompareTemporal) {
|
|
5238
|
+
if (hasCompareTemporal || hasCompareRadix) {
|
|
5009
5239
|
return {
|
|
5010
5240
|
...aeonValueSemanticsDefaultProfile,
|
|
5011
5241
|
...valueSemantics,
|
|
5012
|
-
compareTemporal:
|
|
5242
|
+
compareTemporal: hasCompareTemporal
|
|
5243
|
+
? (left, right) => normalizeComparison(valueSemantics.compareTemporal(left, right))
|
|
5244
|
+
: aeonValueSemanticsDefaultProfile.compareTemporal,
|
|
5245
|
+
...(hasCompareRadix ? {
|
|
5246
|
+
compareRadix: (left, right) => normalizeOptionalComparison(valueSemantics.compareRadix(left, right)),
|
|
5247
|
+
} : {}),
|
|
5013
5248
|
};
|
|
5014
5249
|
}
|
|
5015
5250
|
if (
|
|
@@ -5026,6 +5261,10 @@ function normalizeComparison(value) {
|
|
|
5026
5261
|
return 0;
|
|
5027
5262
|
}
|
|
5028
5263
|
|
|
5264
|
+
function normalizeOptionalComparison(value) {
|
|
5265
|
+
return value === null || value === undefined ? null : normalizeComparison(value);
|
|
5266
|
+
}
|
|
5267
|
+
|
|
5029
5268
|
function compareStringsByUnicodeScalarValue(left, right) {
|
|
5030
5269
|
const leftScalars = Array.from(left);
|
|
5031
5270
|
const rightScalars = Array.from(right);
|
|
@@ -5090,6 +5329,197 @@ function compareTemporalByCanonicalValue(left, right) {
|
|
|
5090
5329
|
return compareStringsByUnicodeScalarValue(String(left.payload ?? ''), String(right.payload ?? ''));
|
|
5091
5330
|
}
|
|
5092
5331
|
|
|
5332
|
+
/**
|
|
5333
|
+
* Compare two temporal claims as completion sets without resolving external
|
|
5334
|
+
* timezone, leap-second, calendar, or clock authorities.
|
|
5335
|
+
*
|
|
5336
|
+
* @returns {'equal'|'before'|'after'|'contains'|'containedBy'|'overlaps'|'incomparable'}
|
|
5337
|
+
*/
|
|
5338
|
+
export function compareTemporalClaims(left, right) {
|
|
5339
|
+
const leftClaim = parseTemporalCompletionSet(left);
|
|
5340
|
+
const rightClaim = parseTemporalCompletionSet(right);
|
|
5341
|
+
if (leftClaim === null || rightClaim === null || leftClaim.domain !== rightClaim.domain) {
|
|
5342
|
+
return 'incomparable';
|
|
5343
|
+
}
|
|
5344
|
+
|
|
5345
|
+
// UTC leap-second chronology requires a leap table. Preserve exact identity,
|
|
5346
|
+
// but do not manufacture an ordering around second 60 without that authority.
|
|
5347
|
+
if (leftClaim.leapSecond || rightClaim.leapSecond) {
|
|
5348
|
+
return leftClaim.leapSecond
|
|
5349
|
+
&& rightClaim.leapSecond
|
|
5350
|
+
&& compareTemporalDecimal(leftClaim.start, rightClaim.start) === 0
|
|
5351
|
+
? 'equal'
|
|
5352
|
+
: 'incomparable';
|
|
5353
|
+
}
|
|
5354
|
+
|
|
5355
|
+
const startOrder = compareTemporalDecimal(leftClaim.start, rightClaim.start);
|
|
5356
|
+
if (leftClaim.point && rightClaim.point) {
|
|
5357
|
+
return startOrder < 0 ? 'before' : startOrder > 0 ? 'after' : 'equal';
|
|
5358
|
+
}
|
|
5359
|
+
if (leftClaim.point) {
|
|
5360
|
+
if (startOrder < 0) return 'before';
|
|
5361
|
+
if (compareTemporalDecimal(leftClaim.start, rightClaim.end) >= 0) return 'after';
|
|
5362
|
+
return 'containedBy';
|
|
5363
|
+
}
|
|
5364
|
+
if (rightClaim.point) {
|
|
5365
|
+
if (compareTemporalDecimal(leftClaim.end, rightClaim.start) <= 0) return 'before';
|
|
5366
|
+
if (startOrder > 0) return 'after';
|
|
5367
|
+
return 'contains';
|
|
5368
|
+
}
|
|
5369
|
+
|
|
5370
|
+
const endOrder = compareTemporalDecimal(leftClaim.end, rightClaim.end);
|
|
5371
|
+
if (startOrder === 0 && endOrder === 0) return 'equal';
|
|
5372
|
+
if (compareTemporalDecimal(leftClaim.end, rightClaim.start) <= 0) return 'before';
|
|
5373
|
+
if (compareTemporalDecimal(rightClaim.end, leftClaim.start) <= 0) return 'after';
|
|
5374
|
+
if (startOrder <= 0 && endOrder >= 0) return 'contains';
|
|
5375
|
+
if (startOrder >= 0 && endOrder <= 0) return 'containedBy';
|
|
5376
|
+
return 'overlaps';
|
|
5377
|
+
}
|
|
5378
|
+
|
|
5379
|
+
function parseTemporalCompletionSet(input) {
|
|
5380
|
+
const semanticType = String(input?.semanticType ?? 'temporal');
|
|
5381
|
+
const payload = String(input?.payload ?? input?.value ?? '');
|
|
5382
|
+
if (semanticType === 'date') {
|
|
5383
|
+
const date = parseTemporalDate(payload);
|
|
5384
|
+
if (date === null) return null;
|
|
5385
|
+
const startMonth = date.month ?? 1;
|
|
5386
|
+
const startDay = date.day ?? 1;
|
|
5387
|
+
const start = temporalInteger(dateOrdinal(date.year, startMonth, startDay) * 86_400n);
|
|
5388
|
+
let endOrdinal;
|
|
5389
|
+
if (date.month === null) {
|
|
5390
|
+
endOrdinal = dateOrdinal(date.year + 1, 1, 1);
|
|
5391
|
+
} else if (date.day === null) {
|
|
5392
|
+
endOrdinal = date.month === 12
|
|
5393
|
+
? dateOrdinal(date.year + 1, 1, 1)
|
|
5394
|
+
: dateOrdinal(date.year, date.month + 1, 1);
|
|
5395
|
+
} else {
|
|
5396
|
+
endOrdinal = dateOrdinal(date.year, date.month, date.day) + 1n;
|
|
5397
|
+
}
|
|
5398
|
+
const end = temporalInteger(endOrdinal * 86_400n);
|
|
5399
|
+
return { domain: 'date', start, end, point: false, leapSecond: false };
|
|
5400
|
+
}
|
|
5401
|
+
if (!['time', 'datetime', 'wtc'].includes(semanticType)) return null;
|
|
5402
|
+
|
|
5403
|
+
let base = payload;
|
|
5404
|
+
let context = null;
|
|
5405
|
+
if (semanticType === 'wtc') {
|
|
5406
|
+
const ampersand = payload.indexOf('&');
|
|
5407
|
+
if (ampersand === -1) return null;
|
|
5408
|
+
base = payload.slice(0, ampersand);
|
|
5409
|
+
context = payload.slice(ampersand + 1);
|
|
5410
|
+
if (context.length === 0) return null;
|
|
5411
|
+
}
|
|
5412
|
+
|
|
5413
|
+
let date = null;
|
|
5414
|
+
let clockText = base;
|
|
5415
|
+
if (semanticType !== 'time') {
|
|
5416
|
+
const marker = base.indexOf('T');
|
|
5417
|
+
if (marker === -1) return null;
|
|
5418
|
+
date = parseTemporalDate(base.slice(0, marker));
|
|
5419
|
+
if (date === null) return null;
|
|
5420
|
+
clockText = base.slice(marker + 1);
|
|
5421
|
+
}
|
|
5422
|
+
const clock = parseTemporalClock(clockText, semanticType === 'time');
|
|
5423
|
+
if (clock === null) return null;
|
|
5424
|
+
const domain = temporalCompletionDomain(semanticType, clock.anchor, context);
|
|
5425
|
+
if (domain === null) return null;
|
|
5426
|
+
|
|
5427
|
+
let wholeSeconds = BigInt(clock.hour * 3_600 + (clock.minute ?? 0) * 60 + (clock.second ?? 0));
|
|
5428
|
+
if (date !== null) wholeSeconds += dateOrdinal(date.year, date.month, date.day) * 86_400n;
|
|
5429
|
+
if (clock.anchor === 'Z') {
|
|
5430
|
+
// already UTC-relative
|
|
5431
|
+
} else if (clock.anchor !== null && clock.anchor !== '-00:00') {
|
|
5432
|
+
const sign = clock.anchor[0] === '-' ? -1n : 1n;
|
|
5433
|
+
const offset = BigInt(Number(clock.anchor.slice(1, 3)) * 3_600 + Number(clock.anchor.slice(4, 6)) * 60);
|
|
5434
|
+
wholeSeconds -= sign * offset;
|
|
5435
|
+
}
|
|
5436
|
+
|
|
5437
|
+
const start = clock.fraction === null
|
|
5438
|
+
? temporalInteger(wholeSeconds)
|
|
5439
|
+
: { coefficient: wholeSeconds * (10n ** BigInt(clock.fraction.length)) + BigInt(clock.fraction), scale: clock.fraction.length };
|
|
5440
|
+
if (clock.second !== null) {
|
|
5441
|
+
return { domain, start, end: start, point: true, leapSecond: clock.second === 60 };
|
|
5442
|
+
}
|
|
5443
|
+
const width = clock.minute === null ? 3_600n : 60n;
|
|
5444
|
+
return { domain, start, end: addTemporalInteger(start, width), point: false, leapSecond: false };
|
|
5445
|
+
}
|
|
5446
|
+
|
|
5447
|
+
function temporalCompletionDomain(semanticType, anchor, context) {
|
|
5448
|
+
const scope = semanticType === 'time' ? 'time' : 'datetime';
|
|
5449
|
+
const recognizedTimescales = new Set(['UTC', 'TAI', 'UT1', 'TT', 'GPS']);
|
|
5450
|
+
if (context !== null && recognizedTimescales.has(context) && anchor !== null) {
|
|
5451
|
+
if (context !== 'UTC') return null;
|
|
5452
|
+
}
|
|
5453
|
+
if (scope === 'time' && anchor !== null && anchor !== '-00:00') {
|
|
5454
|
+
return anchor === 'Z' || anchor === '+00:00' ? 'instant:time:UTC' : `offset-time:${anchor}`;
|
|
5455
|
+
}
|
|
5456
|
+
if (anchor === 'Z' || (anchor !== null && anchor !== '-00:00')) return 'instant:datetime';
|
|
5457
|
+
if (anchor === '-00:00') return `unknown-offset:${scope}:${context ?? ''}`;
|
|
5458
|
+
if (context === 'local') return `resolver-local:${scope}`;
|
|
5459
|
+
if (context !== null && recognizedTimescales.has(context)) return `timescale:${context}:${scope}`;
|
|
5460
|
+
if (context !== null) return `context:${context}:${scope}`;
|
|
5461
|
+
return `civil:${scope}`;
|
|
5462
|
+
}
|
|
5463
|
+
|
|
5464
|
+
function parseTemporalDate(value) {
|
|
5465
|
+
const yearOnly = /^(\d{4})-$/.exec(value);
|
|
5466
|
+
if (yearOnly !== null) {
|
|
5467
|
+
const year = Number(yearOnly[1]);
|
|
5468
|
+
return year >= 1 && year <= 9999 ? { year, month: null, day: null } : null;
|
|
5469
|
+
}
|
|
5470
|
+
const yearMonth = /^(\d{4})-(\d{2})$/.exec(value);
|
|
5471
|
+
if (yearMonth !== null) {
|
|
5472
|
+
const year = Number(yearMonth[1]);
|
|
5473
|
+
const month = Number(yearMonth[2]);
|
|
5474
|
+
return year >= 1 && year <= 9999 && month >= 1 && month <= 12
|
|
5475
|
+
? { year, month, day: null }
|
|
5476
|
+
: null;
|
|
5477
|
+
}
|
|
5478
|
+
const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
5479
|
+
if (fullDate === null || !isValidDateParts(fullDate[1], fullDate[2], fullDate[3])) return null;
|
|
5480
|
+
return { year: Number(fullDate[1]), month: Number(fullDate[2]), day: Number(fullDate[3]) };
|
|
5481
|
+
}
|
|
5482
|
+
|
|
5483
|
+
function parseTemporalClock(value, requireColon) {
|
|
5484
|
+
const pattern = requireColon
|
|
5485
|
+
? /^(\d{2}):(?:(\d{2}))?(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?$/
|
|
5486
|
+
: /^(\d{2})(?::(\d{2})?)?(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?$/;
|
|
5487
|
+
const match = pattern.exec(value);
|
|
5488
|
+
if (match === null) return null;
|
|
5489
|
+
const hour = Number(match[1]);
|
|
5490
|
+
const minute = match[2] === undefined ? null : Number(match[2]);
|
|
5491
|
+
const second = match[3] === undefined ? null : Number(match[3]);
|
|
5492
|
+
const anchor = match[5] ?? null;
|
|
5493
|
+
if (hour > 23 || (minute !== null && minute > 59) || (second !== null && second > 60)) return null;
|
|
5494
|
+
if (anchor !== null && anchor !== 'Z') {
|
|
5495
|
+
if (Number(anchor.slice(1, 3)) > 23 || Number(anchor.slice(4, 6)) > 59) return null;
|
|
5496
|
+
}
|
|
5497
|
+
return { hour, minute, second, fraction: match[4] ?? null, anchor };
|
|
5498
|
+
}
|
|
5499
|
+
|
|
5500
|
+
function dateOrdinal(year, month, day) {
|
|
5501
|
+
const priorYear = BigInt(year - 1);
|
|
5502
|
+
const daysBeforeYear = priorYear * 365n + priorYear / 4n - priorYear / 100n + priorYear / 400n;
|
|
5503
|
+
const monthDays = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
|
5504
|
+
const leapAdjustment = month > 2 && isLeapYear(year) ? 1 : 0;
|
|
5505
|
+
return daysBeforeYear + BigInt(monthDays[month - 1] + leapAdjustment + day - 1);
|
|
5506
|
+
}
|
|
5507
|
+
|
|
5508
|
+
function temporalInteger(value) {
|
|
5509
|
+
return { coefficient: value, scale: 0 };
|
|
5510
|
+
}
|
|
5511
|
+
|
|
5512
|
+
function addTemporalInteger(value, integer) {
|
|
5513
|
+
return { coefficient: value.coefficient + integer * (10n ** BigInt(value.scale)), scale: value.scale };
|
|
5514
|
+
}
|
|
5515
|
+
|
|
5516
|
+
function compareTemporalDecimal(left, right) {
|
|
5517
|
+
const scale = Math.max(left.scale, right.scale);
|
|
5518
|
+
const leftCoefficient = left.coefficient * (10n ** BigInt(scale - left.scale));
|
|
5519
|
+
const rightCoefficient = right.coefficient * (10n ** BigInt(scale - right.scale));
|
|
5520
|
+
return leftCoefficient < rightCoefficient ? -1 : leftCoefficient > rightCoefficient ? 1 : 0;
|
|
5521
|
+
}
|
|
5522
|
+
|
|
5093
5523
|
function isAsciiDigitCodePoint(codePoint) {
|
|
5094
5524
|
return codePoint >= 0x30 && codePoint <= 0x39;
|
|
5095
5525
|
}
|
|
@@ -5100,6 +5530,8 @@ function codePointWidth(codePoint) {
|
|
|
5100
5530
|
|
|
5101
5531
|
export function evaluateValueSemanticsOperation(operation, input = {}, options = {}) {
|
|
5102
5532
|
try {
|
|
5533
|
+
if (operation === 'radixScale') return evaluateValueSemanticsRadixScale(input.value);
|
|
5534
|
+
if (operation === 'temporalRelation') return evaluateValueSemanticsTemporalRelation(input.left, input.right);
|
|
5103
5535
|
const profile = getValueSemanticsProfile(options.valueSemantics ?? input.valueSemantics ?? input.profile);
|
|
5104
5536
|
switch (operation) {
|
|
5105
5537
|
case 'equal':
|
|
@@ -5124,6 +5556,31 @@ export function evaluateValueSemanticsOperation(operation, input = {}, options =
|
|
|
5124
5556
|
}
|
|
5125
5557
|
}
|
|
5126
5558
|
|
|
5559
|
+
function evaluateValueSemanticsTemporalRelation(leftDescriptor, rightDescriptor) {
|
|
5560
|
+
const left = valueDescriptorToScalarInfo(leftDescriptor);
|
|
5561
|
+
const right = valueDescriptorToScalarInfo(rightDescriptor);
|
|
5562
|
+
if (left.category !== 'temporal' || right.category !== 'temporal') {
|
|
5563
|
+
return valueSemanticsDiagnostic('temporal_required', 'Temporal relation is defined only for temporal values');
|
|
5564
|
+
}
|
|
5565
|
+
return {
|
|
5566
|
+
ok: true,
|
|
5567
|
+
outcome: 'value',
|
|
5568
|
+
relation: compareTemporalClaims(left.value, right.value),
|
|
5569
|
+
};
|
|
5570
|
+
}
|
|
5571
|
+
|
|
5572
|
+
function evaluateValueSemanticsRadixScale(descriptor) {
|
|
5573
|
+
const info = valueDescriptorToScalarInfo(descriptor);
|
|
5574
|
+
if (info.category !== 'radix') {
|
|
5575
|
+
return valueSemanticsDiagnostic('radix_required', 'Radix scale is defined only for radix-family values');
|
|
5576
|
+
}
|
|
5577
|
+
const scale = radixScaleOf(info.value.payload, info.value.radixBase);
|
|
5578
|
+
if (scale === null || scale === undefined) {
|
|
5579
|
+
return valueSemanticsDiagnostic('invalid_radix_value', 'Radix payload is invalid for its resolved base');
|
|
5580
|
+
}
|
|
5581
|
+
return { ok: true, outcome: 'value', value: scale };
|
|
5582
|
+
}
|
|
5583
|
+
|
|
5127
5584
|
function evaluateValueSemanticsEquality(operation, leftDescriptor, rightDescriptor, profile) {
|
|
5128
5585
|
const left = valueDescriptorToScalarInfo(leftDescriptor);
|
|
5129
5586
|
const right = valueDescriptorToScalarInfo(rightDescriptor);
|
|
@@ -5133,6 +5590,12 @@ function evaluateValueSemanticsEquality(operation, leftDescriptor, rightDescript
|
|
|
5133
5590
|
if (left.category === 'missing' || right.category === 'missing' || left.category === 'bindingSet' || right.category === 'bindingSet') {
|
|
5134
5591
|
return valueSemanticsDiagnostic('not_equality_comparable', 'Evaluation state or non-scalar value is not equality-comparable');
|
|
5135
5592
|
}
|
|
5593
|
+
if (left.category === 'radix' && right.category === 'radix' && typeof profile.compareRadix === 'function') {
|
|
5594
|
+
const comparison = compareRadixWithProfile(left, right, profile);
|
|
5595
|
+
if (!comparison.ok) return comparison.diagnostic;
|
|
5596
|
+
const value = comparison.value === 0;
|
|
5597
|
+
return { ok: true, outcome: 'value', value: operation === 'equal' ? value : !value };
|
|
5598
|
+
}
|
|
5136
5599
|
if (!sameMinimumEqualityDomain(left, right)) {
|
|
5137
5600
|
return valueSemanticsDiagnostic('mixed_categories', 'Mixed categories do not compare by implicit coercion');
|
|
5138
5601
|
}
|
|
@@ -5156,7 +5619,19 @@ function evaluateValueSemanticsOrdering(leftDescriptor, rightDescriptor, profile
|
|
|
5156
5619
|
if (typeof left.value === 'boolean' && typeof right.value === 'boolean') {
|
|
5157
5620
|
return valueSemanticsDiagnostic('not_orderable', 'Boolean ordering is not part of the minimum profile');
|
|
5158
5621
|
}
|
|
5622
|
+
if (left.category === 'radix' && right.category === 'radix' && typeof profile.compareRadix === 'function') {
|
|
5623
|
+
const comparison = compareRadixWithProfile(left, right, profile);
|
|
5624
|
+
if (!comparison.ok) return comparison.diagnostic;
|
|
5625
|
+
return {
|
|
5626
|
+
ok: true,
|
|
5627
|
+
outcome: 'value',
|
|
5628
|
+
relation: comparison.value < 0 ? 'less' : comparison.value > 0 ? 'greater' : 'equal',
|
|
5629
|
+
};
|
|
5630
|
+
}
|
|
5159
5631
|
if (!sameMinimumOrderingDomain(left, right)) {
|
|
5632
|
+
if (left.category === right.category && left.category !== 'temporal') {
|
|
5633
|
+
return valueSemanticsDiagnostic('not_orderable', 'Value category is not orderable in the minimum profile');
|
|
5634
|
+
}
|
|
5160
5635
|
return valueSemanticsDiagnostic('mixed_categories', 'Mixed categories do not order by implicit coercion');
|
|
5161
5636
|
}
|
|
5162
5637
|
const comparison = compareMinimumOrdering(left, right, profile);
|
|
@@ -5173,8 +5648,10 @@ function valueDescriptorToScalarInfo(descriptor) {
|
|
|
5173
5648
|
}
|
|
5174
5649
|
switch (descriptor.category) {
|
|
5175
5650
|
case 'finiteNumber': {
|
|
5176
|
-
const value =
|
|
5177
|
-
if (
|
|
5651
|
+
const value = String(descriptor.value);
|
|
5652
|
+
if (parseExactFiniteNumber(value) === null) {
|
|
5653
|
+
throw new Error('finiteNumber descriptor must contain a canonical finite numeric value');
|
|
5654
|
+
}
|
|
5178
5655
|
return { category: 'finiteNumber', value };
|
|
5179
5656
|
}
|
|
5180
5657
|
case 'positiveInfinity':
|
|
@@ -5197,12 +5674,15 @@ function valueDescriptorToScalarInfo(descriptor) {
|
|
|
5197
5674
|
value: {
|
|
5198
5675
|
payload: String(descriptor.value ?? ''),
|
|
5199
5676
|
semanticType: descriptor.semanticType ?? 'radix',
|
|
5677
|
+
radixBase: normalizeRadixBase(descriptor.radixBase ?? radixBaseFromSemanticType(descriptor.semanticType)),
|
|
5200
5678
|
},
|
|
5201
5679
|
};
|
|
5202
5680
|
case 'encoding':
|
|
5203
5681
|
return { category: 'encoding', value: String(descriptor.value ?? '') };
|
|
5204
5682
|
case 'separator':
|
|
5205
5683
|
return { category: 'separator', value: String(descriptor.value ?? '') };
|
|
5684
|
+
case 'symbol':
|
|
5685
|
+
return { category: 'symbol', value: String(descriptor.value ?? '') };
|
|
5206
5686
|
case 'sansaAddress':
|
|
5207
5687
|
return { category: 'sansaAddress', value: sansaAddressSemanticValue(descriptor.value) };
|
|
5208
5688
|
case 'referenceForm':
|
|
@@ -5252,6 +5732,9 @@ function scalarInfoToValueDescriptor(info) {
|
|
|
5252
5732
|
? { category: 'negativeInfinity' }
|
|
5253
5733
|
: { category: 'positiveInfinity' };
|
|
5254
5734
|
}
|
|
5735
|
+
if (info.numericLexeme !== undefined) {
|
|
5736
|
+
return { category: 'finiteNumber', value: info.numericLexeme };
|
|
5737
|
+
}
|
|
5255
5738
|
const semanticCategory = VALUE_SEMANTICS_METADATA_CATEGORIES.includes(info.category)
|
|
5256
5739
|
? info.category
|
|
5257
5740
|
: VALUE_SEMANTICS_METADATA_CATEGORIES.includes(info.kind)
|
|
@@ -5263,6 +5746,8 @@ function scalarInfoToValueDescriptor(info) {
|
|
|
5263
5746
|
category,
|
|
5264
5747
|
value: info.value,
|
|
5265
5748
|
...(info.semanticType === undefined ? {} : { semanticType: info.semanticType }),
|
|
5749
|
+
...(info.radixBase === undefined ? {} : { radixBase: info.radixBase }),
|
|
5750
|
+
...(info.radixScale === undefined ? {} : { radixScale: info.radixScale }),
|
|
5266
5751
|
...(info.containerKind === undefined ? {} : { containerKind: info.containerKind }),
|
|
5267
5752
|
};
|
|
5268
5753
|
}
|
|
@@ -5306,6 +5791,7 @@ function sameMinimumEqualityDomain(left, right) {
|
|
|
5306
5791
|
'radix',
|
|
5307
5792
|
'encoding',
|
|
5308
5793
|
'separator',
|
|
5794
|
+
'symbol',
|
|
5309
5795
|
'sansaAddress',
|
|
5310
5796
|
'referenceForm',
|
|
5311
5797
|
].includes(left.category);
|
|
@@ -5335,7 +5821,8 @@ function temporalSemanticType(info) {
|
|
|
5335
5821
|
|
|
5336
5822
|
function compareMinimumEquality(operation, left, right, profile) {
|
|
5337
5823
|
if (isValueSemanticsNumeric(left) && isValueSemanticsNumeric(right)) {
|
|
5338
|
-
|
|
5824
|
+
const equals = compareMinimumNumeric(left, right) === 0;
|
|
5825
|
+
return operation === 'equal' ? equals : !equals;
|
|
5339
5826
|
}
|
|
5340
5827
|
const equals = (() => {
|
|
5341
5828
|
if (left.category === 'string' && right.category === 'string') return profile.compareStrings(left.value, right.value) === 0;
|
|
@@ -5347,6 +5834,9 @@ function compareMinimumEquality(operation, left, right, profile) {
|
|
|
5347
5834
|
}
|
|
5348
5835
|
|
|
5349
5836
|
function compareMinimumOrdering(left, right, profile) {
|
|
5837
|
+
if (isValueSemanticsNumeric(left) && isValueSemanticsNumeric(right)) {
|
|
5838
|
+
return compareMinimumNumeric(left, right);
|
|
5839
|
+
}
|
|
5350
5840
|
if (left.category === 'temporal' && right.category === 'temporal') {
|
|
5351
5841
|
return profile.compareTemporal(left.value, right.value);
|
|
5352
5842
|
}
|
|
@@ -5356,6 +5846,252 @@ function compareMinimumOrdering(left, right, profile) {
|
|
|
5356
5846
|
return comparePrimitiveOrderValues(left.value, right.value, profile);
|
|
5357
5847
|
}
|
|
5358
5848
|
|
|
5849
|
+
function compareMinimumNumeric(left, right) {
|
|
5850
|
+
if (left.category === right.category && left.category !== 'finiteNumber') return 0;
|
|
5851
|
+
if (left.category === 'negativeInfinity' || right.category === 'positiveInfinity') return -1;
|
|
5852
|
+
if (left.category === 'positiveInfinity' || right.category === 'negativeInfinity') return 1;
|
|
5853
|
+
const comparison = compareExactFiniteNumbers(left.value, right.value);
|
|
5854
|
+
if (comparison === null) throw new Error('Invalid finite numeric value reached comparison');
|
|
5855
|
+
return comparison;
|
|
5856
|
+
}
|
|
5857
|
+
|
|
5858
|
+
function compareExactFiniteNumbers(left, right) {
|
|
5859
|
+
const leftValue = parseExactFiniteNumber(String(left));
|
|
5860
|
+
const rightValue = parseExactFiniteNumber(String(right));
|
|
5861
|
+
if (leftValue === null || rightValue === null) return null;
|
|
5862
|
+
if (leftValue.sign !== rightValue.sign) return leftValue.sign < rightValue.sign ? -1 : 1;
|
|
5863
|
+
if (leftValue.sign === 0) return 0;
|
|
5864
|
+
|
|
5865
|
+
const leftOrder = BigInt(leftValue.digits.length) + leftValue.scale;
|
|
5866
|
+
const rightOrder = BigInt(rightValue.digits.length) + rightValue.scale;
|
|
5867
|
+
let comparison;
|
|
5868
|
+
if (leftOrder !== rightOrder) {
|
|
5869
|
+
comparison = leftOrder < rightOrder ? -1 : 1;
|
|
5870
|
+
} else {
|
|
5871
|
+
const width = Math.max(leftValue.digits.length, rightValue.digits.length);
|
|
5872
|
+
const leftDigits = leftValue.digits.padEnd(width, '0');
|
|
5873
|
+
const rightDigits = rightValue.digits.padEnd(width, '0');
|
|
5874
|
+
comparison = leftDigits === rightDigits ? 0 : leftDigits < rightDigits ? -1 : 1;
|
|
5875
|
+
}
|
|
5876
|
+
return leftValue.sign === -1 ? -comparison : comparison;
|
|
5877
|
+
}
|
|
5878
|
+
|
|
5879
|
+
function parseExactFiniteNumber(value) {
|
|
5880
|
+
if (value.length === 0 || value.length > MAX_EXACT_NUMERIC_CHARACTERS) return null;
|
|
5881
|
+
const match = /^([+-]?)(?:(0|[1-9]\d*)(?:\.(\d+))?|\.(\d+))(?:[eE]([+-]?\d+))?$/u.exec(value);
|
|
5882
|
+
if (match === null) return null;
|
|
5883
|
+
const integer = match[2] ?? '';
|
|
5884
|
+
const fraction = match[3] ?? match[4] ?? '';
|
|
5885
|
+
const digits = `${integer}${fraction}`.replace(/^0+/u, '');
|
|
5886
|
+
if (digits.length === 0) return { sign: 0, digits: '0', scale: 0n };
|
|
5887
|
+
return {
|
|
5888
|
+
sign: match[1] === '-' ? -1 : 1,
|
|
5889
|
+
digits,
|
|
5890
|
+
scale: BigInt(match[5] ?? '0') - BigInt(fraction.length),
|
|
5891
|
+
};
|
|
5892
|
+
}
|
|
5893
|
+
|
|
5894
|
+
function compareRadixWithProfile(left, right, profile) {
|
|
5895
|
+
const leftBase = left.value.radixBase;
|
|
5896
|
+
const rightBase = right.value.radixBase;
|
|
5897
|
+
const resolvedLeftBase = leftBase ?? rightBase;
|
|
5898
|
+
const resolvedRightBase = rightBase ?? leftBase;
|
|
5899
|
+
if (resolvedLeftBase === undefined || resolvedRightBase === undefined) {
|
|
5900
|
+
return {
|
|
5901
|
+
ok: false,
|
|
5902
|
+
diagnostic: valueSemanticsDiagnostic(
|
|
5903
|
+
'radix_base_required',
|
|
5904
|
+
'Radix numeric comparison requires at least one operand with a resolved base',
|
|
5905
|
+
),
|
|
5906
|
+
};
|
|
5907
|
+
}
|
|
5908
|
+
if (resolvedLeftBase !== resolvedRightBase && profile.radixComparison !== 'cross-base-exact') {
|
|
5909
|
+
return {
|
|
5910
|
+
ok: false,
|
|
5911
|
+
diagnostic: valueSemanticsDiagnostic(
|
|
5912
|
+
'mixed_radix_bases',
|
|
5913
|
+
`Radix numeric comparison requires the same base (${leftBase} vs ${rightBase})`,
|
|
5914
|
+
),
|
|
5915
|
+
};
|
|
5916
|
+
}
|
|
5917
|
+
|
|
5918
|
+
const value = profile.compareRadix(
|
|
5919
|
+
{ payload: left.value.payload, base: resolvedLeftBase, semanticType: left.value.semanticType },
|
|
5920
|
+
{ payload: right.value.payload, base: resolvedRightBase, semanticType: right.value.semanticType },
|
|
5921
|
+
);
|
|
5922
|
+
if (value === null) {
|
|
5923
|
+
return {
|
|
5924
|
+
ok: false,
|
|
5925
|
+
diagnostic: valueSemanticsDiagnostic(
|
|
5926
|
+
'invalid_radix_value',
|
|
5927
|
+
`Radix payload is invalid for base ${resolvedLeftBase} or ${resolvedRightBase}`,
|
|
5928
|
+
),
|
|
5929
|
+
};
|
|
5930
|
+
}
|
|
5931
|
+
return { ok: true, value: normalizeComparison(value) };
|
|
5932
|
+
}
|
|
5933
|
+
|
|
5934
|
+
function compareExactRadixSemanticValues(left, right) {
|
|
5935
|
+
if (left.base !== right.base) return null;
|
|
5936
|
+
return compareExactRadixValues(left.payload, right.payload, left.base);
|
|
5937
|
+
}
|
|
5938
|
+
|
|
5939
|
+
function compareExactCrossBaseRadixSemanticValues(left, right) {
|
|
5940
|
+
return compareExactCrossBaseRadixValues(left.payload, left.base, right.payload, right.base);
|
|
5941
|
+
}
|
|
5942
|
+
|
|
5943
|
+
function parseExactRadixValue(value, base) {
|
|
5944
|
+
if (!Number.isInteger(base) || base < 2 || base > 64) return null;
|
|
5945
|
+
if (value.length === 0 || value.length > MAX_EXACT_NUMERIC_CHARACTERS) return null;
|
|
5946
|
+
|
|
5947
|
+
let index = 0;
|
|
5948
|
+
let sign = 1;
|
|
5949
|
+
if (value[index] === '+' || value[index] === '-') {
|
|
5950
|
+
sign = value[index] === '-' ? -1 : 1;
|
|
5951
|
+
index += 1;
|
|
5952
|
+
}
|
|
5953
|
+
if (index >= value.length) return null;
|
|
5954
|
+
|
|
5955
|
+
const integerDigits = [];
|
|
5956
|
+
const fractionalDigits = [];
|
|
5957
|
+
let target = integerDigits;
|
|
5958
|
+
let sawPoint = false;
|
|
5959
|
+
let sawDigit = false;
|
|
5960
|
+
for (; index < value.length; index += 1) {
|
|
5961
|
+
const character = value[index];
|
|
5962
|
+
if (character === '.') {
|
|
5963
|
+
if (sawPoint || index === value.length - 1) return null;
|
|
5964
|
+
sawPoint = true;
|
|
5965
|
+
target = fractionalDigits;
|
|
5966
|
+
continue;
|
|
5967
|
+
}
|
|
5968
|
+
if (character === '_') {
|
|
5969
|
+
const previous = value[index - 1];
|
|
5970
|
+
const next = value[index + 1];
|
|
5971
|
+
if (radixDigitValue(previous) === null || radixDigitValue(next) === null) return null;
|
|
5972
|
+
continue;
|
|
5973
|
+
}
|
|
5974
|
+
const digit = radixDigitValue(character);
|
|
5975
|
+
if (digit === null || digit >= base) return null;
|
|
5976
|
+
target.push(digit);
|
|
5977
|
+
sawDigit = true;
|
|
5978
|
+
}
|
|
5979
|
+
if (!sawDigit || fractionalDigits.length === 0 && sawPoint) return null;
|
|
5980
|
+
|
|
5981
|
+
let leadingZeroes = 0;
|
|
5982
|
+
while (leadingZeroes < integerDigits.length && integerDigits[leadingZeroes] === 0) leadingZeroes += 1;
|
|
5983
|
+
if (leadingZeroes > 0) integerDigits.splice(0, leadingZeroes);
|
|
5984
|
+
while (fractionalDigits.length > 0 && fractionalDigits.at(-1) === 0) fractionalDigits.pop();
|
|
5985
|
+
if (integerDigits.length === 0 && fractionalDigits.length === 0) sign = 0;
|
|
5986
|
+
return { sign, integerDigits, fractionalDigits };
|
|
5987
|
+
}
|
|
5988
|
+
|
|
5989
|
+
function compareParsedRadixValues(left, right) {
|
|
5990
|
+
if (left.sign !== right.sign) return left.sign < right.sign ? -1 : 1;
|
|
5991
|
+
if (left.sign === 0) return 0;
|
|
5992
|
+
|
|
5993
|
+
let comparison = 0;
|
|
5994
|
+
if (left.integerDigits.length !== right.integerDigits.length) {
|
|
5995
|
+
comparison = left.integerDigits.length < right.integerDigits.length ? -1 : 1;
|
|
5996
|
+
} else {
|
|
5997
|
+
comparison = compareRadixDigitArrays(left.integerDigits, right.integerDigits);
|
|
5998
|
+
if (comparison === 0) {
|
|
5999
|
+
const width = Math.max(left.fractionalDigits.length, right.fractionalDigits.length);
|
|
6000
|
+
for (let index = 0; index < width; index += 1) {
|
|
6001
|
+
const leftDigit = left.fractionalDigits[index] ?? 0;
|
|
6002
|
+
const rightDigit = right.fractionalDigits[index] ?? 0;
|
|
6003
|
+
if (leftDigit !== rightDigit) {
|
|
6004
|
+
comparison = leftDigit < rightDigit ? -1 : 1;
|
|
6005
|
+
break;
|
|
6006
|
+
}
|
|
6007
|
+
}
|
|
6008
|
+
}
|
|
6009
|
+
}
|
|
6010
|
+
return left.sign === -1 ? -comparison : comparison;
|
|
6011
|
+
}
|
|
6012
|
+
|
|
6013
|
+
function compareParsedCrossBaseRadixValues(left, leftBase, right, rightBase) {
|
|
6014
|
+
if (left.sign !== right.sign) return left.sign < right.sign ? -1 : 1;
|
|
6015
|
+
if (left.sign === 0) return 0;
|
|
6016
|
+
|
|
6017
|
+
const leftNumerator = radixDigitsToBigInt(
|
|
6018
|
+
[...left.integerDigits, ...left.fractionalDigits],
|
|
6019
|
+
leftBase,
|
|
6020
|
+
);
|
|
6021
|
+
const rightNumerator = radixDigitsToBigInt(
|
|
6022
|
+
[...right.integerDigits, ...right.fractionalDigits],
|
|
6023
|
+
rightBase,
|
|
6024
|
+
);
|
|
6025
|
+
const leftDenominator = BigInt(leftBase) ** BigInt(left.fractionalDigits.length);
|
|
6026
|
+
const rightDenominator = BigInt(rightBase) ** BigInt(right.fractionalDigits.length);
|
|
6027
|
+
const leftScaled = leftNumerator * rightDenominator;
|
|
6028
|
+
const rightScaled = rightNumerator * leftDenominator;
|
|
6029
|
+
const comparison = leftScaled < rightScaled ? -1 : leftScaled > rightScaled ? 1 : 0;
|
|
6030
|
+
return left.sign === -1 ? -comparison : comparison;
|
|
6031
|
+
}
|
|
6032
|
+
|
|
6033
|
+
function radixDigitsToBigInt(digits, base) {
|
|
6034
|
+
if (digits.length === 0) return 0n;
|
|
6035
|
+
let chunkSize = 1;
|
|
6036
|
+
let fullChunkMultiplier = base;
|
|
6037
|
+
while (fullChunkMultiplier <= Math.floor(Number.MAX_SAFE_INTEGER / base)) {
|
|
6038
|
+
fullChunkMultiplier *= base;
|
|
6039
|
+
chunkSize += 1;
|
|
6040
|
+
}
|
|
6041
|
+
|
|
6042
|
+
let result = 0n;
|
|
6043
|
+
for (let offset = 0; offset < digits.length; offset += chunkSize) {
|
|
6044
|
+
const length = Math.min(chunkSize, digits.length - offset);
|
|
6045
|
+
let chunkValue = 0;
|
|
6046
|
+
let multiplier = 1;
|
|
6047
|
+
for (let index = 0; index < length; index += 1) {
|
|
6048
|
+
chunkValue = chunkValue * base + digits[offset + index];
|
|
6049
|
+
multiplier *= base;
|
|
6050
|
+
}
|
|
6051
|
+
result = result * BigInt(multiplier) + BigInt(chunkValue);
|
|
6052
|
+
}
|
|
6053
|
+
return result;
|
|
6054
|
+
}
|
|
6055
|
+
|
|
6056
|
+
function compareRadixDigitArrays(left, right) {
|
|
6057
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
6058
|
+
if (left[index] < right[index]) return -1;
|
|
6059
|
+
if (left[index] > right[index]) return 1;
|
|
6060
|
+
}
|
|
6061
|
+
return 0;
|
|
6062
|
+
}
|
|
6063
|
+
|
|
6064
|
+
function radixDigitValue(character) {
|
|
6065
|
+
if (typeof character !== 'string') return null;
|
|
6066
|
+
const codePoint = character.codePointAt(0);
|
|
6067
|
+
if (codePoint >= 48 && codePoint <= 57) return codePoint - 48;
|
|
6068
|
+
if (codePoint >= 65 && codePoint <= 90) return codePoint - 55;
|
|
6069
|
+
if (codePoint >= 97 && codePoint <= 122) return codePoint - 61;
|
|
6070
|
+
if (character === '&') return 62;
|
|
6071
|
+
if (character === '!') return 63;
|
|
6072
|
+
return null;
|
|
6073
|
+
}
|
|
6074
|
+
|
|
6075
|
+
function normalizeRadixBase(value) {
|
|
6076
|
+
if (value === undefined || value === null) return undefined;
|
|
6077
|
+
if (!Number.isInteger(value) || value < 2 || value > 64) {
|
|
6078
|
+
throw new Error('radixBase must be an integer from 2 through 64');
|
|
6079
|
+
}
|
|
6080
|
+
return value;
|
|
6081
|
+
}
|
|
6082
|
+
|
|
6083
|
+
function radixBaseFromSemanticType(semanticType) {
|
|
6084
|
+
if (typeof semanticType !== 'string') return undefined;
|
|
6085
|
+
const normalized = semanticType.trim().toLowerCase();
|
|
6086
|
+
if (normalized === 'decimal') return 10;
|
|
6087
|
+
const alias = /^radix(2|6|8|12)$/u.exec(normalized);
|
|
6088
|
+
if (alias !== null) return Number(alias[1]);
|
|
6089
|
+
const clarified = /^radix\[(\d+)\]$/u.exec(normalized);
|
|
6090
|
+
if (clarified === null) return undefined;
|
|
6091
|
+
const base = Number(clarified[1]);
|
|
6092
|
+
return Number.isInteger(base) && base >= 2 && base <= 64 ? base : undefined;
|
|
6093
|
+
}
|
|
6094
|
+
|
|
5359
6095
|
function normalizeValueSemanticsCategory(category) {
|
|
5360
6096
|
if (category === 'sansa') return 'sansaAddress';
|
|
5361
6097
|
if (category === 'cloneReference' || category === 'pointerReference') return 'referenceForm';
|
|
@@ -5377,6 +6113,13 @@ function structurallyEqualContainers(left, right, profile) {
|
|
|
5377
6113
|
}
|
|
5378
6114
|
|
|
5379
6115
|
function structurallyEqualValues(left, right, profile) {
|
|
6116
|
+
const leftDescriptor = comparableScalarDescriptor(left);
|
|
6117
|
+
const rightDescriptor = comparableScalarDescriptor(right);
|
|
6118
|
+
if (leftDescriptor !== undefined || rightDescriptor !== undefined) {
|
|
6119
|
+
if (leftDescriptor === undefined || rightDescriptor === undefined) return false;
|
|
6120
|
+
const equality = evaluateValueSemanticsEquality('equal', leftDescriptor, rightDescriptor, profile);
|
|
6121
|
+
return equality.ok && equality.value;
|
|
6122
|
+
}
|
|
5380
6123
|
if (Object.is(left, right)) return true;
|
|
5381
6124
|
if (typeof left === 'string' && typeof right === 'string') return profile.compareStrings(left, right) === 0;
|
|
5382
6125
|
if (typeof left !== 'object' || left === null || typeof right !== 'object' || right === null) return false;
|
|
@@ -5394,6 +6137,11 @@ function structurallyEqualValues(left, right, profile) {
|
|
|
5394
6137
|
return true;
|
|
5395
6138
|
}
|
|
5396
6139
|
|
|
6140
|
+
function comparableScalarDescriptor(value) {
|
|
6141
|
+
if (typeof value !== 'object' || value === null) return undefined;
|
|
6142
|
+
return value[COMPARABLE_SCALAR_DESCRIPTOR_PROPERTY];
|
|
6143
|
+
}
|
|
6144
|
+
|
|
5397
6145
|
function isConcreteValueDescriptor(descriptor) {
|
|
5398
6146
|
const info = valueDescriptorToScalarInfo(descriptor);
|
|
5399
6147
|
return isConcreteValueScalar(info);
|
|
@@ -5429,7 +6177,10 @@ function compareQueryScalars(operator, left, right, options = {}) {
|
|
|
5429
6177
|
if (!evaluated.ok) {
|
|
5430
6178
|
return {
|
|
5431
6179
|
ok: false,
|
|
5432
|
-
error: queryEvaluateError(
|
|
6180
|
+
error: queryEvaluateError(
|
|
6181
|
+
'SANSA_QUERY_EVALUATE_INVALID_COMPARISON',
|
|
6182
|
+
queryComparisonMessage(evaluated.reason, operator, leftDescriptor, rightDescriptor),
|
|
6183
|
+
),
|
|
5433
6184
|
};
|
|
5434
6185
|
}
|
|
5435
6186
|
const value = (() => {
|
|
@@ -5454,15 +6205,26 @@ function queryScalarToInfo(scalar) {
|
|
|
5454
6205
|
...(metadata.semanticType === undefined ? {} : { semanticType: metadata.semanticType }),
|
|
5455
6206
|
...(metadata.containerKind === undefined ? {} : { containerKind: metadata.containerKind }),
|
|
5456
6207
|
...(metadata.nullReason === undefined ? {} : { nullReason: metadata.nullReason }),
|
|
6208
|
+
...(metadata.numericLexeme === undefined ? {} : { numericLexeme: metadata.numericLexeme }),
|
|
6209
|
+
...(metadata.radixBase === undefined ? {} : { radixBase: metadata.radixBase }),
|
|
6210
|
+
...(metadata.radixScale === undefined ? {} : { radixScale: metadata.radixScale }),
|
|
5457
6211
|
};
|
|
5458
6212
|
}
|
|
5459
6213
|
return { value: scalar };
|
|
5460
6214
|
}
|
|
5461
6215
|
|
|
5462
|
-
function queryComparisonMessage(reason, operator) {
|
|
5463
|
-
if (reason === 'mixed_categories')
|
|
6216
|
+
function queryComparisonMessage(reason, operator, leftDescriptor, rightDescriptor) {
|
|
6217
|
+
if (reason === 'mixed_categories') {
|
|
6218
|
+
const categories = leftDescriptor?.category && rightDescriptor?.category
|
|
6219
|
+
? ` (${leftDescriptor.category} vs ${rightDescriptor.category})`
|
|
6220
|
+
: '';
|
|
6221
|
+
return `Cross-type comparison is not supported${categories}`;
|
|
6222
|
+
}
|
|
5464
6223
|
if (reason === 'not_equality_comparable') return 'NaN, null, and absence values are not equality-comparable in this evaluator slice';
|
|
5465
6224
|
if (reason === 'not_orderable' && ['<', '<=', '>', '>='].includes(operator)) return 'Ordering comparison is not defined for this value category';
|
|
6225
|
+
if (reason === 'radix_base_required') return 'Radix numeric comparison requires a resolved base from at least one operand';
|
|
6226
|
+
if (reason === 'mixed_radix_bases') return 'Cross-base radix comparison is not enabled by this value-semantics profile';
|
|
6227
|
+
if (reason === 'invalid_radix_value') return 'Radix payload is invalid for its resolved base';
|
|
5466
6228
|
return 'Invalid scalar comparison';
|
|
5467
6229
|
}
|
|
5468
6230
|
|
|
@@ -5647,7 +6409,12 @@ function materializeAttributeComparableValue(namespace, binding, seen) {
|
|
|
5647
6409
|
function materializeBindingComparableValue(namespace, binding, seen) {
|
|
5648
6410
|
const scalar = getBindingScalarValue(namespace, binding);
|
|
5649
6411
|
if (scalar.ok && !(scalar.value === undefined && isContainerBinding(namespace, binding))) {
|
|
5650
|
-
return {
|
|
6412
|
+
return {
|
|
6413
|
+
ok: true,
|
|
6414
|
+
value: {
|
|
6415
|
+
[COMPARABLE_SCALAR_DESCRIPTOR_PROPERTY]: scalarInfoToValueDescriptor(queryScalarToInfo(scalar)),
|
|
6416
|
+
},
|
|
6417
|
+
};
|
|
5651
6418
|
}
|
|
5652
6419
|
if (!isContainerBinding(namespace, binding)) return scalar;
|
|
5653
6420
|
return materializeContainerComparableValue(namespace, binding, seen);
|
|
@@ -5657,11 +6424,14 @@ function getBindingScalarInfo(namespace, binding) {
|
|
|
5657
6424
|
const kind = getBindingScalarKind(namespace, binding);
|
|
5658
6425
|
const semanticType = getBindingSemanticType(namespace, binding);
|
|
5659
6426
|
const nullReason = getBindingNullReason(namespace, binding);
|
|
6427
|
+
const numericLexeme = getBindingNumericLexeme(namespace, binding);
|
|
6428
|
+
const radixBase = getBindingRadixBase(namespace, binding);
|
|
6429
|
+
const radixScale = getBindingRadixScale(namespace, binding);
|
|
5660
6430
|
if (typeof namespace.value === 'function') {
|
|
5661
|
-
return { ok: true, value: namespace.value(binding), kind, semanticType, nullReason };
|
|
6431
|
+
return { ok: true, value: namespace.value(binding), kind, semanticType, nullReason, numericLexeme, radixBase, radixScale };
|
|
5662
6432
|
}
|
|
5663
|
-
if (Object.hasOwn(binding, 'value')) return { ok: true, value: binding.value, kind, semanticType, nullReason };
|
|
5664
|
-
if (Object.hasOwn(binding, 'scalar')) return { ok: true, value: binding.scalar, kind, semanticType, nullReason };
|
|
6433
|
+
if (Object.hasOwn(binding, 'value')) return { ok: true, value: binding.value, kind, semanticType, nullReason, numericLexeme, radixBase, radixScale };
|
|
6434
|
+
if (Object.hasOwn(binding, 'scalar')) return { ok: true, value: binding.scalar, kind, semanticType, nullReason, numericLexeme, radixBase, radixScale };
|
|
5665
6435
|
return {
|
|
5666
6436
|
ok: false,
|
|
5667
6437
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_MISSING_SCALAR', 'Binding does not expose a scalar value'),
|
|
@@ -5669,6 +6439,13 @@ function getBindingScalarInfo(namespace, binding) {
|
|
|
5669
6439
|
}
|
|
5670
6440
|
|
|
5671
6441
|
function containerKindFromBinding(namespace, binding) {
|
|
6442
|
+
const explicitKind = explicitContainerKindFromBinding(namespace, binding);
|
|
6443
|
+
if (explicitKind !== undefined) return explicitKind;
|
|
6444
|
+
if (Array.isArray(binding.children)) return 'container';
|
|
6445
|
+
return undefined;
|
|
6446
|
+
}
|
|
6447
|
+
|
|
6448
|
+
function explicitContainerKindFromBinding(namespace, binding) {
|
|
5672
6449
|
const rawKind = typeof namespace.representationKind === 'function'
|
|
5673
6450
|
? namespace.representationKind(binding)
|
|
5674
6451
|
: binding.representationKind ?? binding.kind ?? binding.type ?? binding.literalKind ?? binding.valueKind;
|
|
@@ -5677,7 +6454,6 @@ function containerKindFromBinding(namespace, binding) {
|
|
|
5677
6454
|
if (['list', 'listNode'].includes(kind)) return 'list';
|
|
5678
6455
|
if (['tuple', 'tupleLiteral'].includes(kind)) return 'tuple';
|
|
5679
6456
|
if (['node', 'nodeLiteral'].includes(kind)) return 'node';
|
|
5680
|
-
if (Array.isArray(binding.children)) return 'container';
|
|
5681
6457
|
return undefined;
|
|
5682
6458
|
}
|
|
5683
6459
|
|
|
@@ -5692,6 +6468,7 @@ function getBindingScalarKind(namespace, binding) {
|
|
|
5692
6468
|
if (actual === 'NullLiteral') return 'null';
|
|
5693
6469
|
if (actual === 'NaNLiteral') return 'nan';
|
|
5694
6470
|
if (actual === 'InfinityLiteral') return 'infinity';
|
|
6471
|
+
if (actual === 'SymbolicLiteral') return 'symbol';
|
|
5695
6472
|
return typeof actual === 'string' ? lowerFirst(actual) : undefined;
|
|
5696
6473
|
}
|
|
5697
6474
|
|
|
@@ -5707,6 +6484,29 @@ function getBindingNullReason(namespace, binding) {
|
|
|
5707
6484
|
return binding.nullReason;
|
|
5708
6485
|
}
|
|
5709
6486
|
|
|
6487
|
+
function getBindingNumericLexeme(namespace, binding) {
|
|
6488
|
+
if (typeof namespace.numericLexeme === 'function') return namespace.numericLexeme(binding);
|
|
6489
|
+
return typeof binding.numericLexeme === 'string' ? binding.numericLexeme : undefined;
|
|
6490
|
+
}
|
|
6491
|
+
|
|
6492
|
+
function getBindingRadixBase(namespace, binding) {
|
|
6493
|
+
if (typeof namespace.radixBase === 'function') return namespace.radixBase(binding);
|
|
6494
|
+
if (Number.isInteger(binding.radixBase)) return binding.radixBase;
|
|
6495
|
+
return radixBaseFromSemanticType(getBindingSemanticType(namespace, binding));
|
|
6496
|
+
}
|
|
6497
|
+
|
|
6498
|
+
function getBindingRadixScale(namespace, binding) {
|
|
6499
|
+
if (typeof namespace.radixScale === 'function') return namespace.radixScale(binding);
|
|
6500
|
+
if (Number.isInteger(binding.radixScale) && binding.radixScale >= 0) return binding.radixScale;
|
|
6501
|
+
const kind = getBindingScalarKind(namespace, binding);
|
|
6502
|
+
if (kind !== 'radix') return undefined;
|
|
6503
|
+
const value = typeof namespace.value === 'function'
|
|
6504
|
+
? namespace.value(binding)
|
|
6505
|
+
: Object.hasOwn(binding, 'value') ? binding.value : binding.scalar;
|
|
6506
|
+
if (typeof value !== 'string') return undefined;
|
|
6507
|
+
return radixScaleOf(value, getBindingRadixBase(namespace, binding)) ?? undefined;
|
|
6508
|
+
}
|
|
6509
|
+
|
|
5710
6510
|
function getBindingNodeTag(namespace, binding) {
|
|
5711
6511
|
if (typeof namespace.nodeTag === 'function') return namespace.nodeTag(binding);
|
|
5712
6512
|
if (typeof namespace.tag === 'function') return namespace.tag(binding);
|
|
@@ -5735,6 +6535,9 @@ function scalarMetadataFromInfo(info) {
|
|
|
5735
6535
|
if (info.kind !== undefined) metadata.kind = info.kind;
|
|
5736
6536
|
if (info.semanticType !== undefined) metadata.semanticType = info.semanticType;
|
|
5737
6537
|
if (info.nullReason !== undefined) metadata.nullReason = info.nullReason;
|
|
6538
|
+
if (info.numericLexeme !== undefined) metadata.numericLexeme = info.numericLexeme;
|
|
6539
|
+
if (info.radixBase !== undefined) metadata.radixBase = info.radixBase;
|
|
6540
|
+
if (info.radixScale !== undefined) metadata.radixScale = info.radixScale;
|
|
5738
6541
|
return Object.keys(metadata).length > 0 ? metadata : undefined;
|
|
5739
6542
|
}
|
|
5740
6543
|
|
|
@@ -7139,6 +7942,7 @@ class QueryExpressionParser {
|
|
|
7139
7942
|
const char = this.peek();
|
|
7140
7943
|
if (!char) this.fail('Expected SANSA query expression', 'SANSA_QUERY_EXPECTED_EXPRESSION');
|
|
7141
7944
|
if (char === '"') return this.parseString();
|
|
7945
|
+
if (char === '|') return this.parseSymbol();
|
|
7142
7946
|
if (char === '#') return this.parseHex();
|
|
7143
7947
|
if (char === '%') return this.parseRadix();
|
|
7144
7948
|
if (char === '&') return this.parseEncoding();
|
|
@@ -7221,6 +8025,39 @@ class QueryExpressionParser {
|
|
|
7221
8025
|
};
|
|
7222
8026
|
}
|
|
7223
8027
|
|
|
8028
|
+
parseSymbol() {
|
|
8029
|
+
const start = this.index;
|
|
8030
|
+
this.index += 1;
|
|
8031
|
+
let value = '';
|
|
8032
|
+
while (!this.atEnd()) {
|
|
8033
|
+
const char = this.peek();
|
|
8034
|
+
if (char === '|') {
|
|
8035
|
+
this.index += 1;
|
|
8036
|
+
if (value.length === 0) {
|
|
8037
|
+
this.fail('Symbol literals must not be empty', 'SANSA_QUERY_INVALID_SYMBOL_LITERAL', start);
|
|
8038
|
+
}
|
|
8039
|
+
return {
|
|
8040
|
+
type: 'literalExpression',
|
|
8041
|
+
kind: 'symbol',
|
|
8042
|
+
value,
|
|
8043
|
+
canonical: symbolPayload(value),
|
|
8044
|
+
};
|
|
8045
|
+
}
|
|
8046
|
+
if (char === '\n' || char === '\r') {
|
|
8047
|
+
this.fail('Symbol literals must not contain raw newlines', 'SANSA_QUERY_INVALID_SYMBOL_LITERAL', this.index);
|
|
8048
|
+
}
|
|
8049
|
+
if (char === '\\') {
|
|
8050
|
+
const escape = readSymbolPayloadEscape(this.input, this.index);
|
|
8051
|
+
value += escape.value;
|
|
8052
|
+
this.index = escape.end;
|
|
8053
|
+
continue;
|
|
8054
|
+
}
|
|
8055
|
+
value += char;
|
|
8056
|
+
this.index += 1;
|
|
8057
|
+
}
|
|
8058
|
+
this.fail('Unterminated symbol literal', 'SANSA_QUERY_INVALID_SYMBOL_LITERAL', start);
|
|
8059
|
+
}
|
|
8060
|
+
|
|
7224
8061
|
parseNumber() {
|
|
7225
8062
|
const start = this.index;
|
|
7226
8063
|
if (this.peek() === '-') this.index += 1;
|
|
@@ -7419,8 +8256,8 @@ class QueryExpressionParser {
|
|
|
7419
8256
|
|
|
7420
8257
|
startsTemporalLiteral() {
|
|
7421
8258
|
const rest = this.input.slice(this.index);
|
|
7422
|
-
return /^\d{4}
|
|
7423
|
-
|| /^\d{2}
|
|
8259
|
+
return /^\d{4}-(?=$|[\s,)}\]]|\d|T)/.test(rest)
|
|
8260
|
+
|| /^\d{2}:/.test(rest);
|
|
7424
8261
|
}
|
|
7425
8262
|
|
|
7426
8263
|
readSimpleLiteralPayload() {
|
|
@@ -7526,7 +8363,7 @@ class QueryExpressionParser {
|
|
|
7526
8363
|
}
|
|
7527
8364
|
continue;
|
|
7528
8365
|
}
|
|
7529
|
-
if (char === '"') {
|
|
8366
|
+
if (char === '"' || isSymbolLiteralStart(this.input, this.index)) {
|
|
7530
8367
|
quote = char;
|
|
7531
8368
|
this.index += 1;
|
|
7532
8369
|
continue;
|
|
@@ -7637,7 +8474,7 @@ function stripQueryComments(input) {
|
|
|
7637
8474
|
}
|
|
7638
8475
|
continue;
|
|
7639
8476
|
}
|
|
7640
|
-
if (char === '"' || char === "'") {
|
|
8477
|
+
if (char === '"' || char === "'" || isSymbolLiteralStart(input, index)) {
|
|
7641
8478
|
quote = char;
|
|
7642
8479
|
output += char;
|
|
7643
8480
|
continue;
|
|
@@ -7759,7 +8596,7 @@ function scanInstructionClauses(source) {
|
|
|
7759
8596
|
else if (char === quote) quote = null;
|
|
7760
8597
|
continue;
|
|
7761
8598
|
}
|
|
7762
|
-
if (char === '"') {
|
|
8599
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
7763
8600
|
quote = char;
|
|
7764
8601
|
continue;
|
|
7765
8602
|
}
|
|
@@ -7860,7 +8697,7 @@ function findTopLevelInstructionKeyword(source, keyword, start = 0) {
|
|
|
7860
8697
|
else if (char === quote) quote = null;
|
|
7861
8698
|
continue;
|
|
7862
8699
|
}
|
|
7863
|
-
if (char === '"') {
|
|
8700
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
7864
8701
|
quote = char;
|
|
7865
8702
|
continue;
|
|
7866
8703
|
}
|
|
@@ -7900,7 +8737,7 @@ function readInstructionToken(source, start) {
|
|
|
7900
8737
|
else if (char === quote) quote = null;
|
|
7901
8738
|
continue;
|
|
7902
8739
|
}
|
|
7903
|
-
if (char === '"') {
|
|
8740
|
+
if (char === '"' || isSymbolLiteralStart(source, cursor)) {
|
|
7904
8741
|
quote = char;
|
|
7905
8742
|
continue;
|
|
7906
8743
|
}
|
|
@@ -7959,7 +8796,7 @@ function unwrapInstructionDelimitedLiteral(source, open, close, offset) {
|
|
|
7959
8796
|
else if (char === quote) quote = null;
|
|
7960
8797
|
continue;
|
|
7961
8798
|
}
|
|
7962
|
-
if (char === '"') {
|
|
8799
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
7963
8800
|
quote = char;
|
|
7964
8801
|
continue;
|
|
7965
8802
|
}
|
|
@@ -8010,7 +8847,7 @@ function splitTopLevelInstructionValueList(source, offset) {
|
|
|
8010
8847
|
else if (char === quote) quote = null;
|
|
8011
8848
|
continue;
|
|
8012
8849
|
}
|
|
8013
|
-
if (char === '"') {
|
|
8850
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
8014
8851
|
quote = char;
|
|
8015
8852
|
continue;
|
|
8016
8853
|
}
|
|
@@ -8081,7 +8918,7 @@ function scanQueryClauses(source) {
|
|
|
8081
8918
|
}
|
|
8082
8919
|
continue;
|
|
8083
8920
|
}
|
|
8084
|
-
if (char === '"' || char === "'") {
|
|
8921
|
+
if (char === '"' || char === "'" || isSymbolLiteralStart(source, index)) {
|
|
8085
8922
|
quote = char;
|
|
8086
8923
|
continue;
|
|
8087
8924
|
}
|
|
@@ -8175,7 +9012,7 @@ function normalizeQueryExpression(source) {
|
|
|
8175
9012
|
}
|
|
8176
9013
|
continue;
|
|
8177
9014
|
}
|
|
8178
|
-
if (char === '"' || char === "'") {
|
|
9015
|
+
if (char === '"' || char === "'" || isSymbolLiteralStart(source, index)) {
|
|
8179
9016
|
if (pendingSpace && output.length > 0) output += ' ';
|
|
8180
9017
|
pendingSpace = false;
|
|
8181
9018
|
quote = char;
|
|
@@ -8199,12 +9036,11 @@ function isQueryCurrentPositionalShorthand(source) {
|
|
|
8199
9036
|
|
|
8200
9037
|
function isQueryTemporalLiteral(source, kind) {
|
|
8201
9038
|
const date = String.raw`(\d{4})-(\d{2})-(\d{2})`;
|
|
8202
|
-
const time = String.raw`(\d{2}):(?:(\d{2}))?(?::(\d{2}))?(?:Z|([+-])(\d{2}):(\d{2}))?`;
|
|
8203
|
-
const datetimeTime = String.raw`(\d{2})(?::(\d{2})?)?(?::(\d{2}))?(?:Z|([+-])(\d{2}):(\d{2}))?`;
|
|
8204
|
-
const zone = String.raw`[A-Za-z0-9_
|
|
9039
|
+
const time = String.raw`(\d{2}):(?:(\d{2}))?(?::(\d{2})(?:\.(\d+))?)?(?:Z|([+-])(\d{2}):(\d{2}))?`;
|
|
9040
|
+
const datetimeTime = String.raw`(\d{2})(?::(\d{2})?)?(?::(\d{2})(?:\.(\d+))?)?(?:Z|([+-])(\d{2}):(\d{2}))?`;
|
|
9041
|
+
const zone = String.raw`[A-Za-z0-9_+.\-]+(?:/[A-Za-z0-9_+.\-]+)*`;
|
|
8205
9042
|
if (kind === 'date') {
|
|
8206
|
-
|
|
8207
|
-
return Boolean(match) && isValidDateParts(match[1], match[2], match[3]);
|
|
9043
|
+
return parseTemporalDate(source) !== null;
|
|
8208
9044
|
}
|
|
8209
9045
|
if (kind === 'time') {
|
|
8210
9046
|
const match = new RegExp(`^${time}$`).exec(source);
|
|
@@ -8229,7 +9065,7 @@ function isValidDateParts(yearText, monthText, dayText) {
|
|
|
8229
9065
|
const year = Number(yearText);
|
|
8230
9066
|
const month = Number(monthText);
|
|
8231
9067
|
const day = Number(dayText);
|
|
8232
|
-
if (month < 1 || month > 12) return false;
|
|
9068
|
+
if (year < 1 || month < 1 || month > 12) return false;
|
|
8233
9069
|
const days = [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
8234
9070
|
return day >= 1 && day <= days[month - 1];
|
|
8235
9071
|
}
|
|
@@ -8242,11 +9078,11 @@ function isValidTimeMatch(match, offset = 1) {
|
|
|
8242
9078
|
const hour = Number(match[offset]);
|
|
8243
9079
|
const minute = match[offset + 1] === undefined ? null : Number(match[offset + 1]);
|
|
8244
9080
|
const second = match[offset + 2] === undefined ? null : Number(match[offset + 2]);
|
|
8245
|
-
const zoneHour = match[offset +
|
|
8246
|
-
const zoneMinute = match[offset +
|
|
9081
|
+
const zoneHour = match[offset + 5] === undefined ? null : Number(match[offset + 5]);
|
|
9082
|
+
const zoneMinute = match[offset + 6] === undefined ? null : Number(match[offset + 6]);
|
|
8247
9083
|
if (hour < 0 || hour > 23) return false;
|
|
8248
9084
|
if (minute !== null && (minute < 0 || minute > 59)) return false;
|
|
8249
|
-
if (second !== null && (second < 0 || second >
|
|
9085
|
+
if (second !== null && (second < 0 || second > 60)) return false;
|
|
8250
9086
|
if (zoneHour !== null && (zoneHour < 0 || zoneHour > 23)) return false;
|
|
8251
9087
|
if (zoneMinute !== null && (zoneMinute < 0 || zoneMinute > 59)) return false;
|
|
8252
9088
|
return true;
|
|
@@ -8309,7 +9145,7 @@ function splitTopLevelQueryList(source) {
|
|
|
8309
9145
|
else if (char === quote) quote = null;
|
|
8310
9146
|
continue;
|
|
8311
9147
|
}
|
|
8312
|
-
if (char === '"' || char === "'") {
|
|
9148
|
+
if (char === '"' || char === "'" || isSymbolLiteralStart(source, index)) {
|
|
8313
9149
|
quote = char;
|
|
8314
9150
|
continue;
|
|
8315
9151
|
}
|
|
@@ -8342,6 +9178,13 @@ function splitProjectionFields(source) {
|
|
|
8342
9178
|
while (isIdentifierContinue(source[cursor] ?? '')) cursor += 1;
|
|
8343
9179
|
const name = source.slice(nameStart, cursor);
|
|
8344
9180
|
while (isLayout(source[cursor] ?? '')) cursor += 1;
|
|
9181
|
+
if (source[cursor] === ':') {
|
|
9182
|
+
throw new SansaParseError(
|
|
9183
|
+
"Projection fields use AEON assignment syntax ('name = expression'); ':' is reserved for datatype annotations",
|
|
9184
|
+
cursor,
|
|
9185
|
+
'SANSA_QUERY_INVALID_PROJECTION',
|
|
9186
|
+
);
|
|
9187
|
+
}
|
|
8345
9188
|
if (source[cursor] !== '=') {
|
|
8346
9189
|
throw new SansaParseError("Expected '=' after projection field name", cursor, 'SANSA_QUERY_INVALID_PROJECTION');
|
|
8347
9190
|
}
|
|
@@ -8440,7 +9283,7 @@ function findNextProjectionField(source, start) {
|
|
|
8440
9283
|
else if (char === quote) quote = null;
|
|
8441
9284
|
continue;
|
|
8442
9285
|
}
|
|
8443
|
-
if (char === '"') {
|
|
9286
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
8444
9287
|
quote = char;
|
|
8445
9288
|
continue;
|
|
8446
9289
|
}
|
|
@@ -8483,7 +9326,7 @@ function findNextInstructionObjectField(source, start) {
|
|
|
8483
9326
|
else if (char === quote) quote = null;
|
|
8484
9327
|
continue;
|
|
8485
9328
|
}
|
|
8486
|
-
if (char === '"') {
|
|
9329
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
8487
9330
|
quote = char;
|
|
8488
9331
|
continue;
|
|
8489
9332
|
}
|
|
@@ -8519,6 +9362,13 @@ function isComparisonStart(char) {
|
|
|
8519
9362
|
return char === '=' || char === '!' || char === '<' || char === '>';
|
|
8520
9363
|
}
|
|
8521
9364
|
|
|
9365
|
+
function isSymbolLiteralStart(source, index) {
|
|
9366
|
+
if (source[index] !== '|') return false;
|
|
9367
|
+
if (index === 0 || isLayout(source[index - 1])) return true;
|
|
9368
|
+
if ('([{,=<>!'.includes(source[index - 1])) return true;
|
|
9369
|
+
return /(?:^|[^A-Za-z0-9_])(?:and|or|not|in)$/u.test(source.slice(0, index));
|
|
9370
|
+
}
|
|
9371
|
+
|
|
8522
9372
|
function readQuotedPayloadEscape(source, start) {
|
|
8523
9373
|
const escape = source[start + 1];
|
|
8524
9374
|
if (!escape) throw new SansaParseError('Unterminated escape sequence', start, 'SANSA_UNTERMINATED_ESCAPE');
|
|
@@ -8539,6 +9389,11 @@ function readQuotedPayloadEscape(source, start) {
|
|
|
8539
9389
|
}
|
|
8540
9390
|
}
|
|
8541
9391
|
|
|
9392
|
+
function readSymbolPayloadEscape(source, start) {
|
|
9393
|
+
if (source[start + 1] === '|') return { value: '|', end: start + 2 };
|
|
9394
|
+
return readQuotedPayloadEscape(source, start);
|
|
9395
|
+
}
|
|
9396
|
+
|
|
8542
9397
|
function readUnicodePayloadEscape(source, start) {
|
|
8543
9398
|
let cursor = start + 2;
|
|
8544
9399
|
if (source[cursor] === '{') {
|
|
@@ -8655,3 +9510,37 @@ function quotePayload(value) {
|
|
|
8655
9510
|
output += '"';
|
|
8656
9511
|
return output;
|
|
8657
9512
|
}
|
|
9513
|
+
|
|
9514
|
+
function symbolPayload(value) {
|
|
9515
|
+
let output = '|';
|
|
9516
|
+
for (const char of value) {
|
|
9517
|
+
switch (char) {
|
|
9518
|
+
case '\\':
|
|
9519
|
+
output += '\\\\';
|
|
9520
|
+
break;
|
|
9521
|
+
case '|':
|
|
9522
|
+
output += '\\|';
|
|
9523
|
+
break;
|
|
9524
|
+
case '\n':
|
|
9525
|
+
output += '\\n';
|
|
9526
|
+
break;
|
|
9527
|
+
case '\r':
|
|
9528
|
+
output += '\\r';
|
|
9529
|
+
break;
|
|
9530
|
+
case '\t':
|
|
9531
|
+
output += '\\t';
|
|
9532
|
+
break;
|
|
9533
|
+
case '\b':
|
|
9534
|
+
output += '\\b';
|
|
9535
|
+
break;
|
|
9536
|
+
case '\f':
|
|
9537
|
+
output += '\\f';
|
|
9538
|
+
break;
|
|
9539
|
+
default:
|
|
9540
|
+
output += char;
|
|
9541
|
+
break;
|
|
9542
|
+
}
|
|
9543
|
+
}
|
|
9544
|
+
output += '|';
|
|
9545
|
+
return output;
|
|
9546
|
+
}
|