@atomic-ehr/fhirpath 0.0.1-canary.35b105d.20250724165800

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 (57) hide show
  1. package/README.md +307 -0
  2. package/dist/index.d.ts +225 -0
  3. package/dist/index.js +8185 -0
  4. package/dist/index.js.map +1 -0
  5. package/package.json +51 -0
  6. package/src/analyzer/analyzer.ts +486 -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 +148 -0
  12. package/src/api/errors.ts +134 -0
  13. package/src/api/expression.ts +152 -0
  14. package/src/api/index.ts +57 -0
  15. package/src/api/registry.ts +128 -0
  16. package/src/api/types.ts +154 -0
  17. package/src/compiler/compiler.ts +579 -0
  18. package/src/compiler/index.ts +2 -0
  19. package/src/compiler/prototype-context-adapter.ts +99 -0
  20. package/src/compiler/types.ts +23 -0
  21. package/src/index.ts +52 -0
  22. package/src/interpreter/README.md +78 -0
  23. package/src/interpreter/interpreter.ts +485 -0
  24. package/src/interpreter/types.ts +110 -0
  25. package/src/lexer/char-tables.ts +37 -0
  26. package/src/lexer/errors.ts +31 -0
  27. package/src/lexer/index.ts +5 -0
  28. package/src/lexer/lexer.ts +745 -0
  29. package/src/lexer/token.ts +104 -0
  30. package/src/parser/ast.ts +123 -0
  31. package/src/parser/index.ts +3 -0
  32. package/src/parser/parser.ts +701 -0
  33. package/src/parser/pprint.ts +169 -0
  34. package/src/registry/default-analyzers.ts +257 -0
  35. package/src/registry/default-compilers.ts +31 -0
  36. package/src/registry/index.ts +93 -0
  37. package/src/registry/operations/arithmetic.ts +506 -0
  38. package/src/registry/operations/collection.ts +425 -0
  39. package/src/registry/operations/comparison.ts +432 -0
  40. package/src/registry/operations/existence.ts +703 -0
  41. package/src/registry/operations/filtering.ts +358 -0
  42. package/src/registry/operations/literals.ts +341 -0
  43. package/src/registry/operations/logical.ts +402 -0
  44. package/src/registry/operations/math.ts +128 -0
  45. package/src/registry/operations/membership.ts +132 -0
  46. package/src/registry/operations/string.ts +507 -0
  47. package/src/registry/operations/subsetting.ts +174 -0
  48. package/src/registry/operations/type-checking.ts +162 -0
  49. package/src/registry/operations/type-conversion.ts +404 -0
  50. package/src/registry/operations/type-operators.ts +307 -0
  51. package/src/registry/operations/utility.ts +542 -0
  52. package/src/registry/registry.ts +146 -0
  53. package/src/registry/types.ts +161 -0
  54. package/src/registry/utils/evaluation-helpers.ts +93 -0
  55. package/src/registry/utils/index.ts +3 -0
  56. package/src/registry/utils/type-system.ts +173 -0
  57. package/src/runtime/context.ts +179 -0
@@ -0,0 +1,104 @@
1
+ export enum TokenType {
2
+ // Literals
3
+ LITERAL = 'LITERAL', // Generic literal token for registry-based literals
4
+ NULL = 'NULL', // {} (nullLiteral in grammar)
5
+ TRUE = 'TRUE', // true
6
+ FALSE = 'FALSE', // false
7
+ STRING = 'STRING', // 'string value'
8
+ NUMBER = 'NUMBER', // 123, 45.67, 0123 (allows leading zeros)
9
+ DATE = 'DATE', // @2024, @2024-01, @2024-01-15
10
+ DATETIME = 'DATETIME', // @2024-01-15T10:30:00Z
11
+ TIME = 'TIME', // @T14:30:00
12
+
13
+ // Identifiers
14
+ IDENTIFIER = 'IDENTIFIER', // [A-Za-z_][A-Za-z0-9_]*
15
+ DELIMITED_IDENTIFIER = 'DELIMITED_IDENTIFIER', // `identifier`
16
+
17
+ // Special variables
18
+ THIS = 'THIS', // $this
19
+ INDEX = 'INDEX', // $index
20
+ TOTAL = 'TOTAL', // $total
21
+
22
+ // Environment variables
23
+ ENV_VAR = 'ENV_VAR', // %context, %`vs-name`
24
+
25
+ // Operators (by precedence)
26
+ DOT = 'DOT', // .
27
+ LBRACKET = 'LBRACKET', // [
28
+ RBRACKET = 'RBRACKET', // ]
29
+ LPAREN = 'LPAREN', // (
30
+ RPAREN = 'RPAREN', // )
31
+
32
+ // Arithmetic
33
+ PLUS = 'PLUS', // +
34
+ MINUS = 'MINUS', // -
35
+ STAR = 'STAR', // *
36
+ SLASH = 'SLASH', // /
37
+ DIV = 'DIV', // div
38
+ MOD = 'MOD', // mod
39
+ CONCAT = 'CONCAT', // &
40
+
41
+ // Type operators
42
+ IS = 'IS', // is
43
+ AS = 'AS', // as
44
+
45
+ // Union
46
+ PIPE = 'PIPE', // |
47
+
48
+ // Comparison
49
+ LT = 'LT', // <
50
+ LTE = 'LTE', // <=
51
+ GT = 'GT', // >
52
+ GTE = 'GTE', // >=
53
+ EQ = 'EQ', // =
54
+ NEQ = 'NEQ', // !=
55
+ EQUIV = 'EQUIV', // ~
56
+ NEQUIV = 'NEQUIV', // !~
57
+
58
+ // Membership
59
+ IN = 'IN', // in
60
+ CONTAINS = 'CONTAINS', // contains
61
+
62
+ // Boolean
63
+ AND = 'AND', // and
64
+ OR = 'OR', // or
65
+ XOR = 'XOR', // xor
66
+ IMPLIES = 'IMPLIES', // implies
67
+ NOT = 'NOT', // not
68
+
69
+ // Collection
70
+ LBRACE = 'LBRACE', // {
71
+ RBRACE = 'RBRACE', // }
72
+
73
+ // Other
74
+ COMMA = 'COMMA', // ,
75
+ EOF = 'EOF',
76
+
77
+ // Units (for quantities)
78
+ UNIT = 'UNIT', // year, month, 'mg', etc.
79
+
80
+ // Trivia tokens (when preserving whitespace/comments)
81
+ WS = 'WS', // Whitespace
82
+ COMMENT = 'COMMENT', // /* Multi-line comment */
83
+ LINE_COMMENT = 'LINE_COMMENT', // // Single-line comment
84
+ }
85
+
86
+ export interface Position {
87
+ line: number;
88
+ column: number;
89
+ offset: number;
90
+ }
91
+
92
+ export enum Channel {
93
+ DEFAULT = 0,
94
+ HIDDEN = 1 // For whitespace and comments
95
+ }
96
+
97
+ export interface Token {
98
+ type: TokenType;
99
+ value: string;
100
+ position: Position;
101
+ channel?: Channel; // Optional channel for trivia
102
+ operation?: any; // Operation from registry (using any to avoid circular dependency)
103
+ literalValue?: any; // Parsed literal value for LITERAL tokens
104
+ }
@@ -0,0 +1,123 @@
1
+ import type { TokenType } from '../lexer/token';
2
+
3
+ // Core AST Node Interface
4
+ export interface ASTNode {
5
+ type: NodeType;
6
+ position: Position;
7
+ // Type analysis fields (optional - added by analyzer)
8
+ resultType?: unknown; // Opaque type reference
9
+ isSingleton?: boolean; // Whether this expression returns a single value
10
+ }
11
+
12
+ export interface Position {
13
+ line: number;
14
+ column: number;
15
+ offset: number;
16
+ }
17
+
18
+ // Node types
19
+ export enum NodeType {
20
+ // Navigation
21
+ Identifier,
22
+ TypeOrIdentifier, // Uppercase identifiers that could be types (Patient, Observation)
23
+
24
+ // Operators
25
+ Binary, // All binary operators including dot
26
+ Unary, // unary +, -, not
27
+ Union, // | operator (special handling for multiple operands)
28
+
29
+ // Functions
30
+ Function, // Function calls
31
+
32
+ // Literals
33
+ Literal, // numbers, strings, booleans, dates, null
34
+ Variable, // $this, $index, $total, %var
35
+ Collection, // {} empty collection or {expr1, expr2, ...}
36
+
37
+ // Type operations
38
+ MembershipTest, // 'is' operator
39
+ TypeCast, // 'as' operator
40
+ TypeReference, // Type name in ofType()
41
+
42
+ // Special
43
+ Index, // [] indexing
44
+ }
45
+
46
+ // Specific node types
47
+ export interface IdentifierNode extends ASTNode {
48
+ type: NodeType.Identifier;
49
+ name: string;
50
+ }
51
+
52
+ export interface TypeOrIdentifierNode extends ASTNode {
53
+ type: NodeType.TypeOrIdentifier;
54
+ name: string;
55
+ }
56
+
57
+ export interface LiteralNode extends ASTNode {
58
+ type: NodeType.Literal;
59
+ value: any;
60
+ valueType: 'string' | 'number' | 'boolean' | 'date' | 'time' | 'datetime' | 'null';
61
+ raw?: string; // Raw string representation
62
+ operation?: any; // Operation from registry (using any to avoid circular dependency)
63
+ }
64
+
65
+ export interface BinaryNode extends ASTNode {
66
+ type: NodeType.Binary;
67
+ operator: TokenType;
68
+ operation?: any; // Operation from registry (using any to avoid circular dependency)
69
+ left: ASTNode;
70
+ right: ASTNode;
71
+ }
72
+
73
+ export interface UnaryNode extends ASTNode {
74
+ type: NodeType.Unary;
75
+ operator: TokenType;
76
+ operation?: any; // Operation from registry (using any to avoid circular dependency)
77
+ operand: ASTNode;
78
+ }
79
+
80
+ export interface FunctionNode extends ASTNode {
81
+ type: NodeType.Function;
82
+ name: ASTNode; // Usually an identifier
83
+ arguments: ASTNode[];
84
+ operation?: any; // Operation from registry (using any to avoid circular dependency)
85
+ }
86
+
87
+ export interface VariableNode extends ASTNode {
88
+ type: NodeType.Variable;
89
+ name: string;
90
+ }
91
+
92
+ export interface IndexNode extends ASTNode {
93
+ type: NodeType.Index;
94
+ expression: ASTNode;
95
+ index: ASTNode;
96
+ }
97
+
98
+ export interface UnionNode extends ASTNode {
99
+ type: NodeType.Union;
100
+ operands: ASTNode[];
101
+ }
102
+
103
+ export interface MembershipTestNode extends ASTNode {
104
+ type: NodeType.MembershipTest;
105
+ expression: ASTNode;
106
+ targetType: string;
107
+ }
108
+
109
+ export interface TypeCastNode extends ASTNode {
110
+ type: NodeType.TypeCast;
111
+ expression: ASTNode;
112
+ targetType: string;
113
+ }
114
+
115
+ export interface CollectionNode extends ASTNode {
116
+ type: NodeType.Collection;
117
+ elements: ASTNode[];
118
+ }
119
+
120
+ export interface TypeReferenceNode extends ASTNode {
121
+ type: NodeType.TypeReference;
122
+ typeName: string;
123
+ }
@@ -0,0 +1,3 @@
1
+ export { FHIRPathParser, ParseError, parse } from './parser';
2
+ export * from './ast';
3
+ export { pprint } from './pprint';