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
818 B

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