| 1 | class 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 | |
| 29 | export function parse(str) { |
| 30 | let stream = new Stream(str) |
nothing calls this directly
no outgoing calls
no test coverage detected