UNPKG

@bitloops/bl-transpiler

Version:
38 lines 1.44 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.produceMetadataFromTo = exports.produceMetadata = void 0; 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; }; exports.produceMetadata = produceMetadata; const produceMetadataFromTo = (from, to) => { const metadata = { start: from?.start, end: to?.end, fileId: from?.fileId, }; return metadata; }; exports.produceMetadataFromTo = produceMetadataFromTo; //# sourceMappingURL=metadata.js.map