skip-cursor.js 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. /**
  2. * @fileoverview Define the cursor which ignores the first few tokens.
  3. * @author Toru Nagashima
  4. */
  5. "use strict";
  6. //------------------------------------------------------------------------------
  7. // Requirements
  8. //------------------------------------------------------------------------------
  9. const DecorativeCursor = require("./decorative-cursor");
  10. //------------------------------------------------------------------------------
  11. // Exports
  12. //------------------------------------------------------------------------------
  13. /**
  14. * The decorative cursor which ignores the first few tokens.
  15. */
  16. module.exports = class SkipCursor extends DecorativeCursor {
  17. /**
  18. * Initializes this cursor.
  19. * @param {Cursor} cursor The cursor to be decorated.
  20. * @param {number} count The count of tokens this cursor skips.
  21. */
  22. constructor(cursor, count) {
  23. super(cursor);
  24. this.count = count;
  25. }
  26. /** @inheritdoc */
  27. moveNext() {
  28. while (this.count > 0) {
  29. this.count -= 1;
  30. if (!super.moveNext()) {
  31. return false;
  32. }
  33. }
  34. return super.moveNext();
  35. }
  36. };