2020-03-07 11:45:40 +08:00
|
|
|
/**
|
|
|
|
* @fileoverview Define the cursor which limits the number of tokens.
|
|
|
|
* @author Toru Nagashima
|
|
|
|
*/
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Requirements
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
const DecorativeCursor = require("./decorative-cursor");
|
|
|
|
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
// Exports
|
|
|
|
//------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The decorative cursor which limits the number of tokens.
|
|
|
|
*/
|
|
|
|
module.exports = class LimitCursor extends DecorativeCursor {
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Initializes this cursor.
|
2020-03-31 20:40:00 +08:00
|
|
|
* @param {Cursor} cursor The cursor to be decorated.
|
|
|
|
* @param {number} count The count of tokens this cursor iterates.
|
2020-03-07 11:45:40 +08:00
|
|
|
*/
|
|
|
|
constructor(cursor, count) {
|
|
|
|
super(cursor);
|
|
|
|
this.count = count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/** @inheritdoc */
|
|
|
|
moveNext() {
|
|
|
|
if (this.count > 0) {
|
|
|
|
this.count -= 1;
|
|
|
|
return super.moveNext();
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|