@abaplint/core
Version:
abaplint - Core API
61 lines • 2.46 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DDLParser = exports.DDLKind = void 0;
const combi_1 = require("../abap/2_statements/combi");
const nodes_1 = require("../abap/nodes");
const version_1 = require("../version");
const ddl_lexer_1 = require("./ddl_lexer");
const Expressions = require("./expressions");
var DDLKind;
(function (DDLKind) {
DDLKind["Structure"] = "structure";
DDLKind["Table"] = "table";
})(DDLKind || (exports.DDLKind = DDLKind = {}));
class DDLParser {
parse(file) {
const tokens = ddl_lexer_1.DDLLexer.run(file);
let res = combi_1.Combi.run(new Expressions.DDLStructure(), tokens, version_1.defaultVersion);
if (res === undefined) {
res = combi_1.Combi.run(new Expressions.DDLTable(), tokens, version_1.defaultVersion);
}
if (res === undefined || !(res[0] instanceof nodes_1.ExpressionNode)) {
return undefined;
}
return this.parsedToResult(res[0]);
}
parsedToResult(node) {
var _a, _b;
const fields = [];
let found = node.findDirectExpressions(Expressions.DDLStructureField);
found = found.concat(node.findDirectExpressions(Expressions.DDLTableField));
found = found.concat(node.findDirectExpressions(Expressions.DDLInclude));
for (const f of found) {
const name = ((_a = f.findDirectExpression(Expressions.DDLName)) === null || _a === void 0 ? void 0 : _a.concatTokens()) || "";
if (f.get() instanceof Expressions.DDLInclude) {
fields.push({
name: ".INCLUDE",
type: name,
key: false,
notNull: false,
});
}
else {
const type = ((_b = f.findDirectExpression(Expressions.DDLType)) === null || _b === void 0 ? void 0 : _b.concatTokens()) || "";
fields.push({
name,
type,
key: false,
notNull: false,
});
}
}
const result = {
name: node.findDirectExpression(Expressions.DDLName).concatTokens(),
kind: node.get() instanceof Expressions.DDLStructure ? DDLKind.Structure : DDLKind.Table,
fields,
};
return result;
}
}
exports.DDLParser = DDLParser;
//# sourceMappingURL=ddl_parser.js.map