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