sequence.cjs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. 'use strict';
  2. const types = require('../tokenizer/types.cjs');
  3. function readSequence(recognizer) {
  4. const children = this.createList();
  5. let space = false;
  6. const context = {
  7. recognizer
  8. };
  9. while (!this.eof) {
  10. switch (this.tokenType) {
  11. case types.Comment:
  12. this.next();
  13. continue;
  14. case types.WhiteSpace:
  15. space = true;
  16. this.next();
  17. continue;
  18. }
  19. let child = recognizer.getNode.call(this, context);
  20. if (child === undefined) {
  21. break;
  22. }
  23. if (space) {
  24. if (recognizer.onWhiteSpace) {
  25. recognizer.onWhiteSpace.call(this, child, children, context);
  26. }
  27. space = false;
  28. }
  29. children.push(child);
  30. }
  31. if (space && recognizer.onWhiteSpace) {
  32. recognizer.onWhiteSpace.call(this, null, children, context);
  33. }
  34. return children;
  35. }
  36. exports.readSequence = readSequence;