tarsec 0.1.6 → 0.1.8
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 +4 -3
- package/dist/trace.d.ts +1 -0
- package/dist/trace.js +20 -27
- package/package.json +1 -1
package/dist/combinators.js
CHANGED
|
@@ -874,7 +874,7 @@ export function parseError(_message, ...parsers) {
|
|
|
874
874
|
const inputStr = getInputStr();
|
|
875
875
|
const messages = [];
|
|
876
876
|
const prefix = "Near: ";
|
|
877
|
-
if (
|
|
877
|
+
if (inputStr.length > 0) {
|
|
878
878
|
const index = inputStr.length - input.length;
|
|
879
879
|
const start = Math.max(0, index - 20);
|
|
880
880
|
const end = Math.min(inputStr.length, index + 20);
|
|
@@ -886,11 +886,12 @@ export function parseError(_message, ...parsers) {
|
|
|
886
886
|
const lines = inputStr.split("\n");
|
|
887
887
|
let acc = 0;
|
|
888
888
|
let i = 0;
|
|
889
|
-
while (index
|
|
889
|
+
while (index >= acc) {
|
|
890
890
|
acc += lines[i].length;
|
|
891
891
|
i++;
|
|
892
892
|
}
|
|
893
|
-
const
|
|
893
|
+
const linesIndex = Math.max(0, i - 1);
|
|
894
|
+
const column = lines[linesIndex].length - (acc - index);
|
|
894
895
|
throw new TarsecError({
|
|
895
896
|
line: i - 1,
|
|
896
897
|
column,
|
package/dist/trace.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { ParserResult, Parser, PlainObject, CaptureParser } from "./types.js";
|
|
2
2
|
export declare function setTraceHost(host: string): void;
|
|
3
3
|
export declare function getTraceHost(): string;
|
|
4
|
+
export declare function setTraceId(id: string): void;
|
|
4
5
|
/**
|
|
5
6
|
* This function is used internally by the `trace` function to create the string for each step.
|
|
6
7
|
* @param name - debug name for parser
|
package/dist/trace.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { escape, round, shorten } from "./utils.js";
|
|
2
2
|
import process from "process";
|
|
3
|
+
import { execSync } from "child_process";
|
|
3
4
|
const isNode = typeof process !== "undefined" &&
|
|
4
5
|
process.versions != null &&
|
|
5
6
|
process.versions.node != null;
|
|
@@ -12,12 +13,16 @@ let stepCount = 0;
|
|
|
12
13
|
let stepLimit = -1;
|
|
13
14
|
let debugMessages = [];
|
|
14
15
|
let traceHost = "";
|
|
16
|
+
let traceId = "1";
|
|
15
17
|
export function setTraceHost(host) {
|
|
16
18
|
traceHost = host;
|
|
17
19
|
}
|
|
18
20
|
export function getTraceHost() {
|
|
19
21
|
return traceHost;
|
|
20
22
|
}
|
|
23
|
+
export function setTraceId(id) {
|
|
24
|
+
traceId = id;
|
|
25
|
+
}
|
|
21
26
|
/**
|
|
22
27
|
* This function is used internally by the `trace` function to create the string for each step.
|
|
23
28
|
* @param name - debug name for parser
|
|
@@ -38,20 +43,14 @@ export function trace(name, parser) {
|
|
|
38
43
|
if (debugFlag) {
|
|
39
44
|
console.log(" ".repeat(level) + `🔍 ${name} -- input: ${shorten(escape(input))}`);
|
|
40
45
|
if (traceHost && traceHost.length > 0) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
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);
|
|
46
|
+
const json = JSON.stringify({
|
|
47
|
+
traceId,
|
|
48
|
+
name,
|
|
49
|
+
type: "start",
|
|
50
|
+
level,
|
|
51
|
+
timestamp: Date.now(),
|
|
54
52
|
});
|
|
53
|
+
execSync(`curl -s -X POST -H "Content-Type: application/json" -d '${json}' ${traceHost}/api/logs`);
|
|
55
54
|
}
|
|
56
55
|
let result;
|
|
57
56
|
const time = parserTime(() => {
|
|
@@ -70,21 +69,15 @@ export function trace(name, parser) {
|
|
|
70
69
|
`⭐ ${name} -- captures: ${JSON.stringify(result.captures)}`);
|
|
71
70
|
}
|
|
72
71
|
if (traceHost && traceHost.length > 0) {
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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);
|
|
72
|
+
const json = JSON.stringify({
|
|
73
|
+
traceId,
|
|
74
|
+
name,
|
|
75
|
+
type: "end",
|
|
76
|
+
level,
|
|
77
|
+
timestamp: Date.now(),
|
|
78
|
+
result,
|
|
87
79
|
});
|
|
80
|
+
execSync(`curl -s -X POST -H "Content-Type: application/json" -d '${json}' ${traceHost}/api/logs`);
|
|
88
81
|
}
|
|
89
82
|
return result;
|
|
90
83
|
}
|