@herb-tools/core 0.2.0 → 0.3.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.
- package/CHANGELOG.md +4 -0
- package/dist/herb-core.browser.js +88 -79
- package/dist/herb-core.browser.js.map +1 -1
- package/dist/herb-core.cjs +89 -78
- package/dist/herb-core.cjs.map +1 -1
- package/dist/herb-core.esm.js +88 -79
- package/dist/herb-core.esm.js.map +1 -1
- package/dist/herb-core.umd.js +89 -78
- package/dist/herb-core.umd.js.map +1 -1
- package/dist/types/errors.d.ts +16 -2
- package/dist/types/index.d.ts +1 -1
- package/dist/types/lex-result.d.ts +13 -8
- package/dist/types/nodes.d.ts +32 -4
- package/dist/types/parse-result.d.ts +4 -4
- package/dist/types/result.d.ts +12 -4
- package/dist/types/visitor.d.ts +1 -2
- package/package.json +1 -1
- package/src/errors.ts +49 -14
- package/src/index.ts +1 -1
- package/src/lex-result.ts +15 -9
- package/src/nodes.ts +149 -39
- package/src/parse-result.ts +7 -5
- package/src/result.ts +14 -6
- package/src/visitor.ts +1 -2
- package/dist/types/error.d.ts +0 -16
- package/dist/types/node.d.ts +0 -30
- package/src/error.ts +0 -38
- package/src/node.ts +0 -109
package/src/error.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { Location, SerializedLocation } from "./location.js"
|
|
2
|
-
import { fromSerializedError } from "./errors.js"
|
|
3
|
-
|
|
4
|
-
export interface SerializedHerbError {
|
|
5
|
-
type: string
|
|
6
|
-
message: string
|
|
7
|
-
location: SerializedLocation
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export abstract class HerbError {
|
|
11
|
-
readonly type: string
|
|
12
|
-
readonly message: string
|
|
13
|
-
readonly location: Location
|
|
14
|
-
|
|
15
|
-
static from(error: SerializedHerbError): HerbError {
|
|
16
|
-
return fromSerializedError(error)
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
constructor(type: string, message: string, location: Location) {
|
|
20
|
-
this.type = type
|
|
21
|
-
this.message = message
|
|
22
|
-
this.location = location
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
toJSON(): SerializedHerbError {
|
|
26
|
-
return {
|
|
27
|
-
type: this.type,
|
|
28
|
-
message: this.message,
|
|
29
|
-
location: this.location.toJSON(),
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
inspect(): string {
|
|
34
|
-
return this.treeInspect(0)
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
abstract treeInspect(indent?: number): string
|
|
38
|
-
}
|
package/src/node.ts
DELETED
|
@@ -1,109 +0,0 @@
|
|
|
1
|
-
import { Location, SerializedLocation } from "./location.js"
|
|
2
|
-
import { HerbError, SerializedHerbError } from "./error.js"
|
|
3
|
-
import { NodeType, SerializedNodeType, fromSerializedNode } from "./nodes.js"
|
|
4
|
-
import type { Visitor } from "./visitor.js"
|
|
5
|
-
|
|
6
|
-
export interface SerializedNode {
|
|
7
|
-
type: SerializedNodeType
|
|
8
|
-
location: SerializedLocation
|
|
9
|
-
errors: SerializedHerbError[]
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
export interface BaseNodeProps {
|
|
13
|
-
type: NodeType
|
|
14
|
-
location: Location
|
|
15
|
-
errors: HerbError[]
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export abstract class Node implements BaseNodeProps {
|
|
19
|
-
readonly type: NodeType
|
|
20
|
-
readonly location: Location
|
|
21
|
-
readonly errors: HerbError[]
|
|
22
|
-
|
|
23
|
-
static from(node: SerializedNode): Node {
|
|
24
|
-
return fromSerializedNode(node)
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
constructor(type: NodeType, location: Location, errors: HerbError[]) {
|
|
28
|
-
this.type = type
|
|
29
|
-
this.location = location
|
|
30
|
-
this.errors = errors
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
toJSON(): SerializedNode {
|
|
34
|
-
return {
|
|
35
|
-
type: this.type,
|
|
36
|
-
location: this.location.toJSON(),
|
|
37
|
-
errors: this.errors,
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
inspect(): string {
|
|
42
|
-
return this.treeInspect(0)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
abstract treeInspect(indent?: number): string
|
|
46
|
-
abstract recursiveErrors(): HerbError[]
|
|
47
|
-
abstract accept(visitor: Visitor): void
|
|
48
|
-
abstract childNodes(): (Node | null | undefined)[]
|
|
49
|
-
abstract compactChildNodes(): Node[]
|
|
50
|
-
|
|
51
|
-
protected inspectArray(
|
|
52
|
-
array: (Node | HerbError)[] | null | undefined,
|
|
53
|
-
prefix: string,
|
|
54
|
-
): string {
|
|
55
|
-
if (!array) return "∅\n"
|
|
56
|
-
if (array.length === 0) return "[]\n"
|
|
57
|
-
|
|
58
|
-
let output = `(${array.length} item${array.length == 1 ? "" : "s"})\n`
|
|
59
|
-
|
|
60
|
-
array.forEach((item, index) => {
|
|
61
|
-
const isLast = index === array.length - 1
|
|
62
|
-
|
|
63
|
-
if (item instanceof Node || item instanceof HerbError) {
|
|
64
|
-
output += this.inspectNode(
|
|
65
|
-
item,
|
|
66
|
-
prefix,
|
|
67
|
-
isLast ? " " : "│ ",
|
|
68
|
-
isLast,
|
|
69
|
-
false,
|
|
70
|
-
)
|
|
71
|
-
} else {
|
|
72
|
-
const symbol = isLast ? "└── " : "├── "
|
|
73
|
-
output += `${prefix}${symbol} ${item}\n`
|
|
74
|
-
}
|
|
75
|
-
})
|
|
76
|
-
|
|
77
|
-
output += `${prefix}\n`
|
|
78
|
-
|
|
79
|
-
return output
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
protected inspectNode(
|
|
83
|
-
node: Node | HerbError | undefined | null,
|
|
84
|
-
prefix: string,
|
|
85
|
-
prefix2: string = " ",
|
|
86
|
-
last: boolean = true,
|
|
87
|
-
trailingNewline: boolean = true,
|
|
88
|
-
): string {
|
|
89
|
-
if (!node) return "∅\n"
|
|
90
|
-
|
|
91
|
-
let output = trailingNewline ? "\n" : ""
|
|
92
|
-
output += `${prefix}`
|
|
93
|
-
|
|
94
|
-
output += last ? "└── " : "├── "
|
|
95
|
-
output += node
|
|
96
|
-
.treeInspect()
|
|
97
|
-
.trimStart()
|
|
98
|
-
.split("\n")
|
|
99
|
-
.map((line, index) =>
|
|
100
|
-
index == 0 ? line.trimStart() : `${prefix}${prefix2}${line}`,
|
|
101
|
-
)
|
|
102
|
-
.join("\n")
|
|
103
|
-
.trimStart()
|
|
104
|
-
|
|
105
|
-
output += `\n`
|
|
106
|
-
|
|
107
|
-
return output
|
|
108
|
-
}
|
|
109
|
-
}
|