This commit is contained in:
Felix Roos 2022-02-21 01:00:12 +01:00
parent 3b248ae94c
commit 966de74d5b
10 changed files with 301 additions and 39 deletions

View file

@ -1936,6 +1936,7 @@ function peg$parse(input, options) {
this.type_ = "element";
this.source_ = source;
this.options_ = options;
this.location_ = location();
}
var CommandStub = function(name, options)

View file

@ -604,6 +604,30 @@ Pattern.prototype.bootstrap = () => {
}));
return bootstrapped;
};
function withLocationOffset(pat, offset) {
let startLine;
return pat.fmap((value) => {
value = typeof value === "object" && !Array.isArray(value) ? value : {value};
let locations = value.locations || [];
startLine = startLine || locations[0].start.line;
locations = locations.map(({start, end}) => {
const colOffset = startLine === end.line ? offset.start.column : 0;
return {
start: {
...start,
line: start.line - 1 + (offset.start.line - 1) + 1,
column: start.column - 1 + colOffset
},
end: {
...end,
line: end.line - 1 + (offset.start.line - 1) + 1,
column: end.column - 1 + colOffset
}
};
});
return {...value, locations};
});
}
export {
Fraction,
TimeSpan,
@ -641,5 +665,6 @@ export {
struct,
mask,
invert,
inv
inv,
withLocationOffset
};