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.

34 lines
812 B

4 years ago
  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. };