Function.js 974 B

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