You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.3 KiB

4 years ago
  1. var TYPE = require('../tokenizer').TYPE;
  2. var WHITESPACE = TYPE.WhiteSpace;
  3. var COMMENT = TYPE.Comment;
  4. module.exports = function readSequence(recognizer) {
  5. var children = this.createList();
  6. var child = null;
  7. var context = {
  8. recognizer: recognizer,
  9. space: null,
  10. ignoreWS: false,
  11. ignoreWSAfter: false
  12. };
  13. this.scanner.skipSC();
  14. while (!this.scanner.eof) {
  15. switch (this.scanner.tokenType) {
  16. case COMMENT:
  17. this.scanner.next();
  18. continue;
  19. case WHITESPACE:
  20. if (context.ignoreWS) {
  21. this.scanner.next();
  22. } else {
  23. context.space = this.WhiteSpace();
  24. }
  25. continue;
  26. }
  27. child = recognizer.getNode.call(this, context);
  28. if (child === undefined) {
  29. break;
  30. }
  31. if (context.space !== null) {
  32. children.push(context.space);
  33. context.space = null;
  34. }
  35. children.push(child);
  36. if (context.ignoreWSAfter) {
  37. context.ignoreWSAfter = false;
  38. context.ignoreWS = true;
  39. } else {
  40. context.ignoreWS = false;
  41. }
  42. }
  43. return children;
  44. };