@nahisaho/musubix-library-learner 2.1.1 → 2.2.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/dist/EnhancedLibraryLearner.d.ts +159 -0
- package/dist/EnhancedLibraryLearner.d.ts.map +1 -0
- package/dist/EnhancedLibraryLearner.js +296 -0
- package/dist/EnhancedLibraryLearner.js.map +1 -0
- package/dist/domain/DomainAwareAbstractor.d.ts +226 -0
- package/dist/domain/DomainAwareAbstractor.d.ts.map +1 -0
- package/dist/domain/DomainAwareAbstractor.js +237 -0
- package/dist/domain/DomainAwareAbstractor.js.map +1 -0
- package/dist/domain/__tests__/DomainAwareAbstractor.test.d.ts +9 -0
- package/dist/domain/__tests__/DomainAwareAbstractor.test.d.ts.map +1 -0
- package/dist/domain/__tests__/DomainAwareAbstractor.test.js +217 -0
- package/dist/domain/__tests__/DomainAwareAbstractor.test.js.map +1 -0
- package/dist/domain/index.d.ts +7 -0
- package/dist/domain/index.d.ts.map +1 -0
- package/dist/domain/index.js +6 -0
- package/dist/domain/index.js.map +1 -0
- package/dist/hierarchy/HierarchyManager.d.ts +227 -0
- package/dist/hierarchy/HierarchyManager.d.ts.map +1 -0
- package/dist/hierarchy/HierarchyManager.js +342 -0
- package/dist/hierarchy/HierarchyManager.js.map +1 -0
- package/dist/hierarchy/index.d.ts +9 -0
- package/dist/hierarchy/index.d.ts.map +1 -0
- package/dist/hierarchy/index.js +8 -0
- package/dist/hierarchy/index.js.map +1 -0
- package/dist/index.d.ts +18 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +13 -0
- package/dist/index.js.map +1 -1
- package/dist/library/IterativeCompressor.d.ts +196 -0
- package/dist/library/IterativeCompressor.d.ts.map +1 -0
- package/dist/library/IterativeCompressor.js +367 -0
- package/dist/library/IterativeCompressor.js.map +1 -0
- package/dist/library/PatternVersionManager.d.ts +177 -0
- package/dist/library/PatternVersionManager.d.ts.map +1 -0
- package/dist/library/PatternVersionManager.js +223 -0
- package/dist/library/PatternVersionManager.js.map +1 -0
- package/dist/library/__tests__/IterativeCompressor.test.d.ts +9 -0
- package/dist/library/__tests__/IterativeCompressor.test.d.ts.map +1 -0
- package/dist/library/__tests__/IterativeCompressor.test.js +200 -0
- package/dist/library/__tests__/IterativeCompressor.test.js.map +1 -0
- package/dist/library/__tests__/PatternVersionManager.test.d.ts +9 -0
- package/dist/library/__tests__/PatternVersionManager.test.d.ts.map +1 -0
- package/dist/library/__tests__/PatternVersionManager.test.js +218 -0
- package/dist/library/__tests__/PatternVersionManager.test.js.map +1 -0
- package/dist/library/index.d.ts +4 -0
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/index.js +4 -0
- package/dist/library/index.js.map +1 -1
- package/dist/metrics/MetricsExporter.d.ts +128 -0
- package/dist/metrics/MetricsExporter.d.ts.map +1 -0
- package/dist/metrics/MetricsExporter.js +157 -0
- package/dist/metrics/MetricsExporter.js.map +1 -0
- package/dist/metrics/index.d.ts +9 -0
- package/dist/metrics/index.d.ts.map +1 -0
- package/dist/metrics/index.js +8 -0
- package/dist/metrics/index.js.map +1 -0
- package/dist/rewrite/RewriteRuleSet.d.ts +136 -0
- package/dist/rewrite/RewriteRuleSet.d.ts.map +1 -0
- package/dist/rewrite/RewriteRuleSet.js +460 -0
- package/dist/rewrite/RewriteRuleSet.js.map +1 -0
- package/dist/rewrite/index.d.ts +9 -0
- package/dist/rewrite/index.d.ts.map +1 -0
- package/dist/rewrite/index.js +8 -0
- package/dist/rewrite/index.js.map +1 -0
- package/dist/search/TypeDirectedPruner.d.ts +138 -0
- package/dist/search/TypeDirectedPruner.d.ts.map +1 -0
- package/dist/search/TypeDirectedPruner.js +245 -0
- package/dist/search/TypeDirectedPruner.js.map +1 -0
- package/dist/search/index.d.ts +9 -0
- package/dist/search/index.d.ts.map +1 -0
- package/dist/search/index.js +8 -0
- package/dist/search/index.js.map +1 -0
- package/dist/updater/IncrementalUpdater.d.ts +152 -0
- package/dist/updater/IncrementalUpdater.d.ts.map +1 -0
- package/dist/updater/IncrementalUpdater.js +283 -0
- package/dist/updater/IncrementalUpdater.js.map +1 -0
- package/dist/updater/index.d.ts +7 -0
- package/dist/updater/index.d.ts.map +1 -0
- package/dist/updater/index.js +6 -0
- package/dist/updater/index.js.map +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RewriteRuleSet - Equivalence Rewrite Rules for E-Graph
|
|
3
|
+
*
|
|
4
|
+
* Provides built-in and custom rewrite rules for AST optimization.
|
|
5
|
+
* Used by E-Graph for equality saturation.
|
|
6
|
+
*
|
|
7
|
+
* @module @nahisaho/musubix-library-learner
|
|
8
|
+
* @see TSK-LL-104
|
|
9
|
+
* @see DES-LL-104
|
|
10
|
+
* @see REQ-LL-104
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createRewriteRuleSet } from './RewriteRuleSet.js';
|
|
15
|
+
*
|
|
16
|
+
* const ruleSet = createRewriteRuleSet();
|
|
17
|
+
* const result = ruleSet.rewrite(ast);
|
|
18
|
+
* console.log(`Applied ${result.rulesApplied.length} rules`);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
import type { ASTNode } from '../types.js';
|
|
22
|
+
/**
|
|
23
|
+
* Pattern for matching AST nodes
|
|
24
|
+
*/
|
|
25
|
+
export type Pattern = Record<string, unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Rewrite rule definition
|
|
28
|
+
*/
|
|
29
|
+
export interface RewriteRule {
|
|
30
|
+
/** Unique identifier */
|
|
31
|
+
id: string;
|
|
32
|
+
/** Human-readable name */
|
|
33
|
+
name: string;
|
|
34
|
+
/** Pattern to match */
|
|
35
|
+
pattern: Pattern;
|
|
36
|
+
/** Replacement template */
|
|
37
|
+
replacement: Pattern;
|
|
38
|
+
/** Rule description */
|
|
39
|
+
description?: string;
|
|
40
|
+
/** Rule category */
|
|
41
|
+
category?: string;
|
|
42
|
+
/** Priority (higher = applied first) */
|
|
43
|
+
priority?: number;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Result of rewrite operation
|
|
47
|
+
*/
|
|
48
|
+
export interface RewriteResult {
|
|
49
|
+
/** Rewritten AST */
|
|
50
|
+
rewritten: ASTNode;
|
|
51
|
+
/** Rules that were applied */
|
|
52
|
+
rulesApplied: string[];
|
|
53
|
+
/** Number of iterations */
|
|
54
|
+
iterationCount: number;
|
|
55
|
+
/** Whether any changes were made */
|
|
56
|
+
changed: boolean;
|
|
57
|
+
}
|
|
58
|
+
/**
|
|
59
|
+
* Configuration for RewriteRuleSet
|
|
60
|
+
*/
|
|
61
|
+
export interface RewriteRuleSetConfig {
|
|
62
|
+
/** Maximum rewrite iterations */
|
|
63
|
+
maxIterations?: number;
|
|
64
|
+
/** Enable built-in rules */
|
|
65
|
+
enableBuiltinRules?: boolean;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* RewriteRuleSet interface
|
|
69
|
+
*/
|
|
70
|
+
export interface RewriteRuleSet {
|
|
71
|
+
/** Add a custom rule */
|
|
72
|
+
addRule(rule: RewriteRule): void;
|
|
73
|
+
/** Remove a rule by ID */
|
|
74
|
+
removeRule(id: string): void;
|
|
75
|
+
/** Get a rule by ID */
|
|
76
|
+
getRule(id: string): RewriteRule | undefined;
|
|
77
|
+
/** List all rules, optionally filtered by category */
|
|
78
|
+
listRules(category?: string): RewriteRule[];
|
|
79
|
+
/** Get total rule count */
|
|
80
|
+
getRuleCount(): number;
|
|
81
|
+
/** Rewrite an AST using rules */
|
|
82
|
+
rewrite(ast: ASTNode): RewriteResult;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Default RewriteRuleSet implementation
|
|
86
|
+
*/
|
|
87
|
+
export declare class DefaultRewriteRuleSet implements RewriteRuleSet {
|
|
88
|
+
private rules;
|
|
89
|
+
private config;
|
|
90
|
+
constructor(config?: RewriteRuleSetConfig);
|
|
91
|
+
/**
|
|
92
|
+
* Add a custom rule
|
|
93
|
+
*/
|
|
94
|
+
addRule(rule: RewriteRule): void;
|
|
95
|
+
/**
|
|
96
|
+
* Remove a rule by ID
|
|
97
|
+
*/
|
|
98
|
+
removeRule(id: string): void;
|
|
99
|
+
/**
|
|
100
|
+
* Get a rule by ID
|
|
101
|
+
*/
|
|
102
|
+
getRule(id: string): RewriteRule | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* List all rules, optionally filtered by category
|
|
105
|
+
*/
|
|
106
|
+
listRules(category?: string): RewriteRule[];
|
|
107
|
+
/**
|
|
108
|
+
* Get total rule count
|
|
109
|
+
*/
|
|
110
|
+
getRuleCount(): number;
|
|
111
|
+
/**
|
|
112
|
+
* Rewrite an AST using rules
|
|
113
|
+
*/
|
|
114
|
+
rewrite(ast: ASTNode): RewriteResult;
|
|
115
|
+
/**
|
|
116
|
+
* Apply a single rule to an AST
|
|
117
|
+
*/
|
|
118
|
+
private applyRule;
|
|
119
|
+
/**
|
|
120
|
+
* Match a pattern against an AST node
|
|
121
|
+
*/
|
|
122
|
+
private matchPattern;
|
|
123
|
+
/**
|
|
124
|
+
* Apply a replacement template
|
|
125
|
+
*/
|
|
126
|
+
private applyReplacement;
|
|
127
|
+
/**
|
|
128
|
+
* Deep clone an AST
|
|
129
|
+
*/
|
|
130
|
+
private cloneAST;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Create a new RewriteRuleSet instance
|
|
134
|
+
*/
|
|
135
|
+
export declare function createRewriteRuleSet(config?: RewriteRuleSetConfig): RewriteRuleSet;
|
|
136
|
+
//# sourceMappingURL=RewriteRuleSet.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RewriteRuleSet.d.ts","sourceRoot":"","sources":["../../src/rewrite/RewriteRuleSet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAA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AC;IAEvB,iCAAiC;IACjC,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa,CAAC;CACtC;AA6PD;;GAEG;AACH,qBAAa,qBAAsB,YAAW,cAAc;IAC1D,OAAO,CAAC,KAAK,CAAuC;IACpD,OAAO,CAAC,MAAM,CAAiC;gBAEnC,MAAM,GAAE,oBAAyB;IAW7C;;OAEG;IACH,OAAO,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAYhC;;OAEG;IACH,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI;IAI5B;;OAEG;IACH,OAAO,CAAC,EAAE,EAAE,MAAM,GAAG,WAAW,GAAG,SAAS;IAI5C;;OAEG;IACH,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,GAAG,WAAW,EAAE;IAQ3C;;OAEG;IACH,YAAY,IAAI,MAAM;IAItB;;OAEG;IACH,OAAO,CAAC,GAAG,EAAE,OAAO,GAAG,aAAa;IAyCpC;;OAEG;IACH,OAAO,CAAC,SAAS;IAwCjB;;OAEG;IACH,OAAO,CAAC,YAAY;IAsCpB;;OAEG;IACH,OAAO,CAAC,gBAAgB;IAqBxB;;OAEG;IACH,OAAO,CAAC,QAAQ;CAGjB;AAMD;;GAEG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,GAAE,oBAAyB,GAAG,cAAc,CAEtF"}
|
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* RewriteRuleSet - Equivalence Rewrite Rules for E-Graph
|
|
3
|
+
*
|
|
4
|
+
* Provides built-in and custom rewrite rules for AST optimization.
|
|
5
|
+
* Used by E-Graph for equality saturation.
|
|
6
|
+
*
|
|
7
|
+
* @module @nahisaho/musubix-library-learner
|
|
8
|
+
* @see TSK-LL-104
|
|
9
|
+
* @see DES-LL-104
|
|
10
|
+
* @see REQ-LL-104
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { createRewriteRuleSet } from './RewriteRuleSet.js';
|
|
15
|
+
*
|
|
16
|
+
* const ruleSet = createRewriteRuleSet();
|
|
17
|
+
* const result = ruleSet.rewrite(ast);
|
|
18
|
+
* console.log(`Applied ${result.rulesApplied.length} rules`);
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
// =============================================================================
|
|
22
|
+
// Built-in Rules
|
|
23
|
+
// =============================================================================
|
|
24
|
+
const BUILTIN_RULES = [
|
|
25
|
+
// Arithmetic: Addition with zero
|
|
26
|
+
{
|
|
27
|
+
id: 'add-zero-right',
|
|
28
|
+
name: 'x + 0 = x (right)',
|
|
29
|
+
pattern: { type: 'BinaryExpression', operator: '+', right: { type: 'Literal', value: 0 } },
|
|
30
|
+
replacement: { $ref: 'left' },
|
|
31
|
+
description: 'Adding zero on the right has no effect',
|
|
32
|
+
category: 'arithmetic',
|
|
33
|
+
priority: 10,
|
|
34
|
+
},
|
|
35
|
+
{
|
|
36
|
+
id: 'add-zero-left',
|
|
37
|
+
name: '0 + x = x (left)',
|
|
38
|
+
pattern: { type: 'BinaryExpression', operator: '+', left: { type: 'Literal', value: 0 } },
|
|
39
|
+
replacement: { $ref: 'right' },
|
|
40
|
+
description: 'Adding zero on the left has no effect',
|
|
41
|
+
category: 'arithmetic',
|
|
42
|
+
priority: 10,
|
|
43
|
+
},
|
|
44
|
+
// Arithmetic: Multiplication with one
|
|
45
|
+
{
|
|
46
|
+
id: 'mul-one-right',
|
|
47
|
+
name: 'x * 1 = x (right)',
|
|
48
|
+
pattern: { type: 'BinaryExpression', operator: '*', right: { type: 'Literal', value: 1 } },
|
|
49
|
+
replacement: { $ref: 'left' },
|
|
50
|
+
description: 'Multiplying by one on the right has no effect',
|
|
51
|
+
category: 'arithmetic',
|
|
52
|
+
priority: 10,
|
|
53
|
+
},
|
|
54
|
+
{
|
|
55
|
+
id: 'mul-one-left',
|
|
56
|
+
name: '1 * x = x (left)',
|
|
57
|
+
pattern: { type: 'BinaryExpression', operator: '*', left: { type: 'Literal', value: 1 } },
|
|
58
|
+
replacement: { $ref: 'right' },
|
|
59
|
+
description: 'Multiplying by one on the left has no effect',
|
|
60
|
+
category: 'arithmetic',
|
|
61
|
+
priority: 10,
|
|
62
|
+
},
|
|
63
|
+
// Arithmetic: Multiplication with zero
|
|
64
|
+
{
|
|
65
|
+
id: 'mul-zero-right',
|
|
66
|
+
name: 'x * 0 = 0 (right)',
|
|
67
|
+
pattern: { type: 'BinaryExpression', operator: '*', right: { type: 'Literal', value: 0 } },
|
|
68
|
+
replacement: { type: 'Literal', value: 0 },
|
|
69
|
+
description: 'Multiplying by zero results in zero',
|
|
70
|
+
category: 'arithmetic',
|
|
71
|
+
priority: 10,
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
id: 'mul-zero-left',
|
|
75
|
+
name: '0 * x = 0 (left)',
|
|
76
|
+
pattern: { type: 'BinaryExpression', operator: '*', left: { type: 'Literal', value: 0 } },
|
|
77
|
+
replacement: { type: 'Literal', value: 0 },
|
|
78
|
+
description: 'Zero multiplied by anything is zero',
|
|
79
|
+
category: 'arithmetic',
|
|
80
|
+
priority: 10,
|
|
81
|
+
},
|
|
82
|
+
// Arithmetic: Subtraction
|
|
83
|
+
{
|
|
84
|
+
id: 'sub-zero',
|
|
85
|
+
name: 'x - 0 = x',
|
|
86
|
+
pattern: { type: 'BinaryExpression', operator: '-', right: { type: 'Literal', value: 0 } },
|
|
87
|
+
replacement: { $ref: 'left' },
|
|
88
|
+
description: 'Subtracting zero has no effect',
|
|
89
|
+
category: 'arithmetic',
|
|
90
|
+
priority: 10,
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
id: 'sub-self',
|
|
94
|
+
name: 'x - x = 0',
|
|
95
|
+
pattern: { type: 'BinaryExpression', operator: '-', $constraint: 'left === right' },
|
|
96
|
+
replacement: { type: 'Literal', value: 0 },
|
|
97
|
+
description: 'Subtracting a value from itself equals zero',
|
|
98
|
+
category: 'arithmetic',
|
|
99
|
+
priority: 9,
|
|
100
|
+
},
|
|
101
|
+
// Arithmetic: Division
|
|
102
|
+
{
|
|
103
|
+
id: 'div-one',
|
|
104
|
+
name: 'x / 1 = x',
|
|
105
|
+
pattern: { type: 'BinaryExpression', operator: '/', right: { type: 'Literal', value: 1 } },
|
|
106
|
+
replacement: { $ref: 'left' },
|
|
107
|
+
description: 'Dividing by one has no effect',
|
|
108
|
+
category: 'arithmetic',
|
|
109
|
+
priority: 10,
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
id: 'div-self',
|
|
113
|
+
name: 'x / x = 1',
|
|
114
|
+
pattern: { type: 'BinaryExpression', operator: '/', $constraint: 'left === right' },
|
|
115
|
+
replacement: { type: 'Literal', value: 1 },
|
|
116
|
+
description: 'Dividing a value by itself equals one',
|
|
117
|
+
category: 'arithmetic',
|
|
118
|
+
priority: 9,
|
|
119
|
+
},
|
|
120
|
+
// Boolean: Identity
|
|
121
|
+
{
|
|
122
|
+
id: 'and-true-right',
|
|
123
|
+
name: 'x && true = x',
|
|
124
|
+
pattern: { type: 'LogicalExpression', operator: '&&', right: { type: 'Literal', value: true } },
|
|
125
|
+
replacement: { $ref: 'left' },
|
|
126
|
+
description: 'AND with true on right has no effect',
|
|
127
|
+
category: 'boolean',
|
|
128
|
+
priority: 10,
|
|
129
|
+
},
|
|
130
|
+
{
|
|
131
|
+
id: 'and-true-left',
|
|
132
|
+
name: 'true && x = x',
|
|
133
|
+
pattern: { type: 'LogicalExpression', operator: '&&', left: { type: 'Literal', value: true } },
|
|
134
|
+
replacement: { $ref: 'right' },
|
|
135
|
+
description: 'AND with true on left has no effect',
|
|
136
|
+
category: 'boolean',
|
|
137
|
+
priority: 10,
|
|
138
|
+
},
|
|
139
|
+
{
|
|
140
|
+
id: 'or-false-right',
|
|
141
|
+
name: 'x || false = x',
|
|
142
|
+
pattern: { type: 'LogicalExpression', operator: '||', right: { type: 'Literal', value: false } },
|
|
143
|
+
replacement: { $ref: 'left' },
|
|
144
|
+
description: 'OR with false on right has no effect',
|
|
145
|
+
category: 'boolean',
|
|
146
|
+
priority: 10,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
id: 'or-false-left',
|
|
150
|
+
name: 'false || x = x',
|
|
151
|
+
pattern: { type: 'LogicalExpression', operator: '||', left: { type: 'Literal', value: false } },
|
|
152
|
+
replacement: { $ref: 'right' },
|
|
153
|
+
description: 'OR with false on left has no effect',
|
|
154
|
+
category: 'boolean',
|
|
155
|
+
priority: 10,
|
|
156
|
+
},
|
|
157
|
+
// Boolean: Absorption
|
|
158
|
+
{
|
|
159
|
+
id: 'and-false',
|
|
160
|
+
name: 'x && false = false',
|
|
161
|
+
pattern: { type: 'LogicalExpression', operator: '&&', right: { type: 'Literal', value: false } },
|
|
162
|
+
replacement: { type: 'Literal', value: false },
|
|
163
|
+
description: 'AND with false is always false',
|
|
164
|
+
category: 'boolean',
|
|
165
|
+
priority: 10,
|
|
166
|
+
},
|
|
167
|
+
{
|
|
168
|
+
id: 'or-true',
|
|
169
|
+
name: 'x || true = true',
|
|
170
|
+
pattern: { type: 'LogicalExpression', operator: '||', right: { type: 'Literal', value: true } },
|
|
171
|
+
replacement: { type: 'Literal', value: true },
|
|
172
|
+
description: 'OR with true is always true',
|
|
173
|
+
category: 'boolean',
|
|
174
|
+
priority: 10,
|
|
175
|
+
},
|
|
176
|
+
// Boolean: Double negation
|
|
177
|
+
{
|
|
178
|
+
id: 'double-not',
|
|
179
|
+
name: '!!x = x',
|
|
180
|
+
pattern: {
|
|
181
|
+
type: 'UnaryExpression',
|
|
182
|
+
operator: '!',
|
|
183
|
+
argument: { type: 'UnaryExpression', operator: '!', $capture: 'inner' },
|
|
184
|
+
},
|
|
185
|
+
replacement: { $ref: 'inner.argument' },
|
|
186
|
+
description: 'Double negation cancels out',
|
|
187
|
+
category: 'boolean',
|
|
188
|
+
priority: 10,
|
|
189
|
+
},
|
|
190
|
+
// Conditional
|
|
191
|
+
{
|
|
192
|
+
id: 'ternary-true',
|
|
193
|
+
name: 'true ? a : b = a',
|
|
194
|
+
pattern: { type: 'ConditionalExpression', test: { type: 'Literal', value: true } },
|
|
195
|
+
replacement: { $ref: 'consequent' },
|
|
196
|
+
description: 'Ternary with true condition returns consequent',
|
|
197
|
+
category: 'conditional',
|
|
198
|
+
priority: 10,
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
id: 'ternary-false',
|
|
202
|
+
name: 'false ? a : b = b',
|
|
203
|
+
pattern: { type: 'ConditionalExpression', test: { type: 'Literal', value: false } },
|
|
204
|
+
replacement: { $ref: 'alternate' },
|
|
205
|
+
description: 'Ternary with false condition returns alternate',
|
|
206
|
+
category: 'conditional',
|
|
207
|
+
priority: 10,
|
|
208
|
+
},
|
|
209
|
+
// Commutativity
|
|
210
|
+
{
|
|
211
|
+
id: 'add-commute',
|
|
212
|
+
name: 'a + b = b + a',
|
|
213
|
+
pattern: { type: 'BinaryExpression', operator: '+', $commutative: true },
|
|
214
|
+
replacement: { $swap: ['left', 'right'] },
|
|
215
|
+
description: 'Addition is commutative',
|
|
216
|
+
category: 'commutativity',
|
|
217
|
+
priority: 1,
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
id: 'mul-commute',
|
|
221
|
+
name: 'a * b = b * a',
|
|
222
|
+
pattern: { type: 'BinaryExpression', operator: '*', $commutative: true },
|
|
223
|
+
replacement: { $swap: ['left', 'right'] },
|
|
224
|
+
description: 'Multiplication is commutative',
|
|
225
|
+
category: 'commutativity',
|
|
226
|
+
priority: 1,
|
|
227
|
+
},
|
|
228
|
+
// Associativity
|
|
229
|
+
{
|
|
230
|
+
id: 'add-assoc',
|
|
231
|
+
name: '(a + b) + c = a + (b + c)',
|
|
232
|
+
pattern: {
|
|
233
|
+
type: 'BinaryExpression',
|
|
234
|
+
operator: '+',
|
|
235
|
+
left: { type: 'BinaryExpression', operator: '+' },
|
|
236
|
+
},
|
|
237
|
+
replacement: { $reassociate: true },
|
|
238
|
+
description: 'Addition is associative',
|
|
239
|
+
category: 'associativity',
|
|
240
|
+
priority: 1,
|
|
241
|
+
},
|
|
242
|
+
{
|
|
243
|
+
id: 'mul-assoc',
|
|
244
|
+
name: '(a * b) * c = a * (b * c)',
|
|
245
|
+
pattern: {
|
|
246
|
+
type: 'BinaryExpression',
|
|
247
|
+
operator: '*',
|
|
248
|
+
left: { type: 'BinaryExpression', operator: '*' },
|
|
249
|
+
},
|
|
250
|
+
replacement: { $reassociate: true },
|
|
251
|
+
description: 'Multiplication is associative',
|
|
252
|
+
category: 'associativity',
|
|
253
|
+
priority: 1,
|
|
254
|
+
},
|
|
255
|
+
];
|
|
256
|
+
// =============================================================================
|
|
257
|
+
// Default Implementation
|
|
258
|
+
// =============================================================================
|
|
259
|
+
/**
|
|
260
|
+
* Default RewriteRuleSet implementation
|
|
261
|
+
*/
|
|
262
|
+
export class DefaultRewriteRuleSet {
|
|
263
|
+
rules = new Map();
|
|
264
|
+
config;
|
|
265
|
+
constructor(config = {}) {
|
|
266
|
+
this.config = {
|
|
267
|
+
maxIterations: config.maxIterations ?? 100,
|
|
268
|
+
enableBuiltinRules: config.enableBuiltinRules ?? true,
|
|
269
|
+
};
|
|
270
|
+
if (this.config.enableBuiltinRules) {
|
|
271
|
+
BUILTIN_RULES.forEach((rule) => this.rules.set(rule.id, rule));
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
/**
|
|
275
|
+
* Add a custom rule
|
|
276
|
+
*/
|
|
277
|
+
addRule(rule) {
|
|
278
|
+
if (!rule.id || !rule.name || !rule.pattern || !rule.replacement) {
|
|
279
|
+
throw new Error('Invalid rule: missing required fields (id, name, pattern, replacement)');
|
|
280
|
+
}
|
|
281
|
+
if (this.rules.has(rule.id)) {
|
|
282
|
+
throw new Error(`Duplicate rule ID: ${rule.id}`);
|
|
283
|
+
}
|
|
284
|
+
this.rules.set(rule.id, rule);
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Remove a rule by ID
|
|
288
|
+
*/
|
|
289
|
+
removeRule(id) {
|
|
290
|
+
this.rules.delete(id);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Get a rule by ID
|
|
294
|
+
*/
|
|
295
|
+
getRule(id) {
|
|
296
|
+
return this.rules.get(id);
|
|
297
|
+
}
|
|
298
|
+
/**
|
|
299
|
+
* List all rules, optionally filtered by category
|
|
300
|
+
*/
|
|
301
|
+
listRules(category) {
|
|
302
|
+
const allRules = Array.from(this.rules.values());
|
|
303
|
+
if (category) {
|
|
304
|
+
return allRules.filter((r) => r.category === category);
|
|
305
|
+
}
|
|
306
|
+
return allRules;
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Get total rule count
|
|
310
|
+
*/
|
|
311
|
+
getRuleCount() {
|
|
312
|
+
return this.rules.size;
|
|
313
|
+
}
|
|
314
|
+
/**
|
|
315
|
+
* Rewrite an AST using rules
|
|
316
|
+
*/
|
|
317
|
+
rewrite(ast) {
|
|
318
|
+
const rulesApplied = [];
|
|
319
|
+
let current = this.cloneAST(ast);
|
|
320
|
+
let changed = false;
|
|
321
|
+
let iterationCount = 0;
|
|
322
|
+
// Sort rules by priority (higher first)
|
|
323
|
+
const sortedRules = this.listRules().sort((a, b) => (b.priority ?? 0) - (a.priority ?? 0));
|
|
324
|
+
for (let i = 0; i < this.config.maxIterations; i++) {
|
|
325
|
+
iterationCount++;
|
|
326
|
+
let iterationChanged = false;
|
|
327
|
+
for (const rule of sortedRules) {
|
|
328
|
+
const result = this.applyRule(current, rule);
|
|
329
|
+
if (result.changed) {
|
|
330
|
+
current = result.ast;
|
|
331
|
+
rulesApplied.push(rule.id);
|
|
332
|
+
iterationChanged = true;
|
|
333
|
+
changed = true;
|
|
334
|
+
break; // Start over with new AST
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
if (!iterationChanged) {
|
|
338
|
+
break; // No more rules apply
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
return {
|
|
342
|
+
rewritten: current,
|
|
343
|
+
rulesApplied,
|
|
344
|
+
iterationCount,
|
|
345
|
+
changed,
|
|
346
|
+
};
|
|
347
|
+
}
|
|
348
|
+
// ===========================================================================
|
|
349
|
+
// Private Methods
|
|
350
|
+
// ===========================================================================
|
|
351
|
+
/**
|
|
352
|
+
* Apply a single rule to an AST
|
|
353
|
+
*/
|
|
354
|
+
applyRule(ast, rule) {
|
|
355
|
+
const match = this.matchPattern(ast, rule.pattern);
|
|
356
|
+
if (match.matches) {
|
|
357
|
+
const replaced = this.applyReplacement(ast, rule.replacement, match.bindings);
|
|
358
|
+
return { ast: replaced, changed: true };
|
|
359
|
+
}
|
|
360
|
+
// Try to apply to children
|
|
361
|
+
const astObj = ast;
|
|
362
|
+
if (astObj.left) {
|
|
363
|
+
const leftResult = this.applyRule(astObj.left, rule);
|
|
364
|
+
if (leftResult.changed) {
|
|
365
|
+
return {
|
|
366
|
+
ast: { ...ast, left: leftResult.ast },
|
|
367
|
+
changed: true,
|
|
368
|
+
};
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
if (astObj.right) {
|
|
372
|
+
const rightResult = this.applyRule(astObj.right, rule);
|
|
373
|
+
if (rightResult.changed) {
|
|
374
|
+
return {
|
|
375
|
+
ast: { ...ast, right: rightResult.ast },
|
|
376
|
+
changed: true,
|
|
377
|
+
};
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
if (astObj.argument) {
|
|
381
|
+
const argResult = this.applyRule(astObj.argument, rule);
|
|
382
|
+
if (argResult.changed) {
|
|
383
|
+
return {
|
|
384
|
+
ast: { ...ast, argument: argResult.ast },
|
|
385
|
+
changed: true,
|
|
386
|
+
};
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
return { ast, changed: false };
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Match a pattern against an AST node
|
|
393
|
+
*/
|
|
394
|
+
matchPattern(ast, pattern) {
|
|
395
|
+
const bindings = {};
|
|
396
|
+
const astObj = ast;
|
|
397
|
+
for (const [key, value] of Object.entries(pattern)) {
|
|
398
|
+
if (key.startsWith('$'))
|
|
399
|
+
continue; // Skip meta keys
|
|
400
|
+
if (typeof value === 'object' && value !== null) {
|
|
401
|
+
// Nested pattern
|
|
402
|
+
if (!astObj[key]) {
|
|
403
|
+
return { matches: false, bindings };
|
|
404
|
+
}
|
|
405
|
+
const nested = this.matchPattern(astObj[key], value);
|
|
406
|
+
if (!nested.matches) {
|
|
407
|
+
return { matches: false, bindings };
|
|
408
|
+
}
|
|
409
|
+
Object.assign(bindings, nested.bindings);
|
|
410
|
+
}
|
|
411
|
+
else {
|
|
412
|
+
// Direct value comparison
|
|
413
|
+
if (astObj[key] !== value) {
|
|
414
|
+
return { matches: false, bindings };
|
|
415
|
+
}
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
// Capture the matched node parts for replacement
|
|
419
|
+
bindings['left'] = astObj.left;
|
|
420
|
+
bindings['right'] = astObj.right;
|
|
421
|
+
bindings['argument'] = astObj.argument;
|
|
422
|
+
bindings['consequent'] = astObj.consequent;
|
|
423
|
+
bindings['alternate'] = astObj.alternate;
|
|
424
|
+
return { matches: true, bindings };
|
|
425
|
+
}
|
|
426
|
+
/**
|
|
427
|
+
* Apply a replacement template
|
|
428
|
+
*/
|
|
429
|
+
applyReplacement(_original, replacement, bindings) {
|
|
430
|
+
// Handle reference to captured binding
|
|
431
|
+
if ('$ref' in replacement) {
|
|
432
|
+
const ref = replacement['$ref'];
|
|
433
|
+
return bindings[ref] ?? _original;
|
|
434
|
+
}
|
|
435
|
+
// Handle direct replacement
|
|
436
|
+
const result = {};
|
|
437
|
+
for (const [key, value] of Object.entries(replacement)) {
|
|
438
|
+
if (key.startsWith('$'))
|
|
439
|
+
continue;
|
|
440
|
+
result[key] = value;
|
|
441
|
+
}
|
|
442
|
+
return result;
|
|
443
|
+
}
|
|
444
|
+
/**
|
|
445
|
+
* Deep clone an AST
|
|
446
|
+
*/
|
|
447
|
+
cloneAST(ast) {
|
|
448
|
+
return JSON.parse(JSON.stringify(ast));
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
// =============================================================================
|
|
452
|
+
// Factory Function
|
|
453
|
+
// =============================================================================
|
|
454
|
+
/**
|
|
455
|
+
* Create a new RewriteRuleSet instance
|
|
456
|
+
*/
|
|
457
|
+
export function createRewriteRuleSet(config = {}) {
|
|
458
|
+
return new DefaultRewriteRuleSet(config);
|
|
459
|
+
}
|
|
460
|
+
//# sourceMappingURL=RewriteRuleSet.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"RewriteRuleSet.js","sourceRoot":"","sources":["../../src/rewrite/RewriteRuleSet.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAgFH,gFAAgF;AAChF,iBAAiB;AACjB,gFAAgF;AAEhF,MAAM,aAAa,GAAkB;IACnC,iCAAiC;IACjC;QACE,EAAE,EAAE,gBAAgB;QACpB,IAAI,EAAE,mBAAmB;QACzB,OAAO,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,EAAE,KAAK,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QAC1F,WAAW,EAAE,EAAE,IAAI,EAAE,MAAM,EAAE;QAC7B,WAAW,EAAE,wCAAwC;QACrD,QAAQ,EAAE,YAAY;QACtB,QAAQ,EAAE,EAAE;KACb;IACD;QACE,EAAE,EAAE,eAAe;QACnB,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE,QAAQ,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,CAAC,EAAE,EAAE;QACzF,WAAW,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE;QAC9B,WAAW,EAAE,uCAAuC;QACpD,QAAQ,EAAE,YAAY;QACtB,QAAQ,EAAE,EAAE;KACb;IAED,sCAAsC;IACtC;QACE,EAAE,EAAE,eAAe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AC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC;IACzC,CAAC;CACF;AAED,gFAAgF;AAChF,mBAAmB;AACnB,gFAAgF;AAEhF;;GAEG;AACH,MAAM,UAAU,oBAAoB,CAAC,SAA+B,EAAE;IACpE,OAAO,IAAI,qBAAqB,CAAC,MAAM,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Rewrite Module - Equivalence Rewrite Rules
|
|
3
|
+
*
|
|
4
|
+
* @module @nahisaho/musubix-library-learner/rewrite
|
|
5
|
+
* @see TSK-LL-104
|
|
6
|
+
*/
|
|
7
|
+
export type { RewriteRuleSet, RewriteRule, RewriteResult, RewriteRuleSetConfig, Pattern, } from './RewriteRuleSet.js';
|
|
8
|
+
export { createRewriteRuleSet, DefaultRewriteRuleSet } from './RewriteRuleSet.js';
|
|
9
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/rewrite/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,YAAY,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,oBAAoB,EACpB,OAAO,GACR,MAAM,qBAAqB,CAAC;AAE7B,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/rewrite/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAUH,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC"}
|