Function.cjs 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. const types = require('../../tokenizer/types.cjs');
  3. const name = 'Function';
  4. const walkContext = 'function';
  5. const structure = {
  6. name: String,
  7. children: [[]]
  8. };
  9. // <function-token> <sequence> )
  10. function parse(readSequence, recognizer) {
  11. const start = this.tokenStart;
  12. const name = this.consumeFunctionName();
  13. const nameLowerCase = name.toLowerCase();
  14. let children;
  15. children = recognizer.hasOwnProperty(nameLowerCase)
  16. ? recognizer[nameLowerCase].call(this, recognizer)
  17. : readSequence.call(this, recognizer);
  18. if (!this.eof) {
  19. this.eat(types.RightParenthesis);
  20. }
  21. return {
  22. type: 'Function',
  23. loc: this.getLocation(start, this.tokenStart),
  24. name,
  25. children
  26. };
  27. }
  28. function generate(node) {
  29. this.token(types.Function, node.name + '(');
  30. this.children(node);
  31. this.token(types.RightParenthesis, ')');
  32. }
  33. exports.generate = generate;
  34. exports.name = name;
  35. exports.parse = parse;
  36. exports.structure = structure;
  37. exports.walkContext = walkContext;