fez-lisp 1.5.40 → 1.5.42
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/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/check.js +745 -413
- package/src/compiler.js +0 -2
- package/src/evaluator.js +0 -1
- package/src/macros.js +3 -3
- package/src/parser.js +2 -8
- package/src/utils.js +1 -0
package/src/compiler.js
CHANGED
package/src/evaluator.js
CHANGED
package/src/macros.js
CHANGED
@@ -16,7 +16,7 @@ import {
|
|
16
16
|
VALUE,
|
17
17
|
WORD
|
18
18
|
} from './keywords.js'
|
19
|
-
import { hasBlock, stringifyArgs } from './utils.js'
|
19
|
+
import { getSuffix, hasBlock, stringifyArgs } from './utils.js'
|
20
20
|
export const SUGGAR = {
|
21
21
|
// Syntactic suggars
|
22
22
|
PIPE: '|>',
|
@@ -524,7 +524,7 @@ export const deSuggarAst = (ast, scope) => {
|
|
524
524
|
const name = exp[1][VALUE]
|
525
525
|
const prefix = name.split(':')[0]
|
526
526
|
if (prefix === OPTIMIZATIONS.RECURSION) {
|
527
|
-
if (name
|
527
|
+
if (getSuffix(name) === PREDICATE_SUFFIX) {
|
528
528
|
throw new TypeError(
|
529
529
|
`Optimized (lambda) ${name} can't be a (Predicate) as it will return a (lambda). Remove the (${PREDICATE_SUFFIX}) from the name`
|
530
530
|
)
|
@@ -625,7 +625,7 @@ export const deSuggarAst = (ast, scope) => {
|
|
625
625
|
]
|
626
626
|
deSuggarAst(exp[exp.length - 1])
|
627
627
|
} else if (prefix === OPTIMIZATIONS.CACHE) {
|
628
|
-
if (name
|
628
|
+
if (getSuffix(name) === PREDICATE_SUFFIX) {
|
629
629
|
throw new TypeError(
|
630
630
|
`Optimized (lambda) ${name} can't be a (Predicate) as it will return a (lambda). Remove the (${PREDICATE_SUFFIX}) from the name`
|
631
631
|
)
|
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 = []
|
@@ -30,14 +29,13 @@ export const LISP = {
|
|
30
29
|
return tree
|
31
30
|
},
|
32
31
|
stringify: (array) => {
|
33
|
-
if (array
|
34
|
-
else if (typeof array === 'function') return '(lambda)'
|
32
|
+
if (typeof array === 'function') return '(lambda)'
|
35
33
|
else if (typeof array === 'boolean') return +array
|
36
34
|
else if (typeof array === 'object')
|
37
35
|
if (Array.isArray(array))
|
38
36
|
return array.length
|
39
37
|
? `(array ${array.map(LISP.stringify).join(' ')})`
|
40
|
-
: '()'
|
38
|
+
: '(array)'
|
41
39
|
else
|
42
40
|
return `(array ${array
|
43
41
|
.map(([key, value]) => `("${key}" ${LISP.stringify(value)})`)
|
@@ -48,7 +46,6 @@ export const LISP = {
|
|
48
46
|
const dfs = (exp) => {
|
49
47
|
let out = ''
|
50
48
|
const [head, ...tail] = isLeaf(exp) ? [exp] : exp
|
51
|
-
if (head == undefined) return (out += '(array)')
|
52
49
|
switch (head[TYPE]) {
|
53
50
|
case WORD:
|
54
51
|
out += head[VALUE]
|
@@ -110,9 +107,6 @@ export const AST = {
|
|
110
107
|
const dfs = (exp) => {
|
111
108
|
let out = ''
|
112
109
|
const [head, ...tail] = isLeaf(exp) ? [exp] : exp
|
113
|
-
if (head == undefined)
|
114
|
-
return (out +=
|
115
|
-
'(Expression::Apply(vec![Expression::Word("array".to_string())]))')
|
116
110
|
switch (head[TYPE]) {
|
117
111
|
case WORD:
|
118
112
|
out += `Expression::Word("${head[VALUE]}".to_string())`
|
package/src/utils.js
CHANGED
@@ -19,6 +19,7 @@ export const formatCallstack = (callstack) =>
|
|
19
19
|
export const formatErrorWithCallstack = (error, callstack) => {
|
20
20
|
return `${error.message}\n${formatCallstack(callstack)}`
|
21
21
|
}
|
22
|
+
export const getSuffix = (str) => str[str.length - 1]
|
22
23
|
export const removeNoCode = (source) =>
|
23
24
|
source
|
24
25
|
.replace(/(;.+|;)/g, '')
|