You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

40 lines
1.0 KiB

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