-
Notifications
You must be signed in to change notification settings - Fork 10
/
parser.js
42 lines (36 loc) · 1.01 KB
/
parser.js
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
36
37
38
39
40
41
42
// @ts-check
'use strict';
module.exports = class Parser {
debug = typeof process === 'object' && process.env.DEBUG_PARSER
/** @typedef {import('./scanner')} Scanner */
/**
* @typedef {object} State
* @prop {(type: string, space: string, text: string, sc: Scanner) => State} next
*/
/**
* @param {State} generator
*/
constructor (generator) {
this.generator = generator;
}
/**
* @param {string} type
* @param {string} space
* @param {string} text
* @param {Scanner} scanner
* @returns {Parser}
*/
next(type, space, text, scanner) {
var prior = this.generator.constructor.name;
this.generator = this.generator.next(type, space, text, scanner);
if (this.debug) {
console.error(
'PAR',
scanner.position(),
type, JSON.stringify(text),
prior + '->' + this.generator.constructor.name
);
}
return this;
}
}