4 var common = require('./common');
7 function Mark(name, buffer, position, line, column) {
10 this.position = position;
16 Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
17 var head, start, tail, end, snippet;
19 if (!this.buffer) return null;
22 maxLength = maxLength || 75;
25 start = this.position;
27 while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
29 if (this.position - start > (maxLength / 2 - 1)) {
39 while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
41 if (end - this.position > (maxLength / 2 - 1)) {
48 snippet = this.buffer.slice(start, end);
50 return common.repeat(' ', indent) + head + snippet + tail + '\n' +
51 common.repeat(' ', indent + this.position - start + head.length) + '^';
55 Mark.prototype.toString = function toString(compact) {
56 var snippet, where = '';
59 where += 'in "' + this.name + '" ';
62 where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
65 snippet = this.getSnippet();
68 where += ':\n' + snippet;
76 module.exports = Mark;