UNPKG

@abaplint/core

Version:
43 lines 2.34 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Constant = void 0; const Expressions = require("../../2_statements/expressions"); const basic_types_1 = require("../basic_types"); const _typed_identifier_1 = require("../../types/_typed_identifier"); const basic_1 = require("../../types/basic"); const _syntax_input_1 = require("../_syntax_input"); const assert_error_1 = require("../assert_error"); const basic_2 = require("../../types/basic"); class Constant { runSyntax(node, input) { const basic = new basic_types_1.BasicTypes(input); const found = basic.simpleType(node); if (found) { const val = basic.findValue(node); const meta = ["read_only" /* IdentifierMeta.ReadOnly */, "static" /* IdentifierMeta.Static */]; if (this.isOnlyDigits(found.getName()) && this.allowOnlyDigitsName(node, input) === false) { const message = "not possible to have a name with only digits"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, found.getToken(), message)); return new _typed_identifier_1.TypedIdentifier(found.getToken(), input.filename, basic_2.VoidType.get(_syntax_input_1.CheckSyntaxKey), meta, val); } return new _typed_identifier_1.TypedIdentifier(found.getToken(), input.filename, found.getType(), meta, val); } const fallback = node.findFirstExpression(Expressions.DefinitionName); if (fallback) { if (this.isOnlyDigits(fallback.concatTokens()) && this.allowOnlyDigitsName(node, input) === false) { const message = "not possible to have a name with only digits"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, fallback.getFirstToken(), message)); } return new _typed_identifier_1.TypedIdentifier(fallback.getFirstToken(), input.filename, new basic_1.UnknownType("constant, fallback")); } throw new assert_error_1.AssertError("Statement Constant: unexpected structure"); } isOnlyDigits(name) { return /^[0-9]+$/.test(name); } allowOnlyDigitsName(node, input) { return input.scope.isAnyOO() === false && node.getColon() !== undefined; } } exports.Constant = Constant; //# sourceMappingURL=constant.js.map