DeclarationList.js 1.2 KB

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