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.
- package/README.md +10 -0
- package/package.json +1 -1
- 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
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
|
-
'
|
384
|
+
'index.js',
|
382
385
|
`import { compile, enhance, parse, LISP, UTILS } from 'fez-lisp'
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
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
|
-
|
403
|
-
|
404
|
-
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
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
|
|