@abaplint/core
Version:
abaplint - Core API
61 lines • 2.68 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StructureParser = void 0;
const _statement_1 = require("../2_statements/statements/_statement");
const Structures = require("./structures");
const issue_1 = require("../../issue");
const nodes_1 = require("../nodes");
const position_1 = require("../../position");
const severity_1 = require("../../severity");
class StructureParser {
static run(input) {
const structure = this.findStructureForFile(input.file.getFilename());
const filtered = [];
for (const s of input.statements) {
const get = s.get();
if (get instanceof _statement_1.Comment || get instanceof _statement_1.Empty || get instanceof _statement_1.Unknown) {
continue;
}
filtered.push(s);
}
return this.runFile(structure, input.file, filtered);
}
//////////////////
static findStructureForFile(filename) {
// todo, not sure this is the right place for this logic
if (filename.endsWith(".clas.abap")) {
return new Structures.ClassGlobal();
}
else if (filename.endsWith(".intf.abap")) {
return new Structures.InterfaceGlobal();
}
else if (filename.match(/\.screen\_\d+\.abap$/i)) {
return new Structures.DynproLogic();
}
else {
// todo, add a special structure for TYPE-POOLS
return new Structures.Any();
}
}
static runFile(structure, file, statements) {
const parent = new nodes_1.StructureNode(structure);
if (this.singletons[structure.constructor.name] === undefined) {
this.singletons[structure.constructor.name] = structure.getMatcher();
}
const result = this.singletons[structure.constructor.name].run(statements, parent);
if (result.error) {
const issue = issue_1.Issue.atPosition(file, new position_1.Position(1, 1), result.errorDescription, "structure", severity_1.Severity.Error);
return { issues: [issue], node: undefined };
}
if (result.unmatched.length > 0) {
const statement = result.unmatched[0];
const descr = "Unexpected " + statement.get().constructor.name.toUpperCase();
const issue = issue_1.Issue.atPosition(file, statement.getStart(), descr, "structure", severity_1.Severity.Error);
return { issues: [issue], node: undefined };
}
return { issues: [], node: parent };
}
}
exports.StructureParser = StructureParser;
StructureParser.singletons = {};
//# sourceMappingURL=structure_parser.js.map