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/src/compiler.js CHANGED
@@ -145,8 +145,6 @@ const comp = (tree, Drill) => {
145
145
  if (isLeaf(tree)) head = tree
146
146
  else {
147
147
  head = tree[0]
148
- if (head == undefined) return '[];'
149
-
150
148
  tail = tree.slice(1)
151
149
  }
152
150
  const token = head[VALUE]
package/src/evaluator.js CHANGED
@@ -16,7 +16,6 @@ export const evaluate = (exp, env = keywords) => {
16
16
  if (isLeaf(exp)) head = exp
17
17
  else {
18
18
  head = exp[0]
19
- if (head == undefined) return []
20
19
  tail = exp.slice(1)
21
20
  }
22
21
  const value = head[VALUE]
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 == undefined) return '()'
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())`