@sasjs/lint
Version:
Linting and formatting for SAS code
46 lines • 1.87 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkIsDataLine = exports.getDataSectionsDetail = void 0;
const splitText_1 = require("./splitText");
const getDataSectionsDetail = (text, config) => {
const dataSections = [];
const lines = (0, splitText_1.splitText)(text, config);
const dataSectionStartRegex1 = new RegExp('^(datalines;)|(cards;)|(parmcards;)');
const dataSectionEndRegex1 = new RegExp(';');
const dataSectionStartRegex2 = new RegExp('^(datalines4;)|(cards4;)|(parmcards4;)');
const dataSectionEndRegex2 = new RegExp(';;;;');
let dataSectionStarted = false;
let dataSectionStartIndex = -1;
let dataSectionEndRegex = dataSectionEndRegex1;
lines.forEach((line, index) => {
if (dataSectionStarted) {
if (dataSectionEndRegex.test(line)) {
dataSections.push({ start: dataSectionStartIndex, end: index });
dataSectionStarted = false;
}
}
else {
if (dataSectionStartRegex1.test(line)) {
dataSectionStarted = true;
dataSectionStartIndex = index;
dataSectionEndRegex = dataSectionEndRegex1;
}
else if (dataSectionStartRegex2.test(line)) {
dataSectionStarted = true;
dataSectionStartIndex = index;
dataSectionEndRegex = dataSectionEndRegex2;
}
}
});
return dataSections;
};
exports.getDataSectionsDetail = getDataSectionsDetail;
const checkIsDataLine = (dataSections, lineIndex) => {
for (const dataSection of dataSections) {
if (lineIndex >= dataSection.start && lineIndex <= dataSection.end)
return true;
}
return false;
};
exports.checkIsDataLine = checkIsDataLine;
//# sourceMappingURL=getDataSectionsDetail.js.map