UNPKG

@abaplint/core

Version:
94 lines 4.77 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Append = void 0; const Expressions = require("../../2_statements/expressions"); const source_1 = require("../expressions/source"); const target_1 = require("../expressions/target"); const basic_1 = require("../../types/basic"); const fstarget_1 = require("../expressions/fstarget"); const inline_data_1 = require("../expressions/inline_data"); const _type_utils_1 = require("../_type_utils"); const _syntax_input_1 = require("../_syntax_input"); // todo: issue error for short APPEND if the source is without header line class Append { runSyntax(node, input) { let targetType = undefined; const target = node.findDirectExpression(Expressions.Target); if (target) { targetType = target_1.Target.runSyntax(target, input); } const fsTarget = node.findExpressionAfterToken("ASSIGNING"); if (fsTarget && fsTarget.get() instanceof Expressions.FSTarget) { if (!(targetType instanceof basic_1.TableType) && !(targetType instanceof basic_1.VoidType)) { const message = "APPEND to non table type"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } const rowType = targetType instanceof basic_1.TableType ? targetType.getRowType() : targetType; fstarget_1.FSTarget.runSyntax(fsTarget, input, rowType); } const dataTarget = node.findExpressionAfterToken("INTO"); if (dataTarget && node.concatTokens().toUpperCase().includes(" REFERENCE INTO DATA(")) { if (!(targetType instanceof basic_1.TableType) && !(targetType instanceof basic_1.VoidType)) { const message = "APPEND to non table type"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } const rowType = targetType instanceof basic_1.TableType ? targetType.getRowType() : targetType; inline_data_1.InlineData.runSyntax(dataTarget, input, new basic_1.DataReference(rowType)); } let source = node.findDirectExpression(Expressions.SimpleSource4); if (source === undefined) { source = node.findDirectExpression(Expressions.Source); } if (source) { if (targetType !== undefined && !(targetType instanceof basic_1.TableType) && dataTarget !== target && !(targetType instanceof basic_1.VoidType)) { const message = "Append, target not a table type"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } let rowType = undefined; if (targetType instanceof basic_1.TableType) { rowType = targetType.getRowType(); } else if (targetType instanceof basic_1.VoidType) { rowType = targetType; } let sourceType = source_1.Source.runSyntax(source, input, rowType); if (node.findDirectTokenByText("LINES")) { // hmm, checking only the row types are compatible will not check the table type, e.g. sorted or hashed if (sourceType instanceof basic_1.TableType) { sourceType = sourceType.getRowType(); } if (targetType instanceof basic_1.TableType) { targetType = targetType.getRowType(); } if (new _type_utils_1.TypeUtils(input.scope).isAssignable(sourceType, targetType) === false) { const message = "Incompatible types"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } } else { if (new _type_utils_1.TypeUtils(input.scope).isAssignable(sourceType, rowType) === false) { const message = "Incompatible types"; input.issues.push((0, _syntax_input_1.syntaxIssue)(input, node.getFirstToken(), message)); return; } } } const from = node.findExpressionAfterToken("FROM"); if (from && from.get() instanceof Expressions.Source) { source_1.Source.runSyntax(from, input); } const to = node.findExpressionAfterToken("TO"); if (to && to.get() instanceof Expressions.Source) { source_1.Source.runSyntax(to, input); } } } exports.Append = Append; //# sourceMappingURL=append.js.map