fez-lisp 1.5.41 → 1.5.43
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/check.js +637 -651
- package/src/compiler.js +0 -2
- package/src/evaluator.js +0 -1
- package/src/parser.js +6 -8
package/src/compiler.js
CHANGED
package/src/evaluator.js
CHANGED
package/src/parser.js
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
import { APPLY, ATOM, TYPE, WORD, VALUE } from './keywords.js'
|
2
2
|
export const leaf = (type, value) => [type, value]
|
3
3
|
export const isLeaf = ([car]) => car === APPLY || car === ATOM || car === WORD
|
4
|
-
export const toPair = (exp) => []
|
5
4
|
export const LISP = {
|
6
5
|
parse: (source) => {
|
7
6
|
const tree = []
|
@@ -12,6 +11,10 @@ export const LISP = {
|
|
12
11
|
const cursor = source[i]
|
13
12
|
if (cursor === '(') {
|
14
13
|
const temp = []
|
14
|
+
if (head == undefined)
|
15
|
+
throw new SyntaxError(
|
16
|
+
`Failed to parse due to invalid lisp programm near ${acc}`
|
17
|
+
)
|
15
18
|
head.push(temp)
|
16
19
|
stack.push(head)
|
17
20
|
head = temp
|
@@ -30,14 +33,13 @@ export const LISP = {
|
|
30
33
|
return tree
|
31
34
|
},
|
32
35
|
stringify: (array) => {
|
33
|
-
if (array
|
34
|
-
else if (typeof array === 'function') return '(lambda)'
|
36
|
+
if (typeof array === 'function') return '(lambda)'
|
35
37
|
else if (typeof array === 'boolean') return +array
|
36
38
|
else if (typeof array === 'object')
|
37
39
|
if (Array.isArray(array))
|
38
40
|
return array.length
|
39
41
|
? `(array ${array.map(LISP.stringify).join(' ')})`
|
40
|
-
: '()'
|
42
|
+
: '(array)'
|
41
43
|
else
|
42
44
|
return `(array ${array
|
43
45
|
.map(([key, value]) => `("${key}" ${LISP.stringify(value)})`)
|
@@ -48,7 +50,6 @@ export const LISP = {
|
|
48
50
|
const dfs = (exp) => {
|
49
51
|
let out = ''
|
50
52
|
const [head, ...tail] = isLeaf(exp) ? [exp] : exp
|
51
|
-
if (head == undefined) return (out += '(array)')
|
52
53
|
switch (head[TYPE]) {
|
53
54
|
case WORD:
|
54
55
|
out += head[VALUE]
|
@@ -110,9 +111,6 @@ export const AST = {
|
|
110
111
|
const dfs = (exp) => {
|
111
112
|
let out = ''
|
112
113
|
const [head, ...tail] = isLeaf(exp) ? [exp] : exp
|
113
|
-
if (head == undefined)
|
114
|
-
return (out +=
|
115
|
-
'(Expression::Apply(vec![Expression::Word("array".to_string())]))')
|
116
114
|
switch (head[TYPE]) {
|
117
115
|
case WORD:
|
118
116
|
out += `Expression::Word("${head[VALUE]}".to_string())`
|