@manifesto-ai/compiler 1.9.0 → 3.0.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/README.md +17 -5
- 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-VAFXIS7J.js +101 -0
- package/dist/chunk-VAFXIS7J.js.map +1 -0
- 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/esbuild.js.map +1 -1
- 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/rollup.js.map +1 -1
- package/dist/rspack.d.ts +6 -7
- package/dist/rspack.js +3 -3
- package/dist/rspack.js.map +1 -1
- package/dist/unplugin.d.ts +19 -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/vite.js.map +1 -1
- package/dist/webpack.d.ts +6 -8
- package/dist/webpack.js +3 -3
- package/dist/webpack.js.map +1 -1
- package/package.json +12 -17
- package/dist/chunk-4JJQCFJH.js.map +0 -1
- package/dist/chunk-K4IKHGOP.js +0 -74
- package/dist/chunk-K4IKHGOP.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/index.js
CHANGED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MEL Lexer
|
|
3
|
+
* Tokenizes MEL source code based on SPEC v0.3.1 Section 3
|
|
4
|
+
*/
|
|
5
|
+
import type { Diagnostic } from "../diagnostics/types.js";
|
|
6
|
+
import { type Token } from "./tokens.js";
|
|
7
|
+
/**
|
|
8
|
+
* Result of lexical analysis
|
|
9
|
+
*/
|
|
10
|
+
export interface LexResult {
|
|
11
|
+
tokens: Token[];
|
|
12
|
+
diagnostics: Diagnostic[];
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Lexer for MEL source code
|
|
16
|
+
*/
|
|
17
|
+
export declare class Lexer {
|
|
18
|
+
private source;
|
|
19
|
+
private sourcePath?;
|
|
20
|
+
private tokens;
|
|
21
|
+
private diagnostics;
|
|
22
|
+
private start;
|
|
23
|
+
private current;
|
|
24
|
+
private line;
|
|
25
|
+
private column;
|
|
26
|
+
private lineStart;
|
|
27
|
+
constructor(source: string, sourcePath?: string);
|
|
28
|
+
/**
|
|
29
|
+
* Tokenize the source code
|
|
30
|
+
*/
|
|
31
|
+
tokenize(): LexResult;
|
|
32
|
+
private scanToken;
|
|
33
|
+
private lineComment;
|
|
34
|
+
private blockComment;
|
|
35
|
+
private string;
|
|
36
|
+
private number;
|
|
37
|
+
private identifier;
|
|
38
|
+
private systemIdentifier;
|
|
39
|
+
private isAtEnd;
|
|
40
|
+
private advance;
|
|
41
|
+
private peek;
|
|
42
|
+
private peekNext;
|
|
43
|
+
private match;
|
|
44
|
+
private newline;
|
|
45
|
+
private isDigit;
|
|
46
|
+
private isHexDigit;
|
|
47
|
+
private isAlpha;
|
|
48
|
+
private isAlphaNumeric;
|
|
49
|
+
private currentLocation;
|
|
50
|
+
private positionAt;
|
|
51
|
+
private addToken;
|
|
52
|
+
private error;
|
|
53
|
+
private getSourceLine;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Tokenize MEL source code
|
|
57
|
+
*/
|
|
58
|
+
export declare function tokenize(source: string, sourcePath?: string): LexResult;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Source Location Types
|
|
3
|
+
* Tracks positions in MEL source code for error reporting
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* A position in source code (1-based line/column)
|
|
7
|
+
*/
|
|
8
|
+
export interface Position {
|
|
9
|
+
/** 1-based line number */
|
|
10
|
+
line: number;
|
|
11
|
+
/** 1-based column number */
|
|
12
|
+
column: number;
|
|
13
|
+
/** 0-based byte offset from start of source */
|
|
14
|
+
offset: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* A span in source code (start to end)
|
|
18
|
+
*/
|
|
19
|
+
export interface SourceLocation {
|
|
20
|
+
start: Position;
|
|
21
|
+
end: Position;
|
|
22
|
+
/** Optional source file path */
|
|
23
|
+
source?: string;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Create a position
|
|
27
|
+
*/
|
|
28
|
+
export declare function createPosition(line: number, column: number, offset: number): Position;
|
|
29
|
+
/**
|
|
30
|
+
* Create a source location from two positions
|
|
31
|
+
*/
|
|
32
|
+
export declare function createLocation(start: Position, end: Position, source?: string): SourceLocation;
|
|
33
|
+
/**
|
|
34
|
+
* Create a zero-width location at a position
|
|
35
|
+
*/
|
|
36
|
+
export declare function createPointLocation(pos: Position, source?: string): SourceLocation;
|
|
37
|
+
/**
|
|
38
|
+
* Merge two locations into one spanning both
|
|
39
|
+
*/
|
|
40
|
+
export declare function mergeLocations(a: SourceLocation, b: SourceLocation): SourceLocation;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Token Types for MEL Lexer
|
|
3
|
+
* Based on MEL SPEC v0.3.3 Section 3
|
|
4
|
+
*/
|
|
5
|
+
import type { SourceLocation } from "./source-location.js";
|
|
6
|
+
/**
|
|
7
|
+
* All token kinds in MEL
|
|
8
|
+
*/
|
|
9
|
+
export type TokenKind = "DOMAIN" | "STATE" | "COMPUTED" | "ACTION" | "EFFECT" | "WHEN" | "ONCE" | "PATCH" | "UNSET" | "MERGE" | "TRUE" | "FALSE" | "NULL" | "AS" | "AVAILABLE" | "FAIL" | "STOP" | "WITH" | "TYPE" | "IMPORT" | "FROM" | "EXPORT" | "PLUS" | "MINUS" | "STAR" | "SLASH" | "PERCENT" | "EQ_EQ" | "BANG_EQ" | "LT" | "LT_EQ" | "GT" | "GT_EQ" | "AMP_AMP" | "PIPE_PIPE" | "BANG" | "QUESTION_QUESTION" | "QUESTION" | "COLON" | "EQ" | "LPAREN" | "RPAREN" | "LBRACE" | "RBRACE" | "LBRACKET" | "RBRACKET" | "COMMA" | "SEMICOLON" | "DOT" | "PIPE" | "NUMBER" | "STRING" | "IDENTIFIER" | "SYSTEM_IDENT" | "ITEM" | "EOF" | "ERROR";
|
|
10
|
+
/**
|
|
11
|
+
* A token produced by the lexer
|
|
12
|
+
*/
|
|
13
|
+
export interface Token {
|
|
14
|
+
kind: TokenKind;
|
|
15
|
+
/** The raw text of the token */
|
|
16
|
+
lexeme: string;
|
|
17
|
+
/** Parsed value for literals */
|
|
18
|
+
value?: unknown;
|
|
19
|
+
/** Location in source */
|
|
20
|
+
location: SourceLocation;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Keywords lookup table
|
|
24
|
+
*/
|
|
25
|
+
export declare const KEYWORDS: Record<string, TokenKind>;
|
|
26
|
+
/**
|
|
27
|
+
* Reserved keywords (JS keywords that are forbidden in MEL)
|
|
28
|
+
*/
|
|
29
|
+
export declare const RESERVED_KEYWORDS: Set<string>;
|
|
30
|
+
/**
|
|
31
|
+
* Check if a token is a keyword
|
|
32
|
+
*/
|
|
33
|
+
export declare function isKeyword(lexeme: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* Check if a token is a reserved word
|
|
36
|
+
*/
|
|
37
|
+
export declare function isReserved(lexeme: string): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Get keyword token kind, or undefined if not a keyword
|
|
40
|
+
* Note: Uses Object.hasOwn to avoid prototype pollution (e.g., "toString")
|
|
41
|
+
*/
|
|
42
|
+
export declare function getKeywordKind(lexeme: string): TokenKind | undefined;
|
|
43
|
+
/**
|
|
44
|
+
* Create a token
|
|
45
|
+
*/
|
|
46
|
+
export declare function createToken(kind: TokenKind, lexeme: string, location: SourceLocation, value?: unknown): Token;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lowering Context Types
|
|
3
|
+
*
|
|
4
|
+
* Defines contexts for expression and patch lowering.
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §17.2
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Allowed system path prefixes.
|
|
10
|
+
*
|
|
11
|
+
* In Translator path, only 'meta' and 'input' are allowed.
|
|
12
|
+
* 'system' is forbidden (requires Flow execution).
|
|
13
|
+
*
|
|
14
|
+
* @see FDR-MEL-071
|
|
15
|
+
*/
|
|
16
|
+
export type AllowedSysPrefix = "meta" | "input";
|
|
17
|
+
/**
|
|
18
|
+
* Context for single expression lowering.
|
|
19
|
+
*
|
|
20
|
+
* @see SPEC v0.4.0 §17.2
|
|
21
|
+
*/
|
|
22
|
+
export interface ExprLoweringContext {
|
|
23
|
+
/**
|
|
24
|
+
* Expression context mode.
|
|
25
|
+
* - 'schema': for addComputed, addConstraint, etc.
|
|
26
|
+
* - 'action': for guards, patches, effects
|
|
27
|
+
*/
|
|
28
|
+
mode: "schema" | "action";
|
|
29
|
+
/**
|
|
30
|
+
* Allowed system path prefixes.
|
|
31
|
+
* In Translator path: only ["meta", "input"]
|
|
32
|
+
*
|
|
33
|
+
* @see FDR-MEL-071
|
|
34
|
+
*/
|
|
35
|
+
allowSysPaths?: {
|
|
36
|
+
prefixes: AllowedSysPrefix[];
|
|
37
|
+
};
|
|
38
|
+
/**
|
|
39
|
+
* Function table version for call lowering.
|
|
40
|
+
*/
|
|
41
|
+
fnTableVersion: string;
|
|
42
|
+
/**
|
|
43
|
+
* Action name (for action context).
|
|
44
|
+
*/
|
|
45
|
+
actionName?: string;
|
|
46
|
+
/**
|
|
47
|
+
* Whether $item is allowed in this context.
|
|
48
|
+
* Only true for effect.args fields.
|
|
49
|
+
*
|
|
50
|
+
* @see FDR-MEL-068
|
|
51
|
+
*/
|
|
52
|
+
allowItem?: boolean;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Context for patch lowering.
|
|
56
|
+
*
|
|
57
|
+
* NO mode field - Compiler determines context per op-field.
|
|
58
|
+
*
|
|
59
|
+
* @see SPEC v0.4.0 §17.2, AD-COMP-LOW-002
|
|
60
|
+
*/
|
|
61
|
+
export interface PatchLoweringContext {
|
|
62
|
+
/**
|
|
63
|
+
* Allowed system path prefixes.
|
|
64
|
+
* In Translator path: only ["meta", "input"]
|
|
65
|
+
*
|
|
66
|
+
* @see FDR-MEL-071
|
|
67
|
+
*/
|
|
68
|
+
allowSysPaths?: {
|
|
69
|
+
prefixes: AllowedSysPrefix[];
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Function table version for call lowering.
|
|
73
|
+
*/
|
|
74
|
+
fnTableVersion: string;
|
|
75
|
+
/**
|
|
76
|
+
* Action name (for action-related ops).
|
|
77
|
+
*/
|
|
78
|
+
actionName?: string;
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Default expression lowering context for schema mode.
|
|
82
|
+
*/
|
|
83
|
+
export declare const DEFAULT_SCHEMA_CONTEXT: ExprLoweringContext;
|
|
84
|
+
/**
|
|
85
|
+
* Default expression lowering context for action mode.
|
|
86
|
+
*/
|
|
87
|
+
export declare const DEFAULT_ACTION_CONTEXT: ExprLoweringContext;
|
|
88
|
+
/**
|
|
89
|
+
* Context for effect.args (allows $item).
|
|
90
|
+
*/
|
|
91
|
+
export declare const EFFECT_ARGS_CONTEXT: ExprLoweringContext;
|
|
92
|
+
/**
|
|
93
|
+
* Default patch lowering context.
|
|
94
|
+
*/
|
|
95
|
+
export declare const DEFAULT_PATCH_CONTEXT: PatchLoweringContext;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lowering Error Types
|
|
3
|
+
*
|
|
4
|
+
* Defines error types for MEL IR → Core IR lowering.
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §17.6
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Lowering error codes.
|
|
10
|
+
*
|
|
11
|
+
* @see SPEC v0.4.0 §17.6
|
|
12
|
+
*/
|
|
13
|
+
export type LoweringErrorCode =
|
|
14
|
+
/** var in non-effect context, sys in schema */
|
|
15
|
+
"INVALID_KIND_FOR_CONTEXT"
|
|
16
|
+
/** Unknown function name in call node */
|
|
17
|
+
| "UNKNOWN_CALL_FN"
|
|
18
|
+
/** sys.system in Translator path */
|
|
19
|
+
| "INVALID_SYS_PATH"
|
|
20
|
+
/** get.base is not var(item) */
|
|
21
|
+
| "UNSUPPORTED_BASE"
|
|
22
|
+
/** Malformed node structure */
|
|
23
|
+
| "INVALID_SHAPE"
|
|
24
|
+
/** Unknown node kind */
|
|
25
|
+
| "UNKNOWN_NODE_KIND";
|
|
26
|
+
/**
|
|
27
|
+
* Lowering error class.
|
|
28
|
+
*
|
|
29
|
+
* Thrown when MEL IR cannot be lowered to Core IR.
|
|
30
|
+
*
|
|
31
|
+
* @see SPEC v0.4.0 §17.6
|
|
32
|
+
*/
|
|
33
|
+
export declare class LoweringError extends Error {
|
|
34
|
+
readonly code: LoweringErrorCode;
|
|
35
|
+
readonly path?: string[];
|
|
36
|
+
readonly details?: Record<string, unknown>;
|
|
37
|
+
constructor(code: LoweringErrorCode, message: string, options?: {
|
|
38
|
+
path?: string[];
|
|
39
|
+
details?: Record<string, unknown>;
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Create a lowering error for invalid kind in context.
|
|
44
|
+
*
|
|
45
|
+
* @example
|
|
46
|
+
* throw invalidKindForContext("var", "schema");
|
|
47
|
+
*/
|
|
48
|
+
export declare function invalidKindForContext(kind: string, context: string, path?: string[]): LoweringError;
|
|
49
|
+
/**
|
|
50
|
+
* Create a lowering error for unknown call function.
|
|
51
|
+
*
|
|
52
|
+
* @example
|
|
53
|
+
* throw unknownCallFn("unknownFunc");
|
|
54
|
+
*/
|
|
55
|
+
export declare function unknownCallFn(fn: string, path?: string[]): LoweringError;
|
|
56
|
+
/**
|
|
57
|
+
* Create a lowering error for invalid sys path.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* throw invalidSysPath(["system", "uuid"]);
|
|
61
|
+
*/
|
|
62
|
+
export declare function invalidSysPath(sysPath: string[], path?: string[]): LoweringError;
|
|
63
|
+
/**
|
|
64
|
+
* Create a lowering error for unsupported base expression.
|
|
65
|
+
*
|
|
66
|
+
* @example
|
|
67
|
+
* throw unsupportedBase("call");
|
|
68
|
+
*/
|
|
69
|
+
export declare function unsupportedBase(baseKind: string, path?: string[]): LoweringError;
|
|
70
|
+
/**
|
|
71
|
+
* Create a lowering error for invalid shape.
|
|
72
|
+
*
|
|
73
|
+
* @example
|
|
74
|
+
* throw invalidShape("missing 'value' field");
|
|
75
|
+
*/
|
|
76
|
+
export declare function invalidShape(description: string, path?: string[]): LoweringError;
|
|
77
|
+
/**
|
|
78
|
+
* Create a lowering error for unknown node kind.
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* throw unknownNodeKind("foo");
|
|
82
|
+
*/
|
|
83
|
+
export declare function unknownNodeKind(kind: string, path?: string[]): LoweringError;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Lowering Module
|
|
3
|
+
*
|
|
4
|
+
* Transforms MEL IR to Core IR.
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §17
|
|
7
|
+
*/
|
|
8
|
+
export type { AllowedSysPrefix, ExprLoweringContext, PatchLoweringContext, } from "./context.js";
|
|
9
|
+
export { DEFAULT_SCHEMA_CONTEXT, DEFAULT_ACTION_CONTEXT, EFFECT_ARGS_CONTEXT, DEFAULT_PATCH_CONTEXT, } from "./context.js";
|
|
10
|
+
export type { LoweringErrorCode } from "./errors.js";
|
|
11
|
+
export { LoweringError, invalidKindForContext, unknownCallFn, invalidSysPath, unsupportedBase, invalidShape, unknownNodeKind, } from "./errors.js";
|
|
12
|
+
export type { MelPrimitive, MelPathSegment, MelPathNode, MelSystemPath, MelObjField, MelExprNode, } from "./lower-expr.js";
|
|
13
|
+
export { lowerExprNode } from "./lower-expr.js";
|
|
14
|
+
export type { MelTypeExpr, MelTypeField, MelPatchOp, MelPatchFragment, LoweredTypeExpr, LoweredTypeField, LoweredPatchOp, SchemaConditionalPatchOp,
|
|
15
|
+
/** @deprecated Use SchemaConditionalPatchOp */
|
|
16
|
+
ConditionalPatchOp, } from "./lower-patch.js";
|
|
17
|
+
export { lowerPatchFragments } from "./lower-patch.js";
|
|
18
|
+
export type { MelRuntimePatchOp, MelIRPathSegment, MelIRPatchPath, MelRuntimePatch, IRPathSegment, IRPatchPath, RuntimeConditionalPatchOp, } from "./lower-runtime-patch.js";
|
|
19
|
+
export { lowerRuntimePatches, lowerRuntimePatch } from "./lower-runtime-patch.js";
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Expression Lowering
|
|
3
|
+
*
|
|
4
|
+
* Transforms MEL Canonical IR (8 kinds) to Core Runtime IR (30+ kinds).
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §17
|
|
7
|
+
*/
|
|
8
|
+
import type { ExprNode as CoreExprNode } from "@manifesto-ai/core";
|
|
9
|
+
import type { ExprLoweringContext } from "./context.js";
|
|
10
|
+
/**
|
|
11
|
+
* MEL primitive value.
|
|
12
|
+
*/
|
|
13
|
+
export type MelPrimitive = null | boolean | number | string;
|
|
14
|
+
/**
|
|
15
|
+
* MEL path segment.
|
|
16
|
+
*/
|
|
17
|
+
export type MelPathSegment = {
|
|
18
|
+
kind: "prop";
|
|
19
|
+
name: string;
|
|
20
|
+
};
|
|
21
|
+
/**
|
|
22
|
+
* MEL path node array.
|
|
23
|
+
*/
|
|
24
|
+
export type MelPathNode = MelPathSegment[];
|
|
25
|
+
/**
|
|
26
|
+
* MEL system path as segment array.
|
|
27
|
+
*/
|
|
28
|
+
export type MelSystemPath = string[];
|
|
29
|
+
/**
|
|
30
|
+
* MEL object field.
|
|
31
|
+
*/
|
|
32
|
+
export type MelObjField = {
|
|
33
|
+
key: string;
|
|
34
|
+
value: MelExprNode;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* MEL Canonical IR (8 kinds).
|
|
38
|
+
*
|
|
39
|
+
* @see SPEC v0.4.0 §17.1.1
|
|
40
|
+
*/
|
|
41
|
+
export type MelExprNode = {
|
|
42
|
+
kind: "lit";
|
|
43
|
+
value: MelPrimitive;
|
|
44
|
+
} | {
|
|
45
|
+
kind: "var";
|
|
46
|
+
name: "item";
|
|
47
|
+
} | {
|
|
48
|
+
kind: "sys";
|
|
49
|
+
path: MelSystemPath;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "get";
|
|
52
|
+
base?: MelExprNode;
|
|
53
|
+
path: MelPathNode;
|
|
54
|
+
} | {
|
|
55
|
+
kind: "field";
|
|
56
|
+
object: MelExprNode;
|
|
57
|
+
property: string;
|
|
58
|
+
} | {
|
|
59
|
+
kind: "call";
|
|
60
|
+
fn: string;
|
|
61
|
+
args: MelExprNode[];
|
|
62
|
+
} | {
|
|
63
|
+
kind: "obj";
|
|
64
|
+
fields: MelObjField[];
|
|
65
|
+
} | {
|
|
66
|
+
kind: "arr";
|
|
67
|
+
elements: MelExprNode[];
|
|
68
|
+
};
|
|
69
|
+
/**
|
|
70
|
+
* Lower MEL expression to Core expression.
|
|
71
|
+
*
|
|
72
|
+
* @param input - MEL canonical IR expression
|
|
73
|
+
* @param ctx - Lowering context
|
|
74
|
+
* @returns Core runtime IR expression
|
|
75
|
+
* @throws LoweringError if expression cannot be lowered
|
|
76
|
+
*
|
|
77
|
+
* @see SPEC v0.4.0 §17.3
|
|
78
|
+
*/
|
|
79
|
+
export declare function lowerExprNode(input: MelExprNode, ctx: ExprLoweringContext): CoreExprNode;
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Patch Lowering
|
|
3
|
+
*
|
|
4
|
+
* Transforms PatchFragment[] (MEL IR) to ConditionalPatchOp[] (Core IR).
|
|
5
|
+
*
|
|
6
|
+
* @see SPEC v0.4.0 §17.4, §17.5
|
|
7
|
+
*/
|
|
8
|
+
import type { ExprNode as CoreExprNode } from "@manifesto-ai/core";
|
|
9
|
+
import type { PatchLoweringContext } from "./context.js";
|
|
10
|
+
import { MelExprNode } from "./lower-expr.js";
|
|
11
|
+
/**
|
|
12
|
+
* MEL TypeExpr (Translator output).
|
|
13
|
+
*/
|
|
14
|
+
export type MelTypeExpr = {
|
|
15
|
+
kind: "primitive";
|
|
16
|
+
name: "string" | "number" | "boolean" | "null";
|
|
17
|
+
} | {
|
|
18
|
+
kind: "array";
|
|
19
|
+
element: MelTypeExpr;
|
|
20
|
+
} | {
|
|
21
|
+
kind: "object";
|
|
22
|
+
fields: MelTypeField[];
|
|
23
|
+
} | {
|
|
24
|
+
kind: "union";
|
|
25
|
+
members: MelTypeExpr[];
|
|
26
|
+
} | {
|
|
27
|
+
kind: "literal";
|
|
28
|
+
value: string | number | boolean | null;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "ref";
|
|
31
|
+
name: string;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* MEL TypeField.
|
|
35
|
+
*/
|
|
36
|
+
export type MelTypeField = {
|
|
37
|
+
name: string;
|
|
38
|
+
type: MelTypeExpr;
|
|
39
|
+
optional?: boolean;
|
|
40
|
+
};
|
|
41
|
+
/**
|
|
42
|
+
* MEL PatchOp (Translator output - schema operations).
|
|
43
|
+
*
|
|
44
|
+
* @see SPEC v0.4.0 §17.4
|
|
45
|
+
*/
|
|
46
|
+
export type MelPatchOp = {
|
|
47
|
+
kind: "addType";
|
|
48
|
+
typeName: string;
|
|
49
|
+
typeExpr: MelTypeExpr;
|
|
50
|
+
} | {
|
|
51
|
+
kind: "addField";
|
|
52
|
+
typeName: string;
|
|
53
|
+
field: MelTypeField & {
|
|
54
|
+
defaultValue?: unknown;
|
|
55
|
+
};
|
|
56
|
+
} | {
|
|
57
|
+
kind: "setFieldType";
|
|
58
|
+
path: string;
|
|
59
|
+
typeExpr: MelTypeExpr;
|
|
60
|
+
} | {
|
|
61
|
+
kind: "setDefaultValue";
|
|
62
|
+
path: string;
|
|
63
|
+
value: unknown;
|
|
64
|
+
} | {
|
|
65
|
+
kind: "addConstraint";
|
|
66
|
+
targetPath: string;
|
|
67
|
+
rule: MelExprNode;
|
|
68
|
+
message?: string;
|
|
69
|
+
} | {
|
|
70
|
+
kind: "addComputed";
|
|
71
|
+
name: string;
|
|
72
|
+
expr: MelExprNode;
|
|
73
|
+
deps?: string[];
|
|
74
|
+
} | {
|
|
75
|
+
kind: "addActionAvailable";
|
|
76
|
+
actionName: string;
|
|
77
|
+
expr: MelExprNode;
|
|
78
|
+
};
|
|
79
|
+
/**
|
|
80
|
+
* MEL PatchFragment (Translator output).
|
|
81
|
+
*
|
|
82
|
+
* Contains MEL IR expressions that need lowering.
|
|
83
|
+
*
|
|
84
|
+
* @see SPEC v0.4.0 §17.4
|
|
85
|
+
*/
|
|
86
|
+
export interface MelPatchFragment {
|
|
87
|
+
/**
|
|
88
|
+
* Unique fragment identifier (content-addressed).
|
|
89
|
+
*/
|
|
90
|
+
fragmentId: string;
|
|
91
|
+
/**
|
|
92
|
+
* Source intent identifier.
|
|
93
|
+
*/
|
|
94
|
+
sourceIntentId: string;
|
|
95
|
+
/**
|
|
96
|
+
* Fragment operation with MEL IR expressions.
|
|
97
|
+
*/
|
|
98
|
+
op: MelPatchOp;
|
|
99
|
+
/**
|
|
100
|
+
* Optional condition (MEL IR).
|
|
101
|
+
* Preserved in output as Core IR.
|
|
102
|
+
*/
|
|
103
|
+
condition?: MelExprNode;
|
|
104
|
+
/**
|
|
105
|
+
* Confidence score (0-1).
|
|
106
|
+
*/
|
|
107
|
+
confidence: number;
|
|
108
|
+
/**
|
|
109
|
+
* Evidence strings.
|
|
110
|
+
*/
|
|
111
|
+
evidence: string[];
|
|
112
|
+
/**
|
|
113
|
+
* Creation timestamp (ISO 8601).
|
|
114
|
+
*/
|
|
115
|
+
createdAt: string;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Lowered TypeExpr (Core format).
|
|
119
|
+
*/
|
|
120
|
+
export type LoweredTypeExpr = {
|
|
121
|
+
kind: "primitive";
|
|
122
|
+
name: "string" | "number" | "boolean" | "null";
|
|
123
|
+
} | {
|
|
124
|
+
kind: "array";
|
|
125
|
+
element: LoweredTypeExpr;
|
|
126
|
+
} | {
|
|
127
|
+
kind: "object";
|
|
128
|
+
fields: LoweredTypeField[];
|
|
129
|
+
} | {
|
|
130
|
+
kind: "union";
|
|
131
|
+
members: LoweredTypeExpr[];
|
|
132
|
+
} | {
|
|
133
|
+
kind: "literal";
|
|
134
|
+
value: string | number | boolean | null;
|
|
135
|
+
} | {
|
|
136
|
+
kind: "ref";
|
|
137
|
+
name: string;
|
|
138
|
+
};
|
|
139
|
+
/**
|
|
140
|
+
* Lowered TypeField.
|
|
141
|
+
*/
|
|
142
|
+
export type LoweredTypeField = {
|
|
143
|
+
name: string;
|
|
144
|
+
type: LoweredTypeExpr;
|
|
145
|
+
optional?: boolean;
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Lowered PatchOp (Core IR expressions).
|
|
149
|
+
*
|
|
150
|
+
* Same structure as MelPatchOp but with Core IR expressions.
|
|
151
|
+
*/
|
|
152
|
+
export type LoweredPatchOp = {
|
|
153
|
+
kind: "addType";
|
|
154
|
+
typeName: string;
|
|
155
|
+
typeExpr: LoweredTypeExpr;
|
|
156
|
+
} | {
|
|
157
|
+
kind: "addField";
|
|
158
|
+
typeName: string;
|
|
159
|
+
field: LoweredTypeField & {
|
|
160
|
+
defaultValue?: unknown;
|
|
161
|
+
};
|
|
162
|
+
} | {
|
|
163
|
+
kind: "setFieldType";
|
|
164
|
+
path: string;
|
|
165
|
+
typeExpr: LoweredTypeExpr;
|
|
166
|
+
} | {
|
|
167
|
+
kind: "setDefaultValue";
|
|
168
|
+
path: string;
|
|
169
|
+
value: unknown;
|
|
170
|
+
} | {
|
|
171
|
+
kind: "addConstraint";
|
|
172
|
+
targetPath: string;
|
|
173
|
+
rule: CoreExprNode;
|
|
174
|
+
message?: string;
|
|
175
|
+
} | {
|
|
176
|
+
kind: "addComputed";
|
|
177
|
+
name: string;
|
|
178
|
+
expr: CoreExprNode;
|
|
179
|
+
deps?: string[];
|
|
180
|
+
} | {
|
|
181
|
+
kind: "addActionAvailable";
|
|
182
|
+
actionName: string;
|
|
183
|
+
expr: CoreExprNode;
|
|
184
|
+
};
|
|
185
|
+
/**
|
|
186
|
+
* Schema conditional patch operation (intermediate IR for Translator → Host).
|
|
187
|
+
*
|
|
188
|
+
* Used for schema evolution operations (addType, addField, addComputed, etc.).
|
|
189
|
+
* Preserves fragment condition for later evaluation.
|
|
190
|
+
*
|
|
191
|
+
* @see SPEC v0.4.0 §17.5
|
|
192
|
+
*/
|
|
193
|
+
export interface SchemaConditionalPatchOp {
|
|
194
|
+
/**
|
|
195
|
+
* Fragment identifier (for tracing).
|
|
196
|
+
*/
|
|
197
|
+
fragmentId: string;
|
|
198
|
+
/**
|
|
199
|
+
* Condition expression (Core IR).
|
|
200
|
+
* If present, op is only applied when condition evaluates to true.
|
|
201
|
+
*
|
|
202
|
+
* @see FDR-MEL-073
|
|
203
|
+
*/
|
|
204
|
+
condition?: CoreExprNode;
|
|
205
|
+
/**
|
|
206
|
+
* Lowered patch operation.
|
|
207
|
+
*/
|
|
208
|
+
op: LoweredPatchOp;
|
|
209
|
+
/**
|
|
210
|
+
* Confidence (preserved from fragment).
|
|
211
|
+
*/
|
|
212
|
+
confidence: number;
|
|
213
|
+
}
|
|
214
|
+
/**
|
|
215
|
+
* @deprecated Use SchemaConditionalPatchOp instead.
|
|
216
|
+
*/
|
|
217
|
+
export type ConditionalPatchOp = SchemaConditionalPatchOp;
|
|
218
|
+
/**
|
|
219
|
+
* Lower PatchFragment[] to SchemaConditionalPatchOp[].
|
|
220
|
+
*
|
|
221
|
+
* Transforms MEL IR expressions to Core IR expressions.
|
|
222
|
+
* Preserves fragment conditions for evaluation phase.
|
|
223
|
+
*
|
|
224
|
+
* @param fragments - MEL IR patch fragments from Translator
|
|
225
|
+
* @param ctx - Patch lowering context
|
|
226
|
+
* @returns Core IR schema conditional patch operations
|
|
227
|
+
*
|
|
228
|
+
* @see SPEC v0.4.0 §17.5
|
|
229
|
+
*/
|
|
230
|
+
export declare function lowerPatchFragments(fragments: MelPatchFragment[], ctx: PatchLoweringContext): SchemaConditionalPatchOp[];
|