Brackets.js 685 B

1234567891011121314151617181920212223242526272829303132333435
  1. import {
  2. Delim,
  3. LeftSquareBracket,
  4. RightSquareBracket
  5. } from '../../tokenizer/index.js';
  6. export const name = 'Brackets';
  7. export const structure = {
  8. children: [[]]
  9. };
  10. export function parse(readSequence, recognizer) {
  11. const start = this.tokenStart;
  12. let children = null;
  13. this.eat(LeftSquareBracket);
  14. children = readSequence.call(this, recognizer);
  15. if (!this.eof) {
  16. this.eat(RightSquareBracket);
  17. }
  18. return {
  19. type: 'Brackets',
  20. loc: this.getLocation(start, this.tokenStart),
  21. children
  22. };
  23. }
  24. export function generate(node) {
  25. this.token(Delim, '[');
  26. this.children(node);
  27. this.token(Delim, ']');
  28. }