parseman 0.41.0 → 0.42.1

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 (51) hide show
  1. package/dist/combinators/expect.d.ts.map +1 -1
  2. package/dist/combinators/grammar.d.ts.map +1 -1
  3. package/dist/combinators/literal.d.ts.map +1 -1
  4. package/dist/combinators/node.d.ts.map +1 -1
  5. package/dist/combinators/parser.d.ts +6 -0
  6. package/dist/combinators/parser.d.ts.map +1 -1
  7. package/dist/combinators/regex.d.ts.map +1 -1
  8. package/dist/combinators/scanTo.d.ts.map +1 -1
  9. package/dist/combinators/trivia-skip.d.ts.map +1 -1
  10. package/dist/compiler/codegen.d.ts +5 -0
  11. package/dist/compiler/codegen.d.ts.map +1 -1
  12. package/dist/compiler/inline-build.d.ts +1 -1
  13. package/dist/compiler/inline-build.d.ts.map +1 -1
  14. package/dist/compiler/line-index.d.ts +1 -15
  15. package/dist/compiler/line-index.d.ts.map +1 -1
  16. package/dist/compiler/linker.d.ts +1 -0
  17. package/dist/compiler/linker.d.ts.map +1 -1
  18. package/dist/cst/capture-buffer.d.ts.map +1 -1
  19. package/dist/index.cjs +483 -181
  20. package/dist/index.cjs.map +4 -4
  21. package/dist/index.d.ts +2 -2
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +483 -181
  24. package/dist/index.js.map +4 -4
  25. package/dist/language-service/index.cjs +48 -2
  26. package/dist/language-service/index.cjs.map +3 -3
  27. package/dist/language-service/index.js +48 -2
  28. package/dist/language-service/index.js.map +3 -3
  29. package/dist/line-index.d.ts +41 -0
  30. package/dist/line-index.d.ts.map +1 -0
  31. package/dist/plugin/index.cjs +646 -169
  32. package/dist/plugin/index.cjs.map +4 -4
  33. package/dist/plugin/index.d.ts.map +1 -1
  34. package/dist/plugin/index.js +646 -169
  35. package/dist/plugin/index.js.map +4 -4
  36. package/dist/recovery/scan.d.ts.map +1 -1
  37. package/dist/regex/first-set.d.ts.map +1 -1
  38. package/dist/run/index.cjs +47 -1
  39. package/dist/run/index.cjs.map +3 -3
  40. package/dist/run/index.d.ts +3 -2
  41. package/dist/run/index.d.ts.map +1 -1
  42. package/dist/run/index.js +47 -1
  43. package/dist/run/index.js.map +3 -3
  44. package/dist/spec/index.cjs +462 -327
  45. package/dist/spec/index.cjs.map +4 -4
  46. package/dist/spec/index.js +462 -327
  47. package/dist/spec/index.js.map +4 -4
  48. package/dist/types.d.ts +18 -0
  49. package/dist/types.d.ts.map +1 -1
  50. package/dist/version.d.ts +1 -1
  51. package/package.json +1 -1
@@ -24,6 +24,50 @@ __export(language_service_exports, {
24
24
  });
25
25
  module.exports = __toCommonJS(language_service_exports);
26
26
 
27
+ // src/line-index.ts
28
+ function recordLineRange(index, input, start, end) {
29
+ const lineStarts = index.lineStarts;
30
+ for (let i = start; i < end; i++) {
31
+ if (input.charCodeAt(i) === 10) lineStarts.push(i + 1);
32
+ }
33
+ }
34
+ function recordLineRangeFromContext(ctx, input, _startHint, end) {
35
+ if (!ctx.trackLines) return;
36
+ const from = ctx._lineScannedTo ?? 0;
37
+ if (end <= from) return;
38
+ const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
39
+ if (!index) return;
40
+ recordLineRange(index, input, from, end);
41
+ ctx._lineScannedTo = end;
42
+ }
43
+ function offsetToLineCol(index, offset) {
44
+ const { lineStarts } = index;
45
+ let lo = 0;
46
+ let hi = lineStarts.length - 1;
47
+ while (lo < hi) {
48
+ const mid = lo + hi + 1 >> 1;
49
+ if (lineStarts[mid] <= offset) lo = mid;
50
+ else hi = mid - 1;
51
+ }
52
+ return { line: lo + 1, col: offset - lineStarts[lo] + 1 };
53
+ }
54
+ function annotateSpan(span, index) {
55
+ const s = offsetToLineCol(index, span.start);
56
+ const e = offsetToLineCol(index, span.end);
57
+ return {
58
+ ...span,
59
+ startLine: s.line,
60
+ startColumn: s.col,
61
+ endLine: e.line,
62
+ endColumn: e.col
63
+ };
64
+ }
65
+ function annotateSpanFromLineContext(span, ctx) {
66
+ if (!ctx.trackLines) return span;
67
+ const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
68
+ return index ? annotateSpan(span, index) : span;
69
+ }
70
+
27
71
  // src/cst/capture-buffer.ts
28
72
  function cstCaptureActive(ctx) {
29
73
  return ctx._cstBuf !== void 0 || ctx._cstLeaves !== void 0;
@@ -124,7 +168,9 @@ function firstSetSentinel(fs) {
124
168
  function recoverScan(input, from, ctx, sync, expected) {
125
169
  let scanPos = from;
126
170
  while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
127
- const error = { _tag: "parseError", span: { start: from, end: scanPos }, expected };
171
+ const span = { start: from, end: scanPos };
172
+ if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
173
+ const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
128
174
  ctx._errors?.push(error);
129
175
  return { error, end: scanPos };
130
176
  }
@@ -431,7 +477,7 @@ function normalizeCstCollapse(collapse) {
431
477
  return typeof collapse === "function" ? collapse : void 0;
432
478
  }
433
479
  function buildCstNode(type, children, _fields, span, _rawChildren, _triviaLog, state) {
434
- return { _tag: "node", type, span: { start: span.start, end: span.end }, state: state ?? null, children: [...children] };
480
+ return { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children] };
435
481
  }
436
482
  function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, triviaLog, state) {
437
483
  if (typeof typeOrOptions === "string") {