supports.js 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var WHITESPACE = TYPE.WhiteSpace;
  3. var COMMENT = TYPE.Comment;
  4. var IDENTIFIER = TYPE.Identifier;
  5. var FUNCTION = TYPE.Function;
  6. var LEFTPARENTHESIS = TYPE.LeftParenthesis;
  7. var HYPHENMINUS = TYPE.HyphenMinus;
  8. var COLON = TYPE.Colon;
  9. function consumeRaw() {
  10. return this.createSingleNodeList(
  11. this.Raw(this.scanner.currentToken, 0, 0, false, false)
  12. );
  13. }
  14. function parentheses() {
  15. var index = 0;
  16. this.scanner.skipSC();
  17. // TODO: make it simplier
  18. if (this.scanner.tokenType === IDENTIFIER) {
  19. index = 1;
  20. } else if (this.scanner.tokenType === HYPHENMINUS &&
  21. this.scanner.lookupType(1) === IDENTIFIER) {
  22. index = 2;
  23. }
  24. if (index !== 0 && this.scanner.lookupNonWSType(index) === COLON) {
  25. return this.createSingleNodeList(
  26. this.Declaration()
  27. );
  28. }
  29. return readSequence.call(this);
  30. }
  31. function readSequence() {
  32. var children = this.createList();
  33. var space = null;
  34. var child;
  35. this.scanner.skipSC();
  36. scan:
  37. while (!this.scanner.eof) {
  38. switch (this.scanner.tokenType) {
  39. case WHITESPACE:
  40. space = this.WhiteSpace();
  41. continue;
  42. case COMMENT:
  43. this.scanner.next();
  44. continue;
  45. case FUNCTION:
  46. child = this.Function(consumeRaw, this.scope.AtrulePrelude);
  47. break;
  48. case IDENTIFIER:
  49. child = this.Identifier();
  50. break;
  51. case LEFTPARENTHESIS:
  52. child = this.Parentheses(parentheses, this.scope.AtrulePrelude);
  53. break;
  54. default:
  55. break scan;
  56. }
  57. if (space !== null) {
  58. children.push(space);
  59. space = null;
  60. }
  61. children.push(child);
  62. }
  63. return children;
  64. }
  65. module.exports = {
  66. parse: {
  67. prelude: function() {
  68. var children = readSequence.call(this);
  69. if (this.getFirstListNode(children) === null) {
  70. this.scanner.error('Condition is expected');
  71. }
  72. return children;
  73. },
  74. block: function() {
  75. return this.Block(false);
  76. }
  77. }
  78. };