UNPKG

@eagleoutice/flowr

Version:

Static Dataflow Analyzer and Program Slicer for the R Programming Language

42 lines 2.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.tryNormalizeIfThen = tryNormalizeIfThen; const normalizer_data_1 = require("../../normalizer-data"); const parser_1 = require("../../../json/parser"); const normalize_meta_1 = require("../../normalize-meta"); const type_1 = require("../../../../model/type"); const normalize_single_node_1 = require("../structure/normalize-single-node"); /** * Try to parse the construct as a {@link RIfThenElse}. */ function tryNormalizeIfThen(data, [ifT, lpT, cT, rpT, tT]) { if (ifT.name !== type_1.RawRType.If) { parser_1.parseLog.debug('encountered non-if token for supposed if-then structure'); return undefined; } else if (lpT.name !== type_1.RawRType.ParenLeft) { throw new normalizer_data_1.ParseError(`expected left-parenthesis for if but found ${JSON.stringify(lpT)}`); } else if (rpT.name !== type_1.RawRType.ParenRight) { throw new normalizer_data_1.ParseError(`expected right-parenthesis for if but found ${JSON.stringify(rpT)}`); } const parsedCondition = (0, normalize_single_node_1.normalizeSingleNode)(data, cT); const parsedThen = (0, normalize_single_node_1.normalizeSingleNode)(data, tT); if (parsedCondition.type === type_1.RType.Delimiter || parsedThen.type === type_1.RType.Delimiter) { throw new normalizer_data_1.ParseError(`unexpected missing parts of if, received ${JSON.stringify([parsedCondition, parsedThen])} for ${JSON.stringify([ifT, lpT, cT, rpT, tT])}`); } const { location, content } = (0, normalize_meta_1.retrieveMetaStructure)(ifT.content); return { type: type_1.RType.IfThenElse, condition: parsedCondition, then: (0, normalize_meta_1.ensureExpressionList)(parsedThen), location, lexeme: content, info: { fullRange: data.currentRange, additionalTokens: [], fullLexeme: data.currentLexeme } }; } //# sourceMappingURL=normalize-if-then.js.map