fez-lisp 1.2.26 → 1.2.28
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/compiler.js +15 -14
- package/src/utils.js +4 -7
package/package.json
CHANGED
package/src/compiler.js
CHANGED
@@ -22,9 +22,9 @@ const dotNamesToEmpty = (name) => name.replace(new RegExp(/\./g), '')
|
|
22
22
|
const arrowFromTo = (name) => name.replace(new RegExp(/->/g), '-to-')
|
23
23
|
const moduleNameToLodashes = (name) => name.replace(new RegExp(/:/g), '_')
|
24
24
|
const questionMarkToPredicate = (name) =>
|
25
|
-
name.replace(new RegExp(/\?/g), '
|
25
|
+
name.replace(new RegExp(/\?/g), '_predicate')
|
26
26
|
const exclamationMarkMarkToEffect = (name) =>
|
27
|
-
name.replace(new RegExp(/\!/g), '
|
27
|
+
name.replace(new RegExp(/\!/g), '_effect')
|
28
28
|
const toCamelCase = (name) => {
|
29
29
|
let out = name[0]
|
30
30
|
for (let i = 1; i < name.length; ++i) {
|
@@ -36,6 +36,7 @@ const toCamelCase = (name) => {
|
|
36
36
|
}
|
37
37
|
return out
|
38
38
|
}
|
39
|
+
const dashToLodashes = (name) => name.replace(new RegExp(/-/g), '_')
|
39
40
|
const keywordToHelper = (name) => {
|
40
41
|
switch (name) {
|
41
42
|
case KEYWORDS.ADDITION:
|
@@ -59,7 +60,7 @@ const keywordToHelper = (name) => {
|
|
59
60
|
}
|
60
61
|
}
|
61
62
|
const lispToJavaScriptVariableName = (name) =>
|
62
|
-
|
63
|
+
dashToLodashes(
|
63
64
|
arrowFromTo(
|
64
65
|
dotNamesToEmpty(
|
65
66
|
exclamationMarkMarkToEffect(
|
@@ -99,16 +100,16 @@ const Helpers = {
|
|
99
100
|
}
|
100
101
|
return args.at(-1) ? 1 : 0
|
101
102
|
}`,
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
103
|
+
log_effect: `log_effect=(msg)=>{console.log(msg);return msg}`,
|
104
|
+
log_char_effect: `log_char_effect=(msg)=>{console.log(String.fromCharCode(msg));return msg}`,
|
105
|
+
log_string_effect: `log_string_effect=(msg)=>{console.log(msg.map(x=>String.fromCharCode(x)).join(''));return msg}`,
|
106
|
+
clear_effect: `clear_effect=()=>{console.clear();return 0}`,
|
106
107
|
get: 'get=(arr,i)=>arr.at(i)',
|
107
108
|
length: 'length=(arr)=>arr.length',
|
108
109
|
__tco: `__tco=fn=>(...args)=>{let result=fn(...args);while(typeof result==='function')result=result();return result}`,
|
109
|
-
|
110
|
-
|
111
|
-
|
110
|
+
atom_predicate: `atom_predicate=(number)=>+(typeof number==='number')`,
|
111
|
+
lambda_predicate: `lambda_predicate=(fm)=>+(typeof fn==='function')`,
|
112
|
+
set_effect: `set_effect=(array,index,value)=>{if(index<0){const target=array.length+index;while(array.length!==target)array.pop()}else array[index] = value;return array}`
|
112
113
|
}
|
113
114
|
const semiColumnEdgeCases = new Set([
|
114
115
|
';)',
|
@@ -190,11 +191,11 @@ const compile = (tree, Drill) => {
|
|
190
191
|
}
|
191
192
|
}
|
192
193
|
case KEYWORDS.IS_ATOM:
|
193
|
-
Drill.Helpers.add('
|
194
|
-
return `
|
194
|
+
Drill.Helpers.add('atom_predicate')
|
195
|
+
return `atom_predicate(${compile(Arguments[0], Drill)});`
|
195
196
|
case KEYWORDS.IS_LAMBDA:
|
196
|
-
Drill.Helpers.add('
|
197
|
-
return `
|
197
|
+
Drill.Helpers.add('lambda_predicate')
|
198
|
+
return `lambda_predicate(${compile(Arguments[0], Drill)});`
|
198
199
|
case KEYWORDS.NUMBER_TYPE:
|
199
200
|
return '0'
|
200
201
|
case KEYWORDS.BOOLEAN_TYPE:
|
package/src/utils.js
CHANGED
@@ -234,13 +234,10 @@ export const fez = (source, options = {}) => {
|
|
234
234
|
try {
|
235
235
|
if (typeof source === 'string') {
|
236
236
|
source = replaceQuotes(replaceStrings(source))
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
)
|
242
|
-
else code = removeNoCode(source)
|
243
|
-
if (!options.mutation) code = removeMutation(code)
|
237
|
+
const valid = handleUnbalancedQuotes(
|
238
|
+
handleUnbalancedParens(removeNoCode(source))
|
239
|
+
)
|
240
|
+
const code = !options.mutation ? removeMutation(valid) : valid
|
244
241
|
if (!code.length && options.throw) throw new Error('Nothing to parse!')
|
245
242
|
const parsed = deSuggar(LISP.parse(code))
|
246
243
|
const ast = [...treeShake(parsed, std), ...parsed]
|