@bitloops/bl-transpiler
Version:
The one and only Bitloops Language transpiler
33 lines • 1.21 kB
JavaScript
export const produceMetadata = (ctx, visitor) => {
const { start, stop } = ctx;
let stopColumn;
// For lexer tokens start.column and stop.column are the same at ctx,
// but stop.stop and start.start are different (these are characters' indexes)
// if (start.column == stop.column) we use the difference of the indexes to find the stop column
// (lexer token is only a word, so it will be in the same line)
if (start.line === stop.line && start.column === stop.column)
stopColumn = stop.column + stop.stop - start.start + 1;
else
stopColumn = stop.column;
const metadata = {
start: {
line: start.line,
column: start.column + 1, // +1 because antlr4 starts counting columns from 0
},
end: {
line: stop.line,
column: stopColumn + 1, // +1 because antlr4 starts counting columns from 0
},
fileId: visitor.currentFile,
};
return metadata;
};
export const produceMetadataFromTo = (from, to) => {
const metadata = {
start: from?.start,
end: to?.end,
fileId: from?.fileId,
};
return metadata;
};
//# sourceMappingURL=metadata.js.map