feature.cjs 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. 'use strict';
  2. const types = require('../../../tokenizer/types.cjs');
  3. const structure = {
  4. name: String,
  5. value: ['Identifier', 'Number', 'Dimension', 'Ratio', null]
  6. };
  7. function createParse(type) {
  8. return function parse() {
  9. const start = this.tokenStart;
  10. let name;
  11. let value = null;
  12. this.eat(types.LeftParenthesis);
  13. this.skipSC();
  14. name = this.consume(types.Ident);
  15. this.skipSC();
  16. if (this.tokenType !== types.RightParenthesis) {
  17. this.eat(types.Colon);
  18. this.skipSC();
  19. switch (this.tokenType) {
  20. case types.Number:
  21. if (this.lookupNonWSType(1) === types.Delim) {
  22. value = this.Ratio();
  23. } else {
  24. value = this.Number();
  25. }
  26. break;
  27. case types.Dimension:
  28. value = this.Dimension();
  29. break;
  30. case types.Ident:
  31. value = this.Identifier();
  32. break;
  33. default:
  34. this.error('Number, dimension, ratio or identifier is expected');
  35. }
  36. this.skipSC();
  37. }
  38. this.eat(types.RightParenthesis);
  39. return {
  40. type,
  41. loc: this.getLocation(start, this.tokenStart),
  42. name,
  43. value
  44. };
  45. };
  46. }
  47. function generate(node) {
  48. this.token(types.LeftParenthesis, '(');
  49. this.token(types.Ident, node.name);
  50. if (node.value !== null) {
  51. this.token(types.Colon, ':');
  52. this.node(node.value);
  53. }
  54. this.token(types.RightParenthesis, ')');
  55. }
  56. exports.createParse = createParse;
  57. exports.generate = generate;
  58. exports.structure = structure;