@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
26 lines • 1.43 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryNormalizeIfThenElse = tryNormalizeIfThenElse;
const normalize_if_then_1 = require("./normalize-if-then");
const assert_1 = require("../../../../../../../util/assert");
const normalize_meta_1 = require("../../normalize-meta");
const normalize_single_node_1 = require("../structure/normalize-single-node");
const type_1 = require("../../../../model/type");
/**
* Try to parse the construct as a {@link RIfThenElse}.
*/
function tryNormalizeIfThenElse(data, [ifT, lpT, cT, rpT, tT, eT, ebT]) {
// we start by parsing a regular if-then structure
const parsedIfThen = (0, normalize_if_then_1.tryNormalizeIfThen)(data, [ifT, lpT, cT, rpT, tT]);
if (parsedIfThen === undefined) {
return undefined;
}
(0, assert_1.guard)(eT.name === type_1.RawRType.Else, () => `expected else token for if-then-else but found ${JSON.stringify(eT)}`);
const parsedElse = (0, normalize_single_node_1.normalizeSingleNode)(data, ebT);
(0, assert_1.guard)(parsedElse.type !== type_1.RType.Delimiter, () => `unexpected missing else-part of if-then-else, received ${JSON.stringify([parsedIfThen, parsedElse])} for ${JSON.stringify([ifT, lpT, cT, rpT, tT, eT, ebT])}`);
return {
...parsedIfThen,
otherwise: (0, normalize_meta_1.ensureExpressionList)(parsedElse)
};
}
//# sourceMappingURL=normalize-if-then-else.js.map