@manifesto-ai/compiler 1.8.3 → 1.9.1
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/dist/analyzer/entity-primitives.d.ts +3 -0
- package/dist/analyzer/expr-type-surface.d.ts +21 -0
- package/dist/analyzer/flow-composition.d.ts +7 -0
- package/dist/analyzer/index.d.ts +5 -0
- package/dist/analyzer/scope.d.ts +76 -0
- package/dist/analyzer/validator.d.ts +69 -0
- package/dist/api/compile-mel-patch-collector.d.ts +33 -0
- package/dist/api/compile-mel-patch-expr.d.ts +8 -0
- package/dist/api/compile-mel-patch-location.d.ts +9 -0
- package/dist/api/compile-mel-patch.d.ts +5 -0
- package/dist/api/compile-mel.d.ts +125 -0
- package/dist/api/index.d.ts +9 -0
- package/dist/{chunk-4JJQCFJH.js → chunk-7TT6Y5ZC.js} +6 -2
- package/dist/chunk-7TT6Y5ZC.js.map +1 -0
- package/dist/{chunk-AYZTDA3J.js → chunk-LI5HNMZV.js} +2 -2
- package/dist/{chunk-K4IKHGOP.js → chunk-WZRGVNJK.js} +3 -3
- package/dist/diagnostics/codes.d.ts +24 -0
- package/dist/diagnostics/format.d.ts +25 -0
- package/dist/diagnostics/index.d.ts +6 -0
- package/dist/diagnostics/types.d.ts +66 -0
- package/dist/esbuild.d.ts +6 -8
- package/dist/esbuild.js +3 -3
- package/dist/evaluation/context.d.ts +90 -0
- package/dist/evaluation/evaluate-expr.d.ts +23 -0
- package/dist/evaluation/evaluate-patch.d.ts +122 -0
- package/dist/evaluation/evaluate-runtime-patch.d.ts +59 -0
- package/dist/evaluation/index.d.ts +14 -0
- package/dist/generator/index.d.ts +6 -0
- package/dist/generator/ir.d.ts +185 -0
- package/dist/generator/lowering.d.ts +10 -0
- package/dist/generator/normalizer.d.ts +15 -0
- package/dist/generator/runtime-lowering.d.ts +2 -0
- package/dist/index.d.ts +19 -2785
- package/dist/index.js +1 -1
- package/dist/lexer/index.d.ts +6 -0
- package/dist/lexer/lexer.d.ts +58 -0
- package/dist/lexer/source-location.d.ts +40 -0
- package/dist/lexer/tokens.d.ts +46 -0
- package/dist/lowering/context.d.ts +95 -0
- package/dist/lowering/errors.d.ts +83 -0
- package/dist/lowering/index.d.ts +19 -0
- package/dist/lowering/lower-expr.d.ts +79 -0
- package/dist/lowering/lower-patch.d.ts +230 -0
- package/dist/lowering/lower-runtime-patch.d.ts +126 -0
- package/dist/lowering/to-mel-expr.d.ts +12 -0
- package/dist/mel-module.d.ts +14 -0
- package/dist/node-loader.d.ts +3 -7
- package/dist/node-loader.js +2 -2
- package/dist/parser/ast.d.ts +367 -0
- package/dist/parser/index.d.ts +6 -0
- package/dist/parser/parser.d.ts +101 -0
- package/dist/parser/precedence.d.ts +43 -0
- package/dist/renderer/expr-node.d.ts +171 -0
- package/dist/renderer/fragment.d.ts +83 -0
- package/dist/renderer/index.d.ts +22 -0
- package/dist/renderer/patch-op.d.ts +81 -0
- package/dist/renderer/type-expr.d.ts +60 -0
- package/dist/rollup.d.ts +6 -8
- package/dist/rollup.js +3 -3
- package/dist/rspack.d.ts +6 -7
- package/dist/rspack.js +3 -3
- package/dist/unplugin.d.ts +14 -0
- package/dist/utils/unicode-order.d.ts +5 -0
- package/dist/vite.d.ts +6 -8
- package/dist/vite.js +3 -3
- package/dist/webpack.d.ts +6 -8
- package/dist/webpack.js +3 -3
- package/package.json +16 -14
- package/dist/chunk-4JJQCFJH.js.map +0 -1
- package/dist/unplugin-6wnvFiEo.d.ts +0 -17
- /package/dist/{chunk-AYZTDA3J.js.map → chunk-LI5HNMZV.js.map} +0 -0
- /package/dist/{chunk-K4IKHGOP.js.map → chunk-WZRGVNJK.js.map} +0 -0
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Runtime Patch Lowering
|
|
3
|
+
*
|
|
4
|
+
* Transforms MEL runtime patches (set/unset/merge) to Core IR.
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §17.5
|
|
7
|
+
*/
|
|
8
|
+
import type { ExprNode as CoreExprNode } from "@manifesto-ai/core";
|
|
9
|
+
import type { ExprLoweringContext } from "./context.js";
|
|
10
|
+
import type { MelExprNode } from "./lower-expr.js";
|
|
11
|
+
/**
|
|
12
|
+
* MEL runtime patch operation type.
|
|
13
|
+
*
|
|
14
|
+
* @see SPEC v0.4.0 §17.5
|
|
15
|
+
*/
|
|
16
|
+
export type MelRuntimePatchOp = "set" | "unset" | "merge";
|
|
17
|
+
/**
|
|
18
|
+
* MEL path segment for runtime patches before expression lowering.
|
|
19
|
+
*/
|
|
20
|
+
export type MelIRPathSegment = {
|
|
21
|
+
kind: "prop";
|
|
22
|
+
name: string;
|
|
23
|
+
} | {
|
|
24
|
+
kind: "expr";
|
|
25
|
+
expr: MelExprNode;
|
|
26
|
+
};
|
|
27
|
+
/**
|
|
28
|
+
* MEL runtime patch path represented as IR segments.
|
|
29
|
+
*/
|
|
30
|
+
export type MelIRPatchPath = MelIRPathSegment[];
|
|
31
|
+
/**
|
|
32
|
+
* Lowered runtime IR path segment.
|
|
33
|
+
*/
|
|
34
|
+
export type IRPathSegment = {
|
|
35
|
+
kind: "prop";
|
|
36
|
+
name: string;
|
|
37
|
+
} | {
|
|
38
|
+
kind: "expr";
|
|
39
|
+
expr: CoreExprNode;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* Runtime patch path represented as IR segments.
|
|
43
|
+
*/
|
|
44
|
+
export type IRPatchPath = IRPathSegment[];
|
|
45
|
+
/**
|
|
46
|
+
* MEL runtime patch (Translator output for action patches).
|
|
47
|
+
*
|
|
48
|
+
* Contains MEL IR expressions that need lowering to Core IR.
|
|
49
|
+
*/
|
|
50
|
+
export interface MelRuntimePatch {
|
|
51
|
+
/**
|
|
52
|
+
* Optional condition (MEL IR).
|
|
53
|
+
* If present, patch is only applied when condition evaluates to true.
|
|
54
|
+
*/
|
|
55
|
+
condition?: MelExprNode;
|
|
56
|
+
/**
|
|
57
|
+
* Patch operation type.
|
|
58
|
+
*/
|
|
59
|
+
op: MelRuntimePatchOp;
|
|
60
|
+
/**
|
|
61
|
+
* Target path in snapshot.
|
|
62
|
+
* Uses IR segments and is resolved to concrete PatchPath at evaluation time.
|
|
63
|
+
*/
|
|
64
|
+
path: MelIRPatchPath;
|
|
65
|
+
/**
|
|
66
|
+
* Value expression (MEL IR) for set/merge operations.
|
|
67
|
+
* Required for "set" and "merge", forbidden for "unset".
|
|
68
|
+
*/
|
|
69
|
+
value?: MelExprNode;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Runtime ConditionalPatchOp for snapshot state mutations.
|
|
73
|
+
*
|
|
74
|
+
* This is the intermediate representation between Translator output
|
|
75
|
+
* and final concrete Patch[]. Host must call evaluateRuntimePatches()
|
|
76
|
+
* to get concrete values.
|
|
77
|
+
*
|
|
78
|
+
* @see SPEC v0.4.0 §17.5, §20
|
|
79
|
+
*/
|
|
80
|
+
export interface RuntimeConditionalPatchOp {
|
|
81
|
+
/**
|
|
82
|
+
* Optional condition expression (Core IR).
|
|
83
|
+
* If present, patch is only applied when condition evaluates to true.
|
|
84
|
+
*
|
|
85
|
+
* @see SPEC v0.4.0 §18.6 (boolean-only conditions)
|
|
86
|
+
*/
|
|
87
|
+
condition?: CoreExprNode;
|
|
88
|
+
/**
|
|
89
|
+
* Patch operation type.
|
|
90
|
+
*/
|
|
91
|
+
op: "set" | "unset" | "merge";
|
|
92
|
+
/**
|
|
93
|
+
* Target path in IR form.
|
|
94
|
+
* Evaluator resolves this to concrete PatchPath.
|
|
95
|
+
*/
|
|
96
|
+
path: IRPatchPath;
|
|
97
|
+
/**
|
|
98
|
+
* Value expression (Core IR) for set/merge operations.
|
|
99
|
+
* Required for "set" and "merge", undefined for "unset".
|
|
100
|
+
*/
|
|
101
|
+
value?: CoreExprNode;
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
* Lower MEL runtime patches to Core IR.
|
|
105
|
+
*
|
|
106
|
+
* Transforms MEL IR expressions to Core IR expressions.
|
|
107
|
+
* The returned patches still contain expressions that need to be
|
|
108
|
+
* evaluated by evaluateRuntimePatches() to get concrete values.
|
|
109
|
+
*
|
|
110
|
+
* @param patches - MEL IR runtime patches from Translator
|
|
111
|
+
* @param ctx - Expression lowering context
|
|
112
|
+
* @returns Core IR runtime conditional patches
|
|
113
|
+
*
|
|
114
|
+
* @see SPEC v0.4.0 §17.5
|
|
115
|
+
*/
|
|
116
|
+
export declare function lowerRuntimePatches(patches: MelRuntimePatch[], ctx: ExprLoweringContext): RuntimeConditionalPatchOp[];
|
|
117
|
+
/**
|
|
118
|
+
* Lower a single MEL runtime patch to Core IR.
|
|
119
|
+
*/
|
|
120
|
+
declare function lowerRuntimePatch(patch: MelRuntimePatch, ctx: ExprLoweringContext): RuntimeConditionalPatchOp;
|
|
121
|
+
/**
|
|
122
|
+
* Lower a single MEL runtime patch to Core IR.
|
|
123
|
+
*
|
|
124
|
+
* Exported for cases where individual patch lowering is needed.
|
|
125
|
+
*/
|
|
126
|
+
export { lowerRuntimePatch };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { ExprNode } from "../parser/ast.js";
|
|
2
|
+
import type { MelExprNode, MelPathNode } from "./lower-expr.js";
|
|
3
|
+
export interface ToMelExprOptions {
|
|
4
|
+
resolveIdentifier?: (name: string) => MelExprNode;
|
|
5
|
+
resolveSystemIdent?: (path: string[]) => MelExprNode;
|
|
6
|
+
}
|
|
7
|
+
export declare function toMelExpr(input: ExprNode, options?: ToMelExprOptions): MelExprNode;
|
|
8
|
+
export declare function getPathExpr(...segments: string[]): MelExprNode;
|
|
9
|
+
export declare function getBasePathExpr(base: MelExprNode, ...segments: string[]): MelExprNode;
|
|
10
|
+
export declare function sysPathExpr(...segments: string[]): MelExprNode;
|
|
11
|
+
export declare function objExpr(fields: Record<string, MelExprNode>): MelExprNode;
|
|
12
|
+
export declare function toMelPath(...segments: string[]): MelPathNode;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MEL Module Helpers
|
|
3
|
+
*
|
|
4
|
+
* Utilities for turning MEL source into JavaScript module code.
|
|
5
|
+
*/
|
|
6
|
+
import type { Diagnostic } from "./diagnostics/types.js";
|
|
7
|
+
export declare function formatDiagnostic(diagnostic: Diagnostic): string;
|
|
8
|
+
/**
|
|
9
|
+
* Compile MEL source and emit ESM source that exports the compiled schema.
|
|
10
|
+
*
|
|
11
|
+
* @param melSource - MEL domain source text
|
|
12
|
+
* @param sourceId - Human-readable source identifier for diagnostics
|
|
13
|
+
*/
|
|
14
|
+
export declare function compileMelToModuleCode(melSource: string, sourceId: string): string;
|
package/dist/node-loader.d.ts
CHANGED
|
@@ -1,18 +1,14 @@
|
|
|
1
|
-
import { ResolveHook, LoadHook } from 'node:module';
|
|
2
|
-
|
|
3
1
|
/**
|
|
4
2
|
* Node ESM Loader Hooks for MEL files.
|
|
5
3
|
*
|
|
6
4
|
* Usage: node --loader @manifesto-ai/compiler/node-loader app.ts
|
|
7
5
|
*/
|
|
8
|
-
|
|
6
|
+
import type { LoadHook, ResolveHook } from "node:module";
|
|
9
7
|
/**
|
|
10
8
|
* Node loader resolve hook.
|
|
11
9
|
*/
|
|
12
|
-
declare const resolve: ResolveHook;
|
|
10
|
+
export declare const resolve: ResolveHook;
|
|
13
11
|
/**
|
|
14
12
|
* Node loader load hook.
|
|
15
13
|
*/
|
|
16
|
-
declare const load: LoadHook;
|
|
17
|
-
|
|
18
|
-
export { load, resolve };
|
|
14
|
+
export declare const load: LoadHook;
|
package/dist/node-loader.js
CHANGED
|
@@ -0,0 +1,367 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AST Node Types for MEL Parser
|
|
3
|
+
* Based on MEL SPEC v0.3.3 Section 4
|
|
4
|
+
*/
|
|
5
|
+
import type { SourceLocation } from "../lexer/source-location.js";
|
|
6
|
+
/**
|
|
7
|
+
* Base interface for all AST nodes
|
|
8
|
+
*/
|
|
9
|
+
export interface ASTNode {
|
|
10
|
+
location: SourceLocation;
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Root node of a MEL program
|
|
14
|
+
*/
|
|
15
|
+
export interface ProgramNode extends ASTNode {
|
|
16
|
+
kind: "program";
|
|
17
|
+
imports: ImportNode[];
|
|
18
|
+
domain: DomainNode;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Import declaration
|
|
22
|
+
*/
|
|
23
|
+
export interface ImportNode extends ASTNode {
|
|
24
|
+
kind: "import";
|
|
25
|
+
names: string[];
|
|
26
|
+
from: string;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Domain declaration
|
|
30
|
+
*/
|
|
31
|
+
export interface DomainNode extends ASTNode {
|
|
32
|
+
kind: "domain";
|
|
33
|
+
name: string;
|
|
34
|
+
/** v0.3.3: Named type declarations */
|
|
35
|
+
types: TypeDeclNode[];
|
|
36
|
+
members: DomainMember[];
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Domain member types
|
|
40
|
+
*/
|
|
41
|
+
export type DomainMember = StateNode | ComputedNode | ActionNode | FlowDeclNode;
|
|
42
|
+
/**
|
|
43
|
+
* Type declaration (v0.3.3)
|
|
44
|
+
* Syntax: type Name = TypeExpr
|
|
45
|
+
*/
|
|
46
|
+
export interface TypeDeclNode extends ASTNode {
|
|
47
|
+
kind: "typeDecl";
|
|
48
|
+
name: string;
|
|
49
|
+
typeExpr: TypeExprNode;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* State block declaration
|
|
53
|
+
*/
|
|
54
|
+
export interface StateNode extends ASTNode {
|
|
55
|
+
kind: "state";
|
|
56
|
+
fields: StateFieldNode[];
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* State field declaration
|
|
60
|
+
*/
|
|
61
|
+
export interface StateFieldNode extends ASTNode {
|
|
62
|
+
kind: "stateField";
|
|
63
|
+
name: string;
|
|
64
|
+
typeExpr: TypeExprNode;
|
|
65
|
+
initializer?: ExprNode;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Computed value declaration
|
|
69
|
+
*/
|
|
70
|
+
export interface ComputedNode extends ASTNode {
|
|
71
|
+
kind: "computed";
|
|
72
|
+
name: string;
|
|
73
|
+
expression: ExprNode;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Action declaration
|
|
77
|
+
*/
|
|
78
|
+
export interface ActionNode extends ASTNode {
|
|
79
|
+
kind: "action";
|
|
80
|
+
name: string;
|
|
81
|
+
params: ParamNode[];
|
|
82
|
+
/** v0.3.2: Optional availability condition */
|
|
83
|
+
available?: ExprNode;
|
|
84
|
+
body: GuardedStmtNode[];
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Flow declaration (v0.7.0 / ADR-013a)
|
|
88
|
+
* Raw AST preserves flow declarations until the expansion pass removes them.
|
|
89
|
+
*/
|
|
90
|
+
export interface FlowDeclNode extends ASTNode {
|
|
91
|
+
kind: "flow";
|
|
92
|
+
name: string;
|
|
93
|
+
params: ParamNode[];
|
|
94
|
+
body: FlowStmtNode[];
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Parameter declaration
|
|
98
|
+
*/
|
|
99
|
+
export interface ParamNode extends ASTNode {
|
|
100
|
+
kind: "param";
|
|
101
|
+
name: string;
|
|
102
|
+
typeExpr: TypeExprNode;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* Guarded statement types (top-level in action body)
|
|
106
|
+
*/
|
|
107
|
+
export type GuardedStmtNode = WhenStmtNode | OnceStmtNode | OnceIntentStmtNode | IncludeStmtNode | FailStmtNode | StopStmtNode;
|
|
108
|
+
/**
|
|
109
|
+
* Raw flow statement types (top-level in flow body).
|
|
110
|
+
* Parser stays permissive; validation narrows the allowed subset.
|
|
111
|
+
*/
|
|
112
|
+
export type FlowStmtNode = WhenStmtNode | IncludeStmtNode | OnceStmtNode | OnceIntentStmtNode | PatchStmtNode | EffectStmtNode;
|
|
113
|
+
/**
|
|
114
|
+
* Inner statement types (inside guards)
|
|
115
|
+
*/
|
|
116
|
+
export type InnerStmtNode = PatchStmtNode | EffectStmtNode | WhenStmtNode | OnceStmtNode | OnceIntentStmtNode | IncludeStmtNode | FailStmtNode | StopStmtNode;
|
|
117
|
+
/**
|
|
118
|
+
* When guard statement
|
|
119
|
+
*/
|
|
120
|
+
export interface WhenStmtNode extends ASTNode {
|
|
121
|
+
kind: "when";
|
|
122
|
+
condition: ExprNode;
|
|
123
|
+
body: InnerStmtNode[];
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Once guard statement (per-intent idempotency)
|
|
127
|
+
*/
|
|
128
|
+
export interface OnceStmtNode extends ASTNode {
|
|
129
|
+
kind: "once";
|
|
130
|
+
marker: PathNode;
|
|
131
|
+
condition?: ExprNode;
|
|
132
|
+
body: InnerStmtNode[];
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Once-intent guard statement (per-intent idempotency sugar)
|
|
136
|
+
*/
|
|
137
|
+
export interface OnceIntentStmtNode extends ASTNode {
|
|
138
|
+
kind: "onceIntent";
|
|
139
|
+
condition?: ExprNode;
|
|
140
|
+
body: InnerStmtNode[];
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
* Include statement (v0.7.0 / ADR-013a)
|
|
144
|
+
* Raw AST preserves include sites until the expansion pass inlines them.
|
|
145
|
+
*/
|
|
146
|
+
export interface IncludeStmtNode extends ASTNode {
|
|
147
|
+
kind: "include";
|
|
148
|
+
flowName: string;
|
|
149
|
+
args: ExprNode[];
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Patch statement
|
|
153
|
+
*/
|
|
154
|
+
export interface PatchStmtNode extends ASTNode {
|
|
155
|
+
kind: "patch";
|
|
156
|
+
path: PathNode;
|
|
157
|
+
op: "set" | "unset" | "merge";
|
|
158
|
+
value?: ExprNode;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Effect statement
|
|
162
|
+
*/
|
|
163
|
+
export interface EffectStmtNode extends ASTNode {
|
|
164
|
+
kind: "effect";
|
|
165
|
+
effectType: string;
|
|
166
|
+
args: EffectArgNode[];
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Effect argument
|
|
170
|
+
*/
|
|
171
|
+
export interface EffectArgNode extends ASTNode {
|
|
172
|
+
kind: "effectArg";
|
|
173
|
+
name: string;
|
|
174
|
+
value: ExprNode | PathNode;
|
|
175
|
+
isPath: boolean;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Fail statement (v0.3.2) - terminates flow with error
|
|
179
|
+
* Compiles to FlowNode { kind: "fail", code, message }
|
|
180
|
+
*/
|
|
181
|
+
export interface FailStmtNode extends ASTNode {
|
|
182
|
+
kind: "fail";
|
|
183
|
+
code: string;
|
|
184
|
+
message?: ExprNode;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Stop statement (v0.3.2) - early exit, no error
|
|
188
|
+
* Compiles to FlowNode { kind: "halt", reason }
|
|
189
|
+
*/
|
|
190
|
+
export interface StopStmtNode extends ASTNode {
|
|
191
|
+
kind: "stop";
|
|
192
|
+
reason: string;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Type expression node
|
|
196
|
+
*/
|
|
197
|
+
export type TypeExprNode = SimpleTypeNode | UnionTypeNode | ArrayTypeNode | RecordTypeNode | LiteralTypeNode | ObjectTypeNode;
|
|
198
|
+
export interface SimpleTypeNode extends ASTNode {
|
|
199
|
+
kind: "simpleType";
|
|
200
|
+
name: string;
|
|
201
|
+
}
|
|
202
|
+
export interface UnionTypeNode extends ASTNode {
|
|
203
|
+
kind: "unionType";
|
|
204
|
+
types: TypeExprNode[];
|
|
205
|
+
}
|
|
206
|
+
export interface ArrayTypeNode extends ASTNode {
|
|
207
|
+
kind: "arrayType";
|
|
208
|
+
elementType: TypeExprNode;
|
|
209
|
+
}
|
|
210
|
+
export interface RecordTypeNode extends ASTNode {
|
|
211
|
+
kind: "recordType";
|
|
212
|
+
keyType: TypeExprNode;
|
|
213
|
+
valueType: TypeExprNode;
|
|
214
|
+
}
|
|
215
|
+
export interface LiteralTypeNode extends ASTNode {
|
|
216
|
+
kind: "literalType";
|
|
217
|
+
value: string | number | boolean | null;
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Object type node (v0.3.3)
|
|
221
|
+
* Represents inline object types: { field: Type, ... }
|
|
222
|
+
* Note: In state fields, this triggers W012 warning (use named type instead)
|
|
223
|
+
*/
|
|
224
|
+
export interface ObjectTypeNode extends ASTNode {
|
|
225
|
+
kind: "objectType";
|
|
226
|
+
fields: TypeFieldNode[];
|
|
227
|
+
}
|
|
228
|
+
/**
|
|
229
|
+
* Type field within an object type
|
|
230
|
+
*/
|
|
231
|
+
export interface TypeFieldNode extends ASTNode {
|
|
232
|
+
kind: "typeField";
|
|
233
|
+
name: string;
|
|
234
|
+
typeExpr: TypeExprNode;
|
|
235
|
+
optional: boolean;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* All expression types
|
|
239
|
+
*/
|
|
240
|
+
export type ExprNode = LiteralExprNode | IdentifierExprNode | SystemIdentExprNode | IterationVarExprNode | PropertyAccessExprNode | IndexAccessExprNode | FunctionCallExprNode | UnaryExprNode | BinaryExprNode | TernaryExprNode | ObjectLiteralExprNode | ArrayLiteralExprNode;
|
|
241
|
+
/**
|
|
242
|
+
* Literal expression (number, string, boolean, null)
|
|
243
|
+
*/
|
|
244
|
+
export interface LiteralExprNode extends ASTNode {
|
|
245
|
+
kind: "literal";
|
|
246
|
+
value: unknown;
|
|
247
|
+
literalType: "number" | "string" | "boolean" | "null";
|
|
248
|
+
}
|
|
249
|
+
/**
|
|
250
|
+
* Identifier expression
|
|
251
|
+
*/
|
|
252
|
+
export interface IdentifierExprNode extends ASTNode {
|
|
253
|
+
kind: "identifier";
|
|
254
|
+
name: string;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* System identifier expression ($system.*, $meta.*, $input.*)
|
|
258
|
+
*/
|
|
259
|
+
export interface SystemIdentExprNode extends ASTNode {
|
|
260
|
+
kind: "systemIdent";
|
|
261
|
+
path: string[];
|
|
262
|
+
}
|
|
263
|
+
/**
|
|
264
|
+
* Iteration variable expression ($item only)
|
|
265
|
+
* v0.3.2: $acc removed - reduce pattern deprecated
|
|
266
|
+
*/
|
|
267
|
+
export interface IterationVarExprNode extends ASTNode {
|
|
268
|
+
kind: "iterationVar";
|
|
269
|
+
name: "item";
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Property access expression (a.b)
|
|
273
|
+
*/
|
|
274
|
+
export interface PropertyAccessExprNode extends ASTNode {
|
|
275
|
+
kind: "propertyAccess";
|
|
276
|
+
object: ExprNode;
|
|
277
|
+
property: string;
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Index access expression (a[b])
|
|
281
|
+
*/
|
|
282
|
+
export interface IndexAccessExprNode extends ASTNode {
|
|
283
|
+
kind: "indexAccess";
|
|
284
|
+
object: ExprNode;
|
|
285
|
+
index: ExprNode;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Function call expression
|
|
289
|
+
*/
|
|
290
|
+
export interface FunctionCallExprNode extends ASTNode {
|
|
291
|
+
kind: "functionCall";
|
|
292
|
+
name: string;
|
|
293
|
+
args: ExprNode[];
|
|
294
|
+
}
|
|
295
|
+
/**
|
|
296
|
+
* Unary expression (!a, -a)
|
|
297
|
+
*/
|
|
298
|
+
export interface UnaryExprNode extends ASTNode {
|
|
299
|
+
kind: "unary";
|
|
300
|
+
operator: "!" | "-";
|
|
301
|
+
operand: ExprNode;
|
|
302
|
+
}
|
|
303
|
+
/**
|
|
304
|
+
* Binary operators
|
|
305
|
+
*/
|
|
306
|
+
export type BinaryOperator = "+" | "-" | "*" | "/" | "%" | "==" | "!=" | "<" | "<=" | ">" | ">=" | "&&" | "||" | "??";
|
|
307
|
+
/**
|
|
308
|
+
* Binary expression (a + b, a && b, etc.)
|
|
309
|
+
*/
|
|
310
|
+
export interface BinaryExprNode extends ASTNode {
|
|
311
|
+
kind: "binary";
|
|
312
|
+
operator: BinaryOperator;
|
|
313
|
+
left: ExprNode;
|
|
314
|
+
right: ExprNode;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
* Ternary expression (a ? b : c)
|
|
318
|
+
*/
|
|
319
|
+
export interface TernaryExprNode extends ASTNode {
|
|
320
|
+
kind: "ternary";
|
|
321
|
+
condition: ExprNode;
|
|
322
|
+
consequent: ExprNode;
|
|
323
|
+
alternate: ExprNode;
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Object literal expression ({ a: 1, b: 2 })
|
|
327
|
+
*/
|
|
328
|
+
export interface ObjectLiteralExprNode extends ASTNode {
|
|
329
|
+
kind: "objectLiteral";
|
|
330
|
+
properties: ObjectPropertyNode[];
|
|
331
|
+
}
|
|
332
|
+
export interface ObjectPropertyNode extends ASTNode {
|
|
333
|
+
kind: "objectProperty";
|
|
334
|
+
key: string;
|
|
335
|
+
value: ExprNode;
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Array literal expression ([1, 2, 3])
|
|
339
|
+
*/
|
|
340
|
+
export interface ArrayLiteralExprNode extends ASTNode {
|
|
341
|
+
kind: "arrayLiteral";
|
|
342
|
+
elements: ExprNode[];
|
|
343
|
+
}
|
|
344
|
+
/**
|
|
345
|
+
* Path node for patch targets and effect destinations
|
|
346
|
+
*/
|
|
347
|
+
export interface PathNode extends ASTNode {
|
|
348
|
+
kind: "path";
|
|
349
|
+
segments: PathSegmentNode[];
|
|
350
|
+
}
|
|
351
|
+
export type PathSegmentNode = PropertySegmentNode | IndexSegmentNode;
|
|
352
|
+
export interface PropertySegmentNode extends ASTNode {
|
|
353
|
+
kind: "propertySegment";
|
|
354
|
+
name: string;
|
|
355
|
+
}
|
|
356
|
+
export interface IndexSegmentNode extends ASTNode {
|
|
357
|
+
kind: "indexSegment";
|
|
358
|
+
index: ExprNode;
|
|
359
|
+
}
|
|
360
|
+
/**
|
|
361
|
+
* Check if a node is an expression
|
|
362
|
+
*/
|
|
363
|
+
export declare function isExprNode(node: ASTNode): node is ExprNode;
|
|
364
|
+
/**
|
|
365
|
+
* Check if a node is a statement
|
|
366
|
+
*/
|
|
367
|
+
export declare function isStmtNode(node: ASTNode): node is InnerStmtNode;
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MEL Parser
|
|
3
|
+
* Recursive descent parser with Pratt parsing for expressions
|
|
4
|
+
* Based on MEL SPEC v0.3.3 Section 4
|
|
5
|
+
*/
|
|
6
|
+
import type { Diagnostic } from "../diagnostics/types.js";
|
|
7
|
+
import type { Token } from "../lexer/tokens.js";
|
|
8
|
+
import { type ProgramNode } from "./ast.js";
|
|
9
|
+
/**
|
|
10
|
+
* Result of parsing
|
|
11
|
+
*/
|
|
12
|
+
export interface ParseResult {
|
|
13
|
+
program: ProgramNode | null;
|
|
14
|
+
diagnostics: Diagnostic[];
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Parser for MEL source code
|
|
18
|
+
*/
|
|
19
|
+
export declare class Parser {
|
|
20
|
+
private tokens;
|
|
21
|
+
private current;
|
|
22
|
+
private diagnostics;
|
|
23
|
+
constructor(tokens: Token[]);
|
|
24
|
+
/**
|
|
25
|
+
* Parse tokens into an AST
|
|
26
|
+
*/
|
|
27
|
+
parse(): ParseResult;
|
|
28
|
+
private parseProgram;
|
|
29
|
+
private parseImport;
|
|
30
|
+
private parseDomain;
|
|
31
|
+
/**
|
|
32
|
+
* v0.3.3: Parse type declaration
|
|
33
|
+
* Syntax: type Name = TypeExpr
|
|
34
|
+
*/
|
|
35
|
+
private parseTypeDecl;
|
|
36
|
+
private parseDomainMember;
|
|
37
|
+
private parseState;
|
|
38
|
+
private parseStateField;
|
|
39
|
+
private parseComputed;
|
|
40
|
+
private parseAction;
|
|
41
|
+
private parseFlowDecl;
|
|
42
|
+
private parseParam;
|
|
43
|
+
private parseGuardedStmt;
|
|
44
|
+
private parseFlowStmt;
|
|
45
|
+
/**
|
|
46
|
+
* Skip tokens until we reach a recovery point (closing brace, guard keyword, or EOF).
|
|
47
|
+
*/
|
|
48
|
+
private skipToRecoveryPoint;
|
|
49
|
+
private parseWhenStmt;
|
|
50
|
+
private parseOnceStmt;
|
|
51
|
+
private parseOnceIntentStmt;
|
|
52
|
+
private parseInnerStmt;
|
|
53
|
+
private parseIncludeStmt;
|
|
54
|
+
private parsePatchStmt;
|
|
55
|
+
private parseEffectStmt;
|
|
56
|
+
private parseEffectArg;
|
|
57
|
+
/**
|
|
58
|
+
* v0.3.2: Parse fail statement
|
|
59
|
+
* FailStmt ::= 'fail' StringLiteral ('with' Expr)?
|
|
60
|
+
*/
|
|
61
|
+
private parseFailStmt;
|
|
62
|
+
/**
|
|
63
|
+
* v0.3.2: Parse stop statement
|
|
64
|
+
* StopStmt ::= 'stop' StringLiteral
|
|
65
|
+
*/
|
|
66
|
+
private parseStopStmt;
|
|
67
|
+
private parseTypeExpr;
|
|
68
|
+
private parseBaseType;
|
|
69
|
+
/**
|
|
70
|
+
* v0.3.3: Parse object type
|
|
71
|
+
* Syntax: { field: Type, field?: Type, ... }
|
|
72
|
+
*/
|
|
73
|
+
private parseObjectType;
|
|
74
|
+
private parseExpression;
|
|
75
|
+
private parseTernary;
|
|
76
|
+
private parsePrimary;
|
|
77
|
+
private parseFunctionCall;
|
|
78
|
+
private parsePostfix;
|
|
79
|
+
private parseObjectLiteral;
|
|
80
|
+
private parseArrayLiteral;
|
|
81
|
+
private parsePath;
|
|
82
|
+
private isUnaryContext;
|
|
83
|
+
private peek;
|
|
84
|
+
private peekNext;
|
|
85
|
+
private peekAt;
|
|
86
|
+
private previous;
|
|
87
|
+
private isAtEnd;
|
|
88
|
+
private advance;
|
|
89
|
+
private check;
|
|
90
|
+
private isOnceIntentContext;
|
|
91
|
+
private isFlowDeclContext;
|
|
92
|
+
private isIncludeContext;
|
|
93
|
+
private match;
|
|
94
|
+
private consume;
|
|
95
|
+
private error;
|
|
96
|
+
private errorAtCurrent;
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Parse tokens into an AST
|
|
100
|
+
*/
|
|
101
|
+
export declare function parse(tokens: Token[]): ParseResult;
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Operator Precedence for MEL Parser
|
|
3
|
+
* Based on MEL SPEC v0.3.1 Section 4.9
|
|
4
|
+
*/
|
|
5
|
+
import type { TokenKind } from "../lexer/tokens.js";
|
|
6
|
+
import type { BinaryOperator } from "./ast.js";
|
|
7
|
+
/**
|
|
8
|
+
* Precedence levels (higher = binds tighter)
|
|
9
|
+
*/
|
|
10
|
+
export declare const enum Precedence {
|
|
11
|
+
NONE = 0,
|
|
12
|
+
TERNARY = 1,// ? :
|
|
13
|
+
NULLISH = 2,// ??
|
|
14
|
+
OR = 3,// ||
|
|
15
|
+
AND = 4,// &&
|
|
16
|
+
EQUALITY = 5,// == !=
|
|
17
|
+
COMPARISON = 6,// < <= > >=
|
|
18
|
+
ADDITIVE = 7,// + -
|
|
19
|
+
MULTIPLICATIVE = 8,// * / %
|
|
20
|
+
UNARY = 9,// ! -
|
|
21
|
+
CALL = 10,// ()
|
|
22
|
+
ACCESS = 11
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Get the precedence of a binary operator token
|
|
26
|
+
*/
|
|
27
|
+
export declare function getBinaryPrecedence(kind: TokenKind): Precedence;
|
|
28
|
+
/**
|
|
29
|
+
* Map token kind to binary operator
|
|
30
|
+
*/
|
|
31
|
+
export declare function tokenToBinaryOp(kind: TokenKind): BinaryOperator | null;
|
|
32
|
+
/**
|
|
33
|
+
* Check if a token is a binary operator
|
|
34
|
+
*/
|
|
35
|
+
export declare function isBinaryOp(kind: TokenKind): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Check if a token is a unary operator
|
|
38
|
+
*/
|
|
39
|
+
export declare function isUnaryOp(kind: TokenKind): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* Check if operators are right-associative
|
|
42
|
+
*/
|
|
43
|
+
export declare function isRightAssociative(kind: TokenKind): boolean;
|