fez-lisp 1.1.1 → 1.1.2

Sign up to get free protection for your applications and to get access to all the features.
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "fez-lisp",
3
3
  "description": "Lisp interpreted & compiled to JavaScript",
4
4
  "author": "AT290690",
5
- "version": "1.1.1",
5
+ "version": "1.1.2",
6
6
  "type": "module",
7
7
  "main": "index.js",
8
8
  "keywords": [
package/src/compiler.js CHANGED
@@ -8,7 +8,63 @@ import {
8
8
  WORD
9
9
  } from './keywords.js'
10
10
  import { leaf, isLeaf } from './parser.js'
11
- import { deepRename, lispToJavaScriptVariableName } from './utils.js'
11
+ import { deepRename } from './utils.js'
12
+ const earMuffsToLodashes = (name) => name.replace(new RegExp(/\*/g), '_')
13
+ const dotNamesToEmpty = (name) => name.replace(new RegExp(/\./g), '')
14
+ const commaToLodash = (name) => name.replace(new RegExp(/\,/g), '_')
15
+ const arrowFromTo = (name) => name.replace(new RegExp(/->/g), '-to-')
16
+ const moduleNameToLodashes = (name) => name.replace(new RegExp(/:/g), '_')
17
+ const questionMarkToPredicate = (name) =>
18
+ name.replace(new RegExp(/\?/g), 'Predicate')
19
+ const exclamationMarkMarkToEffect = (name) =>
20
+ name.replace(new RegExp(/\!/g), 'Effect')
21
+ const toCamelCase = (name) => {
22
+ let out = name[0]
23
+ for (let i = 1; i < name.length; ++i) {
24
+ const current = name[i],
25
+ prev = name[i - 1]
26
+ if (current === '-') continue
27
+ else if (prev === '-') out += current.toUpperCase()
28
+ else out += current
29
+ }
30
+ return out
31
+ }
32
+ const keywordToHelper = (name) => {
33
+ switch (name) {
34
+ case KEYWORDS.ADDITION:
35
+ return '__add'
36
+ case KEYWORDS.MULTIPLICATION:
37
+ return '__mult'
38
+ case KEYWORDS.SUBTRACTION:
39
+ return '__sub'
40
+ case KEYWORDS.GREATHER_THAN:
41
+ return '__gt'
42
+ case KEYWORDS.EQUAL:
43
+ return '__eq'
44
+ case KEYWORDS.GREATHER_THAN_OR_EQUAL:
45
+ return '__gteq'
46
+ case KEYWORDS.LESS_THAN:
47
+ return '__lt'
48
+ case KEYWORDS.LESS_THAN_OR_EQUAL:
49
+ return '__lteq'
50
+ default:
51
+ return name
52
+ }
53
+ }
54
+ const lispToJavaScriptVariableName = (name) =>
55
+ toCamelCase(
56
+ arrowFromTo(
57
+ dotNamesToEmpty(
58
+ exclamationMarkMarkToEffect(
59
+ questionMarkToPredicate(
60
+ commaToLodash(
61
+ moduleNameToLodashes(earMuffsToLodashes(keywordToHelper(name)))
62
+ )
63
+ )
64
+ )
65
+ )
66
+ )
67
+ )
12
68
  const Helpers = {
13
69
  __string: `__string=(...args)=>{const str=args.flat();str.isString=true;return str}`,
14
70
  __add: `__add=(...numbers)=>{return numbers.reduce((a,b)=>a+b,0)}`,
@@ -309,10 +365,7 @@ const compile = (tree, Drill) => {
309
365
  return `${camelCased}(${parseArgs(Arguments, Drill)});`
310
366
  }
311
367
  }
312
- } else if (first[TYPE] === ATOM)
313
- return typeof first[VALUE] === 'string'
314
- ? `\`${first[VALUE]}\``
315
- : first[VALUE]
368
+ } else if (first[TYPE] === ATOM) return first[VALUE]
316
369
  else if (first[TYPE] === WORD) {
317
370
  const camelCased = lispToJavaScriptVariableName(token)
318
371
  if (camelCased in Helpers) Drill.Helpers.add(camelCased)
package/src/utils.js CHANGED
@@ -204,51 +204,6 @@ export const fez = (source, options = {}) => {
204
204
  return err
205
205
  }
206
206
  }
207
-
208
- export const earMuffsToLodashes = (name) => name.replace(new RegExp(/\*/g), '_')
209
- export const dotNamesToEmpty = (name) => name.replace(new RegExp(/\./g), '')
210
- export const colonNamesTo$ = (name) => name.replace(new RegExp(/\:/g), '$')
211
- export const commaToLodash = (name) => name.replace(new RegExp(/\,/g), '_')
212
- export const arrowFromTo = (name) => name.replace(new RegExp(/->/g), '-to-')
213
- export const moduleNameToLodashes = (name) =>
214
- name.replace(new RegExp(/:/g), '_')
215
- export const questionMarkToLodash = (name) =>
216
- name.replace(new RegExp(/\?/g), 'Predicate')
217
- export const exclamationMarkMarkToLodash = (name) =>
218
- name.replace(new RegExp(/\!/g), 'Effect')
219
- export const toCamelCase = (name) => {
220
- let out = name[0]
221
- for (let i = 1; i < name.length; ++i) {
222
- const current = name[i],
223
- prev = name[i - 1]
224
- if (current === '-') continue
225
- else if (prev === '-') out += current.toUpperCase()
226
- else out += current
227
- }
228
- return out
229
- }
230
- export const keywordToHelper = (name) => {
231
- switch (name) {
232
- case KEYWORDS.ADDITION:
233
- return '__add'
234
- case KEYWORDS.MULTIPLICATION:
235
- return '__mult'
236
- case KEYWORDS.SUBTRACTION:
237
- return '__sub'
238
- case KEYWORDS.GREATHER_THAN:
239
- return '__gt'
240
- case KEYWORDS.EQUAL:
241
- return '__eq'
242
- case KEYWORDS.GREATHER_THAN_OR_EQUAL:
243
- return '__gteq'
244
- case KEYWORDS.LESS_THAN:
245
- return '__lt'
246
- case KEYWORDS.LESS_THAN_OR_EQUAL:
247
- return '__lteq'
248
- default:
249
- return name
250
- }
251
- }
252
207
  export const deepRename = (name, newName, tree) => {
253
208
  if (!isLeaf(tree))
254
209
  for (const leaf of tree) {
@@ -296,19 +251,3 @@ export const tree = (source, std) =>
296
251
  std
297
252
  ? shake(LISP.parse(removeNoCode(source)), std)
298
253
  : LISP.parse(removeNoCode(source))
299
- export const lispToJavaScriptVariableName = (name) =>
300
- toCamelCase(
301
- arrowFromTo(
302
- dotNamesToEmpty(
303
- colonNamesTo$(
304
- exclamationMarkMarkToLodash(
305
- questionMarkToLodash(
306
- commaToLodash(
307
- moduleNameToLodashes(earMuffsToLodashes(keywordToHelper(name)))
308
- )
309
- )
310
- )
311
- )
312
- )
313
- )
314
- )