Parentheses.js 812 B

12345678910111213141516171819202122232425262728293031323334
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var LEFTPARENTHESIS = TYPE.LeftParenthesis;
  3. var RIGHTPARENTHESIS = TYPE.RightParenthesis;
  4. module.exports = {
  5. name: 'Parentheses',
  6. structure: {
  7. children: [[]]
  8. },
  9. parse: function(readSequence, recognizer) {
  10. var start = this.scanner.tokenStart;
  11. var children = null;
  12. this.eat(LEFTPARENTHESIS);
  13. children = readSequence.call(this, recognizer);
  14. if (!this.scanner.eof) {
  15. this.eat(RIGHTPARENTHESIS);
  16. }
  17. return {
  18. type: 'Parentheses',
  19. loc: this.getLocation(start, this.scanner.tokenStart),
  20. children: children
  21. };
  22. },
  23. generate: function(node) {
  24. this.chunk('(');
  25. this.children(node);
  26. this.chunk(')');
  27. }
  28. };