Brackets.js 818 B

12345678910111213141516171819202122232425262728293031323334
  1. var TYPE = require('../../tokenizer').TYPE;
  2. var LEFTSQUAREBRACKET = TYPE.LeftSquareBracket;
  3. var RIGHTSQUAREBRACKET = TYPE.RightSquareBracket;
  4. module.exports = {
  5. name: 'Brackets',
  6. structure: {
  7. children: [[]]
  8. },
  9. parse: function(readSequence, recognizer) {
  10. var start = this.scanner.tokenStart;
  11. var children = null;
  12. this.eat(LEFTSQUAREBRACKET);
  13. children = readSequence.call(this, recognizer);
  14. if (!this.scanner.eof) {
  15. this.eat(RIGHTSQUAREBRACKET);
  16. }
  17. return {
  18. type: 'Brackets',
  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. };