fez-lisp 1.6.44 → 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 +50 -33
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.44",
5
+ "version": "1.6.45",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/utils.js CHANGED
@@ -375,45 +375,62 @@ export const isInputVariable = (x) =>
375
375
 
376
376
  export const init = () => {
377
377
  import('fs').then(({ writeFileSync }) => {
378
+ console.log('\x1b[32m')
378
379
  writeFileSync('main.lisp', '')
380
+ console.log('Added main.lisp')
379
381
  writeFileSync('types.lisp', '')
382
+ console.log('Added types.lisp')
380
383
  writeFileSync(
381
- 'main.js',
384
+ 'index.js',
382
385
  `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)
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
+ }
400
404
  }
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
- `
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'
416
432
  )
433
+ process.exit()
417
434
  })
418
435
  }
419
436