tarsec 0.1.4 → 0.1.6
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.
- package/dist/combinators.js +6 -5
- package/dist/trace.d.ts +2 -0
- package/dist/trace.js +40 -0
- package/package.json +1 -1
package/dist/combinators.js
CHANGED
|
@@ -876,9 +876,10 @@ export function parseError(_message, ...parsers) {
|
|
|
876
876
|
const prefix = "Near: ";
|
|
877
877
|
if (input.length > 0) {
|
|
878
878
|
const index = inputStr.length - input.length;
|
|
879
|
-
const start = Math.max(0,
|
|
880
|
-
const end = Math.min(inputStr.length,
|
|
881
|
-
|
|
879
|
+
const start = Math.max(0, index - 20);
|
|
880
|
+
const end = Math.min(inputStr.length, index + 20);
|
|
881
|
+
const previewStr = inputStr.substring(start, end).split("\n")[0];
|
|
882
|
+
messages.push(`${prefix}${previewStr}`);
|
|
882
883
|
messages.push(`${" ".repeat(index + prefix.length)}^`);
|
|
883
884
|
messages.push(_message);
|
|
884
885
|
const message = messages.join("\n");
|
|
@@ -889,9 +890,9 @@ export function parseError(_message, ...parsers) {
|
|
|
889
890
|
acc += lines[i].length;
|
|
890
891
|
i++;
|
|
891
892
|
}
|
|
892
|
-
const column = acc - index;
|
|
893
|
+
const column = lines[i - 1].length - (acc - index);
|
|
893
894
|
throw new TarsecError({
|
|
894
|
-
line: i,
|
|
895
|
+
line: i - 1,
|
|
895
896
|
column,
|
|
896
897
|
length: 1,
|
|
897
898
|
prettyMessage: message,
|
package/dist/trace.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { ParserResult, Parser, PlainObject, CaptureParser } from "./types.js";
|
|
2
|
+
export declare function setTraceHost(host: string): void;
|
|
3
|
+
export declare function getTraceHost(): string;
|
|
2
4
|
/**
|
|
3
5
|
* This function is used internally by the `trace` function to create the string for each step.
|
|
4
6
|
* @param name - debug name for parser
|
package/dist/trace.js
CHANGED
|
@@ -11,6 +11,13 @@ let debugFlag = isNode ? !!process.env.DEBUG : false;
|
|
|
11
11
|
let stepCount = 0;
|
|
12
12
|
let stepLimit = -1;
|
|
13
13
|
let debugMessages = [];
|
|
14
|
+
let traceHost = "";
|
|
15
|
+
export function setTraceHost(host) {
|
|
16
|
+
traceHost = host;
|
|
17
|
+
}
|
|
18
|
+
export function getTraceHost() {
|
|
19
|
+
return traceHost;
|
|
20
|
+
}
|
|
14
21
|
/**
|
|
15
22
|
* This function is used internally by the `trace` function to create the string for each step.
|
|
16
23
|
* @param name - debug name for parser
|
|
@@ -30,6 +37,22 @@ export function trace(name, parser) {
|
|
|
30
37
|
return (input) => {
|
|
31
38
|
if (debugFlag) {
|
|
32
39
|
console.log(" ".repeat(level) + `🔍 ${name} -- input: ${shorten(escape(input))}`);
|
|
40
|
+
if (traceHost && traceHost.length > 0) {
|
|
41
|
+
fetch(`${traceHost}/api/logs`, {
|
|
42
|
+
method: "POST",
|
|
43
|
+
headers: {
|
|
44
|
+
"Content-Type": "application/json",
|
|
45
|
+
},
|
|
46
|
+
body: JSON.stringify({
|
|
47
|
+
name,
|
|
48
|
+
type: "start",
|
|
49
|
+
level,
|
|
50
|
+
timestamp: Date.now(),
|
|
51
|
+
}),
|
|
52
|
+
}).catch((err) => {
|
|
53
|
+
console.error("Failed to send logs to server:", err);
|
|
54
|
+
});
|
|
55
|
+
}
|
|
33
56
|
let result;
|
|
34
57
|
const time = parserTime(() => {
|
|
35
58
|
level += STEP;
|
|
@@ -46,6 +69,23 @@ export function trace(name, parser) {
|
|
|
46
69
|
console.log(" ".repeat(level) +
|
|
47
70
|
`⭐ ${name} -- captures: ${JSON.stringify(result.captures)}`);
|
|
48
71
|
}
|
|
72
|
+
if (traceHost && traceHost.length > 0) {
|
|
73
|
+
fetch(`${traceHost}/api/logs`, {
|
|
74
|
+
method: "POST",
|
|
75
|
+
headers: {
|
|
76
|
+
"Content-Type": "application/json",
|
|
77
|
+
},
|
|
78
|
+
body: JSON.stringify({
|
|
79
|
+
name,
|
|
80
|
+
type: "end",
|
|
81
|
+
level,
|
|
82
|
+
timestamp: Date.now(),
|
|
83
|
+
result,
|
|
84
|
+
}),
|
|
85
|
+
}).catch((err) => {
|
|
86
|
+
console.error("Failed to send logs to server:", err);
|
|
87
|
+
});
|
|
88
|
+
}
|
|
49
89
|
return result;
|
|
50
90
|
}
|
|
51
91
|
else {
|