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.

49 lines
1.2 KiB

4 years ago
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var rawMode = require('./Raw').mode;
  3. var WHITESPACE = TYPE.WhiteSpace;
  4. var COMMENT = TYPE.Comment;
  5. var SEMICOLON = TYPE.Semicolon;
  6. function consumeRaw(startToken) {
  7. return this.Raw(startToken, rawMode.semicolonIncluded, true);
  8. }
  9. module.exports = {
  10. name: 'DeclarationList',
  11. structure: {
  12. children: [[
  13. 'Declaration'
  14. ]]
  15. },
  16. parse: function() {
  17. var children = this.createList();
  18. scan:
  19. while (!this.scanner.eof) {
  20. switch (this.scanner.tokenType) {
  21. case WHITESPACE:
  22. case COMMENT:
  23. case SEMICOLON:
  24. this.scanner.next();
  25. break;
  26. default:
  27. children.push(this.parseWithFallback(this.Declaration, consumeRaw));
  28. }
  29. }
  30. return {
  31. type: 'DeclarationList',
  32. loc: this.getLocationFromList(children),
  33. children: children
  34. };
  35. },
  36. generate: function(node) {
  37. this.children(node, function(prev) {
  38. if (prev.type === 'Declaration') {
  39. this.chunk(';');
  40. }
  41. });
  42. }
  43. };