@kalada/syntax 0.1.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/README.md +98 -0
- package/dist/index.cjs +2027 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +231 -0
- package/dist/index.d.ts +231 -0
- package/dist/index.js +2017 -0
- package/dist/index.js.map +1 -0
- package/package.json +47 -0
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { JsonValue, KaladaV1DiagnosticCode, KaladaType, KaladaV1Options, KaladaV1Program } from '@kalada/core';
|
|
2
|
+
|
|
3
|
+
interface KaladaSourceRange {
|
|
4
|
+
readonly start: number;
|
|
5
|
+
readonly end: number;
|
|
6
|
+
}
|
|
7
|
+
type KaladaTokenKind = "whitespace" | "identifier" | "number" | "string" | "true" | "false" | "null" | "in" | "xor" | "left-parenthesis" | "right-parenthesis" | "dot" | "optional-dot" | "question" | "colon" | "operator" | "unsupported" | "invalid" | "eof";
|
|
8
|
+
interface KaladaToken {
|
|
9
|
+
readonly kind: KaladaTokenKind;
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly range: KaladaSourceRange;
|
|
12
|
+
}
|
|
13
|
+
interface CstBase {
|
|
14
|
+
readonly range: KaladaSourceRange;
|
|
15
|
+
}
|
|
16
|
+
interface KaladaLiteralCstNode extends CstBase {
|
|
17
|
+
readonly kind: "literal";
|
|
18
|
+
readonly literalKind: "number" | "string" | "boolean" | "null";
|
|
19
|
+
readonly token: number;
|
|
20
|
+
readonly value: JsonValue;
|
|
21
|
+
}
|
|
22
|
+
interface KaladaReferenceCstNode extends CstBase {
|
|
23
|
+
readonly kind: "reference";
|
|
24
|
+
readonly token: number;
|
|
25
|
+
readonly name: string;
|
|
26
|
+
}
|
|
27
|
+
interface KaladaGroupCstNode extends CstBase {
|
|
28
|
+
readonly kind: "group";
|
|
29
|
+
readonly openToken: number;
|
|
30
|
+
readonly expression: KaladaCstNode;
|
|
31
|
+
readonly closeToken: number | null;
|
|
32
|
+
}
|
|
33
|
+
interface KaladaFieldAccessCstNode extends CstBase {
|
|
34
|
+
readonly kind: "field-access";
|
|
35
|
+
readonly target: KaladaCstNode;
|
|
36
|
+
readonly optional: boolean;
|
|
37
|
+
readonly operatorToken: number;
|
|
38
|
+
readonly fieldToken: number | null;
|
|
39
|
+
readonly field: string | null;
|
|
40
|
+
}
|
|
41
|
+
interface KaladaUnaryCstNode extends CstBase {
|
|
42
|
+
readonly kind: "unary";
|
|
43
|
+
readonly operator: "!" | "+" | "-";
|
|
44
|
+
readonly operatorToken: number;
|
|
45
|
+
readonly operand: KaladaCstNode;
|
|
46
|
+
}
|
|
47
|
+
type KaladaBinaryOperator = "*" | "/" | "%" | "+" | "-" | "<" | "<=" | ">" | ">=" | "in" | "==" | "!=" | "&&" | "xor" | "||" | "??";
|
|
48
|
+
interface KaladaBinaryCstNode extends CstBase {
|
|
49
|
+
readonly kind: "binary";
|
|
50
|
+
readonly operator: KaladaBinaryOperator;
|
|
51
|
+
readonly operatorToken: number;
|
|
52
|
+
readonly left: KaladaCstNode;
|
|
53
|
+
readonly right: KaladaCstNode;
|
|
54
|
+
}
|
|
55
|
+
interface KaladaConditionalCstNode extends CstBase {
|
|
56
|
+
readonly kind: "conditional";
|
|
57
|
+
readonly condition: KaladaCstNode;
|
|
58
|
+
readonly questionToken: number;
|
|
59
|
+
readonly then: KaladaCstNode;
|
|
60
|
+
readonly colonToken: number | null;
|
|
61
|
+
readonly else: KaladaCstNode;
|
|
62
|
+
}
|
|
63
|
+
interface KaladaErrorCstNode extends CstBase {
|
|
64
|
+
readonly kind: "error";
|
|
65
|
+
readonly token: number | null;
|
|
66
|
+
}
|
|
67
|
+
type KaladaCstNode = KaladaLiteralCstNode | KaladaReferenceCstNode | KaladaGroupCstNode | KaladaFieldAccessCstNode | KaladaUnaryCstNode | KaladaBinaryCstNode | KaladaConditionalCstNode | KaladaErrorCstNode;
|
|
68
|
+
interface KaladaCstDocument {
|
|
69
|
+
readonly source: string;
|
|
70
|
+
readonly tokens: readonly KaladaToken[];
|
|
71
|
+
readonly expression: KaladaCstNode;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface KaladaSyntaxLimits {
|
|
75
|
+
readonly maxSourceLength: number;
|
|
76
|
+
readonly maxTokens: number;
|
|
77
|
+
readonly maxCstDepth: number;
|
|
78
|
+
readonly maxCstNodes: number;
|
|
79
|
+
readonly maxDiagnostics: number;
|
|
80
|
+
readonly maxRecoveryTokens: number;
|
|
81
|
+
readonly maxIdentifierLength: number;
|
|
82
|
+
readonly maxDecodedStringLength: number;
|
|
83
|
+
readonly maxStaticTypeDepth: number;
|
|
84
|
+
}
|
|
85
|
+
interface KaladaParseOptions {
|
|
86
|
+
readonly limits?: Partial<KaladaSyntaxLimits>;
|
|
87
|
+
}
|
|
88
|
+
type KaladaSyntaxDiagnosticCode = "KALADA_SYNTAX_INVALID_INPUT" | "KALADA_SYNTAX_LIMIT_EXCEEDED" | "KALADA_SYNTAX_UNEXPECTED_TOKEN" | "KALADA_SYNTAX_EXPECTED_EXPRESSION" | "KALADA_SYNTAX_EXPECTED_FIELD" | "KALADA_SYNTAX_EXPECTED_RIGHT_PARENTHESIS" | "KALADA_SYNTAX_EXPECTED_COLON" | "KALADA_SYNTAX_INVALID_NUMBER" | "KALADA_SYNTAX_INVALID_STRING" | "KALADA_SYNTAX_UNSUPPORTED_FORM" | "KALADA_SYNTAX_UNSUPPORTED_OPERATOR" | "KALADA_SYNTAX_RELATIONAL_CHAIN" | "KALADA_SYNTAX_COALESCE_LOGICAL_MIX" | "KALADA_SYNTAX_UNKNOWN_REFERENCE" | "KALADA_SYNTAX_WRITE_INELIGIBLE" | "KALADA_SYNTAX_WRITE_BINDING_INVALID" | "KALADA_SYNTAX_WRITE_PROPERTY_INVALID";
|
|
89
|
+
interface KaladaSyntaxDiagnostic {
|
|
90
|
+
readonly phase: "lex" | "parse" | "lower";
|
|
91
|
+
readonly code: KaladaSyntaxDiagnosticCode | KaladaV1DiagnosticCode;
|
|
92
|
+
readonly message: string;
|
|
93
|
+
readonly range: KaladaSourceRange;
|
|
94
|
+
readonly path: readonly (string | number)[];
|
|
95
|
+
}
|
|
96
|
+
interface KaladaParseResult {
|
|
97
|
+
readonly document: KaladaCstDocument;
|
|
98
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
99
|
+
}
|
|
100
|
+
type KaladaSyntaxStaticType = "dynamic" | KaladaType;
|
|
101
|
+
type KaladaSemanticSupport = "supported" | "conditional" | "unsupported";
|
|
102
|
+
interface KaladaSemanticOperatorInfo {
|
|
103
|
+
readonly operator: KaladaBinaryOperator;
|
|
104
|
+
readonly support: KaladaSemanticSupport;
|
|
105
|
+
}
|
|
106
|
+
interface KaladaSemanticNodeInfo {
|
|
107
|
+
readonly range: KaladaSourceRange;
|
|
108
|
+
readonly type: KaladaSyntaxStaticType;
|
|
109
|
+
readonly known: boolean;
|
|
110
|
+
readonly fieldAccess: Readonly<{
|
|
111
|
+
plain: KaladaSemanticSupport;
|
|
112
|
+
optional: KaladaSemanticSupport;
|
|
113
|
+
}>;
|
|
114
|
+
readonly operators: readonly KaladaSemanticOperatorInfo[];
|
|
115
|
+
}
|
|
116
|
+
interface KaladaSemanticQueryResult {
|
|
117
|
+
readonly nodes: readonly KaladaSemanticNodeInfo[];
|
|
118
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
119
|
+
readonly incomplete: boolean;
|
|
120
|
+
}
|
|
121
|
+
interface KaladaReferenceBinding<R extends JsonValue> {
|
|
122
|
+
readonly reference: R;
|
|
123
|
+
readonly type: KaladaSyntaxStaticType;
|
|
124
|
+
}
|
|
125
|
+
interface KaladaLowerOptions<R extends JsonValue> {
|
|
126
|
+
readonly references?: Readonly<Record<string, KaladaReferenceBinding<R>>>;
|
|
127
|
+
readonly coreOptions?: KaladaV1Options<R>;
|
|
128
|
+
}
|
|
129
|
+
type KaladaSourceMapRole = "node" | "operator" | "literal" | "reference" | "field" | "group";
|
|
130
|
+
interface KaladaSourceMapEntry {
|
|
131
|
+
readonly path: readonly (string | number)[];
|
|
132
|
+
readonly role: KaladaSourceMapRole;
|
|
133
|
+
readonly range: KaladaSourceRange;
|
|
134
|
+
}
|
|
135
|
+
type KaladaLowerOutcome<R extends JsonValue = string> = {
|
|
136
|
+
readonly ok: true;
|
|
137
|
+
readonly program: KaladaV1Program<R>;
|
|
138
|
+
readonly sourceMap: readonly KaladaSourceMapEntry[];
|
|
139
|
+
readonly resultType: KaladaSyntaxStaticType;
|
|
140
|
+
} | {
|
|
141
|
+
readonly ok: false;
|
|
142
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
143
|
+
};
|
|
144
|
+
type KaladaFormatOutcome = {
|
|
145
|
+
readonly ok: true;
|
|
146
|
+
readonly text: string;
|
|
147
|
+
} | {
|
|
148
|
+
readonly ok: false;
|
|
149
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
declare const KALADA_SYNTAX_DIAGNOSTIC_MESSAGES: Readonly<{
|
|
153
|
+
KALADA_SYNTAX_INVALID_INPUT: string;
|
|
154
|
+
KALADA_SYNTAX_LIMIT_EXCEEDED: string;
|
|
155
|
+
KALADA_SYNTAX_UNEXPECTED_TOKEN: string;
|
|
156
|
+
KALADA_SYNTAX_EXPECTED_EXPRESSION: string;
|
|
157
|
+
KALADA_SYNTAX_EXPECTED_FIELD: string;
|
|
158
|
+
KALADA_SYNTAX_EXPECTED_RIGHT_PARENTHESIS: string;
|
|
159
|
+
KALADA_SYNTAX_EXPECTED_COLON: string;
|
|
160
|
+
KALADA_SYNTAX_INVALID_NUMBER: string;
|
|
161
|
+
KALADA_SYNTAX_INVALID_STRING: string;
|
|
162
|
+
KALADA_SYNTAX_UNSUPPORTED_FORM: string;
|
|
163
|
+
KALADA_SYNTAX_UNSUPPORTED_OPERATOR: string;
|
|
164
|
+
KALADA_SYNTAX_RELATIONAL_CHAIN: string;
|
|
165
|
+
KALADA_SYNTAX_COALESCE_LOGICAL_MIX: string;
|
|
166
|
+
KALADA_SYNTAX_UNKNOWN_REFERENCE: string;
|
|
167
|
+
KALADA_SYNTAX_WRITE_INELIGIBLE: string;
|
|
168
|
+
KALADA_SYNTAX_WRITE_BINDING_INVALID: string;
|
|
169
|
+
KALADA_SYNTAX_WRITE_PROPERTY_INVALID: string;
|
|
170
|
+
}>;
|
|
171
|
+
|
|
172
|
+
/** Static evidence only; the host must authorize this target again at use time. */
|
|
173
|
+
interface KaladaDataStateRef {
|
|
174
|
+
readonly namespace: "data";
|
|
175
|
+
readonly scope?: string;
|
|
176
|
+
readonly segments: readonly string[];
|
|
177
|
+
}
|
|
178
|
+
interface KaladaDirectLocationProperty {
|
|
179
|
+
readonly type: KaladaType;
|
|
180
|
+
readonly writable: true;
|
|
181
|
+
readonly properties?: Readonly<Record<string, KaladaDirectLocationProperty>>;
|
|
182
|
+
}
|
|
183
|
+
interface KaladaDirectLocationBinding extends KaladaDirectLocationProperty {
|
|
184
|
+
readonly target: KaladaDataStateRef;
|
|
185
|
+
}
|
|
186
|
+
interface KaladaDirectLocationOptions extends KaladaParseOptions {
|
|
187
|
+
readonly bindings: Readonly<Record<string, KaladaDirectLocationBinding>>;
|
|
188
|
+
}
|
|
189
|
+
interface KaladaDirectLocation {
|
|
190
|
+
readonly target: KaladaDataStateRef;
|
|
191
|
+
readonly type: KaladaType;
|
|
192
|
+
readonly range: KaladaSourceRange;
|
|
193
|
+
}
|
|
194
|
+
type KaladaDirectLocationOutcome = {
|
|
195
|
+
readonly ok: true;
|
|
196
|
+
readonly location: KaladaDirectLocation;
|
|
197
|
+
} | {
|
|
198
|
+
readonly ok: false;
|
|
199
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
200
|
+
};
|
|
201
|
+
declare function checkKaladaV1DirectLocation(source: string, options: KaladaDirectLocationOptions): KaladaDirectLocationOutcome;
|
|
202
|
+
|
|
203
|
+
declare function formatKaladaV1Expression(source: string, options?: KaladaParseOptions): KaladaFormatOutcome;
|
|
204
|
+
|
|
205
|
+
interface GuestBoundaryResult {
|
|
206
|
+
readonly ok: boolean;
|
|
207
|
+
readonly range: KaladaSourceRange;
|
|
208
|
+
readonly stop: number;
|
|
209
|
+
readonly reason: "outer-brace" | "unmatched-parentheses" | "unsupported-comment" | "unsupported-quote" | "eof" | "limit" | "invalid-start";
|
|
210
|
+
readonly parsed: KaladaParseResult | null;
|
|
211
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Experimental opt-in syntax seam, not a host grammar contract.
|
|
215
|
+
* The host declares start and independently checks/consumes source[stop] === "}".
|
|
216
|
+
* Only current supported Kalada expressions succeed; future grammar belongs to the guest lexer.
|
|
217
|
+
* An unterminated supported double-quoted string is ambiguous: scanning remains bounded by
|
|
218
|
+
* maxSourceLength and fails closed, but cannot identify a brace inside that string as host-owned.
|
|
219
|
+
*/
|
|
220
|
+
declare function parseGuestExpressionPrefix(source: string, start: number, options?: KaladaParseOptions): GuestBoundaryResult;
|
|
221
|
+
|
|
222
|
+
declare const DEFAULT_KALADA_SYNTAX_LIMITS: Readonly<KaladaSyntaxLimits>;
|
|
223
|
+
declare const MAXIMUM_KALADA_SYNTAX_LIMITS: Readonly<KaladaSyntaxLimits>;
|
|
224
|
+
|
|
225
|
+
declare function lowerKaladaV1Expression<R extends JsonValue = string>(parsed: KaladaParseResult, options?: KaladaLowerOptions<R>): KaladaLowerOutcome<R>;
|
|
226
|
+
|
|
227
|
+
declare function parseKaladaV1Expression(source: string, options?: KaladaParseOptions): KaladaParseResult;
|
|
228
|
+
|
|
229
|
+
declare function queryKaladaV1Semantics<R extends JsonValue = string>(parsed: KaladaParseResult, options?: KaladaLowerOptions<R>): KaladaSemanticQueryResult;
|
|
230
|
+
|
|
231
|
+
export { DEFAULT_KALADA_SYNTAX_LIMITS, type GuestBoundaryResult as ExperimentalKaladaV1GuestPrefixResult, KALADA_SYNTAX_DIAGNOSTIC_MESSAGES, type KaladaBinaryCstNode, type KaladaBinaryOperator, type KaladaConditionalCstNode, type KaladaCstDocument, type KaladaCstNode, type KaladaDataStateRef, type KaladaDirectLocation, type KaladaDirectLocationBinding, type KaladaDirectLocationOptions, type KaladaDirectLocationOutcome, type KaladaDirectLocationProperty, type KaladaErrorCstNode, type KaladaFieldAccessCstNode, type KaladaFormatOutcome, type KaladaGroupCstNode, type KaladaLiteralCstNode, type KaladaLowerOptions, type KaladaLowerOutcome, type KaladaParseOptions, type KaladaParseResult, type KaladaReferenceBinding, type KaladaReferenceCstNode, type KaladaSemanticNodeInfo, type KaladaSemanticOperatorInfo, type KaladaSemanticQueryResult, type KaladaSemanticSupport, type KaladaSourceMapEntry, type KaladaSourceMapRole, type KaladaSourceRange, type KaladaSyntaxDiagnostic, type KaladaSyntaxDiagnosticCode, type KaladaSyntaxLimits, type KaladaSyntaxStaticType, type KaladaToken, type KaladaTokenKind, type KaladaUnaryCstNode, MAXIMUM_KALADA_SYNTAX_LIMITS, checkKaladaV1DirectLocation, parseGuestExpressionPrefix as experimentalParseKaladaV1GuestExpressionPrefix, formatKaladaV1Expression, lowerKaladaV1Expression, parseKaladaV1Expression, queryKaladaV1Semantics };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,231 @@
|
|
|
1
|
+
import { JsonValue, KaladaV1DiagnosticCode, KaladaType, KaladaV1Options, KaladaV1Program } from '@kalada/core';
|
|
2
|
+
|
|
3
|
+
interface KaladaSourceRange {
|
|
4
|
+
readonly start: number;
|
|
5
|
+
readonly end: number;
|
|
6
|
+
}
|
|
7
|
+
type KaladaTokenKind = "whitespace" | "identifier" | "number" | "string" | "true" | "false" | "null" | "in" | "xor" | "left-parenthesis" | "right-parenthesis" | "dot" | "optional-dot" | "question" | "colon" | "operator" | "unsupported" | "invalid" | "eof";
|
|
8
|
+
interface KaladaToken {
|
|
9
|
+
readonly kind: KaladaTokenKind;
|
|
10
|
+
readonly text: string;
|
|
11
|
+
readonly range: KaladaSourceRange;
|
|
12
|
+
}
|
|
13
|
+
interface CstBase {
|
|
14
|
+
readonly range: KaladaSourceRange;
|
|
15
|
+
}
|
|
16
|
+
interface KaladaLiteralCstNode extends CstBase {
|
|
17
|
+
readonly kind: "literal";
|
|
18
|
+
readonly literalKind: "number" | "string" | "boolean" | "null";
|
|
19
|
+
readonly token: number;
|
|
20
|
+
readonly value: JsonValue;
|
|
21
|
+
}
|
|
22
|
+
interface KaladaReferenceCstNode extends CstBase {
|
|
23
|
+
readonly kind: "reference";
|
|
24
|
+
readonly token: number;
|
|
25
|
+
readonly name: string;
|
|
26
|
+
}
|
|
27
|
+
interface KaladaGroupCstNode extends CstBase {
|
|
28
|
+
readonly kind: "group";
|
|
29
|
+
readonly openToken: number;
|
|
30
|
+
readonly expression: KaladaCstNode;
|
|
31
|
+
readonly closeToken: number | null;
|
|
32
|
+
}
|
|
33
|
+
interface KaladaFieldAccessCstNode extends CstBase {
|
|
34
|
+
readonly kind: "field-access";
|
|
35
|
+
readonly target: KaladaCstNode;
|
|
36
|
+
readonly optional: boolean;
|
|
37
|
+
readonly operatorToken: number;
|
|
38
|
+
readonly fieldToken: number | null;
|
|
39
|
+
readonly field: string | null;
|
|
40
|
+
}
|
|
41
|
+
interface KaladaUnaryCstNode extends CstBase {
|
|
42
|
+
readonly kind: "unary";
|
|
43
|
+
readonly operator: "!" | "+" | "-";
|
|
44
|
+
readonly operatorToken: number;
|
|
45
|
+
readonly operand: KaladaCstNode;
|
|
46
|
+
}
|
|
47
|
+
type KaladaBinaryOperator = "*" | "/" | "%" | "+" | "-" | "<" | "<=" | ">" | ">=" | "in" | "==" | "!=" | "&&" | "xor" | "||" | "??";
|
|
48
|
+
interface KaladaBinaryCstNode extends CstBase {
|
|
49
|
+
readonly kind: "binary";
|
|
50
|
+
readonly operator: KaladaBinaryOperator;
|
|
51
|
+
readonly operatorToken: number;
|
|
52
|
+
readonly left: KaladaCstNode;
|
|
53
|
+
readonly right: KaladaCstNode;
|
|
54
|
+
}
|
|
55
|
+
interface KaladaConditionalCstNode extends CstBase {
|
|
56
|
+
readonly kind: "conditional";
|
|
57
|
+
readonly condition: KaladaCstNode;
|
|
58
|
+
readonly questionToken: number;
|
|
59
|
+
readonly then: KaladaCstNode;
|
|
60
|
+
readonly colonToken: number | null;
|
|
61
|
+
readonly else: KaladaCstNode;
|
|
62
|
+
}
|
|
63
|
+
interface KaladaErrorCstNode extends CstBase {
|
|
64
|
+
readonly kind: "error";
|
|
65
|
+
readonly token: number | null;
|
|
66
|
+
}
|
|
67
|
+
type KaladaCstNode = KaladaLiteralCstNode | KaladaReferenceCstNode | KaladaGroupCstNode | KaladaFieldAccessCstNode | KaladaUnaryCstNode | KaladaBinaryCstNode | KaladaConditionalCstNode | KaladaErrorCstNode;
|
|
68
|
+
interface KaladaCstDocument {
|
|
69
|
+
readonly source: string;
|
|
70
|
+
readonly tokens: readonly KaladaToken[];
|
|
71
|
+
readonly expression: KaladaCstNode;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface KaladaSyntaxLimits {
|
|
75
|
+
readonly maxSourceLength: number;
|
|
76
|
+
readonly maxTokens: number;
|
|
77
|
+
readonly maxCstDepth: number;
|
|
78
|
+
readonly maxCstNodes: number;
|
|
79
|
+
readonly maxDiagnostics: number;
|
|
80
|
+
readonly maxRecoveryTokens: number;
|
|
81
|
+
readonly maxIdentifierLength: number;
|
|
82
|
+
readonly maxDecodedStringLength: number;
|
|
83
|
+
readonly maxStaticTypeDepth: number;
|
|
84
|
+
}
|
|
85
|
+
interface KaladaParseOptions {
|
|
86
|
+
readonly limits?: Partial<KaladaSyntaxLimits>;
|
|
87
|
+
}
|
|
88
|
+
type KaladaSyntaxDiagnosticCode = "KALADA_SYNTAX_INVALID_INPUT" | "KALADA_SYNTAX_LIMIT_EXCEEDED" | "KALADA_SYNTAX_UNEXPECTED_TOKEN" | "KALADA_SYNTAX_EXPECTED_EXPRESSION" | "KALADA_SYNTAX_EXPECTED_FIELD" | "KALADA_SYNTAX_EXPECTED_RIGHT_PARENTHESIS" | "KALADA_SYNTAX_EXPECTED_COLON" | "KALADA_SYNTAX_INVALID_NUMBER" | "KALADA_SYNTAX_INVALID_STRING" | "KALADA_SYNTAX_UNSUPPORTED_FORM" | "KALADA_SYNTAX_UNSUPPORTED_OPERATOR" | "KALADA_SYNTAX_RELATIONAL_CHAIN" | "KALADA_SYNTAX_COALESCE_LOGICAL_MIX" | "KALADA_SYNTAX_UNKNOWN_REFERENCE" | "KALADA_SYNTAX_WRITE_INELIGIBLE" | "KALADA_SYNTAX_WRITE_BINDING_INVALID" | "KALADA_SYNTAX_WRITE_PROPERTY_INVALID";
|
|
89
|
+
interface KaladaSyntaxDiagnostic {
|
|
90
|
+
readonly phase: "lex" | "parse" | "lower";
|
|
91
|
+
readonly code: KaladaSyntaxDiagnosticCode | KaladaV1DiagnosticCode;
|
|
92
|
+
readonly message: string;
|
|
93
|
+
readonly range: KaladaSourceRange;
|
|
94
|
+
readonly path: readonly (string | number)[];
|
|
95
|
+
}
|
|
96
|
+
interface KaladaParseResult {
|
|
97
|
+
readonly document: KaladaCstDocument;
|
|
98
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
99
|
+
}
|
|
100
|
+
type KaladaSyntaxStaticType = "dynamic" | KaladaType;
|
|
101
|
+
type KaladaSemanticSupport = "supported" | "conditional" | "unsupported";
|
|
102
|
+
interface KaladaSemanticOperatorInfo {
|
|
103
|
+
readonly operator: KaladaBinaryOperator;
|
|
104
|
+
readonly support: KaladaSemanticSupport;
|
|
105
|
+
}
|
|
106
|
+
interface KaladaSemanticNodeInfo {
|
|
107
|
+
readonly range: KaladaSourceRange;
|
|
108
|
+
readonly type: KaladaSyntaxStaticType;
|
|
109
|
+
readonly known: boolean;
|
|
110
|
+
readonly fieldAccess: Readonly<{
|
|
111
|
+
plain: KaladaSemanticSupport;
|
|
112
|
+
optional: KaladaSemanticSupport;
|
|
113
|
+
}>;
|
|
114
|
+
readonly operators: readonly KaladaSemanticOperatorInfo[];
|
|
115
|
+
}
|
|
116
|
+
interface KaladaSemanticQueryResult {
|
|
117
|
+
readonly nodes: readonly KaladaSemanticNodeInfo[];
|
|
118
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
119
|
+
readonly incomplete: boolean;
|
|
120
|
+
}
|
|
121
|
+
interface KaladaReferenceBinding<R extends JsonValue> {
|
|
122
|
+
readonly reference: R;
|
|
123
|
+
readonly type: KaladaSyntaxStaticType;
|
|
124
|
+
}
|
|
125
|
+
interface KaladaLowerOptions<R extends JsonValue> {
|
|
126
|
+
readonly references?: Readonly<Record<string, KaladaReferenceBinding<R>>>;
|
|
127
|
+
readonly coreOptions?: KaladaV1Options<R>;
|
|
128
|
+
}
|
|
129
|
+
type KaladaSourceMapRole = "node" | "operator" | "literal" | "reference" | "field" | "group";
|
|
130
|
+
interface KaladaSourceMapEntry {
|
|
131
|
+
readonly path: readonly (string | number)[];
|
|
132
|
+
readonly role: KaladaSourceMapRole;
|
|
133
|
+
readonly range: KaladaSourceRange;
|
|
134
|
+
}
|
|
135
|
+
type KaladaLowerOutcome<R extends JsonValue = string> = {
|
|
136
|
+
readonly ok: true;
|
|
137
|
+
readonly program: KaladaV1Program<R>;
|
|
138
|
+
readonly sourceMap: readonly KaladaSourceMapEntry[];
|
|
139
|
+
readonly resultType: KaladaSyntaxStaticType;
|
|
140
|
+
} | {
|
|
141
|
+
readonly ok: false;
|
|
142
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
143
|
+
};
|
|
144
|
+
type KaladaFormatOutcome = {
|
|
145
|
+
readonly ok: true;
|
|
146
|
+
readonly text: string;
|
|
147
|
+
} | {
|
|
148
|
+
readonly ok: false;
|
|
149
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
declare const KALADA_SYNTAX_DIAGNOSTIC_MESSAGES: Readonly<{
|
|
153
|
+
KALADA_SYNTAX_INVALID_INPUT: string;
|
|
154
|
+
KALADA_SYNTAX_LIMIT_EXCEEDED: string;
|
|
155
|
+
KALADA_SYNTAX_UNEXPECTED_TOKEN: string;
|
|
156
|
+
KALADA_SYNTAX_EXPECTED_EXPRESSION: string;
|
|
157
|
+
KALADA_SYNTAX_EXPECTED_FIELD: string;
|
|
158
|
+
KALADA_SYNTAX_EXPECTED_RIGHT_PARENTHESIS: string;
|
|
159
|
+
KALADA_SYNTAX_EXPECTED_COLON: string;
|
|
160
|
+
KALADA_SYNTAX_INVALID_NUMBER: string;
|
|
161
|
+
KALADA_SYNTAX_INVALID_STRING: string;
|
|
162
|
+
KALADA_SYNTAX_UNSUPPORTED_FORM: string;
|
|
163
|
+
KALADA_SYNTAX_UNSUPPORTED_OPERATOR: string;
|
|
164
|
+
KALADA_SYNTAX_RELATIONAL_CHAIN: string;
|
|
165
|
+
KALADA_SYNTAX_COALESCE_LOGICAL_MIX: string;
|
|
166
|
+
KALADA_SYNTAX_UNKNOWN_REFERENCE: string;
|
|
167
|
+
KALADA_SYNTAX_WRITE_INELIGIBLE: string;
|
|
168
|
+
KALADA_SYNTAX_WRITE_BINDING_INVALID: string;
|
|
169
|
+
KALADA_SYNTAX_WRITE_PROPERTY_INVALID: string;
|
|
170
|
+
}>;
|
|
171
|
+
|
|
172
|
+
/** Static evidence only; the host must authorize this target again at use time. */
|
|
173
|
+
interface KaladaDataStateRef {
|
|
174
|
+
readonly namespace: "data";
|
|
175
|
+
readonly scope?: string;
|
|
176
|
+
readonly segments: readonly string[];
|
|
177
|
+
}
|
|
178
|
+
interface KaladaDirectLocationProperty {
|
|
179
|
+
readonly type: KaladaType;
|
|
180
|
+
readonly writable: true;
|
|
181
|
+
readonly properties?: Readonly<Record<string, KaladaDirectLocationProperty>>;
|
|
182
|
+
}
|
|
183
|
+
interface KaladaDirectLocationBinding extends KaladaDirectLocationProperty {
|
|
184
|
+
readonly target: KaladaDataStateRef;
|
|
185
|
+
}
|
|
186
|
+
interface KaladaDirectLocationOptions extends KaladaParseOptions {
|
|
187
|
+
readonly bindings: Readonly<Record<string, KaladaDirectLocationBinding>>;
|
|
188
|
+
}
|
|
189
|
+
interface KaladaDirectLocation {
|
|
190
|
+
readonly target: KaladaDataStateRef;
|
|
191
|
+
readonly type: KaladaType;
|
|
192
|
+
readonly range: KaladaSourceRange;
|
|
193
|
+
}
|
|
194
|
+
type KaladaDirectLocationOutcome = {
|
|
195
|
+
readonly ok: true;
|
|
196
|
+
readonly location: KaladaDirectLocation;
|
|
197
|
+
} | {
|
|
198
|
+
readonly ok: false;
|
|
199
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
200
|
+
};
|
|
201
|
+
declare function checkKaladaV1DirectLocation(source: string, options: KaladaDirectLocationOptions): KaladaDirectLocationOutcome;
|
|
202
|
+
|
|
203
|
+
declare function formatKaladaV1Expression(source: string, options?: KaladaParseOptions): KaladaFormatOutcome;
|
|
204
|
+
|
|
205
|
+
interface GuestBoundaryResult {
|
|
206
|
+
readonly ok: boolean;
|
|
207
|
+
readonly range: KaladaSourceRange;
|
|
208
|
+
readonly stop: number;
|
|
209
|
+
readonly reason: "outer-brace" | "unmatched-parentheses" | "unsupported-comment" | "unsupported-quote" | "eof" | "limit" | "invalid-start";
|
|
210
|
+
readonly parsed: KaladaParseResult | null;
|
|
211
|
+
readonly diagnostics: readonly KaladaSyntaxDiagnostic[];
|
|
212
|
+
}
|
|
213
|
+
/**
|
|
214
|
+
* Experimental opt-in syntax seam, not a host grammar contract.
|
|
215
|
+
* The host declares start and independently checks/consumes source[stop] === "}".
|
|
216
|
+
* Only current supported Kalada expressions succeed; future grammar belongs to the guest lexer.
|
|
217
|
+
* An unterminated supported double-quoted string is ambiguous: scanning remains bounded by
|
|
218
|
+
* maxSourceLength and fails closed, but cannot identify a brace inside that string as host-owned.
|
|
219
|
+
*/
|
|
220
|
+
declare function parseGuestExpressionPrefix(source: string, start: number, options?: KaladaParseOptions): GuestBoundaryResult;
|
|
221
|
+
|
|
222
|
+
declare const DEFAULT_KALADA_SYNTAX_LIMITS: Readonly<KaladaSyntaxLimits>;
|
|
223
|
+
declare const MAXIMUM_KALADA_SYNTAX_LIMITS: Readonly<KaladaSyntaxLimits>;
|
|
224
|
+
|
|
225
|
+
declare function lowerKaladaV1Expression<R extends JsonValue = string>(parsed: KaladaParseResult, options?: KaladaLowerOptions<R>): KaladaLowerOutcome<R>;
|
|
226
|
+
|
|
227
|
+
declare function parseKaladaV1Expression(source: string, options?: KaladaParseOptions): KaladaParseResult;
|
|
228
|
+
|
|
229
|
+
declare function queryKaladaV1Semantics<R extends JsonValue = string>(parsed: KaladaParseResult, options?: KaladaLowerOptions<R>): KaladaSemanticQueryResult;
|
|
230
|
+
|
|
231
|
+
export { DEFAULT_KALADA_SYNTAX_LIMITS, type GuestBoundaryResult as ExperimentalKaladaV1GuestPrefixResult, KALADA_SYNTAX_DIAGNOSTIC_MESSAGES, type KaladaBinaryCstNode, type KaladaBinaryOperator, type KaladaConditionalCstNode, type KaladaCstDocument, type KaladaCstNode, type KaladaDataStateRef, type KaladaDirectLocation, type KaladaDirectLocationBinding, type KaladaDirectLocationOptions, type KaladaDirectLocationOutcome, type KaladaDirectLocationProperty, type KaladaErrorCstNode, type KaladaFieldAccessCstNode, type KaladaFormatOutcome, type KaladaGroupCstNode, type KaladaLiteralCstNode, type KaladaLowerOptions, type KaladaLowerOutcome, type KaladaParseOptions, type KaladaParseResult, type KaladaReferenceBinding, type KaladaReferenceCstNode, type KaladaSemanticNodeInfo, type KaladaSemanticOperatorInfo, type KaladaSemanticQueryResult, type KaladaSemanticSupport, type KaladaSourceMapEntry, type KaladaSourceMapRole, type KaladaSourceRange, type KaladaSyntaxDiagnostic, type KaladaSyntaxDiagnosticCode, type KaladaSyntaxLimits, type KaladaSyntaxStaticType, type KaladaToken, type KaladaTokenKind, type KaladaUnaryCstNode, MAXIMUM_KALADA_SYNTAX_LIMITS, checkKaladaV1DirectLocation, parseGuestExpressionPrefix as experimentalParseKaladaV1GuestExpressionPrefix, formatKaladaV1Expression, lowerKaladaV1Expression, parseKaladaV1Expression, queryKaladaV1Semantics };
|