@calcit/procs 0.8.1 → 0.8.2

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.
@@ -1,6 +1,6 @@
1
1
  var _a;
2
2
  // CALCIT VERSION
3
- export const calcit_version = "0.8.1";
3
+ export const calcit_version = "0.8.2";
4
4
  import { parse } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
6
6
  import { CalcitSymbol, CalcitTag, CalcitRef, CalcitRecur, newTag, refsRegistry, toString, getStringName, _$n__$e_, hashFunction, } from "./calcit-data.mjs";
@@ -1097,7 +1097,13 @@ export let parse_cirru_list = (code) => {
1097
1097
  return to_calcit_data(parse(code), true);
1098
1098
  };
1099
1099
  export let parse_cirru_edn = (code, options) => {
1100
- return extract_cirru_edn(parse(code)[0], options);
1100
+ let nodes = parse(code);
1101
+ if (nodes.length === 1) {
1102
+ return extract_cirru_edn(nodes[0], options);
1103
+ }
1104
+ else {
1105
+ throw new Error(`Expected EDN in a single node, got ${nodes.length}`);
1106
+ }
1101
1107
  };
1102
1108
  export let format_to_lisp = (x) => {
1103
1109
  if (x == null) {
package/lib/js-cirru.mjs CHANGED
@@ -19,7 +19,12 @@ export class CalcitCirruQuote {
19
19
  }
20
20
  /** provide a simple text representation in Console or std out, with indentations */
21
21
  textForm() {
22
- return writeCirruCode(this.value);
22
+ if (Array.isArray(this.value) && this.value.every((x) => Array.isArray(x))) {
23
+ return writeCirruCode(this.value);
24
+ }
25
+ else {
26
+ return this.toString();
27
+ }
23
28
  }
24
29
  }
25
30
  export let format_cirru = (data, useInline) => {
@@ -204,11 +209,18 @@ export let extract_cirru_edn = (x, options) => {
204
209
  if (idx === 0) {
205
210
  return; // skip first `{}` symbol
206
211
  }
207
- if (pair instanceof Array && pair.length === 2) {
208
- result.push(extract_cirru_edn(pair[0], options), extract_cirru_edn(pair[1], options));
212
+ if (pair instanceof Array) {
213
+ if (pair[0] === ";")
214
+ return;
215
+ if (pair.length === 2) {
216
+ result.push(extract_cirru_edn(pair[0], options), extract_cirru_edn(pair[1], options));
217
+ }
218
+ else {
219
+ throw new Error(`Expected a pair, got size ${pair.length}`);
220
+ }
209
221
  }
210
222
  else {
211
- throw new Error("Expected pairs for map");
223
+ throw new Error(`Expected pairs for map, got ${pair}`);
212
224
  }
213
225
  });
214
226
  return new CalcitSliceMap(result);
@@ -224,16 +236,23 @@ export let extract_cirru_edn = (x, options) => {
224
236
  if (idx <= 1) {
225
237
  return; // skip %{} name
226
238
  }
227
- if (pair instanceof Array && pair.length === 2) {
228
- if (typeof pair[0] === "string") {
229
- entries.push([extractFieldTag(pair[0]), extract_cirru_edn(pair[1], options)]);
239
+ if (pair instanceof Array) {
240
+ if (pair[0] === ";")
241
+ return;
242
+ if (pair.length === 2) {
243
+ if (typeof pair[0] === "string") {
244
+ entries.push([extractFieldTag(pair[0]), extract_cirru_edn(pair[1], options)]);
245
+ }
246
+ else {
247
+ throw new Error("Expected string as field");
248
+ }
230
249
  }
231
250
  else {
232
- throw new Error("Expected string as field");
251
+ throw new Error("Expected pair of size 2");
233
252
  }
234
253
  }
235
254
  else {
236
- throw new Error("Expected pairs for map");
255
+ throw new Error("Expected pairs for reocrd");
237
256
  }
238
257
  });
239
258
  entries.sort((a, b) => {
@@ -256,11 +275,23 @@ export let extract_cirru_edn = (x, options) => {
256
275
  }
257
276
  return new CalcitRecord(extractFieldTag(name), fields, values);
258
277
  }
278
+ let notComment = (x) => {
279
+ if (x instanceof Array && x[0] === ";") {
280
+ return false;
281
+ }
282
+ return true;
283
+ };
259
284
  if (x[0] === "[]") {
260
- return new CalcitSliceList(x.slice(1).map((x) => extract_cirru_edn(x, options)));
285
+ return new CalcitSliceList(x
286
+ .slice(1)
287
+ .filter(notComment)
288
+ .map((x) => extract_cirru_edn(x, options)));
261
289
  }
262
290
  if (x[0] === "#{}") {
263
- return new CalcitSet(x.slice(1).map((x) => extract_cirru_edn(x, options)));
291
+ return new CalcitSet(x
292
+ .slice(1)
293
+ .filter(notComment)
294
+ .map((x) => extract_cirru_edn(x, options)));
264
295
  }
265
296
  if (x[0] === "do" && x.length === 2) {
266
297
  return extract_cirru_edn(x[1], options);
@@ -276,7 +307,10 @@ export let extract_cirru_edn = (x, options) => {
276
307
  throw new Error("tuple expects at least 1 value1");
277
308
  }
278
309
  let baseClass = new CalcitRecord(newTag("base-class"), [], []);
279
- return new CalcitTuple(extract_cirru_edn(x[1], options), x.slice(2).map((x) => extract_cirru_edn(x, options)), baseClass);
310
+ return new CalcitTuple(extract_cirru_edn(x[1], options), x
311
+ .slice(2)
312
+ .filter(notComment)
313
+ .map((x) => extract_cirru_edn(x, options)), baseClass);
280
314
  }
281
315
  }
282
316
  console.error(x);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calcit/procs",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "main": "./lib/calcit.procs.mjs",
5
5
  "devDependencies": {
6
6
  "@types/node": "^20.6.2",
@@ -1,5 +1,5 @@
1
1
  // CALCIT VERSION
2
- export const calcit_version = "0.8.1";
2
+ export const calcit_version = "0.8.2";
3
3
 
4
4
  import { parse, ICirruNode } from "@cirru/parser.ts";
5
5
  import { writeCirruCode } from "@cirru/writer.ts";
@@ -1198,7 +1198,12 @@ export let parse_cirru_list = (code: string): CalcitList => {
1198
1198
  };
1199
1199
 
1200
1200
  export let parse_cirru_edn = (code: string, options: CalcitValue) => {
1201
- return extract_cirru_edn(parse(code)[0], options);
1201
+ let nodes = parse(code);
1202
+ if (nodes.length === 1) {
1203
+ return extract_cirru_edn(nodes[0], options);
1204
+ } else {
1205
+ throw new Error(`Expected EDN in a single node, got ${nodes.length}`);
1206
+ }
1202
1207
  };
1203
1208
 
1204
1209
  export let format_to_lisp = (x: CalcitValue): string => {
@@ -25,7 +25,11 @@ export class CalcitCirruQuote {
25
25
  }
26
26
  /** provide a simple text representation in Console or std out, with indentations */
27
27
  textForm(): string {
28
- return writeCirruCode(this.value);
28
+ if (Array.isArray(this.value) && this.value.every((x) => Array.isArray(x))) {
29
+ return writeCirruCode(this.value);
30
+ } else {
31
+ return this.toString();
32
+ }
29
33
  }
30
34
  }
31
35
 
@@ -203,10 +207,15 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
203
207
  if (idx === 0) {
204
208
  return; // skip first `{}` symbol
205
209
  }
206
- if (pair instanceof Array && pair.length === 2) {
207
- result.push(extract_cirru_edn(pair[0], options), extract_cirru_edn(pair[1], options));
210
+ if (pair instanceof Array) {
211
+ if (pair[0] === ";") return;
212
+ if (pair.length === 2) {
213
+ result.push(extract_cirru_edn(pair[0], options), extract_cirru_edn(pair[1], options));
214
+ } else {
215
+ throw new Error(`Expected a pair, got size ${pair.length}`);
216
+ }
208
217
  } else {
209
- throw new Error("Expected pairs for map");
218
+ throw new Error(`Expected pairs for map, got ${pair}`);
210
219
  }
211
220
  });
212
221
  return new CalcitSliceMap(result);
@@ -222,15 +231,19 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
222
231
  if (idx <= 1) {
223
232
  return; // skip %{} name
224
233
  }
225
-
226
- if (pair instanceof Array && pair.length === 2) {
227
- if (typeof pair[0] === "string") {
228
- entries.push([extractFieldTag(pair[0]), extract_cirru_edn(pair[1], options)]);
234
+ if (pair instanceof Array) {
235
+ if (pair[0] === ";") return;
236
+ if (pair.length === 2) {
237
+ if (typeof pair[0] === "string") {
238
+ entries.push([extractFieldTag(pair[0]), extract_cirru_edn(pair[1], options)]);
239
+ } else {
240
+ throw new Error("Expected string as field");
241
+ }
229
242
  } else {
230
- throw new Error("Expected string as field");
243
+ throw new Error("Expected pair of size 2");
231
244
  }
232
245
  } else {
233
- throw new Error("Expected pairs for map");
246
+ throw new Error("Expected pairs for reocrd");
234
247
  }
235
248
  });
236
249
  entries.sort((a, b) => {
@@ -256,11 +269,27 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
256
269
 
257
270
  return new CalcitRecord(extractFieldTag(name), fields, values);
258
271
  }
272
+ let notComment = (x: any) => {
273
+ if (x instanceof Array && x[0] === ";") {
274
+ return false;
275
+ }
276
+ return true;
277
+ };
259
278
  if (x[0] === "[]") {
260
- return new CalcitSliceList(x.slice(1).map((x) => extract_cirru_edn(x, options)));
279
+ return new CalcitSliceList(
280
+ x
281
+ .slice(1)
282
+ .filter(notComment)
283
+ .map((x) => extract_cirru_edn(x, options))
284
+ );
261
285
  }
262
286
  if (x[0] === "#{}") {
263
- return new CalcitSet(x.slice(1).map((x) => extract_cirru_edn(x, options)));
287
+ return new CalcitSet(
288
+ x
289
+ .slice(1)
290
+ .filter(notComment)
291
+ .map((x) => extract_cirru_edn(x, options))
292
+ );
264
293
  }
265
294
  if (x[0] === "do" && x.length === 2) {
266
295
  return extract_cirru_edn(x[1], options);
@@ -278,7 +307,10 @@ export let extract_cirru_edn = (x: CirruEdnFormat, options: CalcitValue): Calcit
278
307
  let baseClass = new CalcitRecord(newTag("base-class"), [], []);
279
308
  return new CalcitTuple(
280
309
  extract_cirru_edn(x[1], options),
281
- x.slice(2).map((x) => extract_cirru_edn(x, options)),
310
+ x
311
+ .slice(2)
312
+ .filter(notComment)
313
+ .map((x) => extract_cirru_edn(x, options)),
282
314
  baseClass
283
315
  );
284
316
  }