fez-lisp 1.1.6 → 1.1.7
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +1 -1
- package/package.json +1 -1
- package/src/evaluator.js +2 -1
- package/src/interpreter.js +1 -1
- package/src/keywords.js +0 -4
- package/src/utils.js +7 -5
package/README.md
CHANGED
package/package.json
CHANGED
package/src/evaluator.js
CHANGED
@@ -13,7 +13,7 @@ export const evaluate = (exp, env) => {
|
|
13
13
|
throw new ReferenceError(`Undefined variable ${first[VALUE]}`)
|
14
14
|
return word
|
15
15
|
}
|
16
|
-
case APPLY:
|
16
|
+
case APPLY: {
|
17
17
|
const apply = env[first[VALUE]]
|
18
18
|
if (apply == undefined)
|
19
19
|
throw new ReferenceError(
|
@@ -24,6 +24,7 @@ export const evaluate = (exp, env) => {
|
|
24
24
|
`${first[VALUE]} is not a (${KEYWORDS.ANONYMOUS_FUNCTION})`
|
25
25
|
)
|
26
26
|
return apply(rest, env)
|
27
|
+
}
|
27
28
|
case ATOM:
|
28
29
|
return first[VALUE]
|
29
30
|
default:
|
package/src/interpreter.js
CHANGED
package/src/keywords.js
CHANGED
@@ -1,13 +1,9 @@
|
|
1
|
-
// AST enums
|
2
1
|
export const TYPE = 0
|
3
2
|
export const VALUE = 1
|
4
|
-
|
5
3
|
export const APPLY = 0
|
6
4
|
export const WORD = 1
|
7
5
|
export const ATOM = 2
|
8
|
-
// tokeniser enums
|
9
6
|
export const PLACEHOLDER = '.'
|
10
|
-
// keywords aliases
|
11
7
|
export const KEYWORDS = {
|
12
8
|
NUMBER_TYPE: 'number',
|
13
9
|
STRING_TYPE: 'string',
|
package/src/utils.js
CHANGED
@@ -18,6 +18,7 @@ export const replaceStrings = (source) => {
|
|
18
18
|
)
|
19
19
|
return source
|
20
20
|
}
|
21
|
+
export const replaceQuotes = (source) => source.replaceAll(/\'\(/g, '(array ')
|
21
22
|
export const removeNoCode = (source) =>
|
22
23
|
source
|
23
24
|
.replace(/;.+/g, '')
|
@@ -72,9 +73,7 @@ export const stringifyArgs = (args) =>
|
|
72
73
|
export const isForbiddenVariableName = (name) => {
|
73
74
|
switch (name) {
|
74
75
|
case '_':
|
75
|
-
case KEYWORDS.CAST_TYPE:
|
76
76
|
case KEYWORDS.DEFINE_VARIABLE:
|
77
|
-
// case KEYWORDS.DESTRUCTURING_ASSIGMENT:
|
78
77
|
return true
|
79
78
|
default:
|
80
79
|
return false
|
@@ -163,7 +162,7 @@ export const fez = (source, options = {}) => {
|
|
163
162
|
const env = Object.create(null)
|
164
163
|
try {
|
165
164
|
if (typeof source === 'string') {
|
166
|
-
|
165
|
+
source = replaceQuotes(replaceStrings(source))
|
167
166
|
let code
|
168
167
|
if (!options.compile)
|
169
168
|
code = handleUnbalancedQuotes(
|
@@ -249,5 +248,8 @@ export const decompress = (raw) => {
|
|
249
248
|
export const shake = (parsed, std) => [...treeShake(parsed, std), ...parsed]
|
250
249
|
export const tree = (source, std) =>
|
251
250
|
std
|
252
|
-
? shake(
|
253
|
-
|
251
|
+
? shake(
|
252
|
+
LISP.parse(replaceQuotes(replaceStrings(removeNoCode(source)))),
|
253
|
+
std
|
254
|
+
)
|
255
|
+
: LISP.parse(replaceQuotes(replaceStrings(removeNoCode(source))))
|