GeneralEnclosed.cjs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. const name = 'GeneralEnclosed';
  4. const structure = {
  5. kind: String,
  6. function: [String, null],
  7. children: [[]]
  8. };
  9. // <function-token> <any-value> )
  10. // ( <any-value> )
  11. function parse(kind) {
  12. const start = this.tokenStart;
  13. let functionName = null;
  14. if (this.tokenType === types.Function) {
  15. functionName = this.consumeFunctionName();
  16. } else {
  17. this.eat(types.LeftParenthesis);
  18. }
  19. const children = this.parseWithFallback(
  20. () => {
  21. const startValueToken = this.tokenIndex;
  22. const children = this.readSequence(this.scope.Value);
  23. if (this.eof === false &&
  24. this.isBalanceEdge(startValueToken) === false) {
  25. this.error();
  26. }
  27. return children;
  28. },
  29. () => this.createSingleNodeList(
  30. this.Raw(null, false)
  31. )
  32. );
  33. if (!this.eof) {
  34. this.eat(types.RightParenthesis);
  35. }
  36. return {
  37. type: 'GeneralEnclosed',
  38. loc: this.getLocation(start, this.tokenStart),
  39. kind,
  40. function: functionName,
  41. children
  42. };
  43. }
  44. function generate(node) {
  45. if (node.function) {
  46. this.token(types.Function, node.function + '(');
  47. } else {
  48. this.token(types.LeftParenthesis, '(');
  49. }
  50. this.children(node);
  51. this.token(types.RightParenthesis, ')');
  52. }
  53. exports.generate = generate;
  54. exports.name = name;
  55. exports.parse = parse;
  56. exports.structure = structure;