UNPKG

@abaplint/core

Version:
67 lines 3.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SelectOption = void 0; const Expressions = require("../../2_statements/expressions"); const _typed_identifier_1 = require("../../types/_typed_identifier"); const basic_1 = require("../../types/basic"); const basic_types_1 = require("../basic_types"); const dynamic_1 = require("../expressions/dynamic"); const _syntax_input_1 = require("../_syntax_input"); const tokens_1 = require("../../1_lexer/tokens"); class SelectOption { runSyntax(node, input) { const nameExpression = node.findFirstExpression(Expressions.FieldSub); if (nameExpression === undefined) { return; } let nameToken = nameExpression.getFirstToken(); // FieldSub can include dashes and optional length, eg s-matnr or s_name(10). if (nameExpression.getChildren().length > 1) { const fullName = nameExpression.concatTokens().replace(/\(.+$/, "").replace(/\[\]$/, ""); nameToken = new tokens_1.Identifier(nameToken.getStart(), fullName); } if (nameToken && nameToken.getStr().length > 8) { const message = "Select-option name too long, " + nameToken.getStr(); input.issues.push((0, _syntax_input_1.syntaxIssue)(input, nameToken, message)); return; } for (const d of node.findDirectExpressions(Expressions.Dynamic)) { dynamic_1.Dynamic.runSyntax(d, input); input.scope.addIdentifier(new _typed_identifier_1.TypedIdentifier(nameToken, input.filename, basic_1.VoidType.get("DYNAMIC_SELECT_OPTION"))); return; } const nameChain = node.findFirstExpression(Expressions.FieldChain); let found = new basic_types_1.BasicTypes(input).resolveLikeName(nameChain); if (found) { if (found instanceof basic_1.StructureType) { let length = 0; for (const c of found.getComponents()) { if (c.type instanceof basic_1.CharacterType) { length += c.type.getLength(); } } if (length === 0) { found = basic_1.VoidType.get("Selectoption, fallback"); } else { found = new basic_1.CharacterType(length); } } const stru = new basic_1.StructureType([ { name: "SIGN", type: new basic_1.CharacterType(1) }, { name: "OPTION", type: new basic_1.CharacterType(2) }, { name: "LOW", type: found }, { name: "HIGH", type: found }, ]); input.scope.addIdentifier(new _typed_identifier_1.TypedIdentifier(nameToken, input.filename, new basic_1.TableType(stru, { withHeader: true, keyType: basic_1.TableKeyType.default }))); } else { input.scope.addIdentifier(new _typed_identifier_1.TypedIdentifier(nameToken, input.filename, new basic_1.UnknownType("Select option, fallback"))); } const magicName = "%_" + nameToken.getStr() + "_%_app_%"; const magicToken = new tokens_1.Identifier(nameToken.getStart(), magicName); input.scope.addIdentifier(new _typed_identifier_1.TypedIdentifier(magicToken, input.filename, basic_1.VoidType.get("SELECT-OPTION magic"))); } } exports.SelectOption = SelectOption; //# sourceMappingURL=selectoption.js.map