| 6 | export const pluginsLoose = {} |
| 7 | |
| 8 | export class LooseParser { |
| 9 | constructor(input, options = {}) { |
| 10 | this.toks = tokenizer(input, options) |
| 11 | this.options = this.toks.options |
| 12 | this.input = this.toks.input |
| 13 | this.tok = this.last = {type: tt.eof, start: 0, end: 0} |
| 14 | this.tok.validateRegExpFlags = noop |
| 15 | this.tok.validateRegExpPattern = noop |
| 16 | if (this.options.locations) { |
| 17 | let here = this.toks.curPosition() |
| 18 | this.tok.loc = new SourceLocation(this.toks, here, here) |
| 19 | } |
| 20 | this.ahead = [] // Tokens ahead |
| 21 | this.context = [] // Indentation contexted |
| 22 | this.curIndent = 0 |
| 23 | this.curLineStart = 0 |
| 24 | this.nextLineStart = this.lineEnd(this.curLineStart) + 1 |
| 25 | this.inAsync = false |
| 26 | // Load plugins |
| 27 | this.options.pluginsLoose = options.pluginsLoose || {} |
| 28 | this.loadPlugins(this.options.pluginsLoose) |
| 29 | } |
| 30 | |
| 31 | startNode() { |
| 32 | return new Node(this.toks, this.tok.start, this.options.locations ? this.tok.loc.start : null) |
| 33 | } |
| 34 | |
| 35 | storeCurrentPos() { |
| 36 | return this.options.locations ? [this.tok.start, this.tok.loc.start] : this.tok.start |
| 37 | } |
| 38 | |
| 39 | startNodeAt(pos) { |
| 40 | if (this.options.locations) { |
| 41 | return new Node(this.toks, pos[0], pos[1]) |
| 42 | } else { |
| 43 | return new Node(this.toks, pos) |
| 44 | } |
| 45 | } |
| 46 | |
| 47 | finishNode(node, type) { |
| 48 | node.type = type |
| 49 | node.end = this.last.end |
| 50 | if (this.options.locations) |
| 51 | node.loc.end = this.last.loc.end |
| 52 | if (this.options.ranges) |
| 53 | node.range[1] = this.last.end |
| 54 | return node |
| 55 | } |
| 56 | |
| 57 | dummyNode(type) { |
| 58 | let dummy = this.startNode() |
| 59 | dummy.type = type |
| 60 | dummy.end = dummy.start |
| 61 | if (this.options.locations) |
| 62 | dummy.loc.end = dummy.loc.start |
| 63 | if (this.options.ranges) |
| 64 | dummy.range[1] = dummy.start |
| 65 | this.last = {type: tt.name, start: dummy.start, end: dummy.start, loc: dummy.loc} |
nothing calls this directly
no outgoing calls
no test coverage detected
searching dependent graphs…