lt-script 1.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.
@@ -0,0 +1,314 @@
1
+ /**
2
+ * LT Language AST Node Definitions
3
+ * All AST node types for the parser
4
+ */
5
+ export declare enum NodeType {
6
+ Program = "Program",
7
+ VariableDecl = "VariableDecl",
8
+ AssignmentStmt = "AssignmentStmt",
9
+ CompoundAssignment = "CompoundAssignment",
10
+ IfStmt = "IfStmt",
11
+ ForStmt = "ForStmt",
12
+ RangeForStmt = "RangeForStmt",
13
+ WhileStmt = "WhileStmt",
14
+ ReturnStmt = "ReturnStmt",
15
+ BreakStmt = "BreakStmt",
16
+ ContinueStmt = "ContinueStmt",
17
+ SwitchStmt = "SwitchStmt",
18
+ Block = "Block",
19
+ GuardStmt = "GuardStmt",
20
+ SafeCallStmt = "SafeCallStmt",
21
+ ThreadStmt = "ThreadStmt",
22
+ LoopStmt = "LoopStmt",
23
+ WaitStmt = "WaitStmt",
24
+ TimeoutStmt = "TimeoutStmt",
25
+ IntervalStmt = "IntervalStmt",
26
+ TryCatchStmt = "TryCatchStmt",
27
+ CommandStmt = "CommandStmt",
28
+ EmitStmt = "EmitStmt",
29
+ EventHandler = "EventHandler",
30
+ ExportDecl = "ExportDecl",
31
+ BinaryExpr = "BinaryExpr",
32
+ UnaryExpr = "UnaryExpr",
33
+ UpdateExpr = "UpdateExpr",// ++, --
34
+ ConditionalExpr = "ConditionalExpr",// Ternary ? :
35
+ CallExpr = "CallExpr",
36
+ MemberExpr = "MemberExpr",
37
+ OptionalChainExpr = "OptionalChainExpr",
38
+ NullCoalesceExpr = "NullCoalesceExpr",
39
+ ArrowFunc = "ArrowFunc",
40
+ FunctionDecl = "FunctionDecl",
41
+ Identifier = "Identifier",
42
+ NumberLiteral = "NumberLiteral",
43
+ StringLiteral = "StringLiteral",
44
+ InterpolatedString = "InterpolatedString",
45
+ BooleanLiteral = "BooleanLiteral",
46
+ NilLiteral = "NilLiteral",
47
+ TableLiteral = "TableLiteral",
48
+ VectorLiteral = "VectorLiteral",
49
+ SpreadExpr = "SpreadExpr",
50
+ ObjectDestructure = "ObjectDestructure",
51
+ ArrayDestructure = "ArrayDestructure"
52
+ }
53
+ export interface Node {
54
+ kind: NodeType;
55
+ line?: number;
56
+ column?: number;
57
+ }
58
+ export interface Statement extends Node {
59
+ }
60
+ export interface Expression extends Node {
61
+ }
62
+ export interface Program extends Node {
63
+ kind: NodeType.Program;
64
+ body: Statement[];
65
+ }
66
+ export interface VariableDecl extends Statement {
67
+ kind: NodeType.VariableDecl;
68
+ scope: "var" | "let" | "const" | "local";
69
+ names: (Identifier | ObjectDestructure | ArrayDestructure)[];
70
+ typeAnnotations?: (string | undefined)[];
71
+ values?: Expression[];
72
+ }
73
+ export interface FunctionDecl extends Statement {
74
+ kind: NodeType.FunctionDecl;
75
+ name?: Identifier | MemberExpr;
76
+ params: Parameter[];
77
+ returnType?: string;
78
+ body: Block;
79
+ isLocal?: boolean;
80
+ }
81
+ export interface Parameter {
82
+ name: Identifier;
83
+ typeAnnotation?: string;
84
+ defaultValue?: Expression;
85
+ }
86
+ export interface AssignmentStmt extends Statement {
87
+ kind: NodeType.AssignmentStmt;
88
+ targets: Expression[];
89
+ values: Expression[];
90
+ }
91
+ export interface CompoundAssignment extends Statement {
92
+ kind: NodeType.CompoundAssignment;
93
+ target: Expression;
94
+ operator: "+=" | "-=" | "*=" | "/=" | "%=" | "..=";
95
+ value: Expression;
96
+ }
97
+ export interface IfStmt extends Statement {
98
+ kind: NodeType.IfStmt;
99
+ condition: Expression;
100
+ thenBody: Block;
101
+ elseIfClauses?: {
102
+ condition: Expression;
103
+ body: Block;
104
+ }[];
105
+ elseBody?: Block;
106
+ }
107
+ export interface ForStmt extends Statement {
108
+ kind: NodeType.ForStmt;
109
+ iterators: Identifier[];
110
+ iterable: Expression;
111
+ body: Block;
112
+ }
113
+ export interface RangeForStmt extends Statement {
114
+ kind: NodeType.RangeForStmt;
115
+ counter: Identifier;
116
+ start: Expression;
117
+ end: Expression;
118
+ step?: Expression;
119
+ body: Block;
120
+ }
121
+ export interface WhileStmt extends Statement {
122
+ kind: NodeType.WhileStmt;
123
+ condition: Expression;
124
+ body: Block;
125
+ }
126
+ export interface ReturnStmt extends Statement {
127
+ kind: NodeType.ReturnStmt;
128
+ values?: Expression[];
129
+ }
130
+ export interface BreakStmt extends Statement {
131
+ kind: NodeType.BreakStmt;
132
+ }
133
+ export interface ContinueStmt extends Statement {
134
+ kind: NodeType.ContinueStmt;
135
+ }
136
+ export interface SwitchStmt extends Statement {
137
+ kind: NodeType.SwitchStmt;
138
+ discriminant: Expression;
139
+ cases: SwitchCase[];
140
+ defaultCase?: Block;
141
+ }
142
+ export interface SwitchCase {
143
+ values: Expression[];
144
+ body: Block;
145
+ }
146
+ export interface Block extends Node {
147
+ kind: NodeType.Block;
148
+ statements: Statement[];
149
+ }
150
+ export interface GuardStmt extends Statement {
151
+ kind: NodeType.GuardStmt;
152
+ condition: Expression;
153
+ elseBody?: Statement[];
154
+ }
155
+ export interface SafeCallStmt extends Statement {
156
+ kind: NodeType.SafeCallStmt;
157
+ call: CallExpr;
158
+ }
159
+ export interface ThreadStmt extends Statement {
160
+ kind: NodeType.ThreadStmt;
161
+ body: Block;
162
+ }
163
+ export interface LoopStmt extends Statement {
164
+ kind: NodeType.LoopStmt;
165
+ conditions: Expression[];
166
+ body: Block;
167
+ }
168
+ export interface WaitStmt extends Statement {
169
+ kind: NodeType.WaitStmt;
170
+ time: Expression;
171
+ }
172
+ export interface TimeoutStmt extends Statement {
173
+ kind: NodeType.TimeoutStmt;
174
+ delay: Expression;
175
+ body: Block;
176
+ }
177
+ export interface IntervalStmt extends Statement {
178
+ kind: NodeType.IntervalStmt;
179
+ interval: Expression;
180
+ body: Block;
181
+ }
182
+ export interface TryCatchStmt extends Statement {
183
+ kind: NodeType.TryCatchStmt;
184
+ tryBody: Block;
185
+ catchParam: Identifier;
186
+ catchBody: Block;
187
+ }
188
+ export interface EmitStmt extends Statement {
189
+ kind: NodeType.EmitStmt;
190
+ emitType: "emit" | "emitClient" | "emitServer";
191
+ eventName: Expression;
192
+ args: Expression[];
193
+ }
194
+ export interface EventHandler extends Statement {
195
+ kind: NodeType.EventHandler;
196
+ isNet: boolean;
197
+ eventName: Expression;
198
+ params: Parameter[];
199
+ body: Block;
200
+ }
201
+ export interface ExportDecl extends Statement {
202
+ kind: NodeType.ExportDecl;
203
+ declaration: FunctionDecl;
204
+ }
205
+ export interface CommandStmt extends Statement {
206
+ kind: NodeType.CommandStmt;
207
+ commandName: string;
208
+ params: Parameter[];
209
+ body: Block;
210
+ }
211
+ export interface BinaryExpr extends Expression {
212
+ kind: NodeType.BinaryExpr;
213
+ left: Expression;
214
+ operator: string;
215
+ right: Expression;
216
+ }
217
+ export interface UnaryExpr extends Expression {
218
+ kind: NodeType.UnaryExpr;
219
+ operator: string;
220
+ operand: Expression;
221
+ }
222
+ export interface UpdateExpr extends Expression {
223
+ kind: NodeType.UpdateExpr;
224
+ operator: "++" | "--";
225
+ argument: Expression;
226
+ prefix: boolean;
227
+ }
228
+ export interface ConditionalExpr extends Expression {
229
+ kind: NodeType.ConditionalExpr;
230
+ test: Expression;
231
+ consequent: Expression;
232
+ alternate: Expression;
233
+ }
234
+ export interface SpreadExpr extends Expression {
235
+ kind: NodeType.SpreadExpr;
236
+ argument: Expression;
237
+ }
238
+ export interface CallExpr extends Expression {
239
+ kind: NodeType.CallExpr;
240
+ callee: Expression;
241
+ args: Expression[];
242
+ }
243
+ export interface MemberExpr extends Expression {
244
+ kind: NodeType.MemberExpr;
245
+ object: Expression;
246
+ property: Expression;
247
+ computed: boolean;
248
+ isMethod?: boolean;
249
+ }
250
+ export interface OptionalChainExpr extends Expression {
251
+ kind: NodeType.OptionalChainExpr;
252
+ object: Expression;
253
+ property: Expression;
254
+ computed: boolean;
255
+ isMethod?: boolean;
256
+ }
257
+ export interface NullCoalesceExpr extends Expression {
258
+ kind: NodeType.NullCoalesceExpr;
259
+ left: Expression;
260
+ right: Expression;
261
+ }
262
+ export interface ArrowFunc extends Expression {
263
+ kind: NodeType.ArrowFunc;
264
+ params: Parameter[];
265
+ body: Block | Expression;
266
+ }
267
+ export interface Identifier extends Expression {
268
+ kind: NodeType.Identifier;
269
+ name: string;
270
+ attribute?: string;
271
+ }
272
+ export interface NumberLiteral extends Expression {
273
+ kind: NodeType.NumberLiteral;
274
+ value: number;
275
+ }
276
+ export interface StringLiteral extends Expression {
277
+ kind: NodeType.StringLiteral;
278
+ value: string;
279
+ isLong?: boolean;
280
+ quote?: "'" | '"';
281
+ }
282
+ export interface InterpolatedString extends Expression {
283
+ kind: NodeType.InterpolatedString;
284
+ parts: (string | Expression)[];
285
+ quote?: "'" | '"';
286
+ }
287
+ export interface BooleanLiteral extends Expression {
288
+ kind: NodeType.BooleanLiteral;
289
+ value: boolean;
290
+ }
291
+ export interface NilLiteral extends Expression {
292
+ kind: NodeType.NilLiteral;
293
+ }
294
+ export interface TableLiteral extends Expression {
295
+ kind: NodeType.TableLiteral;
296
+ fields: TableField[];
297
+ }
298
+ export interface TableField {
299
+ key?: Expression;
300
+ value: Expression;
301
+ shorthand?: boolean;
302
+ }
303
+ export interface VectorLiteral extends Expression {
304
+ kind: NodeType.VectorLiteral;
305
+ components: Expression[];
306
+ }
307
+ export interface ObjectDestructure extends Node {
308
+ kind: NodeType.ObjectDestructure;
309
+ properties: Identifier[];
310
+ }
311
+ export interface ArrayDestructure extends Node {
312
+ kind: NodeType.ArrayDestructure;
313
+ elements: Identifier[];
314
+ }
@@ -0,0 +1,60 @@
1
+ /**
2
+ * LT Language AST Node Definitions
3
+ * All AST node types for the parser
4
+ */
5
+ export var NodeType;
6
+ (function (NodeType) {
7
+ // Program
8
+ NodeType["Program"] = "Program";
9
+ // Statements
10
+ NodeType["VariableDecl"] = "VariableDecl";
11
+ NodeType["AssignmentStmt"] = "AssignmentStmt";
12
+ NodeType["CompoundAssignment"] = "CompoundAssignment";
13
+ NodeType["IfStmt"] = "IfStmt";
14
+ NodeType["ForStmt"] = "ForStmt";
15
+ NodeType["RangeForStmt"] = "RangeForStmt";
16
+ NodeType["WhileStmt"] = "WhileStmt";
17
+ NodeType["ReturnStmt"] = "ReturnStmt";
18
+ NodeType["BreakStmt"] = "BreakStmt";
19
+ NodeType["ContinueStmt"] = "ContinueStmt";
20
+ NodeType["SwitchStmt"] = "SwitchStmt";
21
+ NodeType["Block"] = "Block";
22
+ // LT Sugar Statements
23
+ NodeType["GuardStmt"] = "GuardStmt";
24
+ NodeType["SafeCallStmt"] = "SafeCallStmt";
25
+ NodeType["ThreadStmt"] = "ThreadStmt";
26
+ NodeType["LoopStmt"] = "LoopStmt";
27
+ NodeType["WaitStmt"] = "WaitStmt";
28
+ NodeType["TimeoutStmt"] = "TimeoutStmt";
29
+ NodeType["IntervalStmt"] = "IntervalStmt";
30
+ NodeType["TryCatchStmt"] = "TryCatchStmt";
31
+ NodeType["CommandStmt"] = "CommandStmt";
32
+ // FiveM Events
33
+ NodeType["EmitStmt"] = "EmitStmt";
34
+ NodeType["EventHandler"] = "EventHandler";
35
+ NodeType["ExportDecl"] = "ExportDecl";
36
+ // Expressions
37
+ NodeType["BinaryExpr"] = "BinaryExpr";
38
+ NodeType["UnaryExpr"] = "UnaryExpr";
39
+ NodeType["UpdateExpr"] = "UpdateExpr";
40
+ NodeType["ConditionalExpr"] = "ConditionalExpr";
41
+ NodeType["CallExpr"] = "CallExpr";
42
+ NodeType["MemberExpr"] = "MemberExpr";
43
+ NodeType["OptionalChainExpr"] = "OptionalChainExpr";
44
+ NodeType["NullCoalesceExpr"] = "NullCoalesceExpr";
45
+ NodeType["ArrowFunc"] = "ArrowFunc";
46
+ NodeType["FunctionDecl"] = "FunctionDecl";
47
+ // Literals
48
+ NodeType["Identifier"] = "Identifier";
49
+ NodeType["NumberLiteral"] = "NumberLiteral";
50
+ NodeType["StringLiteral"] = "StringLiteral";
51
+ NodeType["InterpolatedString"] = "InterpolatedString";
52
+ NodeType["BooleanLiteral"] = "BooleanLiteral";
53
+ NodeType["NilLiteral"] = "NilLiteral";
54
+ NodeType["TableLiteral"] = "TableLiteral";
55
+ NodeType["VectorLiteral"] = "VectorLiteral";
56
+ NodeType["SpreadExpr"] = "SpreadExpr";
57
+ // Patterns
58
+ NodeType["ObjectDestructure"] = "ObjectDestructure";
59
+ NodeType["ArrayDestructure"] = "ArrayDestructure";
60
+ })(NodeType || (NodeType = {}));
@@ -0,0 +1,68 @@
1
+ import { Token } from '../lexer/Token.js';
2
+ import * as AST from './AST.js';
3
+ /**
4
+ * LT Language Parser
5
+ * Recursive descent parser for LT → AST
6
+ */
7
+ export declare class Parser {
8
+ private tokens;
9
+ private pos;
10
+ constructor(tokens: Token[]);
11
+ parse(): AST.Program;
12
+ private parseStatement;
13
+ private parseVariableDecl;
14
+ private parseIfStmt;
15
+ private parseForStmt;
16
+ private parseWhileStmt;
17
+ private parseReturnStmt;
18
+ private parseGuardStmt;
19
+ private parseSafeCall;
20
+ private parseThreadStmt;
21
+ private parseLoopStmt;
22
+ private parseWaitStmt;
23
+ private parseTimeoutStmt;
24
+ private parseIntervalStmt;
25
+ private parseTryCatch;
26
+ private parseEmitStmt;
27
+ private parseEventHandler;
28
+ private parseFunctionDecl;
29
+ private parseFunctionExpr;
30
+ private parseSwitchStmt;
31
+ private parseCommandStmt;
32
+ private parseExportDecl;
33
+ private parseExpressionStatement;
34
+ private parseExpression;
35
+ private parseAssignment;
36
+ private parseTernaryExpr;
37
+ private parseNullCoalesce;
38
+ private parseOr;
39
+ private parseAnd;
40
+ private parseEquality;
41
+ private parseComparison;
42
+ private parseConcat;
43
+ private parseAdditive;
44
+ private parseMultiplicative;
45
+ private parseUnary;
46
+ private parseCallMember;
47
+ private parseCallExpr;
48
+ private parsePrimary;
49
+ private parseStringLiteral;
50
+ private parseInterpolatedString;
51
+ private parseParenOrArrow;
52
+ private parseArrayLiteral;
53
+ private parseTableLiteral;
54
+ private parseVectorLiteral;
55
+ private parseIdentifier;
56
+ private parseParameter;
57
+ private parseObjectDestructure;
58
+ private parseArrayDestructure;
59
+ private parseBlockUntil;
60
+ private at;
61
+ private peek;
62
+ private eat;
63
+ private match;
64
+ private check;
65
+ private expect;
66
+ private isEOF;
67
+ private isStatementEnd;
68
+ }