yukigo-ast 0.1.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/CHANGELOG.md +19 -0
- package/dist/globals/generics.d.ts +740 -0
- package/dist/globals/generics.js +1128 -0
- package/dist/globals/helpers.d.ts +4 -0
- package/dist/globals/helpers.js +76 -0
- package/dist/globals/operators.d.ts +251 -0
- package/dist/globals/operators.js +336 -0
- package/dist/globals/patterns.d.ts +170 -0
- package/dist/globals/patterns.js +261 -0
- package/dist/globals/runtime.d.ts +22 -0
- package/dist/globals/runtime.js +6 -0
- package/dist/globals/types.d.ts +185 -0
- package/dist/globals/types.js +329 -0
- package/dist/index.d.ts +12 -0
- package/dist/index.js +12 -0
- package/dist/paradigms/data.d.ts +246 -0
- package/dist/paradigms/data.js +348 -0
- package/dist/paradigms/functional.d.ts +59 -0
- package/dist/paradigms/functional.js +103 -0
- package/dist/paradigms/imperative.d.ts +124 -0
- package/dist/paradigms/imperative.js +188 -0
- package/dist/paradigms/logic.d.ts +163 -0
- package/dist/paradigms/logic.js +240 -0
- package/dist/paradigms/object.d.ts +201 -0
- package/dist/paradigms/object.js +308 -0
- package/dist/visitor.d.ts +254 -0
- package/dist/visitor.js +426 -0
- package/package.json +25 -0
- package/src/globals/generics.ts +1421 -0
- package/src/globals/helpers.ts +107 -0
- package/src/globals/operators.ts +515 -0
- package/src/globals/patterns.ts +321 -0
- package/src/globals/runtime.ts +33 -0
- package/src/globals/types.ts +375 -0
- package/src/index.ts +12 -0
- package/src/paradigms/data.ts +393 -0
- package/src/paradigms/functional.ts +129 -0
- package/src/paradigms/imperative.ts +232 -0
- package/src/paradigms/logic.ts +314 -0
- package/src/paradigms/object.ts +366 -0
- package/src/visitor.ts +692 -0
- package/tsconfig.json +22 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { BooleanPrimitive, NumberPrimitive, ListPrimitive, CharPrimitive, StringPrimitive, NilPrimitive, SymbolPrimitive, } from "./generics.js";
|
|
2
|
+
import { ApplicationPattern, AsPattern, ConsPattern, ConstructorPattern, FunctorPattern, ListPattern, LiteralPattern, TuplePattern, UnionPattern, VariablePattern, WildcardPattern, } from "./patterns.js";
|
|
3
|
+
/* type Visitor = {
|
|
4
|
+
[key: string]: (node: ASTNode, parent?: ASTNode) => boolean | void;
|
|
5
|
+
}; */
|
|
6
|
+
/* export function traverse(ast: AST | ASTNode, visitor: Visitor) {
|
|
7
|
+
function runVisitor(node: ASTNode, parent?: ASTNode) {
|
|
8
|
+
if (!node || typeof node !== "object" || !("type" in node)) {
|
|
9
|
+
return false;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
let stop = false;
|
|
13
|
+
|
|
14
|
+
// Check for specific node type visitor
|
|
15
|
+
if (visitor[node.type]) {
|
|
16
|
+
stop = visitor[node.type](node, parent) === true;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Check for wildcard visitor
|
|
20
|
+
if (!stop && visitor["*"]) {
|
|
21
|
+
stop = visitor["*"](node, parent) === true;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
if (stop) return true;
|
|
25
|
+
|
|
26
|
+
// Recursively visit children based on their type
|
|
27
|
+
for (const key in node) {
|
|
28
|
+
if (!node.hasOwnProperty(key)) continue;
|
|
29
|
+
|
|
30
|
+
const value = node[key];
|
|
31
|
+
|
|
32
|
+
if (!value) return false;
|
|
33
|
+
|
|
34
|
+
const items = Array.isArray(value) ? value : [value];
|
|
35
|
+
|
|
36
|
+
for (const item of items) {
|
|
37
|
+
if (typeof item === "object" && item.type && runVisitor(item, node)) {
|
|
38
|
+
return true;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return false;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Handle the initial AST array or a single node
|
|
46
|
+
if (Array.isArray(ast)) {
|
|
47
|
+
for (const node of ast) {
|
|
48
|
+
if (runVisitor(node)) break;
|
|
49
|
+
}
|
|
50
|
+
} else {
|
|
51
|
+
runVisitor(ast);
|
|
52
|
+
}
|
|
53
|
+
} */
|
|
54
|
+
// disgusting...
|
|
55
|
+
export function isYukigoPrimitive(node) {
|
|
56
|
+
return (node instanceof NumberPrimitive ||
|
|
57
|
+
node instanceof BooleanPrimitive ||
|
|
58
|
+
node instanceof ListPrimitive ||
|
|
59
|
+
node instanceof CharPrimitive ||
|
|
60
|
+
node instanceof StringPrimitive ||
|
|
61
|
+
node instanceof NilPrimitive ||
|
|
62
|
+
node instanceof SymbolPrimitive);
|
|
63
|
+
}
|
|
64
|
+
export function isPattern(node) {
|
|
65
|
+
return (node instanceof VariablePattern ||
|
|
66
|
+
node instanceof LiteralPattern ||
|
|
67
|
+
node instanceof ApplicationPattern ||
|
|
68
|
+
node instanceof TuplePattern ||
|
|
69
|
+
node instanceof ListPattern ||
|
|
70
|
+
node instanceof FunctorPattern ||
|
|
71
|
+
node instanceof AsPattern ||
|
|
72
|
+
node instanceof WildcardPattern ||
|
|
73
|
+
node instanceof ConstructorPattern ||
|
|
74
|
+
node instanceof ConsPattern ||
|
|
75
|
+
node instanceof UnionPattern);
|
|
76
|
+
}
|
|
@@ -0,0 +1,251 @@
|
|
|
1
|
+
import { Visitor } from "../visitor.js";
|
|
2
|
+
import { ASTNode, Expression, SourceLocation } from "./generics.js";
|
|
3
|
+
export type ArithmeticBinaryOperator = "Plus" | "Minus" | "Multiply" | "Divide" | "Modulo" | "Power" | "Max" | "Min";
|
|
4
|
+
export type ArithmeticUnaryOperator = "Round" | "Absolute" | "Ceil" | "Floor" | "Negation" | "Sqrt";
|
|
5
|
+
export type ComparisonOperatorType = "Equal" | "NotEqual" | "Same" | "NotSame" | "Similar" | "NotSimilar" | "GreaterOrEqualThan" | "GreaterThan" | "LessOrEqualThan" | "LessThan";
|
|
6
|
+
export type LogicalBinaryOperator = "And" | "Or";
|
|
7
|
+
export type LogicalUnaryOperator = "Negation";
|
|
8
|
+
export type BitwiseBinaryOperator = "BitwiseOr" | "BitwiseAnd" | "BitwiseLeftShift" | "BitwiseRightShift" | "BitwiseUnsignedRightShift" | "BitwiseXor";
|
|
9
|
+
export type BitwiseUnaryOperator = "BitwiseNot";
|
|
10
|
+
export type ListBinaryOperator = "Push" | "Concat" | "Inject" | "Gather" | "Collect" | "AllSatisfy" | "AnySatisfy" | "Select" | "Detect" | "GetAt" | "Count" | "Slice" | "SetAt";
|
|
11
|
+
export type ListUnaryOperator = "Size" | "DetectMax" | "DetectMin" | "Flatten";
|
|
12
|
+
export type UnifyOperator = "Unify";
|
|
13
|
+
export type AssignOperator = "Assign";
|
|
14
|
+
export type StringBinaryOperator = "Concat";
|
|
15
|
+
export type UnaryOperator = ArithmeticUnaryOperator | LogicalUnaryOperator | ListUnaryOperator;
|
|
16
|
+
export type BinaryOperator = ArithmeticBinaryOperator | ComparisonOperatorType | LogicalBinaryOperator | BitwiseBinaryOperator | BitwiseUnaryOperator | AssignOperator | UnifyOperator | StringBinaryOperator | ListBinaryOperator;
|
|
17
|
+
export type Operator = UnaryOperator | BinaryOperator;
|
|
18
|
+
/**
|
|
19
|
+
* Represents a unary arithmetic operation like negation (-x).
|
|
20
|
+
* @category Operators
|
|
21
|
+
*/
|
|
22
|
+
export declare class ArithmeticUnaryOperation extends ASTNode {
|
|
23
|
+
/** @hidden */
|
|
24
|
+
operand: Expression;
|
|
25
|
+
/** @hidden */
|
|
26
|
+
operator: ArithmeticUnaryOperator;
|
|
27
|
+
constructor(operator: ArithmeticUnaryOperator, operand: Expression, loc?: SourceLocation);
|
|
28
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
29
|
+
toJSON(): {
|
|
30
|
+
type: string;
|
|
31
|
+
operator: ArithmeticUnaryOperator;
|
|
32
|
+
operand: Expression;
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Represents a binary arithmetic operation like addition or multiplication.
|
|
37
|
+
* @category Operators
|
|
38
|
+
*/
|
|
39
|
+
export declare class ArithmeticBinaryOperation extends ASTNode {
|
|
40
|
+
/** @hidden */
|
|
41
|
+
right: Expression;
|
|
42
|
+
/** @hidden */
|
|
43
|
+
left: Expression;
|
|
44
|
+
/** @hidden */
|
|
45
|
+
operator: ArithmeticBinaryOperator;
|
|
46
|
+
constructor(operator: ArithmeticBinaryOperator, left: Expression, right: Expression, loc?: SourceLocation);
|
|
47
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
48
|
+
toJSON(): {
|
|
49
|
+
type: string;
|
|
50
|
+
operator: ArithmeticBinaryOperator;
|
|
51
|
+
left: Expression;
|
|
52
|
+
right: Expression;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Represents a unary operation on a list, such as getting the head or tail.
|
|
57
|
+
* @category Operators
|
|
58
|
+
*/
|
|
59
|
+
export declare class ListUnaryOperation extends ASTNode {
|
|
60
|
+
/** @hidden */
|
|
61
|
+
operand: Expression;
|
|
62
|
+
/** @hidden */
|
|
63
|
+
operator: ListUnaryOperator;
|
|
64
|
+
constructor(operator: ListUnaryOperator, operand: Expression, loc?: SourceLocation);
|
|
65
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
66
|
+
toJSON(): {
|
|
67
|
+
type: string;
|
|
68
|
+
operator: ListUnaryOperator;
|
|
69
|
+
operand: Expression;
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* Represents a binary operation on lists, such as concatenation.
|
|
74
|
+
* @category Operators
|
|
75
|
+
*/
|
|
76
|
+
export declare class ListBinaryOperation extends ASTNode {
|
|
77
|
+
/** @hidden */
|
|
78
|
+
right: Expression;
|
|
79
|
+
/** @hidden */
|
|
80
|
+
left: Expression;
|
|
81
|
+
/** @hidden */
|
|
82
|
+
operator: ListBinaryOperator;
|
|
83
|
+
constructor(operator: ListBinaryOperator, left: Expression, right: Expression, loc?: SourceLocation);
|
|
84
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
85
|
+
toJSON(): {
|
|
86
|
+
type: string;
|
|
87
|
+
operator: ListBinaryOperator;
|
|
88
|
+
left: Expression;
|
|
89
|
+
right: Expression;
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Represents a comparison between two values (e.g., >, <, ==).
|
|
94
|
+
* @category Operators
|
|
95
|
+
*/
|
|
96
|
+
export declare class ComparisonOperation extends ASTNode {
|
|
97
|
+
/** @hidden */
|
|
98
|
+
right: Expression;
|
|
99
|
+
/** @hidden */
|
|
100
|
+
left: Expression;
|
|
101
|
+
/** @hidden */
|
|
102
|
+
operator: ComparisonOperatorType;
|
|
103
|
+
constructor(operator: ComparisonOperatorType, left: Expression, right: Expression, loc?: SourceLocation);
|
|
104
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
105
|
+
toJSON(): {
|
|
106
|
+
type: string;
|
|
107
|
+
operator: ComparisonOperatorType;
|
|
108
|
+
left: Expression;
|
|
109
|
+
right: Expression;
|
|
110
|
+
};
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Represents a binary logical operation like AND or OR.
|
|
114
|
+
* @category Operators
|
|
115
|
+
*/
|
|
116
|
+
export declare class LogicalBinaryOperation extends ASTNode {
|
|
117
|
+
/** @hidden */
|
|
118
|
+
right: Expression;
|
|
119
|
+
/** @hidden */
|
|
120
|
+
left: Expression;
|
|
121
|
+
/** @hidden */
|
|
122
|
+
operator: LogicalBinaryOperator;
|
|
123
|
+
constructor(operator: LogicalBinaryOperator, left: Expression, right: Expression, loc?: SourceLocation);
|
|
124
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
125
|
+
toJSON(): {
|
|
126
|
+
type: string;
|
|
127
|
+
operator: LogicalBinaryOperator;
|
|
128
|
+
left: Expression;
|
|
129
|
+
right: Expression;
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Represents a unary logical operation like NOT.
|
|
134
|
+
* @category Operators
|
|
135
|
+
*/
|
|
136
|
+
export declare class LogicalUnaryOperation extends ASTNode {
|
|
137
|
+
/** @hidden */
|
|
138
|
+
operand: Expression;
|
|
139
|
+
/** @hidden */
|
|
140
|
+
operator: LogicalUnaryOperator;
|
|
141
|
+
constructor(operator: LogicalUnaryOperator, operand: Expression, loc?: SourceLocation);
|
|
142
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
143
|
+
toJSON(): {
|
|
144
|
+
type: string;
|
|
145
|
+
operator: "Negation";
|
|
146
|
+
operand: Expression;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Represents a binary bitwise operation like AND, OR, XOR.
|
|
151
|
+
* @category Operators
|
|
152
|
+
*/
|
|
153
|
+
export declare class BitwiseBinaryOperation extends ASTNode {
|
|
154
|
+
/** @hidden */
|
|
155
|
+
right: Expression;
|
|
156
|
+
/** @hidden */
|
|
157
|
+
left: Expression;
|
|
158
|
+
/** @hidden */
|
|
159
|
+
operator: BitwiseBinaryOperator;
|
|
160
|
+
constructor(operator: BitwiseBinaryOperator, left: Expression, right: Expression, loc?: SourceLocation);
|
|
161
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
162
|
+
toJSON(): {
|
|
163
|
+
type: string;
|
|
164
|
+
operator: BitwiseBinaryOperator;
|
|
165
|
+
left: Expression;
|
|
166
|
+
right: Expression;
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Represents a unary bitwise operation like NOT (complement).
|
|
171
|
+
* @category Operators
|
|
172
|
+
*/
|
|
173
|
+
export declare class BitwiseUnaryOperation extends ASTNode {
|
|
174
|
+
/** @hidden */
|
|
175
|
+
operand: Expression;
|
|
176
|
+
/** @hidden */
|
|
177
|
+
operator: BitwiseUnaryOperator;
|
|
178
|
+
constructor(operator: BitwiseUnaryOperator, operand: Expression, loc?: SourceLocation);
|
|
179
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
180
|
+
toJSON(): {
|
|
181
|
+
type: string;
|
|
182
|
+
operator: "BitwiseNot";
|
|
183
|
+
operand: Expression;
|
|
184
|
+
};
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Represents an operation specific to string manipulation.
|
|
188
|
+
* @category Operators
|
|
189
|
+
*/
|
|
190
|
+
export declare class StringOperation extends ASTNode {
|
|
191
|
+
/** @hidden */
|
|
192
|
+
right: Expression;
|
|
193
|
+
/** @hidden */
|
|
194
|
+
left: Expression;
|
|
195
|
+
/** @hidden */
|
|
196
|
+
operator: StringBinaryOperator;
|
|
197
|
+
constructor(operator: StringBinaryOperator, left: Expression, right: Expression, loc?: SourceLocation);
|
|
198
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
199
|
+
toJSON(): {
|
|
200
|
+
type: string;
|
|
201
|
+
operator: "Concat";
|
|
202
|
+
left: Expression;
|
|
203
|
+
right: Expression;
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Represents a unification operation (=), fundamental to logic programming.
|
|
208
|
+
*
|
|
209
|
+
* @example
|
|
210
|
+
* X = 5
|
|
211
|
+
* @category Logic
|
|
212
|
+
*/
|
|
213
|
+
export declare class UnifyOperation extends ASTNode {
|
|
214
|
+
/** @hidden */
|
|
215
|
+
right: Expression;
|
|
216
|
+
/** @hidden */
|
|
217
|
+
left: Expression;
|
|
218
|
+
/** @hidden */
|
|
219
|
+
operator: UnifyOperator;
|
|
220
|
+
constructor(operator: UnifyOperator, left: Expression, right: Expression, loc?: SourceLocation);
|
|
221
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
222
|
+
toJSON(): {
|
|
223
|
+
type: string;
|
|
224
|
+
operator: "Unify";
|
|
225
|
+
left: Expression;
|
|
226
|
+
right: Expression;
|
|
227
|
+
};
|
|
228
|
+
}
|
|
229
|
+
/**
|
|
230
|
+
* Represents an in-place assignment operation (e.g., +=, -=).
|
|
231
|
+
* @category Operators
|
|
232
|
+
*/
|
|
233
|
+
export declare class AssignOperation extends ASTNode {
|
|
234
|
+
/** @hidden */
|
|
235
|
+
right: Expression;
|
|
236
|
+
/** @hidden */
|
|
237
|
+
left: Expression;
|
|
238
|
+
/** @hidden */
|
|
239
|
+
operator: AssignOperator;
|
|
240
|
+
constructor(operator: AssignOperator, left: Expression, right: Expression, loc?: SourceLocation);
|
|
241
|
+
accept<R>(visitor: Visitor<R>): R;
|
|
242
|
+
toJSON(): {
|
|
243
|
+
type: string;
|
|
244
|
+
operator: "Assign";
|
|
245
|
+
left: Expression;
|
|
246
|
+
right: Expression;
|
|
247
|
+
};
|
|
248
|
+
}
|
|
249
|
+
export type BinaryOperation = ArithmeticBinaryOperation | StringOperation | ListBinaryOperation | LogicalBinaryOperation | ComparisonOperation | UnifyOperation | AssignOperation | BitwiseBinaryOperation;
|
|
250
|
+
export type UnaryOperation = ArithmeticUnaryOperation | ListUnaryOperation | LogicalUnaryOperation | BitwiseUnaryOperation;
|
|
251
|
+
export type Operation = BinaryOperation | UnaryOperation;
|
|
@@ -0,0 +1,336 @@
|
|
|
1
|
+
import { ASTNode } from "./generics.js";
|
|
2
|
+
/**
|
|
3
|
+
* Represents a unary arithmetic operation like negation (-x).
|
|
4
|
+
* @category Operators
|
|
5
|
+
*/
|
|
6
|
+
export class ArithmeticUnaryOperation extends ASTNode {
|
|
7
|
+
/** @hidden */
|
|
8
|
+
operand;
|
|
9
|
+
/** @hidden */
|
|
10
|
+
operator;
|
|
11
|
+
constructor(operator, operand, loc) {
|
|
12
|
+
super(loc);
|
|
13
|
+
this.operator = operator;
|
|
14
|
+
this.operand = operand;
|
|
15
|
+
}
|
|
16
|
+
accept(visitor) {
|
|
17
|
+
return visitor.visitArithmeticUnaryOperation?.(this);
|
|
18
|
+
}
|
|
19
|
+
toJSON() {
|
|
20
|
+
return {
|
|
21
|
+
type: "ArithmeticUnaryOperation",
|
|
22
|
+
operator: this.operator,
|
|
23
|
+
operand: this.operand,
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* Represents a binary arithmetic operation like addition or multiplication.
|
|
29
|
+
* @category Operators
|
|
30
|
+
*/
|
|
31
|
+
export class ArithmeticBinaryOperation extends ASTNode {
|
|
32
|
+
/** @hidden */
|
|
33
|
+
right;
|
|
34
|
+
/** @hidden */
|
|
35
|
+
left;
|
|
36
|
+
/** @hidden */
|
|
37
|
+
operator;
|
|
38
|
+
constructor(operator, left, right, loc) {
|
|
39
|
+
super(loc);
|
|
40
|
+
this.operator = operator;
|
|
41
|
+
this.left = left;
|
|
42
|
+
this.right = right;
|
|
43
|
+
}
|
|
44
|
+
accept(visitor) {
|
|
45
|
+
return visitor.visitArithmeticBinaryOperation?.(this);
|
|
46
|
+
}
|
|
47
|
+
toJSON() {
|
|
48
|
+
return {
|
|
49
|
+
type: "ArithmeticBinaryOperation",
|
|
50
|
+
operator: this.operator,
|
|
51
|
+
left: this.left,
|
|
52
|
+
right: this.right,
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Represents a unary operation on a list, such as getting the head or tail.
|
|
58
|
+
* @category Operators
|
|
59
|
+
*/
|
|
60
|
+
export class ListUnaryOperation extends ASTNode {
|
|
61
|
+
/** @hidden */
|
|
62
|
+
operand;
|
|
63
|
+
/** @hidden */
|
|
64
|
+
operator;
|
|
65
|
+
constructor(operator, operand, loc) {
|
|
66
|
+
super(loc);
|
|
67
|
+
this.operator = operator;
|
|
68
|
+
this.operand = operand;
|
|
69
|
+
}
|
|
70
|
+
accept(visitor) {
|
|
71
|
+
return visitor.visitListUnaryOperation?.(this);
|
|
72
|
+
}
|
|
73
|
+
toJSON() {
|
|
74
|
+
return {
|
|
75
|
+
type: "ListUnaryOperation",
|
|
76
|
+
operator: this.operator,
|
|
77
|
+
operand: this.operand,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Represents a binary operation on lists, such as concatenation.
|
|
83
|
+
* @category Operators
|
|
84
|
+
*/
|
|
85
|
+
export class ListBinaryOperation extends ASTNode {
|
|
86
|
+
/** @hidden */
|
|
87
|
+
right;
|
|
88
|
+
/** @hidden */
|
|
89
|
+
left;
|
|
90
|
+
/** @hidden */
|
|
91
|
+
operator;
|
|
92
|
+
constructor(operator, left, right, loc) {
|
|
93
|
+
super(loc);
|
|
94
|
+
this.operator = operator;
|
|
95
|
+
this.left = left;
|
|
96
|
+
this.right = right;
|
|
97
|
+
}
|
|
98
|
+
accept(visitor) {
|
|
99
|
+
return visitor.visitListBinaryOperation?.(this);
|
|
100
|
+
}
|
|
101
|
+
toJSON() {
|
|
102
|
+
return {
|
|
103
|
+
type: "ListBinaryOperation",
|
|
104
|
+
operator: this.operator,
|
|
105
|
+
left: this.left,
|
|
106
|
+
right: this.right,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* Represents a comparison between two values (e.g., >, <, ==).
|
|
112
|
+
* @category Operators
|
|
113
|
+
*/
|
|
114
|
+
export class ComparisonOperation extends ASTNode {
|
|
115
|
+
/** @hidden */
|
|
116
|
+
right;
|
|
117
|
+
/** @hidden */
|
|
118
|
+
left;
|
|
119
|
+
/** @hidden */
|
|
120
|
+
operator;
|
|
121
|
+
constructor(operator, left, right, loc) {
|
|
122
|
+
super(loc);
|
|
123
|
+
this.operator = operator;
|
|
124
|
+
this.left = left;
|
|
125
|
+
this.right = right;
|
|
126
|
+
}
|
|
127
|
+
accept(visitor) {
|
|
128
|
+
return visitor.visitComparisonOperation?.(this);
|
|
129
|
+
}
|
|
130
|
+
toJSON() {
|
|
131
|
+
return {
|
|
132
|
+
type: "ComparisonOperation",
|
|
133
|
+
operator: this.operator,
|
|
134
|
+
left: this.left,
|
|
135
|
+
right: this.right,
|
|
136
|
+
};
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Represents a binary logical operation like AND or OR.
|
|
141
|
+
* @category Operators
|
|
142
|
+
*/
|
|
143
|
+
export class LogicalBinaryOperation extends ASTNode {
|
|
144
|
+
/** @hidden */
|
|
145
|
+
right;
|
|
146
|
+
/** @hidden */
|
|
147
|
+
left;
|
|
148
|
+
/** @hidden */
|
|
149
|
+
operator;
|
|
150
|
+
constructor(operator, left, right, loc) {
|
|
151
|
+
super(loc);
|
|
152
|
+
this.operator = operator;
|
|
153
|
+
this.left = left;
|
|
154
|
+
this.right = right;
|
|
155
|
+
}
|
|
156
|
+
accept(visitor) {
|
|
157
|
+
return visitor.visitLogicalBinaryOperation?.(this);
|
|
158
|
+
}
|
|
159
|
+
toJSON() {
|
|
160
|
+
return {
|
|
161
|
+
type: "LogicalBinaryOperation",
|
|
162
|
+
operator: this.operator,
|
|
163
|
+
left: this.left,
|
|
164
|
+
right: this.right,
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Represents a unary logical operation like NOT.
|
|
170
|
+
* @category Operators
|
|
171
|
+
*/
|
|
172
|
+
export class LogicalUnaryOperation extends ASTNode {
|
|
173
|
+
/** @hidden */
|
|
174
|
+
operand;
|
|
175
|
+
/** @hidden */
|
|
176
|
+
operator;
|
|
177
|
+
constructor(operator, operand, loc) {
|
|
178
|
+
super(loc);
|
|
179
|
+
this.operator = operator;
|
|
180
|
+
this.operand = operand;
|
|
181
|
+
}
|
|
182
|
+
accept(visitor) {
|
|
183
|
+
return visitor.visitLogicalUnaryOperation?.(this);
|
|
184
|
+
}
|
|
185
|
+
toJSON() {
|
|
186
|
+
return {
|
|
187
|
+
type: "LogicalUnaryOperation",
|
|
188
|
+
operator: this.operator,
|
|
189
|
+
operand: this.operand,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Represents a binary bitwise operation like AND, OR, XOR.
|
|
195
|
+
* @category Operators
|
|
196
|
+
*/
|
|
197
|
+
export class BitwiseBinaryOperation extends ASTNode {
|
|
198
|
+
/** @hidden */
|
|
199
|
+
right;
|
|
200
|
+
/** @hidden */
|
|
201
|
+
left;
|
|
202
|
+
/** @hidden */
|
|
203
|
+
operator;
|
|
204
|
+
constructor(operator, left, right, loc) {
|
|
205
|
+
super(loc);
|
|
206
|
+
this.operator = operator;
|
|
207
|
+
this.left = left;
|
|
208
|
+
this.right = right;
|
|
209
|
+
}
|
|
210
|
+
accept(visitor) {
|
|
211
|
+
return visitor.visitBitwiseBinaryOperation?.(this);
|
|
212
|
+
}
|
|
213
|
+
toJSON() {
|
|
214
|
+
return {
|
|
215
|
+
type: "BitwiseBinaryOperation",
|
|
216
|
+
operator: this.operator,
|
|
217
|
+
left: this.left,
|
|
218
|
+
right: this.right,
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* Represents a unary bitwise operation like NOT (complement).
|
|
224
|
+
* @category Operators
|
|
225
|
+
*/
|
|
226
|
+
export class BitwiseUnaryOperation extends ASTNode {
|
|
227
|
+
/** @hidden */
|
|
228
|
+
operand;
|
|
229
|
+
/** @hidden */
|
|
230
|
+
operator;
|
|
231
|
+
constructor(operator, operand, loc) {
|
|
232
|
+
super(loc);
|
|
233
|
+
this.operator = operator;
|
|
234
|
+
this.operand = operand;
|
|
235
|
+
}
|
|
236
|
+
accept(visitor) {
|
|
237
|
+
return visitor.visitBitwiseUnaryOperation?.(this);
|
|
238
|
+
}
|
|
239
|
+
toJSON() {
|
|
240
|
+
return {
|
|
241
|
+
type: "BitwiseUnaryOperation",
|
|
242
|
+
operator: this.operator,
|
|
243
|
+
operand: this.operand,
|
|
244
|
+
};
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* Represents an operation specific to string manipulation.
|
|
249
|
+
* @category Operators
|
|
250
|
+
*/
|
|
251
|
+
export class StringOperation extends ASTNode {
|
|
252
|
+
/** @hidden */
|
|
253
|
+
right;
|
|
254
|
+
/** @hidden */
|
|
255
|
+
left;
|
|
256
|
+
/** @hidden */
|
|
257
|
+
operator;
|
|
258
|
+
constructor(operator, left, right, loc) {
|
|
259
|
+
super(loc);
|
|
260
|
+
this.operator = operator;
|
|
261
|
+
this.left = left;
|
|
262
|
+
this.right = right;
|
|
263
|
+
}
|
|
264
|
+
accept(visitor) {
|
|
265
|
+
return visitor.visitStringOperation?.(this);
|
|
266
|
+
}
|
|
267
|
+
toJSON() {
|
|
268
|
+
return {
|
|
269
|
+
type: "StringOperation",
|
|
270
|
+
operator: this.operator,
|
|
271
|
+
left: this.left,
|
|
272
|
+
right: this.right,
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* Represents a unification operation (=), fundamental to logic programming.
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* X = 5
|
|
281
|
+
* @category Logic
|
|
282
|
+
*/
|
|
283
|
+
export class UnifyOperation extends ASTNode {
|
|
284
|
+
/** @hidden */
|
|
285
|
+
right;
|
|
286
|
+
/** @hidden */
|
|
287
|
+
left;
|
|
288
|
+
/** @hidden */
|
|
289
|
+
operator;
|
|
290
|
+
constructor(operator, left, right, loc) {
|
|
291
|
+
super(loc);
|
|
292
|
+
this.operator = operator;
|
|
293
|
+
this.left = left;
|
|
294
|
+
this.right = right;
|
|
295
|
+
}
|
|
296
|
+
accept(visitor) {
|
|
297
|
+
return visitor.visitUnifyOperation?.(this);
|
|
298
|
+
}
|
|
299
|
+
toJSON() {
|
|
300
|
+
return {
|
|
301
|
+
type: "UnifyOperation",
|
|
302
|
+
operator: this.operator,
|
|
303
|
+
left: this.left,
|
|
304
|
+
right: this.right,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
/**
|
|
309
|
+
* Represents an in-place assignment operation (e.g., +=, -=).
|
|
310
|
+
* @category Operators
|
|
311
|
+
*/
|
|
312
|
+
export class AssignOperation extends ASTNode {
|
|
313
|
+
/** @hidden */
|
|
314
|
+
right;
|
|
315
|
+
/** @hidden */
|
|
316
|
+
left;
|
|
317
|
+
/** @hidden */
|
|
318
|
+
operator;
|
|
319
|
+
constructor(operator, left, right, loc) {
|
|
320
|
+
super(loc);
|
|
321
|
+
this.operator = operator;
|
|
322
|
+
this.left = left;
|
|
323
|
+
this.right = right;
|
|
324
|
+
}
|
|
325
|
+
accept(visitor) {
|
|
326
|
+
return visitor.visitAssignOperation?.(this);
|
|
327
|
+
}
|
|
328
|
+
toJSON() {
|
|
329
|
+
return {
|
|
330
|
+
type: "AssignOperation",
|
|
331
|
+
operator: this.operator,
|
|
332
|
+
left: this.left,
|
|
333
|
+
right: this.right,
|
|
334
|
+
};
|
|
335
|
+
}
|
|
336
|
+
}
|