fez-lisp 1.6.43 → 1.6.45

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.
Files changed (3) hide show
  1. package/README.md +10 -0
  2. package/package.json +1 -1
  3. package/src/utils.js +72 -0
package/README.md CHANGED
@@ -11,6 +11,16 @@
11
11
  (|> (math:range 1 100) (array:map fezz-buzz) (from:array->string char:space) (string))
12
12
  ```
13
13
 
14
+ ```bash
15
+ npm i fez-lisp
16
+ ```
17
+
18
+ Run node in terminal
19
+
20
+ ```node
21
+ require('fez-lisp').UTILS.init()
22
+ ```
23
+
14
24
  ## [Try it in online editor](https://at-290690.github.io/fez/)
15
25
 
16
26
  ```lisp
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "fez-lisp",
3
3
  "description": "Lisp interpreted & compiled to JavaScript",
4
4
  "author": "AT290690",
5
- "version": "1.6.43",
5
+ "version": "1.6.45",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
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,76 @@ 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
+ console.log('\x1b[32m')
379
+ writeFileSync('main.lisp', '')
380
+ console.log('Added main.lisp')
381
+ writeFileSync('types.lisp', '')
382
+ console.log('Added types.lisp')
383
+ writeFileSync(
384
+ 'index.js',
385
+ `import { compile, enhance, parse, LISP, UTILS } from 'fez-lisp'
386
+ import { readFileSync, writeFileSync } from 'fs'
387
+ export const dev = (source, types) => {
388
+ try {
389
+ const parsed = parse(source)
390
+ const { evaluated, type, error } = UTILS.debug(
391
+ parsed,
392
+ true,
393
+ types ? types : undefined
394
+ )
395
+ if (error == null) {
396
+ if (type) {
397
+ UTILS.logType(type)
398
+ }
399
+ UTILS.logResult(LISP.serialise(evaluated))
400
+ } else UTILS.logError(error.message)
401
+ } catch (error) {
402
+ UTILS.logError(error.message)
403
+ }
404
+ }
405
+ export const comp = (source) => compile(enhance(parse(source)))
406
+ const file = readFileSync('./main.lisp', 'utf-8')
407
+ switch (process.argv[2]) {
408
+ case 'comp':
409
+ writeFileSync('./main.js', 'var _ = ' + comp(file) + '\nconsole.log(_)')
410
+ break
411
+ case 'dev':
412
+ default:
413
+ dev(file, readFileSync('./types.lisp', 'utf-8'))
414
+ break
415
+ }
416
+ `
417
+ )
418
+ console.log('Added index.js')
419
+ console.log(
420
+ `Done!
421
+
422
+ Write code in main.lisp and types (if any) in types.lisp
423
+ Run node index.js with the following flags:
424
+ - dev (static type check and run time validations)
425
+ - comp (compile Fez to JavaScript file main.js)
426
+
427
+ If no flag is specified it defaults to dev
428
+
429
+ That's it! You are all set!
430
+ `,
431
+ '\x1b[0m'
432
+ )
433
+ process.exit()
434
+ })
435
+ }
436
+
368
437
  export const UTILS = {
438
+ init,
369
439
  debug,
370
440
  startDebug,
371
441
  debugStackToString,
372
442
  handleUnbalancedQuotes,
373
443
  handleUnbalancedParens,
444
+ logType,
445
+ logResult,
374
446
  logError,
375
447
  logSuccess,
376
448
  formatErrorWithCallstack,