@herb-tools/core 0.1.1 → 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/src/lex-result.ts CHANGED
@@ -1,11 +1,17 @@
1
1
  import { Result } from "./result.js"
2
- import { TokenList, SerializedTokenList } from "./token-list.js"
2
+ import { TokenList } from "./token-list.js"
3
+ import { HerbError } from "./errors.js"
4
+ import { HerbWarning } from "./warning.js"
5
+
6
+ import type { SerializedHerbError } from "./errors.js"
7
+ import type { SerializedHerbWarning } from "./warning.js"
8
+ import type { SerializedTokenList } from "./token-list.js"
3
9
 
4
10
  export type SerializedLexResult = {
5
11
  tokens: SerializedTokenList
6
12
  source: string
7
- warnings: any[]
8
- errors: any[]
13
+ warnings: SerializedHerbWarning[]
14
+ errors: SerializedHerbError[]
9
15
  }
10
16
 
11
17
  /**
@@ -25,8 +31,8 @@ export class LexResult extends Result {
25
31
  return new LexResult(
26
32
  TokenList.from(result.tokens || []),
27
33
  result.source,
28
- result.warnings,
29
- result.errors,
34
+ result.warnings.map((warning) => HerbWarning.from(warning)),
35
+ result.errors.map((error) => HerbError.from(error)),
30
36
  )
31
37
  }
32
38
 
@@ -40,8 +46,8 @@ export class LexResult extends Result {
40
46
  constructor(
41
47
  value: TokenList,
42
48
  source: string,
43
- warnings: any[] = [],
44
- errors: any[] = [],
49
+ warnings: HerbWarning[] = [],
50
+ errors: HerbError[] = [],
45
51
  ) {
46
52
  super(source, warnings, errors)
47
53
  this.value = value
@@ -51,7 +57,7 @@ export class LexResult extends Result {
51
57
  * Determines if the lexing was successful.
52
58
  * @returns `true` if there are no errors, otherwise `false`.
53
59
  */
54
- override success(): boolean {
60
+ get successful(): boolean {
55
61
  return this.errors.length === 0
56
62
  }
57
63
 
@@ -59,7 +65,7 @@ export class LexResult extends Result {
59
65
  * Determines if the lexing failed.
60
66
  * @returns `true` if there are errors, otherwise `false`.
61
67
  */
62
- override failed(): boolean {
68
+ get failed(): boolean {
63
69
  return this.errors.length > 0
64
70
  }
65
71