blob: 44647e5d0f617e1d8f92f422999793bde6bcfe0b [file] [log] [blame]
Tim van der Lippe706ec962021-06-04 13:24:42 +01001var TYPE = require('../tokenizer').TYPE;
2var WHITESPACE = TYPE.WhiteSpace;
3var COMMENT = TYPE.Comment;
4
5module.exports = function readSequence(recognizer) {
6 var children = this.createList();
7 var child = null;
8 var context = {
9 recognizer: recognizer,
10 space: null,
11 ignoreWS: false,
12 ignoreWSAfter: false
13 };
14
15 this.scanner.skipSC();
16
17 while (!this.scanner.eof) {
18 switch (this.scanner.tokenType) {
19 case COMMENT:
20 this.scanner.next();
21 continue;
22
23 case WHITESPACE:
24 if (context.ignoreWS) {
25 this.scanner.next();
26 } else {
27 context.space = this.WhiteSpace();
28 }
29 continue;
30 }
31
32 child = recognizer.getNode.call(this, context);
33
34 if (child === undefined) {
35 break;
36 }
37
38 if (context.space !== null) {
39 children.push(context.space);
40 context.space = null;
41 }
42
43 children.push(child);
44
45 if (context.ignoreWSAfter) {
46 context.ignoreWSAfter = false;
47 context.ignoreWS = true;
48 } else {
49 context.ignoreWS = false;
50 }
51 }
52
53 return children;
54};