Combinator.cjs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. const PLUSSIGN = 0x002B; // U+002B PLUS SIGN (+)
  4. const SOLIDUS = 0x002F; // U+002F SOLIDUS (/)
  5. const GREATERTHANSIGN = 0x003E; // U+003E GREATER-THAN SIGN (>)
  6. const TILDE = 0x007E; // U+007E TILDE (~)
  7. const name = 'Combinator';
  8. const structure = {
  9. name: String
  10. };
  11. // + | > | ~ | /deep/
  12. function parse() {
  13. const start = this.tokenStart;
  14. let name;
  15. switch (this.tokenType) {
  16. case types.WhiteSpace:
  17. name = ' ';
  18. break;
  19. case types.Delim:
  20. switch (this.charCodeAt(this.tokenStart)) {
  21. case GREATERTHANSIGN:
  22. case PLUSSIGN:
  23. case TILDE:
  24. this.next();
  25. break;
  26. case SOLIDUS:
  27. this.next();
  28. this.eatIdent('deep');
  29. this.eatDelim(SOLIDUS);
  30. break;
  31. default:
  32. this.error('Combinator is expected');
  33. }
  34. name = this.substrToCursor(start);
  35. break;
  36. }
  37. return {
  38. type: 'Combinator',
  39. loc: this.getLocation(start, this.tokenStart),
  40. name
  41. };
  42. }
  43. function generate(node) {
  44. this.tokenize(node.name);
  45. }
  46. exports.generate = generate;
  47. exports.name = name;
  48. exports.parse = parse;
  49. exports.structure = structure;