@atomic-ehr/fhirpath 0.0.1-canary.0c6931e.20250727185306
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 +473 -0
- package/dist/index.d.ts +462 -0
- package/dist/index.js +10307 -0
- package/dist/index.js.map +1 -0
- package/package.json +58 -0
- package/src/analyzer/analyzer.ts +499 -0
- package/src/analyzer/model-provider.ts +244 -0
- package/src/analyzer/schemas/index.ts +2 -0
- package/src/analyzer/schemas/types.ts +40 -0
- package/src/analyzer/types.ts +142 -0
- package/src/api/builder.ts +157 -0
- package/src/api/errors.ts +145 -0
- package/src/api/expression.ts +156 -0
- package/src/api/index.ts +122 -0
- package/src/api/inspect.ts +99 -0
- package/src/api/registry.ts +128 -0
- package/src/api/types.ts +210 -0
- package/src/compiler/compiler.ts +546 -0
- package/src/compiler/index.ts +2 -0
- package/src/compiler/prototype-context-adapter.ts +99 -0
- package/src/compiler/types.ts +24 -0
- package/src/index.ts +107 -0
- package/src/interpreter/README.md +78 -0
- package/src/interpreter/interpreter.ts +475 -0
- package/src/interpreter/types.ts +108 -0
- package/src/lexer/char-tables.ts +37 -0
- package/src/lexer/errors.ts +31 -0
- package/src/lexer/index.ts +5 -0
- package/src/lexer/lexer.ts +745 -0
- package/src/lexer/token.ts +104 -0
- package/src/lexer2/index.md +232 -0
- package/src/lexer2/index.perf.test.ts +68 -0
- package/src/lexer2/index.test.ts +549 -0
- package/src/lexer2/index.ts +1251 -0
- package/src/lexer2/notes.md +173 -0
- package/src/lexer2/optimization-summary.md +718 -0
- package/src/parser/ast-factory.ts +220 -0
- package/src/parser/ast.ts +144 -0
- package/src/parser/collection-parser.ts +89 -0
- package/src/parser/diagnostic-messages.ts +216 -0
- package/src/parser/diagnostics.ts +85 -0
- package/src/parser/error-reporter.ts +230 -0
- package/src/parser/index.ts +3 -0
- package/src/parser/literal-parser.ts +103 -0
- package/src/parser/parse-error.ts +16 -0
- package/src/parser/parser-error-factory.ts +141 -0
- package/src/parser/parser-state.ts +134 -0
- package/src/parser/parser.ts +1272 -0
- package/src/parser/pprint.ts +169 -0
- package/src/parser/precedence-manager.ts +64 -0
- package/src/parser/source-mapper.ts +248 -0
- package/src/parser/special-constructs.ts +142 -0
- package/src/parser/token-navigator.ts +110 -0
- package/src/parser/types.ts +60 -0
- package/src/parser2/index.md +177 -0
- package/src/parser2/index.perf.test.ts +184 -0
- package/src/parser2/index.test.ts +305 -0
- package/src/parser2/index.ts +578 -0
- package/src/parser2/optimization-summary.md +176 -0
- package/src/registry/default-analyzers.ts +257 -0
- package/src/registry/default-compilers.ts +31 -0
- package/src/registry/index.ts +96 -0
- package/src/registry/operations/arithmetic.ts +506 -0
- package/src/registry/operations/collection.ts +425 -0
- package/src/registry/operations/comparison.ts +432 -0
- package/src/registry/operations/existence.ts +703 -0
- package/src/registry/operations/filtering.ts +358 -0
- package/src/registry/operations/literals.ts +341 -0
- package/src/registry/operations/logical.ts +439 -0
- package/src/registry/operations/math.ts +128 -0
- package/src/registry/operations/membership.ts +132 -0
- package/src/registry/operations/navigation.ts +52 -0
- package/src/registry/operations/string.ts +507 -0
- package/src/registry/operations/subsetting.ts +174 -0
- package/src/registry/operations/type-checking.ts +162 -0
- package/src/registry/operations/type-conversion.ts +404 -0
- package/src/registry/operations/type-operators.ts +308 -0
- package/src/registry/operations/utility.ts +644 -0
- package/src/registry/registry.ts +146 -0
- package/src/registry/types.ts +161 -0
- package/src/registry/utils/evaluation-helpers.ts +93 -0
- package/src/registry/utils/index.ts +3 -0
- package/src/registry/utils/type-system.ts +173 -0
- package/src/runtime/context.ts +158 -0
- package/src/runtime/debug-context.ts +135 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { TokenType } from '../lexer/token';
|
|
2
|
+
import type { Token } from '../lexer/token';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Manages parser state and recovery operations
|
|
6
|
+
*/
|
|
7
|
+
export class ParserState {
|
|
8
|
+
private isPartial: boolean = false;
|
|
9
|
+
private currentContext: string = 'Expression';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Mark the parse result as partial (incomplete due to errors)
|
|
13
|
+
*/
|
|
14
|
+
markPartial(): void {
|
|
15
|
+
this.isPartial = true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Check if the parse result is partial
|
|
20
|
+
*/
|
|
21
|
+
getIsPartial(): boolean {
|
|
22
|
+
return this.isPartial;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Set current parsing context for better error messages
|
|
27
|
+
*/
|
|
28
|
+
setContext(context: string): void {
|
|
29
|
+
this.currentContext = context;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Get current parsing context
|
|
34
|
+
*/
|
|
35
|
+
getContext(): string {
|
|
36
|
+
return this.currentContext;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Check if a token is a synchronization point for error recovery
|
|
41
|
+
*/
|
|
42
|
+
static isSyncPoint(token: Token): boolean {
|
|
43
|
+
const syncTokens = new Set([
|
|
44
|
+
TokenType.COMMA,
|
|
45
|
+
TokenType.RPAREN,
|
|
46
|
+
TokenType.RBRACKET,
|
|
47
|
+
TokenType.RBRACE,
|
|
48
|
+
TokenType.EOF,
|
|
49
|
+
TokenType.EOF
|
|
50
|
+
]);
|
|
51
|
+
return syncTokens.has(token.type);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Check if a token represents a statement boundary
|
|
56
|
+
*/
|
|
57
|
+
static isStatementBoundary(token: Token): boolean {
|
|
58
|
+
return token.type === TokenType.EOF ||
|
|
59
|
+
token.type === TokenType.RBRACE;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Check if a token type is an operator keyword
|
|
64
|
+
*/
|
|
65
|
+
static isOperatorKeyword(type: TokenType): boolean {
|
|
66
|
+
const operatorKeywords = new Set([
|
|
67
|
+
TokenType.AND,
|
|
68
|
+
TokenType.OR,
|
|
69
|
+
TokenType.XOR,
|
|
70
|
+
TokenType.IMPLIES,
|
|
71
|
+
TokenType.AS,
|
|
72
|
+
TokenType.IS,
|
|
73
|
+
TokenType.MOD,
|
|
74
|
+
TokenType.DIV,
|
|
75
|
+
TokenType.IN,
|
|
76
|
+
TokenType.CONTAINS
|
|
77
|
+
]);
|
|
78
|
+
return operatorKeywords.has(type);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* Check if a token type is a literal
|
|
83
|
+
*/
|
|
84
|
+
static isLiteral(type: TokenType): boolean {
|
|
85
|
+
return type === TokenType.NUMBER ||
|
|
86
|
+
type === TokenType.STRING ||
|
|
87
|
+
type === TokenType.TRUE ||
|
|
88
|
+
type === TokenType.FALSE ||
|
|
89
|
+
type === TokenType.LITERAL;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Check if a token can start an expression
|
|
94
|
+
*/
|
|
95
|
+
static canStartExpression(token: Token): boolean {
|
|
96
|
+
const startTokens = new Set([
|
|
97
|
+
TokenType.IDENTIFIER,
|
|
98
|
+
TokenType.NUMBER,
|
|
99
|
+
TokenType.STRING,
|
|
100
|
+
TokenType.TRUE,
|
|
101
|
+
TokenType.FALSE,
|
|
102
|
+
TokenType.LPAREN,
|
|
103
|
+
TokenType.LBRACE,
|
|
104
|
+
TokenType.LBRACKET,
|
|
105
|
+
TokenType.PLUS,
|
|
106
|
+
TokenType.MINUS,
|
|
107
|
+
TokenType.NOT,
|
|
108
|
+
TokenType.ENV_VAR,
|
|
109
|
+
TokenType.LITERAL
|
|
110
|
+
]);
|
|
111
|
+
return startTokens.has(token.type);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Get expected tokens for a given context
|
|
116
|
+
*/
|
|
117
|
+
static getExpectedTokens(context: string): TokenType[] {
|
|
118
|
+
switch (context) {
|
|
119
|
+
case 'FunctionCall':
|
|
120
|
+
return [TokenType.IDENTIFIER, TokenType.NUMBER, TokenType.STRING,
|
|
121
|
+
TokenType.LPAREN, TokenType.LBRACE];
|
|
122
|
+
case 'TypeCast':
|
|
123
|
+
case 'MembershipTest':
|
|
124
|
+
return [TokenType.IDENTIFIER];
|
|
125
|
+
case 'Collection':
|
|
126
|
+
return [TokenType.IDENTIFIER, TokenType.NUMBER, TokenType.STRING,
|
|
127
|
+
TokenType.TRUE, TokenType.FALSE, TokenType.RBRACE];
|
|
128
|
+
case 'Index':
|
|
129
|
+
return [TokenType.NUMBER, TokenType.IDENTIFIER, TokenType.RBRACKET];
|
|
130
|
+
default:
|
|
131
|
+
return [TokenType.EOF];
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|