fez-lisp 1.0.6 → 1.0.8
Sign up to get free protection for your applications and to get access to all the features.
- package/README.md +18 -18
- package/lib/baked/std.js +1 -1
- package/package.json +1 -1
- package/src/compiler.js +14 -0
- package/src/enums.js +2 -0
- package/src/interpreter.js +3 -3
- package/src/parser.js +2 -1
- package/src/tokeniser.js +206 -117
- package/src/utils.js +9 -5
package/src/utils.js
CHANGED
@@ -127,7 +127,7 @@ export const handleUnbalancedQuotes = (source) => {
|
|
127
127
|
if (diff !== 0) throw new SyntaxError(`Quotes are unbalanced "`)
|
128
128
|
return source
|
129
129
|
}
|
130
|
-
|
130
|
+
export const removeMutation = (source) => source.replace(new RegExp(/!/g), 'ǃ')
|
131
131
|
export const treeShake = (ast, libs) => {
|
132
132
|
const deps = libs.reduce((a, x) => a.add(x.at(1)[VALUE]), new Set())
|
133
133
|
const visited = new Set()
|
@@ -179,6 +179,7 @@ export const fez = (source, options = {}) => {
|
|
179
179
|
handleUnbalancedParens(removeNoCode(source))
|
180
180
|
)
|
181
181
|
else code = removeNoCode(source)
|
182
|
+
if (options.immutable) code = removeMutation(code)
|
182
183
|
const parsed = parse(code)
|
183
184
|
const standard = options.std
|
184
185
|
? options.shake
|
@@ -186,7 +187,10 @@ export const fez = (source, options = {}) => {
|
|
186
187
|
: std
|
187
188
|
: []
|
188
189
|
const ast = [...standard, ...parsed]
|
189
|
-
if (options.compile)
|
190
|
+
if (options.compile) {
|
191
|
+
const js = Object.values(comp(deepClone(ast))).join('')
|
192
|
+
return options.eval ? eval(js) : js
|
193
|
+
}
|
190
194
|
return run(ast, env)
|
191
195
|
} catch (error) {
|
192
196
|
const err = error.message
|
@@ -204,8 +208,8 @@ export const dotNamesToEmpty = (name) => name.replace(new RegExp(/\./g), '')
|
|
204
208
|
export const colonNamesTo$ = (name) => name.replace(new RegExp(/\:/g), '$')
|
205
209
|
export const commaToLodash = (name) => name.replace(new RegExp(/\,/g), '_')
|
206
210
|
export const arrowToTo = (name) => name.replace(new RegExp(/->/g), '-to-')
|
207
|
-
export const
|
208
|
-
name.replace(new RegExp(
|
211
|
+
export const moduleNameToLodashes = (name) =>
|
212
|
+
name.replace(new RegExp(/:/g), '_')
|
209
213
|
|
210
214
|
export const questionMarkToLodash = (name) =>
|
211
215
|
name.replace(new RegExp(/\?/g), 'Predicate')
|
@@ -238,7 +242,7 @@ export const lispToJavaScriptVariableName = (name) =>
|
|
238
242
|
colonNamesTo$(
|
239
243
|
exclamationMarkMarkToLodash(
|
240
244
|
questionMarkToLodash(
|
241
|
-
commaToLodash(
|
245
|
+
commaToLodash(moduleNameToLodashes(earMuffsToLodashes(name)))
|
242
246
|
)
|
243
247
|
)
|
244
248
|
)
|