@altopelago/sansa 0.11.1 → 0.13.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 +94 -0
- package/CONTRIBUTING.md +1 -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 +69 -17
- package/fixtures/query-inventory.aeon +7 -0
- package/fixtures/query-inventory.telex.aes +5 -0
- package/package.json +3 -2
- package/scripts/cts-value-semantics.mjs +1 -1
- package/scripts/query.mjs +17 -0
- package/scripts/version.mjs +54 -3
- package/src/index.d.ts +79 -4
- package/src/index.js +952 -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;
|
|
@@ -4172,6 +4355,9 @@ function consumeFallbackOperand(value, namespace) {
|
|
|
4172
4355
|
};
|
|
4173
4356
|
}
|
|
4174
4357
|
const scalar = getBindingScalarValue(namespace, value.bindings[0]);
|
|
4358
|
+
if (!scalar.ok && scalar.error.code === 'SANSA_QUERY_EVALUATE_MISSING_SCALAR') {
|
|
4359
|
+
return { ok: false, missing: true };
|
|
4360
|
+
}
|
|
4175
4361
|
if (!scalar.ok) return scalar;
|
|
4176
4362
|
return scalarQueryValue(scalar.value, scalar.metadata);
|
|
4177
4363
|
}
|
|
@@ -4213,10 +4399,11 @@ function evaluateResolveChildExpression(expression, currentBinding, namespace, o
|
|
|
4213
4399
|
if (!keyScalar.ok) return keyScalar;
|
|
4214
4400
|
|
|
4215
4401
|
let bindings;
|
|
4216
|
-
|
|
4402
|
+
const numericPosition = queryScalarPosition(keyScalar);
|
|
4403
|
+
if (numericPosition !== null) {
|
|
4404
|
+
bindings = selectPosition(namespace, base.value.bindings[0], numericPosition);
|
|
4405
|
+
} else if (isStringQueryScalar(keyScalar)) {
|
|
4217
4406
|
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
4407
|
} else {
|
|
4221
4408
|
return {
|
|
4222
4409
|
ok: false,
|
|
@@ -4389,7 +4576,7 @@ function evaluateFieldsFromExpression(expression, currentBinding, namespace, opt
|
|
|
4389
4576
|
if (!evaluated.ok) return evaluated;
|
|
4390
4577
|
const scalar = expectScalarQueryValue(evaluated.value, namespace);
|
|
4391
4578
|
if (!scalar.ok) return scalar;
|
|
4392
|
-
if (
|
|
4579
|
+
if (!isStringQueryScalar(scalar)) {
|
|
4393
4580
|
return {
|
|
4394
4581
|
ok: false,
|
|
4395
4582
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'fieldsFrom' expects string field names"),
|
|
@@ -4426,7 +4613,7 @@ function objectFromBindingSets(keyBindings, valueBindings, namespace, functionNa
|
|
|
4426
4613
|
for (let index = 0; index < keyBindings.length; index += 1) {
|
|
4427
4614
|
const keyScalar = getBindingScalarValue(namespace, keyBindings[index]);
|
|
4428
4615
|
if (!keyScalar.ok) return keyScalar;
|
|
4429
|
-
if (
|
|
4616
|
+
if (!isStringQueryScalar(keyScalar)) {
|
|
4430
4617
|
return {
|
|
4431
4618
|
ok: false,
|
|
4432
4619
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', `Function '${functionName}' expects string key bindings`),
|
|
@@ -4500,7 +4687,7 @@ function evaluateSpecialValuePredicate(expression, currentBinding, namespace, op
|
|
|
4500
4687
|
if (!reason.ok) return reason;
|
|
4501
4688
|
const scalarReason = expectScalarQueryValue(reason.value, namespace);
|
|
4502
4689
|
if (!scalarReason.ok) return scalarReason;
|
|
4503
|
-
if (
|
|
4690
|
+
if (!isStringQueryScalar(scalarReason)) {
|
|
4504
4691
|
return {
|
|
4505
4692
|
ok: false,
|
|
4506
4693
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', "Function 'isNullReason' expects a string reason"),
|
|
@@ -4614,6 +4801,8 @@ function scalarBoolean(value) {
|
|
|
4614
4801
|
|
|
4615
4802
|
function queryLiteralMetadata(expression) {
|
|
4616
4803
|
switch (expression.kind) {
|
|
4804
|
+
case 'number':
|
|
4805
|
+
return { kind: 'number', category: 'finiteNumber', numericLexeme: expression.canonical };
|
|
4617
4806
|
case 'toggle':
|
|
4618
4807
|
return { kind: 'toggle', category: 'toggle' };
|
|
4619
4808
|
case 'hex':
|
|
@@ -4624,6 +4813,8 @@ function queryLiteralMetadata(expression) {
|
|
|
4624
4813
|
return { kind: 'encoding', category: 'encoding' };
|
|
4625
4814
|
case 'separator':
|
|
4626
4815
|
return { kind: 'separator', category: 'separator' };
|
|
4816
|
+
case 'symbol':
|
|
4817
|
+
return { kind: 'symbol', category: 'symbol' };
|
|
4627
4818
|
case 'date':
|
|
4628
4819
|
case 'time':
|
|
4629
4820
|
case 'datetime':
|
|
@@ -4660,7 +4851,7 @@ function evaluateStringFunction(name, args, arity, operation) {
|
|
|
4660
4851
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', `Function '${name}' expects ${arity} argument${arity === 1 ? '' : 's'}`),
|
|
4661
4852
|
};
|
|
4662
4853
|
}
|
|
4663
|
-
if (args.some((arg) =>
|
|
4854
|
+
if (args.some((arg) => !isStringQueryScalar(arg))) {
|
|
4664
4855
|
return {
|
|
4665
4856
|
ok: false,
|
|
4666
4857
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_INVALID_FUNCTION_CALL', `Function '${name}' expects string arguments`),
|
|
@@ -4670,11 +4861,43 @@ function evaluateStringFunction(name, args, arity, operation) {
|
|
|
4670
4861
|
ok: true,
|
|
4671
4862
|
value: {
|
|
4672
4863
|
type: 'scalar',
|
|
4673
|
-
value: operation(args),
|
|
4864
|
+
value: operation(args.map((arg) => arg.value)),
|
|
4674
4865
|
},
|
|
4675
4866
|
};
|
|
4676
4867
|
}
|
|
4677
4868
|
|
|
4869
|
+
function isStringQueryScalar(scalar) {
|
|
4870
|
+
if (typeof scalar.value !== 'string' || scalar.metadata?.numericLexeme !== undefined) return false;
|
|
4871
|
+
const info = queryScalarToInfo(scalar);
|
|
4872
|
+
const category = normalizeValueSemanticsCategory(info.category ?? info.kind);
|
|
4873
|
+
return category === undefined || category === 'string' || category === 'stringLiteral';
|
|
4874
|
+
}
|
|
4875
|
+
|
|
4876
|
+
function queryScalarPosition(scalar) {
|
|
4877
|
+
const numericLexeme = scalar.metadata?.numericLexeme;
|
|
4878
|
+
if (typeof numericLexeme === 'string') {
|
|
4879
|
+
const parsed = parseExactFiniteNumber(numericLexeme);
|
|
4880
|
+
if (parsed === null || parsed.sign < 0) return null;
|
|
4881
|
+
if (parsed.sign === 0) return 0;
|
|
4882
|
+
|
|
4883
|
+
let integerDigits = parsed.digits;
|
|
4884
|
+
if (parsed.scale < 0n) {
|
|
4885
|
+
const fractionalWidth = -parsed.scale;
|
|
4886
|
+
if (fractionalWidth > BigInt(integerDigits.length)) return null;
|
|
4887
|
+
const split = integerDigits.length - Number(fractionalWidth);
|
|
4888
|
+
if (!/^0*$/u.test(integerDigits.slice(split))) return null;
|
|
4889
|
+
integerDigits = integerDigits.slice(0, split) || '0';
|
|
4890
|
+
} else {
|
|
4891
|
+
if (BigInt(integerDigits.length) + parsed.scale > 16n) return null;
|
|
4892
|
+
integerDigits += '0'.repeat(Number(parsed.scale));
|
|
4893
|
+
}
|
|
4894
|
+
|
|
4895
|
+
const value = Number(integerDigits);
|
|
4896
|
+
return Number.isSafeInteger(value) ? value : null;
|
|
4897
|
+
}
|
|
4898
|
+
return Number.isSafeInteger(scalar.value) && scalar.value >= 0 ? scalar.value : null;
|
|
4899
|
+
}
|
|
4900
|
+
|
|
4678
4901
|
function evaluateExistenceExpression(expression, currentBinding, namespace, options) {
|
|
4679
4902
|
const resolution = unwrapResolutionExpression(expression.argument);
|
|
4680
4903
|
if (!resolution) {
|
|
@@ -4822,7 +5045,7 @@ function evaluateCardinalityFunctionBooleans(expression, currentBinding, namespa
|
|
|
4822
5045
|
}
|
|
4823
5046
|
const scalar = expectScalarQueryValue(evaluatedArgs[index], namespace);
|
|
4824
5047
|
if (!scalar.ok) return scalar;
|
|
4825
|
-
scalarArgs.push(scalar
|
|
5048
|
+
scalarArgs.push(scalar);
|
|
4826
5049
|
}
|
|
4827
5050
|
|
|
4828
5051
|
const values = [];
|
|
@@ -4830,7 +5053,7 @@ function evaluateCardinalityFunctionBooleans(expression, currentBinding, namespa
|
|
|
4830
5053
|
const bindingScalar = getBindingScalarValue(namespace, binding);
|
|
4831
5054
|
if (!bindingScalar.ok) return bindingScalar;
|
|
4832
5055
|
const args = scalarArgs.slice();
|
|
4833
|
-
args[bindingSetArgs[0].index] = bindingScalar
|
|
5056
|
+
args[bindingSetArgs[0].index] = bindingScalar;
|
|
4834
5057
|
const evaluated = evaluateOrdinaryFunction(expression.name, args);
|
|
4835
5058
|
if (!evaluated.ok) return evaluated;
|
|
4836
5059
|
if (evaluated.value.type !== 'scalar' || typeof evaluated.value.value !== 'boolean') {
|
|
@@ -4981,6 +5204,12 @@ function getValueSemanticsProfile(valueSemantics) {
|
|
|
4981
5204
|
if (valueSemantics === NATURAL_ASCII_STRING_PROFILE_ID || valueSemantics === 'natural-ascii') {
|
|
4982
5205
|
return createNaturalAsciiValueSemanticsProfile();
|
|
4983
5206
|
}
|
|
5207
|
+
if (valueSemantics === RADIX_NUMERIC_SAME_BASE_PROFILE_ID || valueSemantics === 'radix-numeric') {
|
|
5208
|
+
return createRadixNumericValueSemanticsProfile();
|
|
5209
|
+
}
|
|
5210
|
+
if (valueSemantics === RADIX_NUMERIC_CROSS_BASE_PROFILE_ID || valueSemantics === 'radix-numeric-cross-base') {
|
|
5211
|
+
return createCrossBaseRadixNumericValueSemanticsProfile();
|
|
5212
|
+
}
|
|
4984
5213
|
if (valueSemantics === 'fr' || valueSemantics === 'fr-FR') {
|
|
4985
5214
|
return createFrenchValueSemanticsProfile({ locale: valueSemantics });
|
|
4986
5215
|
}
|
|
@@ -4992,6 +5221,7 @@ function getValueSemanticsProfile(valueSemantics) {
|
|
|
4992
5221
|
const hasLowerString = typeof valueSemantics.lowerString === 'function';
|
|
4993
5222
|
const hasUpperString = typeof valueSemantics.upperString === 'function';
|
|
4994
5223
|
const hasCompareTemporal = typeof valueSemantics.compareTemporal === 'function';
|
|
5224
|
+
const hasCompareRadix = typeof valueSemantics.compareRadix === 'function';
|
|
4995
5225
|
if (hasCompareStrings && hasLowerString && hasUpperString) {
|
|
4996
5226
|
return {
|
|
4997
5227
|
...aeonValueSemanticsDefaultProfile,
|
|
@@ -5000,16 +5230,24 @@ function getValueSemanticsProfile(valueSemantics) {
|
|
|
5000
5230
|
compareTemporal: typeof valueSemantics.compareTemporal === 'function'
|
|
5001
5231
|
? (left, right) => normalizeComparison(valueSemantics.compareTemporal(left, right))
|
|
5002
5232
|
: aeonValueSemanticsDefaultProfile.compareTemporal,
|
|
5233
|
+
...(hasCompareRadix ? {
|
|
5234
|
+
compareRadix: (left, right) => normalizeOptionalComparison(valueSemantics.compareRadix(left, right)),
|
|
5235
|
+
} : {}),
|
|
5003
5236
|
};
|
|
5004
5237
|
}
|
|
5005
5238
|
if (hasCompareStrings || hasLowerString || hasUpperString) {
|
|
5006
5239
|
throw new Error('Custom value-semantics profiles must define compareStrings, lowerString, and upperString together.');
|
|
5007
5240
|
}
|
|
5008
|
-
if (hasCompareTemporal) {
|
|
5241
|
+
if (hasCompareTemporal || hasCompareRadix) {
|
|
5009
5242
|
return {
|
|
5010
5243
|
...aeonValueSemanticsDefaultProfile,
|
|
5011
5244
|
...valueSemantics,
|
|
5012
|
-
compareTemporal:
|
|
5245
|
+
compareTemporal: hasCompareTemporal
|
|
5246
|
+
? (left, right) => normalizeComparison(valueSemantics.compareTemporal(left, right))
|
|
5247
|
+
: aeonValueSemanticsDefaultProfile.compareTemporal,
|
|
5248
|
+
...(hasCompareRadix ? {
|
|
5249
|
+
compareRadix: (left, right) => normalizeOptionalComparison(valueSemantics.compareRadix(left, right)),
|
|
5250
|
+
} : {}),
|
|
5013
5251
|
};
|
|
5014
5252
|
}
|
|
5015
5253
|
if (
|
|
@@ -5026,6 +5264,10 @@ function normalizeComparison(value) {
|
|
|
5026
5264
|
return 0;
|
|
5027
5265
|
}
|
|
5028
5266
|
|
|
5267
|
+
function normalizeOptionalComparison(value) {
|
|
5268
|
+
return value === null || value === undefined ? null : normalizeComparison(value);
|
|
5269
|
+
}
|
|
5270
|
+
|
|
5029
5271
|
function compareStringsByUnicodeScalarValue(left, right) {
|
|
5030
5272
|
const leftScalars = Array.from(left);
|
|
5031
5273
|
const rightScalars = Array.from(right);
|
|
@@ -5090,6 +5332,197 @@ function compareTemporalByCanonicalValue(left, right) {
|
|
|
5090
5332
|
return compareStringsByUnicodeScalarValue(String(left.payload ?? ''), String(right.payload ?? ''));
|
|
5091
5333
|
}
|
|
5092
5334
|
|
|
5335
|
+
/**
|
|
5336
|
+
* Compare two temporal claims as completion sets without resolving external
|
|
5337
|
+
* timezone, leap-second, calendar, or clock authorities.
|
|
5338
|
+
*
|
|
5339
|
+
* @returns {'equal'|'before'|'after'|'contains'|'containedBy'|'overlaps'|'incomparable'}
|
|
5340
|
+
*/
|
|
5341
|
+
export function compareTemporalClaims(left, right) {
|
|
5342
|
+
const leftClaim = parseTemporalCompletionSet(left);
|
|
5343
|
+
const rightClaim = parseTemporalCompletionSet(right);
|
|
5344
|
+
if (leftClaim === null || rightClaim === null || leftClaim.domain !== rightClaim.domain) {
|
|
5345
|
+
return 'incomparable';
|
|
5346
|
+
}
|
|
5347
|
+
|
|
5348
|
+
// UTC leap-second chronology requires a leap table. Preserve exact identity,
|
|
5349
|
+
// but do not manufacture an ordering around second 60 without that authority.
|
|
5350
|
+
if (leftClaim.leapSecond || rightClaim.leapSecond) {
|
|
5351
|
+
return leftClaim.leapSecond
|
|
5352
|
+
&& rightClaim.leapSecond
|
|
5353
|
+
&& compareTemporalDecimal(leftClaim.start, rightClaim.start) === 0
|
|
5354
|
+
? 'equal'
|
|
5355
|
+
: 'incomparable';
|
|
5356
|
+
}
|
|
5357
|
+
|
|
5358
|
+
const startOrder = compareTemporalDecimal(leftClaim.start, rightClaim.start);
|
|
5359
|
+
if (leftClaim.point && rightClaim.point) {
|
|
5360
|
+
return startOrder < 0 ? 'before' : startOrder > 0 ? 'after' : 'equal';
|
|
5361
|
+
}
|
|
5362
|
+
if (leftClaim.point) {
|
|
5363
|
+
if (startOrder < 0) return 'before';
|
|
5364
|
+
if (compareTemporalDecimal(leftClaim.start, rightClaim.end) >= 0) return 'after';
|
|
5365
|
+
return 'containedBy';
|
|
5366
|
+
}
|
|
5367
|
+
if (rightClaim.point) {
|
|
5368
|
+
if (compareTemporalDecimal(leftClaim.end, rightClaim.start) <= 0) return 'before';
|
|
5369
|
+
if (startOrder > 0) return 'after';
|
|
5370
|
+
return 'contains';
|
|
5371
|
+
}
|
|
5372
|
+
|
|
5373
|
+
const endOrder = compareTemporalDecimal(leftClaim.end, rightClaim.end);
|
|
5374
|
+
if (startOrder === 0 && endOrder === 0) return 'equal';
|
|
5375
|
+
if (compareTemporalDecimal(leftClaim.end, rightClaim.start) <= 0) return 'before';
|
|
5376
|
+
if (compareTemporalDecimal(rightClaim.end, leftClaim.start) <= 0) return 'after';
|
|
5377
|
+
if (startOrder <= 0 && endOrder >= 0) return 'contains';
|
|
5378
|
+
if (startOrder >= 0 && endOrder <= 0) return 'containedBy';
|
|
5379
|
+
return 'overlaps';
|
|
5380
|
+
}
|
|
5381
|
+
|
|
5382
|
+
function parseTemporalCompletionSet(input) {
|
|
5383
|
+
const semanticType = String(input?.semanticType ?? 'temporal');
|
|
5384
|
+
const payload = String(input?.payload ?? input?.value ?? '');
|
|
5385
|
+
if (semanticType === 'date') {
|
|
5386
|
+
const date = parseTemporalDate(payload);
|
|
5387
|
+
if (date === null) return null;
|
|
5388
|
+
const startMonth = date.month ?? 1;
|
|
5389
|
+
const startDay = date.day ?? 1;
|
|
5390
|
+
const start = temporalInteger(dateOrdinal(date.year, startMonth, startDay) * 86_400n);
|
|
5391
|
+
let endOrdinal;
|
|
5392
|
+
if (date.month === null) {
|
|
5393
|
+
endOrdinal = dateOrdinal(date.year + 1, 1, 1);
|
|
5394
|
+
} else if (date.day === null) {
|
|
5395
|
+
endOrdinal = date.month === 12
|
|
5396
|
+
? dateOrdinal(date.year + 1, 1, 1)
|
|
5397
|
+
: dateOrdinal(date.year, date.month + 1, 1);
|
|
5398
|
+
} else {
|
|
5399
|
+
endOrdinal = dateOrdinal(date.year, date.month, date.day) + 1n;
|
|
5400
|
+
}
|
|
5401
|
+
const end = temporalInteger(endOrdinal * 86_400n);
|
|
5402
|
+
return { domain: 'date', start, end, point: false, leapSecond: false };
|
|
5403
|
+
}
|
|
5404
|
+
if (!['time', 'datetime', 'wtc'].includes(semanticType)) return null;
|
|
5405
|
+
|
|
5406
|
+
let base = payload;
|
|
5407
|
+
let context = null;
|
|
5408
|
+
if (semanticType === 'wtc') {
|
|
5409
|
+
const ampersand = payload.indexOf('&');
|
|
5410
|
+
if (ampersand === -1) return null;
|
|
5411
|
+
base = payload.slice(0, ampersand);
|
|
5412
|
+
context = payload.slice(ampersand + 1);
|
|
5413
|
+
if (context.length === 0) return null;
|
|
5414
|
+
}
|
|
5415
|
+
|
|
5416
|
+
let date = null;
|
|
5417
|
+
let clockText = base;
|
|
5418
|
+
if (semanticType !== 'time') {
|
|
5419
|
+
const marker = base.indexOf('T');
|
|
5420
|
+
if (marker === -1) return null;
|
|
5421
|
+
date = parseTemporalDate(base.slice(0, marker));
|
|
5422
|
+
if (date === null) return null;
|
|
5423
|
+
clockText = base.slice(marker + 1);
|
|
5424
|
+
}
|
|
5425
|
+
const clock = parseTemporalClock(clockText, semanticType === 'time');
|
|
5426
|
+
if (clock === null) return null;
|
|
5427
|
+
const domain = temporalCompletionDomain(semanticType, clock.anchor, context);
|
|
5428
|
+
if (domain === null) return null;
|
|
5429
|
+
|
|
5430
|
+
let wholeSeconds = BigInt(clock.hour * 3_600 + (clock.minute ?? 0) * 60 + (clock.second ?? 0));
|
|
5431
|
+
if (date !== null) wholeSeconds += dateOrdinal(date.year, date.month, date.day) * 86_400n;
|
|
5432
|
+
if (clock.anchor === 'Z') {
|
|
5433
|
+
// already UTC-relative
|
|
5434
|
+
} else if (clock.anchor !== null && clock.anchor !== '-00:00') {
|
|
5435
|
+
const sign = clock.anchor[0] === '-' ? -1n : 1n;
|
|
5436
|
+
const offset = BigInt(Number(clock.anchor.slice(1, 3)) * 3_600 + Number(clock.anchor.slice(4, 6)) * 60);
|
|
5437
|
+
wholeSeconds -= sign * offset;
|
|
5438
|
+
}
|
|
5439
|
+
|
|
5440
|
+
const start = clock.fraction === null
|
|
5441
|
+
? temporalInteger(wholeSeconds)
|
|
5442
|
+
: { coefficient: wholeSeconds * (10n ** BigInt(clock.fraction.length)) + BigInt(clock.fraction), scale: clock.fraction.length };
|
|
5443
|
+
if (clock.second !== null) {
|
|
5444
|
+
return { domain, start, end: start, point: true, leapSecond: clock.second === 60 };
|
|
5445
|
+
}
|
|
5446
|
+
const width = clock.minute === null ? 3_600n : 60n;
|
|
5447
|
+
return { domain, start, end: addTemporalInteger(start, width), point: false, leapSecond: false };
|
|
5448
|
+
}
|
|
5449
|
+
|
|
5450
|
+
function temporalCompletionDomain(semanticType, anchor, context) {
|
|
5451
|
+
const scope = semanticType === 'time' ? 'time' : 'datetime';
|
|
5452
|
+
const recognizedTimescales = new Set(['UTC', 'TAI', 'UT1', 'TT', 'GPS']);
|
|
5453
|
+
if (context !== null && recognizedTimescales.has(context) && anchor !== null) {
|
|
5454
|
+
if (context !== 'UTC') return null;
|
|
5455
|
+
}
|
|
5456
|
+
if (scope === 'time' && anchor !== null && anchor !== '-00:00') {
|
|
5457
|
+
return anchor === 'Z' || anchor === '+00:00' ? 'instant:time:UTC' : `offset-time:${anchor}`;
|
|
5458
|
+
}
|
|
5459
|
+
if (anchor === 'Z' || (anchor !== null && anchor !== '-00:00')) return 'instant:datetime';
|
|
5460
|
+
if (anchor === '-00:00') return `unknown-offset:${scope}:${context ?? ''}`;
|
|
5461
|
+
if (context === 'local') return `resolver-local:${scope}`;
|
|
5462
|
+
if (context !== null && recognizedTimescales.has(context)) return `timescale:${context}:${scope}`;
|
|
5463
|
+
if (context !== null) return `context:${context}:${scope}`;
|
|
5464
|
+
return `civil:${scope}`;
|
|
5465
|
+
}
|
|
5466
|
+
|
|
5467
|
+
function parseTemporalDate(value) {
|
|
5468
|
+
const yearOnly = /^(\d{4})-$/.exec(value);
|
|
5469
|
+
if (yearOnly !== null) {
|
|
5470
|
+
const year = Number(yearOnly[1]);
|
|
5471
|
+
return year >= 1 && year <= 9999 ? { year, month: null, day: null } : null;
|
|
5472
|
+
}
|
|
5473
|
+
const yearMonth = /^(\d{4})-(\d{2})$/.exec(value);
|
|
5474
|
+
if (yearMonth !== null) {
|
|
5475
|
+
const year = Number(yearMonth[1]);
|
|
5476
|
+
const month = Number(yearMonth[2]);
|
|
5477
|
+
return year >= 1 && year <= 9999 && month >= 1 && month <= 12
|
|
5478
|
+
? { year, month, day: null }
|
|
5479
|
+
: null;
|
|
5480
|
+
}
|
|
5481
|
+
const fullDate = /^(\d{4})-(\d{2})-(\d{2})$/.exec(value);
|
|
5482
|
+
if (fullDate === null || !isValidDateParts(fullDate[1], fullDate[2], fullDate[3])) return null;
|
|
5483
|
+
return { year: Number(fullDate[1]), month: Number(fullDate[2]), day: Number(fullDate[3]) };
|
|
5484
|
+
}
|
|
5485
|
+
|
|
5486
|
+
function parseTemporalClock(value, requireColon) {
|
|
5487
|
+
const pattern = requireColon
|
|
5488
|
+
? /^(\d{2}):(?:(\d{2}))?(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?$/
|
|
5489
|
+
: /^(\d{2})(?::(\d{2})?)?(?::(\d{2})(?:\.(\d+))?)?(Z|[+-]\d{2}:\d{2})?$/;
|
|
5490
|
+
const match = pattern.exec(value);
|
|
5491
|
+
if (match === null) return null;
|
|
5492
|
+
const hour = Number(match[1]);
|
|
5493
|
+
const minute = match[2] === undefined ? null : Number(match[2]);
|
|
5494
|
+
const second = match[3] === undefined ? null : Number(match[3]);
|
|
5495
|
+
const anchor = match[5] ?? null;
|
|
5496
|
+
if (hour > 23 || (minute !== null && minute > 59) || (second !== null && second > 60)) return null;
|
|
5497
|
+
if (anchor !== null && anchor !== 'Z') {
|
|
5498
|
+
if (Number(anchor.slice(1, 3)) > 23 || Number(anchor.slice(4, 6)) > 59) return null;
|
|
5499
|
+
}
|
|
5500
|
+
return { hour, minute, second, fraction: match[4] ?? null, anchor };
|
|
5501
|
+
}
|
|
5502
|
+
|
|
5503
|
+
function dateOrdinal(year, month, day) {
|
|
5504
|
+
const priorYear = BigInt(year - 1);
|
|
5505
|
+
const daysBeforeYear = priorYear * 365n + priorYear / 4n - priorYear / 100n + priorYear / 400n;
|
|
5506
|
+
const monthDays = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334];
|
|
5507
|
+
const leapAdjustment = month > 2 && isLeapYear(year) ? 1 : 0;
|
|
5508
|
+
return daysBeforeYear + BigInt(monthDays[month - 1] + leapAdjustment + day - 1);
|
|
5509
|
+
}
|
|
5510
|
+
|
|
5511
|
+
function temporalInteger(value) {
|
|
5512
|
+
return { coefficient: value, scale: 0 };
|
|
5513
|
+
}
|
|
5514
|
+
|
|
5515
|
+
function addTemporalInteger(value, integer) {
|
|
5516
|
+
return { coefficient: value.coefficient + integer * (10n ** BigInt(value.scale)), scale: value.scale };
|
|
5517
|
+
}
|
|
5518
|
+
|
|
5519
|
+
function compareTemporalDecimal(left, right) {
|
|
5520
|
+
const scale = Math.max(left.scale, right.scale);
|
|
5521
|
+
const leftCoefficient = left.coefficient * (10n ** BigInt(scale - left.scale));
|
|
5522
|
+
const rightCoefficient = right.coefficient * (10n ** BigInt(scale - right.scale));
|
|
5523
|
+
return leftCoefficient < rightCoefficient ? -1 : leftCoefficient > rightCoefficient ? 1 : 0;
|
|
5524
|
+
}
|
|
5525
|
+
|
|
5093
5526
|
function isAsciiDigitCodePoint(codePoint) {
|
|
5094
5527
|
return codePoint >= 0x30 && codePoint <= 0x39;
|
|
5095
5528
|
}
|
|
@@ -5100,6 +5533,8 @@ function codePointWidth(codePoint) {
|
|
|
5100
5533
|
|
|
5101
5534
|
export function evaluateValueSemanticsOperation(operation, input = {}, options = {}) {
|
|
5102
5535
|
try {
|
|
5536
|
+
if (operation === 'radixScale') return evaluateValueSemanticsRadixScale(input.value);
|
|
5537
|
+
if (operation === 'temporalRelation') return evaluateValueSemanticsTemporalRelation(input.left, input.right);
|
|
5103
5538
|
const profile = getValueSemanticsProfile(options.valueSemantics ?? input.valueSemantics ?? input.profile);
|
|
5104
5539
|
switch (operation) {
|
|
5105
5540
|
case 'equal':
|
|
@@ -5124,6 +5559,31 @@ export function evaluateValueSemanticsOperation(operation, input = {}, options =
|
|
|
5124
5559
|
}
|
|
5125
5560
|
}
|
|
5126
5561
|
|
|
5562
|
+
function evaluateValueSemanticsTemporalRelation(leftDescriptor, rightDescriptor) {
|
|
5563
|
+
const left = valueDescriptorToScalarInfo(leftDescriptor);
|
|
5564
|
+
const right = valueDescriptorToScalarInfo(rightDescriptor);
|
|
5565
|
+
if (left.category !== 'temporal' || right.category !== 'temporal') {
|
|
5566
|
+
return valueSemanticsDiagnostic('temporal_required', 'Temporal relation is defined only for temporal values');
|
|
5567
|
+
}
|
|
5568
|
+
return {
|
|
5569
|
+
ok: true,
|
|
5570
|
+
outcome: 'value',
|
|
5571
|
+
relation: compareTemporalClaims(left.value, right.value),
|
|
5572
|
+
};
|
|
5573
|
+
}
|
|
5574
|
+
|
|
5575
|
+
function evaluateValueSemanticsRadixScale(descriptor) {
|
|
5576
|
+
const info = valueDescriptorToScalarInfo(descriptor);
|
|
5577
|
+
if (info.category !== 'radix') {
|
|
5578
|
+
return valueSemanticsDiagnostic('radix_required', 'Radix scale is defined only for radix-family values');
|
|
5579
|
+
}
|
|
5580
|
+
const scale = radixScaleOf(info.value.payload, info.value.radixBase);
|
|
5581
|
+
if (scale === null || scale === undefined) {
|
|
5582
|
+
return valueSemanticsDiagnostic('invalid_radix_value', 'Radix payload is invalid for its resolved base');
|
|
5583
|
+
}
|
|
5584
|
+
return { ok: true, outcome: 'value', value: scale };
|
|
5585
|
+
}
|
|
5586
|
+
|
|
5127
5587
|
function evaluateValueSemanticsEquality(operation, leftDescriptor, rightDescriptor, profile) {
|
|
5128
5588
|
const left = valueDescriptorToScalarInfo(leftDescriptor);
|
|
5129
5589
|
const right = valueDescriptorToScalarInfo(rightDescriptor);
|
|
@@ -5133,6 +5593,12 @@ function evaluateValueSemanticsEquality(operation, leftDescriptor, rightDescript
|
|
|
5133
5593
|
if (left.category === 'missing' || right.category === 'missing' || left.category === 'bindingSet' || right.category === 'bindingSet') {
|
|
5134
5594
|
return valueSemanticsDiagnostic('not_equality_comparable', 'Evaluation state or non-scalar value is not equality-comparable');
|
|
5135
5595
|
}
|
|
5596
|
+
if (left.category === 'radix' && right.category === 'radix' && typeof profile.compareRadix === 'function') {
|
|
5597
|
+
const comparison = compareRadixWithProfile(left, right, profile);
|
|
5598
|
+
if (!comparison.ok) return comparison.diagnostic;
|
|
5599
|
+
const value = comparison.value === 0;
|
|
5600
|
+
return { ok: true, outcome: 'value', value: operation === 'equal' ? value : !value };
|
|
5601
|
+
}
|
|
5136
5602
|
if (!sameMinimumEqualityDomain(left, right)) {
|
|
5137
5603
|
return valueSemanticsDiagnostic('mixed_categories', 'Mixed categories do not compare by implicit coercion');
|
|
5138
5604
|
}
|
|
@@ -5156,7 +5622,19 @@ function evaluateValueSemanticsOrdering(leftDescriptor, rightDescriptor, profile
|
|
|
5156
5622
|
if (typeof left.value === 'boolean' && typeof right.value === 'boolean') {
|
|
5157
5623
|
return valueSemanticsDiagnostic('not_orderable', 'Boolean ordering is not part of the minimum profile');
|
|
5158
5624
|
}
|
|
5625
|
+
if (left.category === 'radix' && right.category === 'radix' && typeof profile.compareRadix === 'function') {
|
|
5626
|
+
const comparison = compareRadixWithProfile(left, right, profile);
|
|
5627
|
+
if (!comparison.ok) return comparison.diagnostic;
|
|
5628
|
+
return {
|
|
5629
|
+
ok: true,
|
|
5630
|
+
outcome: 'value',
|
|
5631
|
+
relation: comparison.value < 0 ? 'less' : comparison.value > 0 ? 'greater' : 'equal',
|
|
5632
|
+
};
|
|
5633
|
+
}
|
|
5159
5634
|
if (!sameMinimumOrderingDomain(left, right)) {
|
|
5635
|
+
if (left.category === right.category && left.category !== 'temporal') {
|
|
5636
|
+
return valueSemanticsDiagnostic('not_orderable', 'Value category is not orderable in the minimum profile');
|
|
5637
|
+
}
|
|
5160
5638
|
return valueSemanticsDiagnostic('mixed_categories', 'Mixed categories do not order by implicit coercion');
|
|
5161
5639
|
}
|
|
5162
5640
|
const comparison = compareMinimumOrdering(left, right, profile);
|
|
@@ -5173,8 +5651,10 @@ function valueDescriptorToScalarInfo(descriptor) {
|
|
|
5173
5651
|
}
|
|
5174
5652
|
switch (descriptor.category) {
|
|
5175
5653
|
case 'finiteNumber': {
|
|
5176
|
-
const value =
|
|
5177
|
-
if (
|
|
5654
|
+
const value = String(descriptor.value);
|
|
5655
|
+
if (parseExactFiniteNumber(value) === null) {
|
|
5656
|
+
throw new Error('finiteNumber descriptor must contain a canonical finite numeric value');
|
|
5657
|
+
}
|
|
5178
5658
|
return { category: 'finiteNumber', value };
|
|
5179
5659
|
}
|
|
5180
5660
|
case 'positiveInfinity':
|
|
@@ -5197,12 +5677,15 @@ function valueDescriptorToScalarInfo(descriptor) {
|
|
|
5197
5677
|
value: {
|
|
5198
5678
|
payload: String(descriptor.value ?? ''),
|
|
5199
5679
|
semanticType: descriptor.semanticType ?? 'radix',
|
|
5680
|
+
radixBase: normalizeRadixBase(descriptor.radixBase ?? radixBaseFromSemanticType(descriptor.semanticType)),
|
|
5200
5681
|
},
|
|
5201
5682
|
};
|
|
5202
5683
|
case 'encoding':
|
|
5203
5684
|
return { category: 'encoding', value: String(descriptor.value ?? '') };
|
|
5204
5685
|
case 'separator':
|
|
5205
5686
|
return { category: 'separator', value: String(descriptor.value ?? '') };
|
|
5687
|
+
case 'symbol':
|
|
5688
|
+
return { category: 'symbol', value: String(descriptor.value ?? '') };
|
|
5206
5689
|
case 'sansaAddress':
|
|
5207
5690
|
return { category: 'sansaAddress', value: sansaAddressSemanticValue(descriptor.value) };
|
|
5208
5691
|
case 'referenceForm':
|
|
@@ -5252,6 +5735,9 @@ function scalarInfoToValueDescriptor(info) {
|
|
|
5252
5735
|
? { category: 'negativeInfinity' }
|
|
5253
5736
|
: { category: 'positiveInfinity' };
|
|
5254
5737
|
}
|
|
5738
|
+
if (info.numericLexeme !== undefined) {
|
|
5739
|
+
return { category: 'finiteNumber', value: info.numericLexeme };
|
|
5740
|
+
}
|
|
5255
5741
|
const semanticCategory = VALUE_SEMANTICS_METADATA_CATEGORIES.includes(info.category)
|
|
5256
5742
|
? info.category
|
|
5257
5743
|
: VALUE_SEMANTICS_METADATA_CATEGORIES.includes(info.kind)
|
|
@@ -5263,6 +5749,8 @@ function scalarInfoToValueDescriptor(info) {
|
|
|
5263
5749
|
category,
|
|
5264
5750
|
value: info.value,
|
|
5265
5751
|
...(info.semanticType === undefined ? {} : { semanticType: info.semanticType }),
|
|
5752
|
+
...(info.radixBase === undefined ? {} : { radixBase: info.radixBase }),
|
|
5753
|
+
...(info.radixScale === undefined ? {} : { radixScale: info.radixScale }),
|
|
5266
5754
|
...(info.containerKind === undefined ? {} : { containerKind: info.containerKind }),
|
|
5267
5755
|
};
|
|
5268
5756
|
}
|
|
@@ -5306,6 +5794,7 @@ function sameMinimumEqualityDomain(left, right) {
|
|
|
5306
5794
|
'radix',
|
|
5307
5795
|
'encoding',
|
|
5308
5796
|
'separator',
|
|
5797
|
+
'symbol',
|
|
5309
5798
|
'sansaAddress',
|
|
5310
5799
|
'referenceForm',
|
|
5311
5800
|
].includes(left.category);
|
|
@@ -5335,7 +5824,8 @@ function temporalSemanticType(info) {
|
|
|
5335
5824
|
|
|
5336
5825
|
function compareMinimumEquality(operation, left, right, profile) {
|
|
5337
5826
|
if (isValueSemanticsNumeric(left) && isValueSemanticsNumeric(right)) {
|
|
5338
|
-
|
|
5827
|
+
const equals = compareMinimumNumeric(left, right) === 0;
|
|
5828
|
+
return operation === 'equal' ? equals : !equals;
|
|
5339
5829
|
}
|
|
5340
5830
|
const equals = (() => {
|
|
5341
5831
|
if (left.category === 'string' && right.category === 'string') return profile.compareStrings(left.value, right.value) === 0;
|
|
@@ -5347,6 +5837,9 @@ function compareMinimumEquality(operation, left, right, profile) {
|
|
|
5347
5837
|
}
|
|
5348
5838
|
|
|
5349
5839
|
function compareMinimumOrdering(left, right, profile) {
|
|
5840
|
+
if (isValueSemanticsNumeric(left) && isValueSemanticsNumeric(right)) {
|
|
5841
|
+
return compareMinimumNumeric(left, right);
|
|
5842
|
+
}
|
|
5350
5843
|
if (left.category === 'temporal' && right.category === 'temporal') {
|
|
5351
5844
|
return profile.compareTemporal(left.value, right.value);
|
|
5352
5845
|
}
|
|
@@ -5356,6 +5849,252 @@ function compareMinimumOrdering(left, right, profile) {
|
|
|
5356
5849
|
return comparePrimitiveOrderValues(left.value, right.value, profile);
|
|
5357
5850
|
}
|
|
5358
5851
|
|
|
5852
|
+
function compareMinimumNumeric(left, right) {
|
|
5853
|
+
if (left.category === right.category && left.category !== 'finiteNumber') return 0;
|
|
5854
|
+
if (left.category === 'negativeInfinity' || right.category === 'positiveInfinity') return -1;
|
|
5855
|
+
if (left.category === 'positiveInfinity' || right.category === 'negativeInfinity') return 1;
|
|
5856
|
+
const comparison = compareExactFiniteNumbers(left.value, right.value);
|
|
5857
|
+
if (comparison === null) throw new Error('Invalid finite numeric value reached comparison');
|
|
5858
|
+
return comparison;
|
|
5859
|
+
}
|
|
5860
|
+
|
|
5861
|
+
function compareExactFiniteNumbers(left, right) {
|
|
5862
|
+
const leftValue = parseExactFiniteNumber(String(left));
|
|
5863
|
+
const rightValue = parseExactFiniteNumber(String(right));
|
|
5864
|
+
if (leftValue === null || rightValue === null) return null;
|
|
5865
|
+
if (leftValue.sign !== rightValue.sign) return leftValue.sign < rightValue.sign ? -1 : 1;
|
|
5866
|
+
if (leftValue.sign === 0) return 0;
|
|
5867
|
+
|
|
5868
|
+
const leftOrder = BigInt(leftValue.digits.length) + leftValue.scale;
|
|
5869
|
+
const rightOrder = BigInt(rightValue.digits.length) + rightValue.scale;
|
|
5870
|
+
let comparison;
|
|
5871
|
+
if (leftOrder !== rightOrder) {
|
|
5872
|
+
comparison = leftOrder < rightOrder ? -1 : 1;
|
|
5873
|
+
} else {
|
|
5874
|
+
const width = Math.max(leftValue.digits.length, rightValue.digits.length);
|
|
5875
|
+
const leftDigits = leftValue.digits.padEnd(width, '0');
|
|
5876
|
+
const rightDigits = rightValue.digits.padEnd(width, '0');
|
|
5877
|
+
comparison = leftDigits === rightDigits ? 0 : leftDigits < rightDigits ? -1 : 1;
|
|
5878
|
+
}
|
|
5879
|
+
return leftValue.sign === -1 ? -comparison : comparison;
|
|
5880
|
+
}
|
|
5881
|
+
|
|
5882
|
+
function parseExactFiniteNumber(value) {
|
|
5883
|
+
if (value.length === 0 || value.length > MAX_EXACT_NUMERIC_CHARACTERS) return null;
|
|
5884
|
+
const match = /^([+-]?)(?:(0|[1-9]\d*)(?:\.(\d+))?|\.(\d+))(?:[eE]([+-]?\d+))?$/u.exec(value);
|
|
5885
|
+
if (match === null) return null;
|
|
5886
|
+
const integer = match[2] ?? '';
|
|
5887
|
+
const fraction = match[3] ?? match[4] ?? '';
|
|
5888
|
+
const digits = `${integer}${fraction}`.replace(/^0+/u, '');
|
|
5889
|
+
if (digits.length === 0) return { sign: 0, digits: '0', scale: 0n };
|
|
5890
|
+
return {
|
|
5891
|
+
sign: match[1] === '-' ? -1 : 1,
|
|
5892
|
+
digits,
|
|
5893
|
+
scale: BigInt(match[5] ?? '0') - BigInt(fraction.length),
|
|
5894
|
+
};
|
|
5895
|
+
}
|
|
5896
|
+
|
|
5897
|
+
function compareRadixWithProfile(left, right, profile) {
|
|
5898
|
+
const leftBase = left.value.radixBase;
|
|
5899
|
+
const rightBase = right.value.radixBase;
|
|
5900
|
+
const resolvedLeftBase = leftBase ?? rightBase;
|
|
5901
|
+
const resolvedRightBase = rightBase ?? leftBase;
|
|
5902
|
+
if (resolvedLeftBase === undefined || resolvedRightBase === undefined) {
|
|
5903
|
+
return {
|
|
5904
|
+
ok: false,
|
|
5905
|
+
diagnostic: valueSemanticsDiagnostic(
|
|
5906
|
+
'radix_base_required',
|
|
5907
|
+
'Radix numeric comparison requires at least one operand with a resolved base',
|
|
5908
|
+
),
|
|
5909
|
+
};
|
|
5910
|
+
}
|
|
5911
|
+
if (resolvedLeftBase !== resolvedRightBase && profile.radixComparison !== 'cross-base-exact') {
|
|
5912
|
+
return {
|
|
5913
|
+
ok: false,
|
|
5914
|
+
diagnostic: valueSemanticsDiagnostic(
|
|
5915
|
+
'mixed_radix_bases',
|
|
5916
|
+
`Radix numeric comparison requires the same base (${leftBase} vs ${rightBase})`,
|
|
5917
|
+
),
|
|
5918
|
+
};
|
|
5919
|
+
}
|
|
5920
|
+
|
|
5921
|
+
const value = profile.compareRadix(
|
|
5922
|
+
{ payload: left.value.payload, base: resolvedLeftBase, semanticType: left.value.semanticType },
|
|
5923
|
+
{ payload: right.value.payload, base: resolvedRightBase, semanticType: right.value.semanticType },
|
|
5924
|
+
);
|
|
5925
|
+
if (value === null) {
|
|
5926
|
+
return {
|
|
5927
|
+
ok: false,
|
|
5928
|
+
diagnostic: valueSemanticsDiagnostic(
|
|
5929
|
+
'invalid_radix_value',
|
|
5930
|
+
`Radix payload is invalid for base ${resolvedLeftBase} or ${resolvedRightBase}`,
|
|
5931
|
+
),
|
|
5932
|
+
};
|
|
5933
|
+
}
|
|
5934
|
+
return { ok: true, value: normalizeComparison(value) };
|
|
5935
|
+
}
|
|
5936
|
+
|
|
5937
|
+
function compareExactRadixSemanticValues(left, right) {
|
|
5938
|
+
if (left.base !== right.base) return null;
|
|
5939
|
+
return compareExactRadixValues(left.payload, right.payload, left.base);
|
|
5940
|
+
}
|
|
5941
|
+
|
|
5942
|
+
function compareExactCrossBaseRadixSemanticValues(left, right) {
|
|
5943
|
+
return compareExactCrossBaseRadixValues(left.payload, left.base, right.payload, right.base);
|
|
5944
|
+
}
|
|
5945
|
+
|
|
5946
|
+
function parseExactRadixValue(value, base) {
|
|
5947
|
+
if (!Number.isInteger(base) || base < 2 || base > 64) return null;
|
|
5948
|
+
if (value.length === 0 || value.length > MAX_EXACT_NUMERIC_CHARACTERS) return null;
|
|
5949
|
+
|
|
5950
|
+
let index = 0;
|
|
5951
|
+
let sign = 1;
|
|
5952
|
+
if (value[index] === '+' || value[index] === '-') {
|
|
5953
|
+
sign = value[index] === '-' ? -1 : 1;
|
|
5954
|
+
index += 1;
|
|
5955
|
+
}
|
|
5956
|
+
if (index >= value.length) return null;
|
|
5957
|
+
|
|
5958
|
+
const integerDigits = [];
|
|
5959
|
+
const fractionalDigits = [];
|
|
5960
|
+
let target = integerDigits;
|
|
5961
|
+
let sawPoint = false;
|
|
5962
|
+
let sawDigit = false;
|
|
5963
|
+
for (; index < value.length; index += 1) {
|
|
5964
|
+
const character = value[index];
|
|
5965
|
+
if (character === '.') {
|
|
5966
|
+
if (sawPoint || index === value.length - 1) return null;
|
|
5967
|
+
sawPoint = true;
|
|
5968
|
+
target = fractionalDigits;
|
|
5969
|
+
continue;
|
|
5970
|
+
}
|
|
5971
|
+
if (character === '_') {
|
|
5972
|
+
const previous = value[index - 1];
|
|
5973
|
+
const next = value[index + 1];
|
|
5974
|
+
if (radixDigitValue(previous) === null || radixDigitValue(next) === null) return null;
|
|
5975
|
+
continue;
|
|
5976
|
+
}
|
|
5977
|
+
const digit = radixDigitValue(character);
|
|
5978
|
+
if (digit === null || digit >= base) return null;
|
|
5979
|
+
target.push(digit);
|
|
5980
|
+
sawDigit = true;
|
|
5981
|
+
}
|
|
5982
|
+
if (!sawDigit || fractionalDigits.length === 0 && sawPoint) return null;
|
|
5983
|
+
|
|
5984
|
+
let leadingZeroes = 0;
|
|
5985
|
+
while (leadingZeroes < integerDigits.length && integerDigits[leadingZeroes] === 0) leadingZeroes += 1;
|
|
5986
|
+
if (leadingZeroes > 0) integerDigits.splice(0, leadingZeroes);
|
|
5987
|
+
while (fractionalDigits.length > 0 && fractionalDigits.at(-1) === 0) fractionalDigits.pop();
|
|
5988
|
+
if (integerDigits.length === 0 && fractionalDigits.length === 0) sign = 0;
|
|
5989
|
+
return { sign, integerDigits, fractionalDigits };
|
|
5990
|
+
}
|
|
5991
|
+
|
|
5992
|
+
function compareParsedRadixValues(left, right) {
|
|
5993
|
+
if (left.sign !== right.sign) return left.sign < right.sign ? -1 : 1;
|
|
5994
|
+
if (left.sign === 0) return 0;
|
|
5995
|
+
|
|
5996
|
+
let comparison = 0;
|
|
5997
|
+
if (left.integerDigits.length !== right.integerDigits.length) {
|
|
5998
|
+
comparison = left.integerDigits.length < right.integerDigits.length ? -1 : 1;
|
|
5999
|
+
} else {
|
|
6000
|
+
comparison = compareRadixDigitArrays(left.integerDigits, right.integerDigits);
|
|
6001
|
+
if (comparison === 0) {
|
|
6002
|
+
const width = Math.max(left.fractionalDigits.length, right.fractionalDigits.length);
|
|
6003
|
+
for (let index = 0; index < width; index += 1) {
|
|
6004
|
+
const leftDigit = left.fractionalDigits[index] ?? 0;
|
|
6005
|
+
const rightDigit = right.fractionalDigits[index] ?? 0;
|
|
6006
|
+
if (leftDigit !== rightDigit) {
|
|
6007
|
+
comparison = leftDigit < rightDigit ? -1 : 1;
|
|
6008
|
+
break;
|
|
6009
|
+
}
|
|
6010
|
+
}
|
|
6011
|
+
}
|
|
6012
|
+
}
|
|
6013
|
+
return left.sign === -1 ? -comparison : comparison;
|
|
6014
|
+
}
|
|
6015
|
+
|
|
6016
|
+
function compareParsedCrossBaseRadixValues(left, leftBase, right, rightBase) {
|
|
6017
|
+
if (left.sign !== right.sign) return left.sign < right.sign ? -1 : 1;
|
|
6018
|
+
if (left.sign === 0) return 0;
|
|
6019
|
+
|
|
6020
|
+
const leftNumerator = radixDigitsToBigInt(
|
|
6021
|
+
[...left.integerDigits, ...left.fractionalDigits],
|
|
6022
|
+
leftBase,
|
|
6023
|
+
);
|
|
6024
|
+
const rightNumerator = radixDigitsToBigInt(
|
|
6025
|
+
[...right.integerDigits, ...right.fractionalDigits],
|
|
6026
|
+
rightBase,
|
|
6027
|
+
);
|
|
6028
|
+
const leftDenominator = BigInt(leftBase) ** BigInt(left.fractionalDigits.length);
|
|
6029
|
+
const rightDenominator = BigInt(rightBase) ** BigInt(right.fractionalDigits.length);
|
|
6030
|
+
const leftScaled = leftNumerator * rightDenominator;
|
|
6031
|
+
const rightScaled = rightNumerator * leftDenominator;
|
|
6032
|
+
const comparison = leftScaled < rightScaled ? -1 : leftScaled > rightScaled ? 1 : 0;
|
|
6033
|
+
return left.sign === -1 ? -comparison : comparison;
|
|
6034
|
+
}
|
|
6035
|
+
|
|
6036
|
+
function radixDigitsToBigInt(digits, base) {
|
|
6037
|
+
if (digits.length === 0) return 0n;
|
|
6038
|
+
let chunkSize = 1;
|
|
6039
|
+
let fullChunkMultiplier = base;
|
|
6040
|
+
while (fullChunkMultiplier <= Math.floor(Number.MAX_SAFE_INTEGER / base)) {
|
|
6041
|
+
fullChunkMultiplier *= base;
|
|
6042
|
+
chunkSize += 1;
|
|
6043
|
+
}
|
|
6044
|
+
|
|
6045
|
+
let result = 0n;
|
|
6046
|
+
for (let offset = 0; offset < digits.length; offset += chunkSize) {
|
|
6047
|
+
const length = Math.min(chunkSize, digits.length - offset);
|
|
6048
|
+
let chunkValue = 0;
|
|
6049
|
+
let multiplier = 1;
|
|
6050
|
+
for (let index = 0; index < length; index += 1) {
|
|
6051
|
+
chunkValue = chunkValue * base + digits[offset + index];
|
|
6052
|
+
multiplier *= base;
|
|
6053
|
+
}
|
|
6054
|
+
result = result * BigInt(multiplier) + BigInt(chunkValue);
|
|
6055
|
+
}
|
|
6056
|
+
return result;
|
|
6057
|
+
}
|
|
6058
|
+
|
|
6059
|
+
function compareRadixDigitArrays(left, right) {
|
|
6060
|
+
for (let index = 0; index < left.length; index += 1) {
|
|
6061
|
+
if (left[index] < right[index]) return -1;
|
|
6062
|
+
if (left[index] > right[index]) return 1;
|
|
6063
|
+
}
|
|
6064
|
+
return 0;
|
|
6065
|
+
}
|
|
6066
|
+
|
|
6067
|
+
function radixDigitValue(character) {
|
|
6068
|
+
if (typeof character !== 'string') return null;
|
|
6069
|
+
const codePoint = character.codePointAt(0);
|
|
6070
|
+
if (codePoint >= 48 && codePoint <= 57) return codePoint - 48;
|
|
6071
|
+
if (codePoint >= 65 && codePoint <= 90) return codePoint - 55;
|
|
6072
|
+
if (codePoint >= 97 && codePoint <= 122) return codePoint - 61;
|
|
6073
|
+
if (character === '&') return 62;
|
|
6074
|
+
if (character === '!') return 63;
|
|
6075
|
+
return null;
|
|
6076
|
+
}
|
|
6077
|
+
|
|
6078
|
+
function normalizeRadixBase(value) {
|
|
6079
|
+
if (value === undefined || value === null) return undefined;
|
|
6080
|
+
if (!Number.isInteger(value) || value < 2 || value > 64) {
|
|
6081
|
+
throw new Error('radixBase must be an integer from 2 through 64');
|
|
6082
|
+
}
|
|
6083
|
+
return value;
|
|
6084
|
+
}
|
|
6085
|
+
|
|
6086
|
+
function radixBaseFromSemanticType(semanticType) {
|
|
6087
|
+
if (typeof semanticType !== 'string') return undefined;
|
|
6088
|
+
const normalized = semanticType.trim().toLowerCase();
|
|
6089
|
+
if (normalized === 'decimal') return 10;
|
|
6090
|
+
const alias = /^radix(2|6|8|12)$/u.exec(normalized);
|
|
6091
|
+
if (alias !== null) return Number(alias[1]);
|
|
6092
|
+
const clarified = /^radix\[(\d+)\]$/u.exec(normalized);
|
|
6093
|
+
if (clarified === null) return undefined;
|
|
6094
|
+
const base = Number(clarified[1]);
|
|
6095
|
+
return Number.isInteger(base) && base >= 2 && base <= 64 ? base : undefined;
|
|
6096
|
+
}
|
|
6097
|
+
|
|
5359
6098
|
function normalizeValueSemanticsCategory(category) {
|
|
5360
6099
|
if (category === 'sansa') return 'sansaAddress';
|
|
5361
6100
|
if (category === 'cloneReference' || category === 'pointerReference') return 'referenceForm';
|
|
@@ -5377,6 +6116,13 @@ function structurallyEqualContainers(left, right, profile) {
|
|
|
5377
6116
|
}
|
|
5378
6117
|
|
|
5379
6118
|
function structurallyEqualValues(left, right, profile) {
|
|
6119
|
+
const leftDescriptor = comparableScalarDescriptor(left);
|
|
6120
|
+
const rightDescriptor = comparableScalarDescriptor(right);
|
|
6121
|
+
if (leftDescriptor !== undefined || rightDescriptor !== undefined) {
|
|
6122
|
+
if (leftDescriptor === undefined || rightDescriptor === undefined) return false;
|
|
6123
|
+
const equality = evaluateValueSemanticsEquality('equal', leftDescriptor, rightDescriptor, profile);
|
|
6124
|
+
return equality.ok && equality.value;
|
|
6125
|
+
}
|
|
5380
6126
|
if (Object.is(left, right)) return true;
|
|
5381
6127
|
if (typeof left === 'string' && typeof right === 'string') return profile.compareStrings(left, right) === 0;
|
|
5382
6128
|
if (typeof left !== 'object' || left === null || typeof right !== 'object' || right === null) return false;
|
|
@@ -5394,6 +6140,11 @@ function structurallyEqualValues(left, right, profile) {
|
|
|
5394
6140
|
return true;
|
|
5395
6141
|
}
|
|
5396
6142
|
|
|
6143
|
+
function comparableScalarDescriptor(value) {
|
|
6144
|
+
if (typeof value !== 'object' || value === null) return undefined;
|
|
6145
|
+
return value[COMPARABLE_SCALAR_DESCRIPTOR_PROPERTY];
|
|
6146
|
+
}
|
|
6147
|
+
|
|
5397
6148
|
function isConcreteValueDescriptor(descriptor) {
|
|
5398
6149
|
const info = valueDescriptorToScalarInfo(descriptor);
|
|
5399
6150
|
return isConcreteValueScalar(info);
|
|
@@ -5429,7 +6180,10 @@ function compareQueryScalars(operator, left, right, options = {}) {
|
|
|
5429
6180
|
if (!evaluated.ok) {
|
|
5430
6181
|
return {
|
|
5431
6182
|
ok: false,
|
|
5432
|
-
error: queryEvaluateError(
|
|
6183
|
+
error: queryEvaluateError(
|
|
6184
|
+
'SANSA_QUERY_EVALUATE_INVALID_COMPARISON',
|
|
6185
|
+
queryComparisonMessage(evaluated.reason, operator, leftDescriptor, rightDescriptor),
|
|
6186
|
+
),
|
|
5433
6187
|
};
|
|
5434
6188
|
}
|
|
5435
6189
|
const value = (() => {
|
|
@@ -5454,15 +6208,26 @@ function queryScalarToInfo(scalar) {
|
|
|
5454
6208
|
...(metadata.semanticType === undefined ? {} : { semanticType: metadata.semanticType }),
|
|
5455
6209
|
...(metadata.containerKind === undefined ? {} : { containerKind: metadata.containerKind }),
|
|
5456
6210
|
...(metadata.nullReason === undefined ? {} : { nullReason: metadata.nullReason }),
|
|
6211
|
+
...(metadata.numericLexeme === undefined ? {} : { numericLexeme: metadata.numericLexeme }),
|
|
6212
|
+
...(metadata.radixBase === undefined ? {} : { radixBase: metadata.radixBase }),
|
|
6213
|
+
...(metadata.radixScale === undefined ? {} : { radixScale: metadata.radixScale }),
|
|
5457
6214
|
};
|
|
5458
6215
|
}
|
|
5459
6216
|
return { value: scalar };
|
|
5460
6217
|
}
|
|
5461
6218
|
|
|
5462
|
-
function queryComparisonMessage(reason, operator) {
|
|
5463
|
-
if (reason === 'mixed_categories')
|
|
6219
|
+
function queryComparisonMessage(reason, operator, leftDescriptor, rightDescriptor) {
|
|
6220
|
+
if (reason === 'mixed_categories') {
|
|
6221
|
+
const categories = leftDescriptor?.category && rightDescriptor?.category
|
|
6222
|
+
? ` (${leftDescriptor.category} vs ${rightDescriptor.category})`
|
|
6223
|
+
: '';
|
|
6224
|
+
return `Cross-type comparison is not supported${categories}`;
|
|
6225
|
+
}
|
|
5464
6226
|
if (reason === 'not_equality_comparable') return 'NaN, null, and absence values are not equality-comparable in this evaluator slice';
|
|
5465
6227
|
if (reason === 'not_orderable' && ['<', '<=', '>', '>='].includes(operator)) return 'Ordering comparison is not defined for this value category';
|
|
6228
|
+
if (reason === 'radix_base_required') return 'Radix numeric comparison requires a resolved base from at least one operand';
|
|
6229
|
+
if (reason === 'mixed_radix_bases') return 'Cross-base radix comparison is not enabled by this value-semantics profile';
|
|
6230
|
+
if (reason === 'invalid_radix_value') return 'Radix payload is invalid for its resolved base';
|
|
5466
6231
|
return 'Invalid scalar comparison';
|
|
5467
6232
|
}
|
|
5468
6233
|
|
|
@@ -5647,7 +6412,12 @@ function materializeAttributeComparableValue(namespace, binding, seen) {
|
|
|
5647
6412
|
function materializeBindingComparableValue(namespace, binding, seen) {
|
|
5648
6413
|
const scalar = getBindingScalarValue(namespace, binding);
|
|
5649
6414
|
if (scalar.ok && !(scalar.value === undefined && isContainerBinding(namespace, binding))) {
|
|
5650
|
-
return {
|
|
6415
|
+
return {
|
|
6416
|
+
ok: true,
|
|
6417
|
+
value: {
|
|
6418
|
+
[COMPARABLE_SCALAR_DESCRIPTOR_PROPERTY]: scalarInfoToValueDescriptor(queryScalarToInfo(scalar)),
|
|
6419
|
+
},
|
|
6420
|
+
};
|
|
5651
6421
|
}
|
|
5652
6422
|
if (!isContainerBinding(namespace, binding)) return scalar;
|
|
5653
6423
|
return materializeContainerComparableValue(namespace, binding, seen);
|
|
@@ -5657,11 +6427,21 @@ function getBindingScalarInfo(namespace, binding) {
|
|
|
5657
6427
|
const kind = getBindingScalarKind(namespace, binding);
|
|
5658
6428
|
const semanticType = getBindingSemanticType(namespace, binding);
|
|
5659
6429
|
const nullReason = getBindingNullReason(namespace, binding);
|
|
6430
|
+
const numericLexeme = getBindingNumericLexeme(namespace, binding);
|
|
6431
|
+
const radixBase = getBindingRadixBase(namespace, binding);
|
|
6432
|
+
const radixScale = getBindingRadixScale(namespace, binding);
|
|
5660
6433
|
if (typeof namespace.value === 'function') {
|
|
5661
|
-
|
|
6434
|
+
const value = namespace.value(binding);
|
|
6435
|
+
if (value !== undefined) {
|
|
6436
|
+
return { ok: true, value, kind, semanticType, nullReason, numericLexeme, radixBase, radixScale };
|
|
6437
|
+
}
|
|
6438
|
+
}
|
|
6439
|
+
if (Object.hasOwn(binding, 'value') && binding.value !== undefined) {
|
|
6440
|
+
return { ok: true, value: binding.value, kind, semanticType, nullReason, numericLexeme, radixBase, radixScale };
|
|
6441
|
+
}
|
|
6442
|
+
if (Object.hasOwn(binding, 'scalar') && binding.scalar !== undefined) {
|
|
6443
|
+
return { ok: true, value: binding.scalar, kind, semanticType, nullReason, numericLexeme, radixBase, radixScale };
|
|
5662
6444
|
}
|
|
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 };
|
|
5665
6445
|
return {
|
|
5666
6446
|
ok: false,
|
|
5667
6447
|
error: queryEvaluateError('SANSA_QUERY_EVALUATE_MISSING_SCALAR', 'Binding does not expose a scalar value'),
|
|
@@ -5669,6 +6449,13 @@ function getBindingScalarInfo(namespace, binding) {
|
|
|
5669
6449
|
}
|
|
5670
6450
|
|
|
5671
6451
|
function containerKindFromBinding(namespace, binding) {
|
|
6452
|
+
const explicitKind = explicitContainerKindFromBinding(namespace, binding);
|
|
6453
|
+
if (explicitKind !== undefined) return explicitKind;
|
|
6454
|
+
if (Array.isArray(binding.children)) return 'container';
|
|
6455
|
+
return undefined;
|
|
6456
|
+
}
|
|
6457
|
+
|
|
6458
|
+
function explicitContainerKindFromBinding(namespace, binding) {
|
|
5672
6459
|
const rawKind = typeof namespace.representationKind === 'function'
|
|
5673
6460
|
? namespace.representationKind(binding)
|
|
5674
6461
|
: binding.representationKind ?? binding.kind ?? binding.type ?? binding.literalKind ?? binding.valueKind;
|
|
@@ -5677,7 +6464,6 @@ function containerKindFromBinding(namespace, binding) {
|
|
|
5677
6464
|
if (['list', 'listNode'].includes(kind)) return 'list';
|
|
5678
6465
|
if (['tuple', 'tupleLiteral'].includes(kind)) return 'tuple';
|
|
5679
6466
|
if (['node', 'nodeLiteral'].includes(kind)) return 'node';
|
|
5680
|
-
if (Array.isArray(binding.children)) return 'container';
|
|
5681
6467
|
return undefined;
|
|
5682
6468
|
}
|
|
5683
6469
|
|
|
@@ -5692,6 +6478,7 @@ function getBindingScalarKind(namespace, binding) {
|
|
|
5692
6478
|
if (actual === 'NullLiteral') return 'null';
|
|
5693
6479
|
if (actual === 'NaNLiteral') return 'nan';
|
|
5694
6480
|
if (actual === 'InfinityLiteral') return 'infinity';
|
|
6481
|
+
if (actual === 'SymbolicLiteral') return 'symbol';
|
|
5695
6482
|
return typeof actual === 'string' ? lowerFirst(actual) : undefined;
|
|
5696
6483
|
}
|
|
5697
6484
|
|
|
@@ -5707,6 +6494,29 @@ function getBindingNullReason(namespace, binding) {
|
|
|
5707
6494
|
return binding.nullReason;
|
|
5708
6495
|
}
|
|
5709
6496
|
|
|
6497
|
+
function getBindingNumericLexeme(namespace, binding) {
|
|
6498
|
+
if (typeof namespace.numericLexeme === 'function') return namespace.numericLexeme(binding);
|
|
6499
|
+
return typeof binding.numericLexeme === 'string' ? binding.numericLexeme : undefined;
|
|
6500
|
+
}
|
|
6501
|
+
|
|
6502
|
+
function getBindingRadixBase(namespace, binding) {
|
|
6503
|
+
if (typeof namespace.radixBase === 'function') return namespace.radixBase(binding);
|
|
6504
|
+
if (Number.isInteger(binding.radixBase)) return binding.radixBase;
|
|
6505
|
+
return radixBaseFromSemanticType(getBindingSemanticType(namespace, binding));
|
|
6506
|
+
}
|
|
6507
|
+
|
|
6508
|
+
function getBindingRadixScale(namespace, binding) {
|
|
6509
|
+
if (typeof namespace.radixScale === 'function') return namespace.radixScale(binding);
|
|
6510
|
+
if (Number.isInteger(binding.radixScale) && binding.radixScale >= 0) return binding.radixScale;
|
|
6511
|
+
const kind = getBindingScalarKind(namespace, binding);
|
|
6512
|
+
if (kind !== 'radix') return undefined;
|
|
6513
|
+
const value = typeof namespace.value === 'function'
|
|
6514
|
+
? namespace.value(binding)
|
|
6515
|
+
: Object.hasOwn(binding, 'value') ? binding.value : binding.scalar;
|
|
6516
|
+
if (typeof value !== 'string') return undefined;
|
|
6517
|
+
return radixScaleOf(value, getBindingRadixBase(namespace, binding)) ?? undefined;
|
|
6518
|
+
}
|
|
6519
|
+
|
|
5710
6520
|
function getBindingNodeTag(namespace, binding) {
|
|
5711
6521
|
if (typeof namespace.nodeTag === 'function') return namespace.nodeTag(binding);
|
|
5712
6522
|
if (typeof namespace.tag === 'function') return namespace.tag(binding);
|
|
@@ -5735,6 +6545,9 @@ function scalarMetadataFromInfo(info) {
|
|
|
5735
6545
|
if (info.kind !== undefined) metadata.kind = info.kind;
|
|
5736
6546
|
if (info.semanticType !== undefined) metadata.semanticType = info.semanticType;
|
|
5737
6547
|
if (info.nullReason !== undefined) metadata.nullReason = info.nullReason;
|
|
6548
|
+
if (info.numericLexeme !== undefined) metadata.numericLexeme = info.numericLexeme;
|
|
6549
|
+
if (info.radixBase !== undefined) metadata.radixBase = info.radixBase;
|
|
6550
|
+
if (info.radixScale !== undefined) metadata.radixScale = info.radixScale;
|
|
5738
6551
|
return Object.keys(metadata).length > 0 ? metadata : undefined;
|
|
5739
6552
|
}
|
|
5740
6553
|
|
|
@@ -7139,6 +7952,7 @@ class QueryExpressionParser {
|
|
|
7139
7952
|
const char = this.peek();
|
|
7140
7953
|
if (!char) this.fail('Expected SANSA query expression', 'SANSA_QUERY_EXPECTED_EXPRESSION');
|
|
7141
7954
|
if (char === '"') return this.parseString();
|
|
7955
|
+
if (char === '|') return this.parseSymbol();
|
|
7142
7956
|
if (char === '#') return this.parseHex();
|
|
7143
7957
|
if (char === '%') return this.parseRadix();
|
|
7144
7958
|
if (char === '&') return this.parseEncoding();
|
|
@@ -7221,6 +8035,39 @@ class QueryExpressionParser {
|
|
|
7221
8035
|
};
|
|
7222
8036
|
}
|
|
7223
8037
|
|
|
8038
|
+
parseSymbol() {
|
|
8039
|
+
const start = this.index;
|
|
8040
|
+
this.index += 1;
|
|
8041
|
+
let value = '';
|
|
8042
|
+
while (!this.atEnd()) {
|
|
8043
|
+
const char = this.peek();
|
|
8044
|
+
if (char === '|') {
|
|
8045
|
+
this.index += 1;
|
|
8046
|
+
if (value.length === 0) {
|
|
8047
|
+
this.fail('Symbol literals must not be empty', 'SANSA_QUERY_INVALID_SYMBOL_LITERAL', start);
|
|
8048
|
+
}
|
|
8049
|
+
return {
|
|
8050
|
+
type: 'literalExpression',
|
|
8051
|
+
kind: 'symbol',
|
|
8052
|
+
value,
|
|
8053
|
+
canonical: symbolPayload(value),
|
|
8054
|
+
};
|
|
8055
|
+
}
|
|
8056
|
+
if (char === '\n' || char === '\r') {
|
|
8057
|
+
this.fail('Symbol literals must not contain raw newlines', 'SANSA_QUERY_INVALID_SYMBOL_LITERAL', this.index);
|
|
8058
|
+
}
|
|
8059
|
+
if (char === '\\') {
|
|
8060
|
+
const escape = readSymbolPayloadEscape(this.input, this.index);
|
|
8061
|
+
value += escape.value;
|
|
8062
|
+
this.index = escape.end;
|
|
8063
|
+
continue;
|
|
8064
|
+
}
|
|
8065
|
+
value += char;
|
|
8066
|
+
this.index += 1;
|
|
8067
|
+
}
|
|
8068
|
+
this.fail('Unterminated symbol literal', 'SANSA_QUERY_INVALID_SYMBOL_LITERAL', start);
|
|
8069
|
+
}
|
|
8070
|
+
|
|
7224
8071
|
parseNumber() {
|
|
7225
8072
|
const start = this.index;
|
|
7226
8073
|
if (this.peek() === '-') this.index += 1;
|
|
@@ -7419,8 +8266,8 @@ class QueryExpressionParser {
|
|
|
7419
8266
|
|
|
7420
8267
|
startsTemporalLiteral() {
|
|
7421
8268
|
const rest = this.input.slice(this.index);
|
|
7422
|
-
return /^\d{4}
|
|
7423
|
-
|| /^\d{2}
|
|
8269
|
+
return /^\d{4}-(?=$|[\s,)}\]]|\d|T)/.test(rest)
|
|
8270
|
+
|| /^\d{2}:/.test(rest);
|
|
7424
8271
|
}
|
|
7425
8272
|
|
|
7426
8273
|
readSimpleLiteralPayload() {
|
|
@@ -7526,7 +8373,7 @@ class QueryExpressionParser {
|
|
|
7526
8373
|
}
|
|
7527
8374
|
continue;
|
|
7528
8375
|
}
|
|
7529
|
-
if (char === '"') {
|
|
8376
|
+
if (char === '"' || isSymbolLiteralStart(this.input, this.index)) {
|
|
7530
8377
|
quote = char;
|
|
7531
8378
|
this.index += 1;
|
|
7532
8379
|
continue;
|
|
@@ -7637,7 +8484,7 @@ function stripQueryComments(input) {
|
|
|
7637
8484
|
}
|
|
7638
8485
|
continue;
|
|
7639
8486
|
}
|
|
7640
|
-
if (char === '"' || char === "'") {
|
|
8487
|
+
if (char === '"' || char === "'" || isSymbolLiteralStart(input, index)) {
|
|
7641
8488
|
quote = char;
|
|
7642
8489
|
output += char;
|
|
7643
8490
|
continue;
|
|
@@ -7759,7 +8606,7 @@ function scanInstructionClauses(source) {
|
|
|
7759
8606
|
else if (char === quote) quote = null;
|
|
7760
8607
|
continue;
|
|
7761
8608
|
}
|
|
7762
|
-
if (char === '"') {
|
|
8609
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
7763
8610
|
quote = char;
|
|
7764
8611
|
continue;
|
|
7765
8612
|
}
|
|
@@ -7860,7 +8707,7 @@ function findTopLevelInstructionKeyword(source, keyword, start = 0) {
|
|
|
7860
8707
|
else if (char === quote) quote = null;
|
|
7861
8708
|
continue;
|
|
7862
8709
|
}
|
|
7863
|
-
if (char === '"') {
|
|
8710
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
7864
8711
|
quote = char;
|
|
7865
8712
|
continue;
|
|
7866
8713
|
}
|
|
@@ -7900,7 +8747,7 @@ function readInstructionToken(source, start) {
|
|
|
7900
8747
|
else if (char === quote) quote = null;
|
|
7901
8748
|
continue;
|
|
7902
8749
|
}
|
|
7903
|
-
if (char === '"') {
|
|
8750
|
+
if (char === '"' || isSymbolLiteralStart(source, cursor)) {
|
|
7904
8751
|
quote = char;
|
|
7905
8752
|
continue;
|
|
7906
8753
|
}
|
|
@@ -7959,7 +8806,7 @@ function unwrapInstructionDelimitedLiteral(source, open, close, offset) {
|
|
|
7959
8806
|
else if (char === quote) quote = null;
|
|
7960
8807
|
continue;
|
|
7961
8808
|
}
|
|
7962
|
-
if (char === '"') {
|
|
8809
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
7963
8810
|
quote = char;
|
|
7964
8811
|
continue;
|
|
7965
8812
|
}
|
|
@@ -8010,7 +8857,7 @@ function splitTopLevelInstructionValueList(source, offset) {
|
|
|
8010
8857
|
else if (char === quote) quote = null;
|
|
8011
8858
|
continue;
|
|
8012
8859
|
}
|
|
8013
|
-
if (char === '"') {
|
|
8860
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
8014
8861
|
quote = char;
|
|
8015
8862
|
continue;
|
|
8016
8863
|
}
|
|
@@ -8081,7 +8928,7 @@ function scanQueryClauses(source) {
|
|
|
8081
8928
|
}
|
|
8082
8929
|
continue;
|
|
8083
8930
|
}
|
|
8084
|
-
if (char === '"' || char === "'") {
|
|
8931
|
+
if (char === '"' || char === "'" || isSymbolLiteralStart(source, index)) {
|
|
8085
8932
|
quote = char;
|
|
8086
8933
|
continue;
|
|
8087
8934
|
}
|
|
@@ -8175,7 +9022,7 @@ function normalizeQueryExpression(source) {
|
|
|
8175
9022
|
}
|
|
8176
9023
|
continue;
|
|
8177
9024
|
}
|
|
8178
|
-
if (char === '"' || char === "'") {
|
|
9025
|
+
if (char === '"' || char === "'" || isSymbolLiteralStart(source, index)) {
|
|
8179
9026
|
if (pendingSpace && output.length > 0) output += ' ';
|
|
8180
9027
|
pendingSpace = false;
|
|
8181
9028
|
quote = char;
|
|
@@ -8199,12 +9046,11 @@ function isQueryCurrentPositionalShorthand(source) {
|
|
|
8199
9046
|
|
|
8200
9047
|
function isQueryTemporalLiteral(source, kind) {
|
|
8201
9048
|
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_
|
|
9049
|
+
const time = String.raw`(\d{2}):(?:(\d{2}))?(?::(\d{2})(?:\.(\d+))?)?(?:Z|([+-])(\d{2}):(\d{2}))?`;
|
|
9050
|
+
const datetimeTime = String.raw`(\d{2})(?::(\d{2})?)?(?::(\d{2})(?:\.(\d+))?)?(?:Z|([+-])(\d{2}):(\d{2}))?`;
|
|
9051
|
+
const zone = String.raw`[A-Za-z0-9_+.\-]+(?:/[A-Za-z0-9_+.\-]+)*`;
|
|
8205
9052
|
if (kind === 'date') {
|
|
8206
|
-
|
|
8207
|
-
return Boolean(match) && isValidDateParts(match[1], match[2], match[3]);
|
|
9053
|
+
return parseTemporalDate(source) !== null;
|
|
8208
9054
|
}
|
|
8209
9055
|
if (kind === 'time') {
|
|
8210
9056
|
const match = new RegExp(`^${time}$`).exec(source);
|
|
@@ -8229,7 +9075,7 @@ function isValidDateParts(yearText, monthText, dayText) {
|
|
|
8229
9075
|
const year = Number(yearText);
|
|
8230
9076
|
const month = Number(monthText);
|
|
8231
9077
|
const day = Number(dayText);
|
|
8232
|
-
if (month < 1 || month > 12) return false;
|
|
9078
|
+
if (year < 1 || month < 1 || month > 12) return false;
|
|
8233
9079
|
const days = [31, isLeapYear(year) ? 29 : 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
8234
9080
|
return day >= 1 && day <= days[month - 1];
|
|
8235
9081
|
}
|
|
@@ -8242,11 +9088,11 @@ function isValidTimeMatch(match, offset = 1) {
|
|
|
8242
9088
|
const hour = Number(match[offset]);
|
|
8243
9089
|
const minute = match[offset + 1] === undefined ? null : Number(match[offset + 1]);
|
|
8244
9090
|
const second = match[offset + 2] === undefined ? null : Number(match[offset + 2]);
|
|
8245
|
-
const zoneHour = match[offset +
|
|
8246
|
-
const zoneMinute = match[offset +
|
|
9091
|
+
const zoneHour = match[offset + 5] === undefined ? null : Number(match[offset + 5]);
|
|
9092
|
+
const zoneMinute = match[offset + 6] === undefined ? null : Number(match[offset + 6]);
|
|
8247
9093
|
if (hour < 0 || hour > 23) return false;
|
|
8248
9094
|
if (minute !== null && (minute < 0 || minute > 59)) return false;
|
|
8249
|
-
if (second !== null && (second < 0 || second >
|
|
9095
|
+
if (second !== null && (second < 0 || second > 60)) return false;
|
|
8250
9096
|
if (zoneHour !== null && (zoneHour < 0 || zoneHour > 23)) return false;
|
|
8251
9097
|
if (zoneMinute !== null && (zoneMinute < 0 || zoneMinute > 59)) return false;
|
|
8252
9098
|
return true;
|
|
@@ -8309,7 +9155,7 @@ function splitTopLevelQueryList(source) {
|
|
|
8309
9155
|
else if (char === quote) quote = null;
|
|
8310
9156
|
continue;
|
|
8311
9157
|
}
|
|
8312
|
-
if (char === '"' || char === "'") {
|
|
9158
|
+
if (char === '"' || char === "'" || isSymbolLiteralStart(source, index)) {
|
|
8313
9159
|
quote = char;
|
|
8314
9160
|
continue;
|
|
8315
9161
|
}
|
|
@@ -8342,6 +9188,13 @@ function splitProjectionFields(source) {
|
|
|
8342
9188
|
while (isIdentifierContinue(source[cursor] ?? '')) cursor += 1;
|
|
8343
9189
|
const name = source.slice(nameStart, cursor);
|
|
8344
9190
|
while (isLayout(source[cursor] ?? '')) cursor += 1;
|
|
9191
|
+
if (source[cursor] === ':') {
|
|
9192
|
+
throw new SansaParseError(
|
|
9193
|
+
"Projection fields use AEON assignment syntax ('name = expression'); ':' is reserved for datatype annotations",
|
|
9194
|
+
cursor,
|
|
9195
|
+
'SANSA_QUERY_INVALID_PROJECTION',
|
|
9196
|
+
);
|
|
9197
|
+
}
|
|
8345
9198
|
if (source[cursor] !== '=') {
|
|
8346
9199
|
throw new SansaParseError("Expected '=' after projection field name", cursor, 'SANSA_QUERY_INVALID_PROJECTION');
|
|
8347
9200
|
}
|
|
@@ -8440,7 +9293,7 @@ function findNextProjectionField(source, start) {
|
|
|
8440
9293
|
else if (char === quote) quote = null;
|
|
8441
9294
|
continue;
|
|
8442
9295
|
}
|
|
8443
|
-
if (char === '"') {
|
|
9296
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
8444
9297
|
quote = char;
|
|
8445
9298
|
continue;
|
|
8446
9299
|
}
|
|
@@ -8483,7 +9336,7 @@ function findNextInstructionObjectField(source, start) {
|
|
|
8483
9336
|
else if (char === quote) quote = null;
|
|
8484
9337
|
continue;
|
|
8485
9338
|
}
|
|
8486
|
-
if (char === '"') {
|
|
9339
|
+
if (char === '"' || isSymbolLiteralStart(source, index)) {
|
|
8487
9340
|
quote = char;
|
|
8488
9341
|
continue;
|
|
8489
9342
|
}
|
|
@@ -8519,6 +9372,13 @@ function isComparisonStart(char) {
|
|
|
8519
9372
|
return char === '=' || char === '!' || char === '<' || char === '>';
|
|
8520
9373
|
}
|
|
8521
9374
|
|
|
9375
|
+
function isSymbolLiteralStart(source, index) {
|
|
9376
|
+
if (source[index] !== '|') return false;
|
|
9377
|
+
if (index === 0 || isLayout(source[index - 1])) return true;
|
|
9378
|
+
if ('([{,=<>!'.includes(source[index - 1])) return true;
|
|
9379
|
+
return /(?:^|[^A-Za-z0-9_])(?:and|or|not|in)$/u.test(source.slice(0, index));
|
|
9380
|
+
}
|
|
9381
|
+
|
|
8522
9382
|
function readQuotedPayloadEscape(source, start) {
|
|
8523
9383
|
const escape = source[start + 1];
|
|
8524
9384
|
if (!escape) throw new SansaParseError('Unterminated escape sequence', start, 'SANSA_UNTERMINATED_ESCAPE');
|
|
@@ -8539,6 +9399,11 @@ function readQuotedPayloadEscape(source, start) {
|
|
|
8539
9399
|
}
|
|
8540
9400
|
}
|
|
8541
9401
|
|
|
9402
|
+
function readSymbolPayloadEscape(source, start) {
|
|
9403
|
+
if (source[start + 1] === '|') return { value: '|', end: start + 2 };
|
|
9404
|
+
return readQuotedPayloadEscape(source, start);
|
|
9405
|
+
}
|
|
9406
|
+
|
|
8542
9407
|
function readUnicodePayloadEscape(source, start) {
|
|
8543
9408
|
let cursor = start + 2;
|
|
8544
9409
|
if (source[cursor] === '{') {
|
|
@@ -8655,3 +9520,37 @@ function quotePayload(value) {
|
|
|
8655
9520
|
output += '"';
|
|
8656
9521
|
return output;
|
|
8657
9522
|
}
|
|
9523
|
+
|
|
9524
|
+
function symbolPayload(value) {
|
|
9525
|
+
let output = '|';
|
|
9526
|
+
for (const char of value) {
|
|
9527
|
+
switch (char) {
|
|
9528
|
+
case '\\':
|
|
9529
|
+
output += '\\\\';
|
|
9530
|
+
break;
|
|
9531
|
+
case '|':
|
|
9532
|
+
output += '\\|';
|
|
9533
|
+
break;
|
|
9534
|
+
case '\n':
|
|
9535
|
+
output += '\\n';
|
|
9536
|
+
break;
|
|
9537
|
+
case '\r':
|
|
9538
|
+
output += '\\r';
|
|
9539
|
+
break;
|
|
9540
|
+
case '\t':
|
|
9541
|
+
output += '\\t';
|
|
9542
|
+
break;
|
|
9543
|
+
case '\b':
|
|
9544
|
+
output += '\\b';
|
|
9545
|
+
break;
|
|
9546
|
+
case '\f':
|
|
9547
|
+
output += '\\f';
|
|
9548
|
+
break;
|
|
9549
|
+
default:
|
|
9550
|
+
output += char;
|
|
9551
|
+
break;
|
|
9552
|
+
}
|
|
9553
|
+
}
|
|
9554
|
+
output += '|';
|
|
9555
|
+
return output;
|
|
9556
|
+
}
|