fhir-runtime 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +211 -0
- package/LICENSE +21 -0
- package/README.md +261 -0
- package/dist/cjs/index.cjs +7368 -0
- package/dist/cjs/index.cjs.map +7 -0
- package/dist/cjs/index.d.ts +4224 -0
- package/dist/cjs/package.json +5 -0
- package/dist/esm/index.d.ts +4224 -0
- package/dist/esm/index.mjs +7250 -0
- package/dist/esm/index.mjs.map +7 -0
- package/dist/esm/package.json +5 -0
- package/dist/index.d.ts +4224 -0
- package/dist/lib/context/bundle-loader.d.ts +124 -0
- package/dist/lib/context/bundle-loader.d.ts.map +1 -0
- package/dist/lib/context/core-definitions/index.d.ts +72 -0
- package/dist/lib/context/core-definitions/index.d.ts.map +1 -0
- package/dist/lib/context/errors.d.ts +114 -0
- package/dist/lib/context/errors.d.ts.map +1 -0
- package/dist/lib/context/fhir-context.d.ts +72 -0
- package/dist/lib/context/fhir-context.d.ts.map +1 -0
- package/dist/lib/context/index.d.ts +21 -0
- package/dist/lib/context/index.d.ts.map +1 -0
- package/dist/lib/context/inheritance-resolver.d.ts +98 -0
- package/dist/lib/context/inheritance-resolver.d.ts.map +1 -0
- package/dist/lib/context/inner-type-extractor.d.ts +80 -0
- package/dist/lib/context/inner-type-extractor.d.ts.map +1 -0
- package/dist/lib/context/loaders/composite-loader.d.ts +47 -0
- package/dist/lib/context/loaders/composite-loader.d.ts.map +1 -0
- package/dist/lib/context/loaders/file-loader.d.ts +47 -0
- package/dist/lib/context/loaders/file-loader.d.ts.map +1 -0
- package/dist/lib/context/loaders/index.d.ts +11 -0
- package/dist/lib/context/loaders/index.d.ts.map +1 -0
- package/dist/lib/context/loaders/memory-loader.d.ts +42 -0
- package/dist/lib/context/loaders/memory-loader.d.ts.map +1 -0
- package/dist/lib/context/registry.d.ts +116 -0
- package/dist/lib/context/registry.d.ts.map +1 -0
- package/dist/lib/context/types.d.ts +266 -0
- package/dist/lib/context/types.d.ts.map +1 -0
- package/dist/lib/fhirpath/atoms.d.ts +228 -0
- package/dist/lib/fhirpath/atoms.d.ts.map +1 -0
- package/dist/lib/fhirpath/cache.d.ts +79 -0
- package/dist/lib/fhirpath/cache.d.ts.map +1 -0
- package/dist/lib/fhirpath/date.d.ts +17 -0
- package/dist/lib/fhirpath/date.d.ts.map +1 -0
- package/dist/lib/fhirpath/functions.d.ts +28 -0
- package/dist/lib/fhirpath/functions.d.ts.map +1 -0
- package/dist/lib/fhirpath/index.d.ts +20 -0
- package/dist/lib/fhirpath/index.d.ts.map +1 -0
- package/dist/lib/fhirpath/lexer/parse.d.ts +100 -0
- package/dist/lib/fhirpath/lexer/parse.d.ts.map +1 -0
- package/dist/lib/fhirpath/lexer/tokenize.d.ts +80 -0
- package/dist/lib/fhirpath/lexer/tokenize.d.ts.map +1 -0
- package/dist/lib/fhirpath/parse.d.ts +101 -0
- package/dist/lib/fhirpath/parse.d.ts.map +1 -0
- package/dist/lib/fhirpath/tokenize.d.ts +20 -0
- package/dist/lib/fhirpath/tokenize.d.ts.map +1 -0
- package/dist/lib/fhirpath/types.d.ts +111 -0
- package/dist/lib/fhirpath/types.d.ts.map +1 -0
- package/dist/lib/fhirpath/utils.d.ts +81 -0
- package/dist/lib/fhirpath/utils.d.ts.map +1 -0
- package/dist/lib/index.d.ts +24 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/model/canonical-profile.d.ts +381 -0
- package/dist/lib/model/canonical-profile.d.ts.map +1 -0
- package/dist/lib/model/element-definition.d.ts +503 -0
- package/dist/lib/model/element-definition.d.ts.map +1 -0
- package/dist/lib/model/index.d.ts +14 -0
- package/dist/lib/model/index.d.ts.map +1 -0
- package/dist/lib/model/primitives.d.ts +464 -0
- package/dist/lib/model/primitives.d.ts.map +1 -0
- package/dist/lib/model/structure-definition.d.ts +263 -0
- package/dist/lib/model/structure-definition.d.ts.map +1 -0
- package/dist/lib/parser/choice-type-parser.d.ts +182 -0
- package/dist/lib/parser/choice-type-parser.d.ts.map +1 -0
- package/dist/lib/parser/index.d.ts +16 -0
- package/dist/lib/parser/index.d.ts.map +1 -0
- package/dist/lib/parser/json-parser.d.ts +171 -0
- package/dist/lib/parser/json-parser.d.ts.map +1 -0
- package/dist/lib/parser/parse-error.d.ts +146 -0
- package/dist/lib/parser/parse-error.d.ts.map +1 -0
- package/dist/lib/parser/primitive-parser.d.ts +136 -0
- package/dist/lib/parser/primitive-parser.d.ts.map +1 -0
- package/dist/lib/parser/serializer.d.ts +64 -0
- package/dist/lib/parser/serializer.d.ts.map +1 -0
- package/dist/lib/parser/structure-definition-parser.d.ts +63 -0
- package/dist/lib/parser/structure-definition-parser.d.ts.map +1 -0
- package/dist/lib/profile/canonical-builder.d.ts +87 -0
- package/dist/lib/profile/canonical-builder.d.ts.map +1 -0
- package/dist/lib/profile/constraint-merger.d.ts +100 -0
- package/dist/lib/profile/constraint-merger.d.ts.map +1 -0
- package/dist/lib/profile/element-merger.d.ts +80 -0
- package/dist/lib/profile/element-merger.d.ts.map +1 -0
- package/dist/lib/profile/element-sorter.d.ts +81 -0
- package/dist/lib/profile/element-sorter.d.ts.map +1 -0
- package/dist/lib/profile/errors.d.ts +150 -0
- package/dist/lib/profile/errors.d.ts.map +1 -0
- package/dist/lib/profile/index.d.ts +27 -0
- package/dist/lib/profile/index.d.ts.map +1 -0
- package/dist/lib/profile/path-utils.d.ts +180 -0
- package/dist/lib/profile/path-utils.d.ts.map +1 -0
- package/dist/lib/profile/slicing-handler.d.ts +121 -0
- package/dist/lib/profile/slicing-handler.d.ts.map +1 -0
- package/dist/lib/profile/snapshot-generator.d.ts +73 -0
- package/dist/lib/profile/snapshot-generator.d.ts.map +1 -0
- package/dist/lib/profile/types.d.ts +220 -0
- package/dist/lib/profile/types.d.ts.map +1 -0
- package/dist/lib/validator/errors.d.ts +83 -0
- package/dist/lib/validator/errors.d.ts.map +1 -0
- package/dist/lib/validator/index.d.ts +23 -0
- package/dist/lib/validator/index.d.ts.map +1 -0
- package/dist/lib/validator/invariant-validator.d.ts +62 -0
- package/dist/lib/validator/invariant-validator.d.ts.map +1 -0
- package/dist/lib/validator/path-extractor.d.ts +123 -0
- package/dist/lib/validator/path-extractor.d.ts.map +1 -0
- package/dist/lib/validator/slicing-validator.d.ts +119 -0
- package/dist/lib/validator/slicing-validator.d.ts.map +1 -0
- package/dist/lib/validator/structure-validator.d.ts +74 -0
- package/dist/lib/validator/structure-validator.d.ts.map +1 -0
- package/dist/lib/validator/types.d.ts +288 -0
- package/dist/lib/validator/types.d.ts.map +1 -0
- package/dist/lib/validator/validation-rules.d.ts +198 -0
- package/dist/lib/validator/validation-rules.d.ts.map +1 -0
- package/dist/tsdoc-metadata.json +11 -0
- package/package.json +76 -0
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FHIRPath AST Node Classes (Atoms)
|
|
3
|
+
*
|
|
4
|
+
* Each class implements the {@link Atom} interface and represents a node
|
|
5
|
+
* in the parsed FHIRPath expression tree.
|
|
6
|
+
*
|
|
7
|
+
* **Basic atoms** (Task 6.2):
|
|
8
|
+
* - {@link FhirPathAtom} — Root wrapper
|
|
9
|
+
* - {@link LiteralAtom} — String, number, boolean, DateTime, Quantity literals
|
|
10
|
+
* - {@link SymbolAtom} — Identifiers and variables (`$this`, `%context`)
|
|
11
|
+
* - {@link EmptySetAtom} — The empty set `{}`
|
|
12
|
+
* - {@link UnaryOperatorAtom} — Unary `+` and `-`
|
|
13
|
+
* - {@link DotAtom} — Property navigation (`.`)
|
|
14
|
+
* - {@link FunctionAtom} — Function calls (`where()`, `exists()`, etc.)
|
|
15
|
+
* - {@link IndexerAtom} — Indexer access (`[0]`)
|
|
16
|
+
*
|
|
17
|
+
* **Operator atoms** (Task 6.3):
|
|
18
|
+
* - {@link ArithmeticOperatorAtom} — `+`, `-`, `*`, `/`, `div`, `mod`
|
|
19
|
+
* - {@link ConcatAtom} — String concatenation `&`
|
|
20
|
+
* - {@link UnionAtom} — Collection union `|`
|
|
21
|
+
* - {@link EqualsAtom} / {@link NotEqualsAtom} — `=`, `!=`
|
|
22
|
+
* - {@link EquivalentAtom} / {@link NotEquivalentAtom} — `~`, `!~`
|
|
23
|
+
* - {@link IsAtom} / {@link AsAtom} — Type operators
|
|
24
|
+
* - {@link ContainsAtom} / {@link InAtom} — Membership operators
|
|
25
|
+
* - {@link AndAtom} / {@link OrAtom} / {@link XorAtom} / {@link ImpliesAtom} — Boolean operators
|
|
26
|
+
*
|
|
27
|
+
* @module fhirpath
|
|
28
|
+
*/
|
|
29
|
+
import type { Atom, AtomContext, TypedValue } from './types.js';
|
|
30
|
+
import { InfixOperatorAtom, PrefixOperatorAtom } from './types.js';
|
|
31
|
+
/**
|
|
32
|
+
* Root wrapper atom for a parsed FHIRPath expression.
|
|
33
|
+
* Iterates over each input element, setting `$this` for each evaluation.
|
|
34
|
+
*/
|
|
35
|
+
export declare class FhirPathAtom implements Atom {
|
|
36
|
+
readonly original: string;
|
|
37
|
+
readonly child: Atom;
|
|
38
|
+
constructor(original: string, child: Atom);
|
|
39
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
40
|
+
toString(): string;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Literal value atom (string, number, boolean, DateTime, Quantity).
|
|
44
|
+
*/
|
|
45
|
+
export declare class LiteralAtom implements Atom {
|
|
46
|
+
readonly value: TypedValue;
|
|
47
|
+
constructor(value: TypedValue);
|
|
48
|
+
eval(): TypedValue[];
|
|
49
|
+
toString(): string;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Symbol atom — identifiers, variables (`$this`, `%context`), and resource type names.
|
|
53
|
+
*/
|
|
54
|
+
export declare class SymbolAtom implements Atom {
|
|
55
|
+
readonly name: string;
|
|
56
|
+
constructor(name: string);
|
|
57
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
58
|
+
private getVariable;
|
|
59
|
+
private evalValue;
|
|
60
|
+
toString(): string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Empty set atom — represents `{}`.
|
|
64
|
+
*/
|
|
65
|
+
export declare class EmptySetAtom implements Atom {
|
|
66
|
+
eval(): TypedValue[];
|
|
67
|
+
toString(): string;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Unary operator atom (prefix `+` and `-`).
|
|
71
|
+
*/
|
|
72
|
+
export declare class UnaryOperatorAtom extends PrefixOperatorAtom {
|
|
73
|
+
readonly impl: (x: TypedValue[]) => TypedValue[];
|
|
74
|
+
constructor(operator: string, child: Atom, impl: (x: TypedValue[]) => TypedValue[]);
|
|
75
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
76
|
+
toString(): string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Dot (property navigation) atom.
|
|
80
|
+
* Evaluates left, then feeds result as input to right.
|
|
81
|
+
*/
|
|
82
|
+
export declare class DotAtom extends InfixOperatorAtom {
|
|
83
|
+
constructor(left: Atom, right: Atom);
|
|
84
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
85
|
+
toString(): string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Function call atom.
|
|
89
|
+
* Delegates to the function registry at evaluation time.
|
|
90
|
+
*/
|
|
91
|
+
export declare class FunctionAtom implements Atom {
|
|
92
|
+
readonly name: string;
|
|
93
|
+
readonly args: Atom[];
|
|
94
|
+
constructor(name: string, args: Atom[]);
|
|
95
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
96
|
+
toString(): string;
|
|
97
|
+
}
|
|
98
|
+
export type FhirPathFunction = (context: AtomContext, input: TypedValue[], ...args: Atom[]) => TypedValue[];
|
|
99
|
+
export declare function setFunctionRegistry(registry: Record<string, FhirPathFunction>): void;
|
|
100
|
+
/**
|
|
101
|
+
* Indexer atom — `collection[index]`.
|
|
102
|
+
*/
|
|
103
|
+
export declare class IndexerAtom implements Atom {
|
|
104
|
+
readonly left: Atom;
|
|
105
|
+
readonly expr: Atom;
|
|
106
|
+
constructor(left: Atom, expr: Atom);
|
|
107
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
108
|
+
toString(): string;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Base class for boolean-producing infix operators.
|
|
112
|
+
*/
|
|
113
|
+
export declare abstract class BooleanInfixOperatorAtom extends InfixOperatorAtom {
|
|
114
|
+
abstract eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Arithmetic operator atom — handles `+`, `-`, `*`, `/`, `div`, `mod`,
|
|
118
|
+
* and comparison operators `<`, `<=`, `>`, `>=`.
|
|
119
|
+
* Works on numbers and Quantity values.
|
|
120
|
+
*/
|
|
121
|
+
export declare class ArithmeticOperatorAtom extends BooleanInfixOperatorAtom {
|
|
122
|
+
readonly impl: (x: number, y: number) => number | boolean;
|
|
123
|
+
constructor(operator: string, left: Atom, right: Atom, impl: (x: number, y: number) => number | boolean);
|
|
124
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* String concatenation operator `&`.
|
|
128
|
+
* Concatenates string values; for non-strings, collects into a union.
|
|
129
|
+
*/
|
|
130
|
+
export declare class ConcatAtom extends InfixOperatorAtom {
|
|
131
|
+
constructor(left: Atom, right: Atom);
|
|
132
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Union operator `|`.
|
|
136
|
+
* Combines two collections, removing duplicates.
|
|
137
|
+
*/
|
|
138
|
+
export declare class UnionAtom extends InfixOperatorAtom {
|
|
139
|
+
constructor(left: Atom, right: Atom);
|
|
140
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Equality operator `=`.
|
|
144
|
+
*/
|
|
145
|
+
export declare class EqualsAtom extends BooleanInfixOperatorAtom {
|
|
146
|
+
constructor(left: Atom, right: Atom);
|
|
147
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Not-equals operator `!=`.
|
|
151
|
+
*/
|
|
152
|
+
export declare class NotEqualsAtom extends BooleanInfixOperatorAtom {
|
|
153
|
+
constructor(left: Atom, right: Atom);
|
|
154
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Equivalence operator `~`.
|
|
158
|
+
*/
|
|
159
|
+
export declare class EquivalentAtom extends BooleanInfixOperatorAtom {
|
|
160
|
+
constructor(left: Atom, right: Atom);
|
|
161
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Not-equivalent operator `!~`.
|
|
165
|
+
*/
|
|
166
|
+
export declare class NotEquivalentAtom extends BooleanInfixOperatorAtom {
|
|
167
|
+
constructor(left: Atom, right: Atom);
|
|
168
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Type-check operator `is`.
|
|
172
|
+
*/
|
|
173
|
+
export declare class IsAtom extends BooleanInfixOperatorAtom {
|
|
174
|
+
constructor(left: Atom, right: Atom);
|
|
175
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Type-cast operator `as`.
|
|
179
|
+
*/
|
|
180
|
+
export declare class AsAtom extends InfixOperatorAtom {
|
|
181
|
+
constructor(left: Atom, right: Atom);
|
|
182
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
183
|
+
}
|
|
184
|
+
/**
|
|
185
|
+
* Collection membership operator `contains`.
|
|
186
|
+
* `collection contains value` → true if value is in collection.
|
|
187
|
+
*/
|
|
188
|
+
export declare class ContainsAtom extends BooleanInfixOperatorAtom {
|
|
189
|
+
constructor(left: Atom, right: Atom);
|
|
190
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* Collection membership operator `in`.
|
|
194
|
+
* `value in collection` → true if value is in collection.
|
|
195
|
+
*/
|
|
196
|
+
export declare class InAtom extends BooleanInfixOperatorAtom {
|
|
197
|
+
constructor(left: Atom, right: Atom);
|
|
198
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
199
|
+
}
|
|
200
|
+
/**
|
|
201
|
+
* Logical AND — three-valued logic per FHIRPath spec §6.5.1.
|
|
202
|
+
*/
|
|
203
|
+
export declare class AndAtom extends BooleanInfixOperatorAtom {
|
|
204
|
+
constructor(left: Atom, right: Atom);
|
|
205
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Logical OR — three-valued logic per FHIRPath spec §6.5.2.
|
|
209
|
+
*/
|
|
210
|
+
export declare class OrAtom extends BooleanInfixOperatorAtom {
|
|
211
|
+
constructor(left: Atom, right: Atom);
|
|
212
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* Logical XOR — three-valued logic per FHIRPath spec §6.5.4.
|
|
216
|
+
*/
|
|
217
|
+
export declare class XorAtom extends BooleanInfixOperatorAtom {
|
|
218
|
+
constructor(left: Atom, right: Atom);
|
|
219
|
+
eval(context: AtomContext, input: TypedValue[]): TypedValue[];
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Logical IMPLIES — three-valued logic per FHIRPath spec §6.5.5.
|
|
223
|
+
*/
|
|
224
|
+
export declare class ImpliesAtom extends BooleanInfixOperatorAtom {
|
|
225
|
+
constructor(left: Atom, right: Atom);
|
|
226
|
+
eval(context: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AAG,UAAU,EAAE;CAK9D;AAED;;;GAGG;AACH,qBAAa,MAAO,SAAQ,wBAAwB;gBACtC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI;IAInC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE;CAQ9D;AAMD;;GAEG;AACH,qBAAa,OAAQ,SAAQ,wBAAwB;gBACvC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI;IAInC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE;CAW9D;AAED;;GAEG;AACH,qBAAa,MAAO,SAAQ,wBAAwB;gBACtC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI;IAInC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE;CAW9D;AAED;;GAEG;AACH,qBAAa,OAAQ,SAAQ,wBAAwB;gBACvC,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI;IAInC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE;CAQ9D;AAED;;GAEG;AACH,qBAAa,WAAY,SAAQ,wBAAwB;gBAC3C,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,IAAI;IAInC,IAAI,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,GAAG,UAAU,EAAE;CAU9D"}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LRU (Least Recently Used) Cache for parsed FHIRPath expressions.
|
|
3
|
+
*
|
|
4
|
+
* Caches parsed AST nodes so that repeated evaluation of the same
|
|
5
|
+
* expression string avoids re-parsing.
|
|
6
|
+
*
|
|
7
|
+
* @module fhirpath
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* A generic LRU cache with O(1) get/set via a Map (insertion-ordered).
|
|
11
|
+
*
|
|
12
|
+
* When the cache exceeds `maxSize`, the least-recently-used entry is evicted.
|
|
13
|
+
*
|
|
14
|
+
* @typeParam K - Key type.
|
|
15
|
+
* @typeParam V - Value type.
|
|
16
|
+
*/
|
|
17
|
+
export declare class LRUCache<K, V> {
|
|
18
|
+
private readonly map;
|
|
19
|
+
private readonly _maxSize;
|
|
20
|
+
/** Total number of `get` calls. */
|
|
21
|
+
private _gets;
|
|
22
|
+
/** Number of `get` calls that returned a cached value. */
|
|
23
|
+
private _hits;
|
|
24
|
+
constructor(maxSize: number);
|
|
25
|
+
/** Maximum number of entries before eviction. */
|
|
26
|
+
get maxSize(): number;
|
|
27
|
+
/** Current number of cached entries. */
|
|
28
|
+
get size(): number;
|
|
29
|
+
/** Total `get` calls since creation or last `resetStats()`. */
|
|
30
|
+
get gets(): number;
|
|
31
|
+
/** Cache hits since creation or last `resetStats()`. */
|
|
32
|
+
get hits(): number;
|
|
33
|
+
/**
|
|
34
|
+
* Cache hit rate as a number between 0 and 1.
|
|
35
|
+
* Returns 0 if no `get` calls have been made.
|
|
36
|
+
*/
|
|
37
|
+
get hitRate(): number;
|
|
38
|
+
/**
|
|
39
|
+
* Retrieve a value by key.
|
|
40
|
+
*
|
|
41
|
+
* If found, the entry is promoted to most-recently-used.
|
|
42
|
+
*/
|
|
43
|
+
get(key: K): V | undefined;
|
|
44
|
+
/**
|
|
45
|
+
* Insert or update a key-value pair.
|
|
46
|
+
*
|
|
47
|
+
* If the key already exists it is updated and promoted.
|
|
48
|
+
* If the cache is full the least-recently-used entry is evicted.
|
|
49
|
+
*/
|
|
50
|
+
set(key: K, value: V): void;
|
|
51
|
+
/** Check whether a key exists without affecting LRU order or stats. */
|
|
52
|
+
has(key: K): boolean;
|
|
53
|
+
/** Remove a specific key. Returns `true` if the key existed. */
|
|
54
|
+
delete(key: K): boolean;
|
|
55
|
+
/** Remove all entries. Does not reset stats. */
|
|
56
|
+
clear(): void;
|
|
57
|
+
/** Reset hit/get counters to zero. */
|
|
58
|
+
resetStats(): void;
|
|
59
|
+
/** Iterate over entries in LRU order (least-recent first). */
|
|
60
|
+
entries(): IterableIterator<[K, V]>;
|
|
61
|
+
/** Iterate over keys in LRU order (least-recent first). */
|
|
62
|
+
keys(): IterableIterator<K>;
|
|
63
|
+
}
|
|
64
|
+
/** Default cache size for parsed FHIRPath expressions. */
|
|
65
|
+
export declare const DEFAULT_CACHE_SIZE = 1000;
|
|
66
|
+
/**
|
|
67
|
+
* Get the global expression cache instance.
|
|
68
|
+
* The cache stores parsed FHIRPath AST nodes keyed by expression string.
|
|
69
|
+
*/
|
|
70
|
+
export declare function getExpressionCache(): LRUCache<string, unknown>;
|
|
71
|
+
/**
|
|
72
|
+
* Replace the global expression cache (e.g. to change max size).
|
|
73
|
+
*/
|
|
74
|
+
export declare function setExpressionCache(cache: LRUCache<string, unknown>): void;
|
|
75
|
+
/**
|
|
76
|
+
* Clear the global expression cache.
|
|
77
|
+
*/
|
|
78
|
+
export declare function clearExpressionCache(): void;
|
|
79
|
+
//# sourceMappingURL=cache.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cache.d.ts","sourceRoot":"","sources":["../../../src/fhirpath/cache.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH;;;;;;;GAOG;AACH,qBAAa,QAAQ,CAAC,CAAC,EAAE,CAAC;IACxB,OAAO,CAAC,QAAQ,CAAC,GAAG,CAAmB;IACvC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAElC,mCAAmC;IACnC,OAAO,CAAC,KAAK,CAAK;IAClB,0DAA0D;IAC1D,OAAO,CAAC,KAAK,CAAK;gBAEN,OAAO,EAAE,MAAM;IAO3B,iDAAiD;IACjD,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED,wCAAwC;IACxC,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,+DAA+D;IAC/D,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,wDAAwD;IACxD,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED;;;OAGG;IACH,IAAI,OAAO,IAAI,MAAM,CAEpB;IAED;;;;OAIG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,GAAG,SAAS;IAa1B;;;;;OAKG;IACH,GAAG,CAAC,GAAG,EAAE,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;IAW3B,uEAAuE;IACvE,GAAG,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIpB,gEAAgE;IAChE,MAAM,CAAC,GAAG,EAAE,CAAC,GAAG,OAAO;IAIvB,gDAAgD;IAChD,KAAK,IAAI,IAAI;IAIb,sCAAsC;IACtC,UAAU,IAAI,IAAI;IAKlB,8DAA8D;IAC7D,OAAO,IAAI,gBAAgB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;IAIpC,2DAA2D;IAC1D,IAAI,IAAI,gBAAgB,CAAC,CAAC,CAAC;CAG7B;AAMD,0DAA0D;AAC1D,eAAO,MAAM,kBAAkB,OAAO,CAAC;AAKvC;;;GAGG;AACH,wBAAgB,kBAAkB,IAAI,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,CAE9D;AAED;;GAEG;AACH,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,IAAI,CAEzE;AAED;;GAEG;AACH,wBAAgB,oBAAoB,IAAI,IAAI,CAG3C"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FHIRPath date/time parsing utilities.
|
|
3
|
+
*
|
|
4
|
+
* @module fhirpath
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Parse a FHIRPath date/time string into a normalized string.
|
|
8
|
+
*
|
|
9
|
+
* - Time-only strings (`T10:30:00`) are padded to full length.
|
|
10
|
+
* - Local dates (`2021-01-01`) are returned as-is.
|
|
11
|
+
* - DateTime strings are normalized to UTC via `Date.toISOString()`.
|
|
12
|
+
*
|
|
13
|
+
* @param str - The date/time string from a DateTime token.
|
|
14
|
+
* @returns The normalized date/time string.
|
|
15
|
+
*/
|
|
16
|
+
export declare function parseDateString(str: string): string;
|
|
17
|
+
//# sourceMappingURL=date.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"date.d.ts","sourceRoot":"","sources":["../../../src/fhirpath/date.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;GASG;AACH,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAkBnD"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FHIRPath Standard Functions
|
|
3
|
+
*
|
|
4
|
+
* Implements FHIRPath §5.1–5.9 and §6.3–6.5 functions.
|
|
5
|
+
* Organized by FHIRPath spec section:
|
|
6
|
+
* - §5.1 Existence (empty, exists, all, allTrue, anyTrue, allFalse, anyFalse, subsetOf, supersetOf, count, distinct, isDistinct)
|
|
7
|
+
* - §5.2 Filtering and projection (where, select, repeat, ofType)
|
|
8
|
+
* - §5.3 Subsetting (single, first, last, tail, skip, take, intersect, exclude)
|
|
9
|
+
* - §5.4 Combining (union, combine)
|
|
10
|
+
* - §5.5 Conversion (iif, toBoolean, convertsToBoolean, toInteger, convertsToInteger, toDecimal, convertsToDecimal, toQuantity, convertsToQuantity, toString, convertsToString, toDateTime, convertsToDateTime, toTime, convertsToTime)
|
|
11
|
+
* - §5.6 String manipulation (indexOf, substring, startsWith, endsWith, contains, upper, lower, replace, matches, replaceMatches, length, toChars, join)
|
|
12
|
+
* - §5.7 Math (abs, ceiling, exp, floor, ln, log, power, round, sqrt, truncate)
|
|
13
|
+
* - §5.8 Tree navigation (children, descendants)
|
|
14
|
+
* - §5.9 Utility (trace, now, timeOfDay, today)
|
|
15
|
+
* - §6.3 Types (is, as, type, conformsTo)
|
|
16
|
+
* - §6.5 Boolean logic (not)
|
|
17
|
+
* - FHIR-specific (resolve, extension, hasValue, htmlChecks, getResourceKey, getReferenceKey)
|
|
18
|
+
*
|
|
19
|
+
* @module fhirpath
|
|
20
|
+
*/
|
|
21
|
+
import type { Atom, AtomContext, TypedValue } from './types.js';
|
|
22
|
+
export type FhirPathFunction = (context: AtomContext, input: TypedValue[], ...args: Atom[]) => TypedValue[];
|
|
23
|
+
/**
|
|
24
|
+
* Global function registry.
|
|
25
|
+
* Keys are function names as they appear in FHIRPath expressions.
|
|
26
|
+
*/
|
|
27
|
+
export declare const functions: Record<string, FhirPathFunction>;
|
|
28
|
+
//# sourceMappingURL=functions.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../../../src/fhirpath/functions.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,WAAW,EAAE,UAAU,EAAE,MAAM,YAAY,CAAC;AAYhE,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,UAAU,EAAE,EAAE,GAAG,IAAI,EAAE,IAAI,EAAE,KAAK,UAAU,EAAE,CAAC;AAkH5G;;;GAGG;AACH,eAAO,MAAM,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,gBAAgB,CA6uBtD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FHIRPath Module — Public API
|
|
3
|
+
*
|
|
4
|
+
* @module fhirpath
|
|
5
|
+
*/
|
|
6
|
+
export type { TypedValue, AtomContext, Atom } from './types.js';
|
|
7
|
+
export { PropertyType, PrefixOperatorAtom, InfixOperatorAtom } from './types.js';
|
|
8
|
+
export type { Token, Marker, TokenizerOptions } from './lexer/tokenize.js';
|
|
9
|
+
export { Tokenizer } from './lexer/tokenize.js';
|
|
10
|
+
export type { PrefixParselet, InfixParselet } from './lexer/parse.js';
|
|
11
|
+
export { ParserBuilder, Parser } from './lexer/parse.js';
|
|
12
|
+
export { tokenize, FHIRPATH_KEYWORDS, FHIRPATH_OPERATORS } from './tokenize.js';
|
|
13
|
+
export { parseFhirPath, evalFhirPath, evalFhirPathTyped, evalFhirPathBoolean, evalFhirPathString, OperatorPrecedence, initFhirPathParserBuilder } from './parse.js';
|
|
14
|
+
export { LRUCache, getExpressionCache, setExpressionCache, clearExpressionCache, DEFAULT_CACHE_SIZE } from './cache.js';
|
|
15
|
+
export { FhirPathAtom, LiteralAtom, SymbolAtom, EmptySetAtom, UnaryOperatorAtom, DotAtom, FunctionAtom, IndexerAtom, ArithmeticOperatorAtom, ConcatAtom, UnionAtom, EqualsAtom, NotEqualsAtom, EquivalentAtom, NotEquivalentAtom, IsAtom, AsAtom, ContainsAtom, InAtom, AndAtom, OrAtom, XorAtom, ImpliesAtom, BooleanInfixOperatorAtom, } from './atoms.js';
|
|
16
|
+
export { booleanToTypedValue, toTypedValue, toJsBoolean, singleton, getTypedPropertyValue, fhirPathEquals, fhirPathArrayEquals, fhirPathArrayNotEquals, fhirPathEquivalent, fhirPathArrayEquivalent, fhirPathNot, removeDuplicates, fhirPathIs, isQuantity, isResource, isResourceType, } from './utils.js';
|
|
17
|
+
export { parseDateString } from './date.js';
|
|
18
|
+
export { functions } from './functions.js';
|
|
19
|
+
export type { FhirPathFunction } from './functions.js';
|
|
20
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/fhirpath/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,YAAY,EAAE,UAAU,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,YAAY,CAAC;AAChE,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,YAAY,CAAC;AAGjF,YAAY,EAAE,KAAK,EAAE,MAAM,EAAE,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,CAAC"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Pratt Parser Framework
|
|
3
|
+
*
|
|
4
|
+
* A top-down operator precedence parser based on
|
|
5
|
+
* {@link https://github.com/JacksonKearl/PrattParse | PrattParse}.
|
|
6
|
+
*
|
|
7
|
+
* The parser uses two kinds of "parselets":
|
|
8
|
+
* - **PrefixParselet** — handles tokens that appear at the start of an expression
|
|
9
|
+
* (literals, identifiers, unary operators, parenthesised groups)
|
|
10
|
+
* - **InfixParselet** — handles tokens that appear between two expressions
|
|
11
|
+
* (binary operators, function calls, indexers)
|
|
12
|
+
*
|
|
13
|
+
* @module fhirpath/lexer
|
|
14
|
+
*/
|
|
15
|
+
import type { Atom } from '../types.js';
|
|
16
|
+
import type { Token } from './tokenize.js';
|
|
17
|
+
/**
|
|
18
|
+
* A parselet that handles a token appearing in prefix position.
|
|
19
|
+
*/
|
|
20
|
+
export interface PrefixParselet {
|
|
21
|
+
parse(parser: Parser, token: Token): Atom;
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* A parselet that handles a token appearing in infix position.
|
|
25
|
+
* `precedence` controls how tightly this operator binds.
|
|
26
|
+
*/
|
|
27
|
+
export interface InfixParselet {
|
|
28
|
+
precedence: number;
|
|
29
|
+
parse?(parser: Parser, left: Atom, token: Token): Atom;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Fluent builder for constructing a {@link Parser} with registered parselets.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* ```ts
|
|
36
|
+
* const builder = new ParserBuilder()
|
|
37
|
+
* .registerPrefix('Number', { parse: (_, token) => new LiteralAtom(...) })
|
|
38
|
+
* .infixLeft('+', 5, (left, _, right) => new AddAtom(left, right));
|
|
39
|
+
*
|
|
40
|
+
* const parser = builder.construct(tokens);
|
|
41
|
+
* const ast = parser.consumeAndParse();
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export declare class ParserBuilder {
|
|
45
|
+
private readonly prefixParselets;
|
|
46
|
+
private readonly infixParselets;
|
|
47
|
+
registerInfix(tokenType: string, parselet: InfixParselet): this;
|
|
48
|
+
registerPrefix(tokenType: string, parselet: PrefixParselet): this;
|
|
49
|
+
/**
|
|
50
|
+
* Register a prefix operator with a given precedence.
|
|
51
|
+
* The builder callback receives the consumed token and the right-hand operand.
|
|
52
|
+
*/
|
|
53
|
+
prefix(tokenType: string, precedence: number, builder: (token: Token, right: Atom) => Atom): this;
|
|
54
|
+
/**
|
|
55
|
+
* Register a left-associative infix operator with a given precedence.
|
|
56
|
+
* The builder callback receives left operand, the consumed token, and right operand.
|
|
57
|
+
*/
|
|
58
|
+
infixLeft(tokenType: string, precedence: number, builder: (left: Atom, token: Token, right: Atom) => Atom): this;
|
|
59
|
+
/** Construct a {@link Parser} from the given token stream. */
|
|
60
|
+
construct(input: Token[]): Parser;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Pratt parser that converts a token stream into an AST of {@link Atom} nodes.
|
|
64
|
+
*/
|
|
65
|
+
export declare class Parser {
|
|
66
|
+
private tokens;
|
|
67
|
+
private readonly prefixParselets;
|
|
68
|
+
private readonly infixParselets;
|
|
69
|
+
constructor(tokens: Token[], prefixParselets: Record<string, PrefixParselet>, infixParselets: Record<string, InfixParselet>);
|
|
70
|
+
/** Returns true if there are more tokens to consume. */
|
|
71
|
+
hasMore(): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* If the next token has the expected `id`, consume it and return `true`.
|
|
74
|
+
* Otherwise return `false` without consuming.
|
|
75
|
+
*/
|
|
76
|
+
match(expected: string): boolean;
|
|
77
|
+
/**
|
|
78
|
+
* Core Pratt parsing loop.
|
|
79
|
+
* Consumes one prefix token, then continues consuming infix tokens
|
|
80
|
+
* as long as their precedence is lower (tighter) than the given threshold.
|
|
81
|
+
*
|
|
82
|
+
* @param precedence - The precedence ceiling (default: `Infinity` = parse everything).
|
|
83
|
+
* @returns The parsed AST node.
|
|
84
|
+
*/
|
|
85
|
+
consumeAndParse(precedence?: number): Atom;
|
|
86
|
+
/** Returns the precedence of the next infix parselet, or `Infinity` if none. */
|
|
87
|
+
getPrecedence(): number;
|
|
88
|
+
/**
|
|
89
|
+
* Consume the next token, optionally asserting its `id` and/or `value`.
|
|
90
|
+
* Throws if no tokens remain or if the assertion fails.
|
|
91
|
+
*/
|
|
92
|
+
consume(expectedId?: string, expectedValue?: string): Token;
|
|
93
|
+
/** Peek at the next token without consuming it. */
|
|
94
|
+
peek(): Token | undefined;
|
|
95
|
+
/** Remove all Comment tokens from the stream. */
|
|
96
|
+
removeComments(): void;
|
|
97
|
+
/** Look up the infix parselet for a token (by id, or by value for Symbols). */
|
|
98
|
+
getInfixParselet(token: Token): InfixParselet | undefined;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=parse.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parse.d.ts","sourceRoot":"","sources":["../../../../src/fhirpath/lexer/parse.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAM3C;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B,KAAK,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CAC3C;AAED;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,UAAU,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK,GAAG,IAAI,CAAC;CACxD;AAMD;;;;;;;;;;;;GAYG;AACH,qBAAa,aAAa;IACxB,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAsC;IACtE,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAqC;IAE7D,aAAa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,cAAc,IAAI,IAAI;IAItB,+EAA+E;IAC/E,gBAAgB,CAAC,KAAK,EAAE,KAAK,GAAG,aAAa,GAAG,SAAS;CAG1D"}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Generic Tokenizer for FHIR languages (FHIRPath, FML).
|
|
3
|
+
*
|
|
4
|
+
* Based on Medplum's fhirlexer, which is itself inspired by
|
|
5
|
+
* {@link https://github.com/JacksonKearl/PrattParse | PrattParse}.
|
|
6
|
+
*
|
|
7
|
+
* Supports:
|
|
8
|
+
* - String literals (single/double quotes, escape sequences)
|
|
9
|
+
* - Number literals (integer, decimal)
|
|
10
|
+
* - DateTime literals (`@2024-01-15T10:30:00Z`)
|
|
11
|
+
* - Quantity literals (`5 'mg'`, `10 days`)
|
|
12
|
+
* - Operators (`.`, `+`, `-`, `*`, `/`, `=`, `!=`, `<`, `>`, etc.)
|
|
13
|
+
* - Keywords (`and`, `or`, `xor`, `implies`, `is`, `as`, etc.)
|
|
14
|
+
* - Symbols (identifiers: `name`, `birthDate`, `$this`, `%context`, etc.)
|
|
15
|
+
* - Comments (`//` line comments, `/* ... */` block comments)
|
|
16
|
+
*
|
|
17
|
+
* @module fhirpath/lexer
|
|
18
|
+
*/
|
|
19
|
+
/** Position marker in source text. */
|
|
20
|
+
export interface Marker {
|
|
21
|
+
index: number;
|
|
22
|
+
line: number;
|
|
23
|
+
column: number;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* A single token produced by the tokenizer.
|
|
27
|
+
* `id` is the token type (e.g. `'Number'`, `'String'`, `'Symbol'`, `'+'`).
|
|
28
|
+
* `value` is the raw text content.
|
|
29
|
+
*/
|
|
30
|
+
export interface Token extends Marker {
|
|
31
|
+
id: string;
|
|
32
|
+
value: string;
|
|
33
|
+
}
|
|
34
|
+
export interface TokenizerOptions {
|
|
35
|
+
/** Enable `@`-prefixed DateTime literal parsing. */
|
|
36
|
+
dateTimeLiterals?: boolean;
|
|
37
|
+
/** Regex for valid symbol characters (default: `/[$\w%]/`). */
|
|
38
|
+
symbolRegex?: RegExp;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Generic tokenizer for FHIR languages.
|
|
42
|
+
*
|
|
43
|
+
* Usage:
|
|
44
|
+
* ```ts
|
|
45
|
+
* const tokens = new Tokenizer(input, keywords, operators).tokenize();
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
export declare class Tokenizer {
|
|
49
|
+
private readonly str;
|
|
50
|
+
private readonly keywords;
|
|
51
|
+
private readonly operators;
|
|
52
|
+
private readonly dateTimeLiterals;
|
|
53
|
+
private readonly symbolRegex;
|
|
54
|
+
private readonly result;
|
|
55
|
+
private readonly pos;
|
|
56
|
+
private readonly markStack;
|
|
57
|
+
constructor(str: string, keywords: string[], operators: string[], options?: TokenizerOptions);
|
|
58
|
+
tokenize(): Token[];
|
|
59
|
+
private prevToken;
|
|
60
|
+
private peekToken;
|
|
61
|
+
private consumeToken;
|
|
62
|
+
private consumeWhitespace;
|
|
63
|
+
private consumeMultiLineComment;
|
|
64
|
+
private consumeSingleLineComment;
|
|
65
|
+
private consumeString;
|
|
66
|
+
private consumeChar;
|
|
67
|
+
private consumeQuotedSymbol;
|
|
68
|
+
private consumeDateTime;
|
|
69
|
+
private consumeNumber;
|
|
70
|
+
private consumeSymbol;
|
|
71
|
+
private consumeOperator;
|
|
72
|
+
private consumeWhile;
|
|
73
|
+
private curr;
|
|
74
|
+
private peek;
|
|
75
|
+
private mark;
|
|
76
|
+
private reset;
|
|
77
|
+
private advance;
|
|
78
|
+
private buildToken;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=tokenize.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tokenize.d.ts","sourceRoot":"","sources":["../../../../src/fhirpath/lexer/tokenize.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,sCAAsC;AACtC,MAAM,WAAW,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