MCPcopy Create free account
hub / github.com/marijnh/Eloquent-JavaScript / Stream

Class Stream

src/pseudo_json.mjs:1–27  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1class Stream {
2 constructor(str) {
3 this.str = str
4 this.pos = 0
5 }
6
7 err(msg) {
8 throw new SyntaxError(msg + " at " + this.pos + " in " + JSON.stringify(this.str))
9 }
10
11 space() {
12 for (;;) {
13 let next = this.next
14 if (next == 32 || next == 9 || next == 10 || next == 13) this.pos++
15 else break
16 }
17 }
18
19 get next() {
20 return this.str.charCodeAt(this.pos)
21 }
22
23 ahead(n) {
24 this.pos += n
25 this.space()
26 }
27}
28
29export function parse(str) {
30 let stream = new Stream(str)

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected