parse.js 944 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. 'use strict';
  2. var xtend = require('xtend');
  3. var removePosition = require('unist-util-remove-position');
  4. module.exports = parse;
  5. var C_NEWLINE = '\n';
  6. var EXPRESSION_LINE_BREAKS = /\r\n|\r/g;
  7. /* Parse the bound file. */
  8. function parse() {
  9. var self = this;
  10. var value = String(self.file);
  11. var start = {line: 1, column: 1, offset: 0};
  12. var content = xtend(start);
  13. var node;
  14. /* Clean non-unix newlines: `\r\n` and `\r` are all
  15. * changed to `\n`. This should not affect positional
  16. * information. */
  17. value = value.replace(EXPRESSION_LINE_BREAKS, C_NEWLINE);
  18. if (value.charCodeAt(0) === 0xFEFF) {
  19. value = value.slice(1);
  20. content.column++;
  21. content.offset++;
  22. }
  23. node = {
  24. type: 'root',
  25. children: self.tokenizeBlock(value, content),
  26. position: {
  27. start: start,
  28. end: self.eof || xtend(start)
  29. }
  30. };
  31. if (!self.options.position) {
  32. removePosition(node, true);
  33. }
  34. return node;
  35. }