parseman 0.41.0 → 0.42.0

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 (46) 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/regex.d.ts.map +1 -1
  6. package/dist/combinators/scanTo.d.ts.map +1 -1
  7. package/dist/combinators/trivia-skip.d.ts.map +1 -1
  8. package/dist/compiler/codegen.d.ts +3 -0
  9. package/dist/compiler/codegen.d.ts.map +1 -1
  10. package/dist/compiler/inline-build.d.ts +1 -1
  11. package/dist/compiler/inline-build.d.ts.map +1 -1
  12. package/dist/compiler/line-index.d.ts +1 -15
  13. package/dist/compiler/line-index.d.ts.map +1 -1
  14. package/dist/cst/capture-buffer.d.ts.map +1 -1
  15. package/dist/index.cjs +364 -99
  16. package/dist/index.cjs.map +4 -4
  17. package/dist/index.d.ts +2 -2
  18. package/dist/index.d.ts.map +1 -1
  19. package/dist/index.js +364 -99
  20. package/dist/index.js.map +4 -4
  21. package/dist/language-service/index.cjs +48 -2
  22. package/dist/language-service/index.cjs.map +3 -3
  23. package/dist/language-service/index.js +48 -2
  24. package/dist/language-service/index.js.map +3 -3
  25. package/dist/line-index.d.ts +41 -0
  26. package/dist/line-index.d.ts.map +1 -0
  27. package/dist/plugin/index.cjs +334 -93
  28. package/dist/plugin/index.cjs.map +4 -4
  29. package/dist/plugin/index.js +334 -93
  30. package/dist/plugin/index.js.map +4 -4
  31. package/dist/recovery/scan.d.ts.map +1 -1
  32. package/dist/regex/first-set.d.ts.map +1 -1
  33. package/dist/run/index.cjs +47 -1
  34. package/dist/run/index.cjs.map +3 -3
  35. package/dist/run/index.d.ts +3 -2
  36. package/dist/run/index.d.ts.map +1 -1
  37. package/dist/run/index.js +47 -1
  38. package/dist/run/index.js.map +3 -3
  39. package/dist/spec/index.cjs +170 -50
  40. package/dist/spec/index.cjs.map +4 -4
  41. package/dist/spec/index.js +170 -50
  42. package/dist/spec/index.js.map +4 -4
  43. package/dist/types.d.ts +12 -0
  44. package/dist/types.d.ts.map +1 -1
  45. package/dist/version.d.ts +1 -1
  46. package/package.json +1 -1
@@ -1,3 +1,47 @@
1
+ // src/line-index.ts
2
+ function recordLineRange(index, input, start, end) {
3
+ const lineStarts = index.lineStarts;
4
+ for (let i = start; i < end; i++) {
5
+ if (input.charCodeAt(i) === 10) lineStarts.push(i + 1);
6
+ }
7
+ }
8
+ function recordLineRangeFromContext(ctx, input, _startHint, end) {
9
+ if (!ctx.trackLines) return;
10
+ const from = ctx._lineScannedTo ?? 0;
11
+ if (end <= from) return;
12
+ const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
13
+ if (!index) return;
14
+ recordLineRange(index, input, from, end);
15
+ ctx._lineScannedTo = end;
16
+ }
17
+ function offsetToLineCol(index, offset) {
18
+ const { lineStarts } = index;
19
+ let lo = 0;
20
+ let hi = lineStarts.length - 1;
21
+ while (lo < hi) {
22
+ const mid = lo + hi + 1 >> 1;
23
+ if (lineStarts[mid] <= offset) lo = mid;
24
+ else hi = mid - 1;
25
+ }
26
+ return { line: lo + 1, col: offset - lineStarts[lo] + 1 };
27
+ }
28
+ function annotateSpan(span, index) {
29
+ const s = offsetToLineCol(index, span.start);
30
+ const e = offsetToLineCol(index, span.end);
31
+ return {
32
+ ...span,
33
+ startLine: s.line,
34
+ startColumn: s.col,
35
+ endLine: e.line,
36
+ endColumn: e.col
37
+ };
38
+ }
39
+ function annotateSpanFromLineContext(span, ctx) {
40
+ if (!ctx.trackLines) return span;
41
+ const index = ctx._lineIndex ?? (ctx._lineStarts ? { lineStarts: ctx._lineStarts } : void 0);
42
+ return index ? annotateSpan(span, index) : span;
43
+ }
44
+
1
45
  // src/cst/capture-buffer.ts
2
46
  function cstCaptureActive(ctx) {
3
47
  return ctx._cstBuf !== void 0 || ctx._cstLeaves !== void 0;
@@ -98,7 +142,9 @@ function firstSetSentinel(fs) {
98
142
  function recoverScan(input, from, ctx, sync, expected) {
99
143
  let scanPos = from;
100
144
  while (scanPos < input.length && !probeAt(sync, input, scanPos, ctx)) scanPos++;
101
- const error = { _tag: "parseError", span: { start: from, end: scanPos }, expected };
145
+ const span = { start: from, end: scanPos };
146
+ if (ctx.trackLines) recordLineRangeFromContext(ctx, input, from, scanPos);
147
+ const error = { _tag: "parseError", span: ctx.trackLines ? annotateSpanFromLineContext(span, ctx) : span, expected };
102
148
  ctx._errors?.push(error);
103
149
  return { error, end: scanPos };
104
150
  }
@@ -405,7 +451,7 @@ function normalizeCstCollapse(collapse) {
405
451
  return typeof collapse === "function" ? collapse : void 0;
406
452
  }
407
453
  function buildCstNode(type, children, _fields, span, _rawChildren, _triviaLog, state) {
408
- return { _tag: "node", type, span: { start: span.start, end: span.end }, state: state ?? null, children: [...children] };
454
+ return { _tag: "node", type, span: { ...span }, state: state ?? null, children: [...children] };
409
455
  }
410
456
  function cstBuildHost(typeOrOptions, children, _fields, span, rawChildren, triviaLog, state) {
411
457
  if (typeof typeOrOptions === "string") {