@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
60 lines • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ValueStringBot = exports.ValueStringTop = exports.ValueEmptyString = void 0;
exports.stringFrom = stringFrom;
exports.liftString = liftString;
exports.collectStrings = collectStrings;
const general_1 = require("../general");
const r_value_1 = require("../r-value");
/**
* Lift a raw string or R string value into a ValueString.
* @see {@link liftString} - for lifting a Lift<RStringValue>
*/
function stringFrom(str) {
return {
type: 'string',
value: typeof str === 'string' ? {
quotes: '"',
str: str
} : str,
};
}
/**
* Lift a Lift<RStringValue> into a ValueString.
* @see {@link stringFrom} - for lifting a raw string or R string value.
*/
function liftString(str) {
return {
type: 'string',
value: str
};
}
/**
* Collect strings from an array of ValueString.
* If any value is not a string, or is Bottom/Top, undefined is returned.
* @param a - The array of Value to collect strings from.
* @param withQuotes - Whether to include the quotes in the returned strings.
* @returns - An array of strings, or undefined if any value is not a string.
*/
function collectStrings(a, withQuotes = false) {
if ((0, general_1.bottomTopGuard)(a)) {
return undefined;
}
const values = [];
for (const value of a) {
if (value.type !== 'string' || !(0, r_value_1.isValue)(value) || !(0, r_value_1.isValue)(value.value)) {
return undefined;
}
if (withQuotes) {
values.push(`${value.value.quotes}${value.value.str}${value.value.quotes}`);
}
else {
values.push(value.value.str);
}
}
return values;
}
exports.ValueEmptyString = stringFrom('');
exports.ValueStringTop = liftString(r_value_1.Top);
exports.ValueStringBot = liftString(r_value_1.Bottom);
//# sourceMappingURL=string-constants.js.map