sequence.js 983 B

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