tarsec 0.1.2 → 0.1.4

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.
@@ -880,13 +880,36 @@ export function parseError(_message, ...parsers) {
880
880
  const end = Math.min(inputStr.length, input.length + 20);
881
881
  messages.push(`${prefix}${inputStr.substring(start, end)}`);
882
882
  messages.push(`${" ".repeat(index + prefix.length)}^`);
883
+ messages.push(_message);
884
+ const message = messages.join("\n");
885
+ const lines = inputStr.split("\n");
886
+ let acc = 0;
887
+ let i = 0;
888
+ while (index > acc) {
889
+ acc += lines[i].length;
890
+ i++;
891
+ }
892
+ const column = acc - index;
893
+ throw new TarsecError({
894
+ line: i,
895
+ column,
896
+ length: 1,
897
+ prettyMessage: message,
898
+ message: _message,
899
+ });
883
900
  }
884
901
  else {
885
902
  messages.push(`${prefix}${input.substring(1, 100)}`);
903
+ messages.push(_message);
904
+ const message = messages.join("\n");
905
+ throw new TarsecError({
906
+ line: 0,
907
+ column: 0,
908
+ length: 0,
909
+ prettyMessage: message,
910
+ message: _message,
911
+ });
886
912
  }
887
- messages.push(_message);
888
- const message = messages.join("\n");
889
- throw new TarsecError(message);
890
913
  }
891
914
  };
892
915
  }
package/dist/index.d.ts CHANGED
@@ -2,3 +2,4 @@ export * from "./parsers.js";
2
2
  export * from "./combinators.js";
3
3
  export * from "./trace.js";
4
4
  export * from "./types.js";
5
+ export * from "./tarsecError.js";
package/dist/index.js CHANGED
@@ -2,3 +2,4 @@ export * from "./parsers.js";
2
2
  export * from "./combinators.js";
3
3
  export * from "./trace.js";
4
4
  export * from "./types.js";
5
+ export * from "./tarsecError.js";
@@ -1,3 +1,12 @@
1
+ type TarsecErrorData = {
2
+ line: number;
3
+ column: number;
4
+ length: number;
5
+ prettyMessage: string;
6
+ message: string;
7
+ };
1
8
  export declare class TarsecError extends Error {
2
- constructor(message: string);
9
+ data: TarsecErrorData;
10
+ constructor(error: TarsecErrorData);
3
11
  }
12
+ export {};
@@ -1,6 +1,7 @@
1
1
  export class TarsecError extends Error {
2
- constructor(message) {
3
- super(message);
2
+ constructor(error) {
3
+ super(error.message);
4
4
  this.name = "TarsecError";
5
+ this.data = error;
5
6
  }
6
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "tarsec",
3
- "version": "0.1.2",
3
+ "version": "0.1.4",
4
4
  "description": "A parser combinator library for TypeScript, inspired by Parsec.",
5
5
  "homepage": "https://github.com/egonSchiele/tarsec",
6
6
  "scripts": {