@podlite/schema 0.0.83 → 0.0.85

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.
Files changed (70) hide show
  1. package/CHANGELOG.podlite +30 -0
  2. package/esm/ast-inerator.js +1 -3
  3. package/esm/ast-inerator.js.map +1 -1
  4. package/esm/codes/scan.js +26 -22
  5. package/esm/codes/scan.js.map +1 -1
  6. package/esm/grammar.js +531 -416
  7. package/esm/grammar.js.map +1 -1
  8. package/esm/helpers/flatten-deep.d.ts +2 -0
  9. package/esm/helpers/flatten-deep.js +32 -0
  10. package/esm/helpers/flatten-deep.js.map +1 -0
  11. package/esm/helpers/itemNumbering.d.ts +2 -1
  12. package/esm/helpers/itemNumbering.js +3 -2
  13. package/esm/helpers/itemNumbering.js.map +1 -1
  14. package/esm/helpers/makeInterator.js +3 -6
  15. package/esm/helpers/makeInterator.js.map +1 -1
  16. package/esm/helpers/makeTransformer.js +1 -3
  17. package/esm/helpers/makeTransformer.js.map +1 -1
  18. package/esm/helpers/numberedShorthand.d.ts +2 -1
  19. package/esm/helpers/numberedShorthand.js +24 -4
  20. package/esm/helpers/numberedShorthand.js.map +1 -1
  21. package/esm/index.d.ts +3 -0
  22. package/esm/index.js +3 -0
  23. package/esm/index.js.map +1 -1
  24. package/esm/markup-code-letters.d.ts +2 -0
  25. package/esm/markup-code-letters.js +65 -0
  26. package/esm/markup-code-letters.js.map +1 -0
  27. package/esm/pluggableParser.js +13 -5
  28. package/esm/pluggableParser.js.map +1 -1
  29. package/esm/plugin-defn-fill-term.js +7 -0
  30. package/esm/plugin-defn-fill-term.js.map +1 -1
  31. package/esm/plugin-group-defn.js +6 -8
  32. package/esm/plugin-group-defn.js.map +1 -1
  33. package/esm/plugin-group-items.d.ts +4 -1
  34. package/esm/plugin-group-items.js +43 -9
  35. package/esm/plugin-group-items.js.map +1 -1
  36. package/esm/plugin-items.js +6 -5
  37. package/esm/plugin-items.js.map +1 -1
  38. package/esm/plugin-tables.js +33 -10
  39. package/esm/plugin-tables.js.map +1 -1
  40. package/esm/types.d.ts +1 -1
  41. package/esm/version.d.ts +1 -1
  42. package/esm/version.js +1 -1
  43. package/lib/ast-inerator.js +2 -4
  44. package/lib/codes/scan.js +26 -22
  45. package/lib/grammar.js +531 -416
  46. package/lib/helpers/flatten-deep.d.ts +2 -0
  47. package/lib/helpers/flatten-deep.js +35 -0
  48. package/lib/helpers/itemNumbering.d.ts +2 -1
  49. package/lib/helpers/itemNumbering.js +5 -3
  50. package/lib/helpers/makeInterator.js +3 -6
  51. package/lib/helpers/makeTransformer.js +2 -4
  52. package/lib/helpers/numberedShorthand.d.ts +2 -1
  53. package/lib/helpers/numberedShorthand.js +26 -5
  54. package/lib/index.d.ts +3 -0
  55. package/lib/index.js +7 -2
  56. package/lib/markup-code-letters.d.ts +2 -0
  57. package/lib/markup-code-letters.js +69 -0
  58. package/lib/pluggableParser.js +13 -5
  59. package/lib/plugin-defn-fill-term.js +7 -0
  60. package/lib/plugin-group-defn.js +6 -8
  61. package/lib/plugin-group-items.d.ts +4 -1
  62. package/lib/plugin-group-items.js +44 -12
  63. package/lib/plugin-items.js +5 -4
  64. package/lib/plugin-tables.js +37 -14
  65. package/lib/types.d.ts +1 -1
  66. package/lib/version.d.ts +1 -1
  67. package/lib/version.js +1 -1
  68. package/package.json +1 -1
  69. package/schema/AstTree.json +1 -0
  70. package/schema/PodliteDocument.json +1 -0
@@ -21,9 +21,7 @@ const config_1 = __importDefault(require("./helpers/config"));
21
21
  const scan_1 = require("./codes/scan");
22
22
  const configPropagation_1 = require("./helpers/configPropagation");
23
23
  const code_config_1 = require("./helpers/code-config");
24
- function flattenDeep(arr) {
25
- return arr.reduce((acc, val) => (Array.isArray(val) ? acc.concat(flattenDeep(val)) : acc.concat(val)), []);
26
- }
24
+ const flatten_deep_1 = require("./helpers/flatten-deep");
27
25
  // ─── CSV source for =table (spec §1672) ────────────────────────────────────
28
26
  // Parse CSV content per RFC 4180: comma delimiter, `"`-quoted fields with
29
27
  // `""` as embedded-quote escape. Supports LF or CRLF line endings. Leading
@@ -257,9 +255,12 @@ function normalizeCellCounts(tableNode, source = 'table', report = noReport) {
257
255
  if (expected === 0)
258
256
  return tableNode;
259
257
  let mutated = false;
258
+ // a report names its row by its place among the rows, the header and even rows counted
259
+ let rowNumber = 0;
260
260
  const newContent = tableNode.content.map(child => {
261
261
  if (!child || child.type !== 'block' || child.name !== 'row')
262
262
  return child;
263
+ rowNumber++;
263
264
  const cells = cellsOf(child);
264
265
  if (cells.length === expected)
265
266
  return child;
@@ -267,13 +268,13 @@ function normalizeCellCounts(tableNode, source = 'table', report = noReport) {
267
268
  const padding = [];
268
269
  for (let i = cells.length; i < expected; i++)
269
270
  padding.push(buildCellBlock(''));
270
- report('table-row-cells', `${source} row has ${cells.length} of ${expected} cells, padded with ${padding.length} empty. A row continued on the next line needs a blank line before the next row`, tableNode);
271
+ report('table-row-cells', `${source} row ${rowNumber} has ${cells.length} of ${expected} cells, padded with ${padding.length} empty. A row continued on the next line needs a blank line before the next row`, tableNode);
271
272
  mutated = true;
272
273
  return { ...child, content: [...child.content, ...padding] };
273
274
  }
274
275
  // cells.length > expected → truncate
275
276
  const dropped = cells.length - expected;
276
- report('table-row-cells', `${source} row has ${cells.length} of ${expected} cells, dropped ${dropped}`, tableNode);
277
+ report('table-row-cells', `${source} row ${rowNumber} has ${cells.length} of ${expected} cells, dropped ${dropped}`, tableNode);
277
278
  mutated = true;
278
279
  // Keep non-cell entries (e.g. blanklines) and the first `expected` cells
279
280
  let keepCells = expected;
@@ -392,10 +393,30 @@ const strbin = (str1, str2, cb) => {
392
393
  }
393
394
  return res.join('');
394
395
  };
395
- // Build a unified column-position mask across a set of lines. Used as a
396
- // fallback when a row spans multiple lines (continuation lines that align
397
- // content by character position rather than by separator). Returns a binary
398
- // string where `0` runs mark column ranges and `1` runs mark gaps.
396
+ // the norm puts a separator between every row on several lines, so the lines after the last one are a row too
397
+ const groupRows = (content) => {
398
+ const isTextRow = (c) => Boolean(c) && c.name === 'row' && c.type === 'text';
399
+ const groups = [[]];
400
+ content.forEach((c, i) => {
401
+ if (isTextRow(c))
402
+ groups[groups.length - 1].push(i);
403
+ else if (c && c.type === 'separator' && groups[groups.length - 1].length)
404
+ groups.push([]);
405
+ });
406
+ const filled = groups.filter(g => g.length);
407
+ if (filled.length < 2)
408
+ return content;
409
+ const firstOf = new Map(filled.map(g => [g[0], g]));
410
+ const merged = new Set(filled.flatMap(g => g.slice(1)));
411
+ return content.flatMap((c, i) => {
412
+ if (merged.has(i))
413
+ return [];
414
+ const group = firstOf.get(i);
415
+ if (!group || group.length === 1)
416
+ return [c];
417
+ return [{ ...c, value: group.map(k => content[k].value ?? '').join('') }];
418
+ });
419
+ };
399
420
  const makeMask = (lines, separators) => {
400
421
  const tmplLength = Math.max(...[...lines, ...separators].map(s => s.length));
401
422
  // a table held apart by spaces alone splits on two of them, as a row on one line
@@ -419,7 +440,7 @@ const makeMask = (lines, separators) => {
419
440
  // per-column substrings and aggregating across lines (continuation lines
420
441
  // append to the cell at the same column position).
421
442
  const extractColumnsByTemplate = (text, template) => {
422
- const lines = flattenDeep(text.split(/\n/).filter(s => s.length > 0));
443
+ const lines = (0, flatten_deep_1.flattenDeep)(text.split(/\n/).filter(s => s.length > 0));
423
444
  const cols = lines.map(line => {
424
445
  const re = /((1+|0+))/g;
425
446
  const columns = [];
@@ -621,6 +642,8 @@ exports.default = (opt = {}) => tree => {
621
642
  const recursed = visiter ? visiter(transformedContent, ctx) : transformedContent;
622
643
  return normalizeCellCounts({ ...attached, content: recursed }, 'table', report);
623
644
  }
645
+ const ownScope = scopes.get(node) || {};
646
+ node = { ...node, content: groupRows(node.content || []) };
624
647
  let rows = [];
625
648
  const collectValues = row => {
626
649
  rows.push(row.value);
@@ -642,9 +665,9 @@ exports.default = (opt = {}) => tree => {
642
665
  .split(/\n/) // split each row by eol
643
666
  .filter(str => str.length > 0); // filter empty strings ( after slit )
644
667
  // split each row into lines
645
- const lines = flattenDeep(rows.map(splitToLines));
646
- const separators = flattenDeep(seps.map(splitToLines));
647
- const codeScope = codeScopeOf(node, scopes.get(node) || {});
668
+ const lines = (0, flatten_deep_1.flattenDeep)(rows.map(splitToLines));
669
+ const separators = (0, flatten_deep_1.flattenDeep)(seps.map(splitToLines));
670
+ const codeScope = codeScopeOf(node, ownScope);
648
671
  const protect = (line) => protectCodes(line, codeScope);
649
672
  const masks = lines.map(protect);
650
673
  // Rule 3: warn on mixed separator types within a single table
@@ -697,7 +720,7 @@ exports.default = (opt = {}) => tree => {
697
720
  'row:text': row => {
698
721
  if (textRows.length == 1) {
699
722
  // the only text row of the table: each of its lines becomes its own row
700
- const textRowsLines = flattenDeep([row.value].map(splitToLines));
723
+ const textRowsLines = (0, flatten_deep_1.flattenDeep)([row.value].map(splitToLines));
701
724
  return textRowsLines.map(line => makeRow((byLines
702
725
  ? splitVisibleLine(line, protect(line))
703
726
  : splitsItself(line)
package/lib/types.d.ts CHANGED
@@ -148,7 +148,7 @@ export interface RootBlock extends Omit<Block, 'location'> {
148
148
  }
149
149
  export interface ParseDiagnostic {
150
150
  severity: 'warning';
151
- code: 'value-unreadable' | 'directive-unreadable' | 'table-row-cells' | 'table-cell-outside-row' | 'table-mixed-separators' | 'table-source-unreadable' | 'table-source-empty' | 'table-source-deferred' | 'markup-code-unclosed' | 'markup-code-longer-run' | 'markup-code-foreign-closer' | 'markup-code-reserved' | 'markup-code-unsupported' | 'markup-code-unreadable' | 'markup-code-too-deep';
151
+ code: 'value-unreadable' | 'directive-unreadable' | 'table-row-cells' | 'table-cell-outside-row' | 'table-mixed-separators' | 'table-source-unreadable' | 'table-source-empty' | 'table-source-deferred' | 'markup-code-unclosed' | 'markup-code-longer-run' | 'markup-code-foreign-closer' | 'markup-code-reserved' | 'markup-code-unsupported' | 'markup-code-unreadable' | 'markup-code-too-deep' | 'list-too-deep';
152
152
  message: string;
153
153
  location: Location;
154
154
  }
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const version = "0.0.83";
1
+ export declare const version = "0.0.85";
package/lib/version.js CHANGED
@@ -2,5 +2,5 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.version = void 0;
4
4
  // generated by scripts/inject-version.mjs — do not edit by hand
5
- exports.version = '0.0.83';
5
+ exports.version = '0.0.85';
6
6
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@podlite/schema",
3
- "version": "0.0.83",
3
+ "version": "0.0.85",
4
4
  "description": "Parser and AST schema for Podlite: typed blocks with positions, selectors, validate, traverse, and transform.",
5
5
  "main": "./lib/index.js",
6
6
  "sideEffects": false,
@@ -2154,6 +2154,7 @@
2154
2154
  "code": {
2155
2155
  "enum": [
2156
2156
  "directive-unreadable",
2157
+ "list-too-deep",
2157
2158
  "markup-code-foreign-closer",
2158
2159
  "markup-code-longer-run",
2159
2160
  "markup-code-reserved",
@@ -2154,6 +2154,7 @@
2154
2154
  "code": {
2155
2155
  "enum": [
2156
2156
  "directive-unreadable",
2157
+ "list-too-deep",
2157
2158
  "markup-code-foreign-closer",
2158
2159
  "markup-code-longer-run",
2159
2160
  "markup-code-reserved",