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.

89 lines
1.9 KiB

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