fez-lisp 1.6.43 → 1.6.44
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/package.json +1 -1
- package/src/utils.js +55 -0
package/package.json
CHANGED
package/src/utils.js
CHANGED
@@ -30,6 +30,14 @@ import { debugStackToString, startDebug, debug } from './debugger.js'
|
|
30
30
|
export const logError = (error) =>
|
31
31
|
console.log('\x1b[31m', `\n${error}\n`, '\x1b[0m')
|
32
32
|
export const logSuccess = (output) => console.log('\x1b[32m', output, '\x1b[0m')
|
33
|
+
export const logType = (type) => {
|
34
|
+
console.log('\n\x1b[34m')
|
35
|
+
console.log(type, '\n\x1b[0m')
|
36
|
+
}
|
37
|
+
export const logResult = (result) => {
|
38
|
+
console.log('\x1b[34m')
|
39
|
+
console.log(result, '\n\x1b[0m')
|
40
|
+
}
|
33
41
|
export const wrapInBracesString = (exp) => `(${stringifyArgs(exp)})`
|
34
42
|
export const logExp = function (exp, ...args) {
|
35
43
|
console.log(wrapInBracesString(exp), ...args)
|
@@ -365,12 +373,59 @@ export const isInputVariable = (x) =>
|
|
365
373
|
x[1][TYPE] === WORD &&
|
366
374
|
x[1][VALUE] === 'INPUT'
|
367
375
|
|
376
|
+
export const init = () => {
|
377
|
+
import('fs').then(({ writeFileSync }) => {
|
378
|
+
writeFileSync('main.lisp', '')
|
379
|
+
writeFileSync('types.lisp', '')
|
380
|
+
writeFileSync(
|
381
|
+
'main.js',
|
382
|
+
`import { compile, enhance, parse, LISP, UTILS } from 'fez-lisp'
|
383
|
+
import { readFileSync } from 'fs'
|
384
|
+
export const dev = (source, types) => {
|
385
|
+
try {
|
386
|
+
const parsed = parse(source)
|
387
|
+
const { evaluated, type, error } = UTILS.debug(
|
388
|
+
parsed,
|
389
|
+
true,
|
390
|
+
types ? types : undefined
|
391
|
+
)
|
392
|
+
if (error == null) {
|
393
|
+
if (type) {
|
394
|
+
UTILS.logType(type)
|
395
|
+
}
|
396
|
+
UTILS.logResult(LISP.serialise(evaluated))
|
397
|
+
} else UTILS.logError(error.message)
|
398
|
+
} catch (error) {
|
399
|
+
UTILS.logError(error.message)
|
400
|
+
}
|
401
|
+
}
|
402
|
+
export const comp = (source) =>
|
403
|
+
UTILS.logResult(
|
404
|
+
LISP.serialise(new Function('return ' + compile(enhance(parse(source))))())
|
405
|
+
)
|
406
|
+
const file = readFileSync('./main.lisp', 'utf-8')
|
407
|
+
switch (process.argv[2]) {
|
408
|
+
case 'comp':
|
409
|
+
comp(file)
|
410
|
+
break
|
411
|
+
case 'dev':
|
412
|
+
dev(file, readFileSync('./types.lisp', 'utf-8'))
|
413
|
+
break
|
414
|
+
}
|
415
|
+
`
|
416
|
+
)
|
417
|
+
})
|
418
|
+
}
|
419
|
+
|
368
420
|
export const UTILS = {
|
421
|
+
init,
|
369
422
|
debug,
|
370
423
|
startDebug,
|
371
424
|
debugStackToString,
|
372
425
|
handleUnbalancedQuotes,
|
373
426
|
handleUnbalancedParens,
|
427
|
+
logType,
|
428
|
+
logResult,
|
374
429
|
logError,
|
375
430
|
logSuccess,
|
376
431
|
formatErrorWithCallstack,
|