@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.
Files changed (85) hide show
  1. package/README.md +473 -0
  2. package/dist/index.d.ts +462 -0
  3. package/dist/index.js +10307 -0
  4. package/dist/index.js.map +1 -0
  5. package/package.json +58 -0
  6. package/src/analyzer/analyzer.ts +499 -0
  7. package/src/analyzer/model-provider.ts +244 -0
  8. package/src/analyzer/schemas/index.ts +2 -0
  9. package/src/analyzer/schemas/types.ts +40 -0
  10. package/src/analyzer/types.ts +142 -0
  11. package/src/api/builder.ts +157 -0
  12. package/src/api/errors.ts +145 -0
  13. package/src/api/expression.ts +156 -0
  14. package/src/api/index.ts +122 -0
  15. package/src/api/inspect.ts +99 -0
  16. package/src/api/registry.ts +128 -0
  17. package/src/api/types.ts +210 -0
  18. package/src/compiler/compiler.ts +546 -0
  19. package/src/compiler/index.ts +2 -0
  20. package/src/compiler/prototype-context-adapter.ts +99 -0
  21. package/src/compiler/types.ts +24 -0
  22. package/src/index.ts +107 -0
  23. package/src/interpreter/README.md +78 -0
  24. package/src/interpreter/interpreter.ts +475 -0
  25. package/src/interpreter/types.ts +108 -0
  26. package/src/lexer/char-tables.ts +37 -0
  27. package/src/lexer/errors.ts +31 -0
  28. package/src/lexer/index.ts +5 -0
  29. package/src/lexer/lexer.ts +745 -0
  30. package/src/lexer/token.ts +104 -0
  31. package/src/lexer2/index.md +232 -0
  32. package/src/lexer2/index.perf.test.ts +68 -0
  33. package/src/lexer2/index.test.ts +549 -0
  34. package/src/lexer2/index.ts +1251 -0
  35. package/src/lexer2/notes.md +173 -0
  36. package/src/lexer2/optimization-summary.md +718 -0
  37. package/src/parser/ast-factory.ts +220 -0
  38. package/src/parser/ast.ts +144 -0
  39. package/src/parser/collection-parser.ts +89 -0
  40. package/src/parser/diagnostic-messages.ts +216 -0
  41. package/src/parser/diagnostics.ts +85 -0
  42. package/src/parser/error-reporter.ts +230 -0
  43. package/src/parser/index.ts +3 -0
  44. package/src/parser/literal-parser.ts +103 -0
  45. package/src/parser/parse-error.ts +16 -0
  46. package/src/parser/parser-error-factory.ts +141 -0
  47. package/src/parser/parser-state.ts +134 -0
  48. package/src/parser/parser.ts +1272 -0
  49. package/src/parser/pprint.ts +169 -0
  50. package/src/parser/precedence-manager.ts +64 -0
  51. package/src/parser/source-mapper.ts +248 -0
  52. package/src/parser/special-constructs.ts +142 -0
  53. package/src/parser/token-navigator.ts +110 -0
  54. package/src/parser/types.ts +60 -0
  55. package/src/parser2/index.md +177 -0
  56. package/src/parser2/index.perf.test.ts +184 -0
  57. package/src/parser2/index.test.ts +305 -0
  58. package/src/parser2/index.ts +578 -0
  59. package/src/parser2/optimization-summary.md +176 -0
  60. package/src/registry/default-analyzers.ts +257 -0
  61. package/src/registry/default-compilers.ts +31 -0
  62. package/src/registry/index.ts +96 -0
  63. package/src/registry/operations/arithmetic.ts +506 -0
  64. package/src/registry/operations/collection.ts +425 -0
  65. package/src/registry/operations/comparison.ts +432 -0
  66. package/src/registry/operations/existence.ts +703 -0
  67. package/src/registry/operations/filtering.ts +358 -0
  68. package/src/registry/operations/literals.ts +341 -0
  69. package/src/registry/operations/logical.ts +439 -0
  70. package/src/registry/operations/math.ts +128 -0
  71. package/src/registry/operations/membership.ts +132 -0
  72. package/src/registry/operations/navigation.ts +52 -0
  73. package/src/registry/operations/string.ts +507 -0
  74. package/src/registry/operations/subsetting.ts +174 -0
  75. package/src/registry/operations/type-checking.ts +162 -0
  76. package/src/registry/operations/type-conversion.ts +404 -0
  77. package/src/registry/operations/type-operators.ts +308 -0
  78. package/src/registry/operations/utility.ts +644 -0
  79. package/src/registry/registry.ts +146 -0
  80. package/src/registry/types.ts +161 -0
  81. package/src/registry/utils/evaluation-helpers.ts +93 -0
  82. package/src/registry/utils/index.ts +3 -0
  83. package/src/registry/utils/type-system.ts +173 -0
  84. package/src/runtime/context.ts +158 -0
  85. 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
+ }