@@ -19,20 +19,42 @@ export class SyntaxScriptCompiler {
19
19
20
20
public readonly exportData : Record < string , AnyExportable [ ] > = { } ;
21
21
22
+ /**
23
+ * Constructs a new compiler.
24
+ * @param rootDir Root dir to search for source files.
25
+ * @param outDir Out dir to write compiled files.
26
+ * @param format File format to compile.
27
+ * @param watch Whether is it watch mode or not. Will affect how errors are handled.
28
+ * @author efekos
29
+ * @version 1.0.0
30
+ * @since 0.0.1-alpha
31
+ */
22
32
constructor ( rootDir : string , outDir : string , format : string , watch : boolean = false ) {
23
33
this . rootDir = join ( process . cwd ( ) , rootDir ) ;
24
34
this . outDir = join ( process . cwd ( ) , outDir ) ;
25
35
this . mainFileFormat = format ;
26
36
this . watchMode = watch ;
27
37
}
28
38
39
+ /**
40
+ * Parses .syx files and compiles .sys files using them.
41
+ * @author efekos
42
+ * @since 0.0.1-alpha
43
+ * @version 1.0.0
44
+ */
29
45
public async compile ( ) {
30
-
31
46
await this . compileSyxFiles ( this . rootDir ) ;
32
47
await this . compileSysFiles ( this . rootDir ) ;
33
48
return Promise . resolve ( ) ;
34
49
}
35
50
51
+ /**
52
+ * Compiles every .syx file found in the path.
53
+ * @param folderPath A folder path to search for .syx files.
54
+ * @author efekos
55
+ * @version 1.0.0
56
+ * @since 0.0.1-alpha
57
+ */
36
58
public compileSyxFiles ( folderPath : string ) {
37
59
38
60
const files = readdirSync ( folderPath ) ;
@@ -44,6 +66,13 @@ export class SyntaxScriptCompiler {
44
66
} ) ;
45
67
}
46
68
69
+ /**
70
+ * Compiles one .syx file from the path given.
71
+ * @param file Path to a file to compile.
72
+ * @author efekos
73
+ * @version 1.0.0
74
+ * @since 0.0.1-alpha
75
+ */
47
76
public compileSyx ( file : string ) {
48
77
const ast = syxparser . parseTokens ( tokenizeSyx ( readFileSync ( file ) . toString ( ) , this . watchMode ) , this . watchMode ) ;
49
78
const out : AnyExportable [ ] = [ ] ;
@@ -151,6 +180,13 @@ export class SyntaxScriptCompiler {
151
180
this . exportData [ file ] = out ;
152
181
}
153
182
183
+ /**
184
+ * Compiles every .sys file found in the given folder.
185
+ * @param folderPath Folder path to search for .sys files.
186
+ * @author efekos
187
+ * @version 1.0.0
188
+ * @since 0.0.1-alpha
189
+ */
154
190
public compileSysFiles ( folderPath : string ) {
155
191
const files = readdirSync ( folderPath ) ;
156
192
log . debug ( 'HEREHEREHERE' , folderPath , files ) ;
@@ -161,6 +197,13 @@ export class SyntaxScriptCompiler {
161
197
} ) ;
162
198
}
163
199
200
+ /**
201
+ * Compiles a .sys file at the path given.
202
+ * @param file Path to the .sys file to compile.
203
+ * @author efekos
204
+ * @since 0.0.1-alpha
205
+ * @version 1.0.0
206
+ */
164
207
public compileSys ( file : string ) {
165
208
const ast = sysparser . parseTokens ( tokenizeSys ( readFileSync ( file ) . toString ( ) ) , this . watchMode ) ;
166
209
@@ -216,23 +259,60 @@ export class SyntaxScriptCompiler {
216
259
217
260
}
218
261
262
+ /**
263
+ * Type of something that can be exported.
264
+ * @version 1.0.0
265
+ * @since 0.0.1-alpha
266
+ * @author efekos
267
+ */
219
268
export enum ExportType {
269
+
270
+ /**
271
+ * Used for exported operators.
272
+ */
220
273
Operator ,
274
+
275
+ /**
276
+ * Used for exported functions.
277
+ */
221
278
Function ,
279
+
280
+ /**
281
+ * Used for exported keyword.
282
+ */
222
283
Keyword
284
+
223
285
}
224
286
287
+ /**
288
+ * Base exportable interface.
289
+ * @author efekos
290
+ * @version 1.0.0
291
+ * @since 0.0.1-alpha
292
+ */
225
293
export interface Export {
226
294
type : ExportType ;
227
295
}
228
296
297
+ /**
298
+ * Represents an exported operator. Uses type {@link ExportType.Operator}.
299
+ * @author efekos
300
+ * @version 1.0.0
301
+ * @since 0.0.1-alpha
302
+ */
229
303
export interface Operator extends Export {
230
304
type : ExportType . Operator ,
231
305
regexMatcher : RegExp ;
232
306
outputGenerators : Record < string , OneParameterMethod < string , string > > ;
233
307
imports : Record < string , string > ;
234
308
}
235
309
310
+ /**
311
+ * Represents an exported function. Uses type {@link ExportType.Function}.
312
+ * @author efekos
313
+ * @version 1.0.0
314
+ * @since 0.0.1-alpha
315
+ */
236
316
export interface Function extends Export {
237
317
type : ExportType . Function ;
238
318
name : string ;
@@ -241,14 +321,36 @@ export interface Function extends Export {
241
321
imports : Record < string , string > ;
242
322
}
243
323
324
+ /**
325
+ * Represents an exported keyword. Uses type {@link ExportType.Keyword}.
326
+ * @author efekos
327
+ * @version 1.0.0
328
+ * @since 0.0.1-alpha
329
+ */
244
330
export interface Keyword extends Export {
245
331
type : ExportType . Keyword ;
246
332
word : string ;
247
333
}
248
334
335
+ /**
336
+ * A method that has one parameter with the type {@link V} and returns {@link R}.
337
+ * @author efekos
338
+ * @version 1.0.0
339
+ * @since 0.0.1-alpha
340
+ */
249
341
export type OneParameterMethod < V , R > = ( v : V ) => R ;
342
+
343
+ /**
344
+ * A method that takes no parameters and returns an {@link R}.
345
+ * @author efekos
346
+ * @version 1.0.0
347
+ * @since 0.0.1-alpha
348
+ */
250
349
export type ReturnerMethod < R > = ( ) => R ;
251
350
351
+ /**
352
+ * Any interface that represents something exportable.
353
+ */
252
354
export type AnyExportable = Operator | Function | Keyword ;
253
355
254
356
export const regexes : Record < string , RegExp > = {
0 commit comments