-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathParserSuccess.ts
More file actions
35 lines (28 loc) · 819 Bytes
/
Copy pathParserSuccess.ts
File metadata and controls
35 lines (28 loc) · 819 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import ParserLocation from "./ParserLocation.ts";
export default class ParserSuccess<A> {
constructor(
public readonly data: A,
private readonly consumedCount: number
) {}
hasConsumed(): boolean {
return this.consumedCount > 0;
}
map<B>(f: (a: A) => B): ParserSuccess<B> {
return new ParserSuccess(f(this.data), this.consumedCount);
}
advance(loc: ParserLocation): ParserLocation {
return loc.advance(this.consumedCount);
}
append<B>(b: ParserSuccess<B>): ParserSuccess<[A, B]> {
return new ParserSuccess(
[this.data, b.data],
this.consumedCount + b.consumedCount
);
}
asSliceAt(loc: ParserLocation) {
return new ParserSuccess(loc.peek(this.consumedCount), this.consumedCount);
}
get consumed(): number {
return this.consumedCount;
}
}