1 | /**
|
2 | * @fileoverview Define the cursor which ignores specified tokens.
|
3 | * @author Toru Nagashima
|
4 | */
|
5 | ;
|
6 |
|
7 | //------------------------------------------------------------------------------
|
8 | // Requirements
|
9 | //------------------------------------------------------------------------------
|
10 |
|
11 | const DecorativeCursor = require("./decorative-cursor");
|
12 |
|
13 | //------------------------------------------------------------------------------
|
14 | // Exports
|
15 | //------------------------------------------------------------------------------
|
16 |
|
17 | /**
|
18 | * The decorative cursor which ignores specified tokens.
|
19 | */
|
20 | module.exports = class FilterCursor extends DecorativeCursor {
|
21 |
|
22 | /**
|
23 | * Initializes this cursor.
|
24 | * @param {Cursor} cursor - The cursor to be decorated.
|
25 | * @param {Function} predicate - The predicate function to decide tokens this cursor iterates.
|
26 | */
|
27 | constructor(cursor, predicate) {
|
28 | super(cursor);
|
29 | this.predicate = predicate;
|
30 | }
|
31 |
|
32 | /** @inheritdoc */
|
33 | moveNext() {
|
34 | const predicate = this.predicate;
|
35 |
|
36 | while (super.moveNext()) {
|
37 | if (predicate(this.current)) {
|
38 | return true;
|
39 | }
|
40 | }
|
41 | return false;
|
42 | }
|
43 | };
|