@eagleoutice/flowr
Version:
Static Dataflow Analyzer and Program Slicer for the R Programming Language
47 lines • 1.99 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.tryNormalizeSymbol = tryNormalizeSymbol;
const assert_1 = require("../../../../../../../util/assert");
const normalize_meta_1 = require("../../normalize-meta");
const type_1 = require("../../../../model/type");
const identifier_1 = require("../../../../../../../dataflow/environments/identifier");
/**
* Normalize the given object as an R symbol (incorporating namespace information).
* @param data - The data used by the parser (see {@link NormalizerData})
* @param objs - The JSON object to extract the meta-information from
* @returns The parsed symbol (with populated namespace information) or `undefined` if the given object is not a symbol.
* @see {@link RSymbol} for more information about R symbols.
*/
function tryNormalizeSymbol(data, objs) {
(0, assert_1.guard)(objs.length > 0, 'to parse symbols we need at least one object to work on!');
let content, location;
let meta;
if (objs.length === 1 && (0, type_1.isSymbol)(objs[0].name)) {
meta = (0, normalize_meta_1.retrieveMetaStructure)(objs[0].content);
location = meta.location;
content = identifier_1.Identifier.make(meta.content);
}
else if (objs.length === 3 && (0, type_1.isSymbol)(objs[2].name)) {
meta = (0, normalize_meta_1.retrieveMetaStructure)(objs[2].content);
location = meta.location;
const namespace = objs[0].content.text;
const internal = objs[1].content.text === ':::';
content = identifier_1.Identifier.make(meta.content, namespace, internal);
}
else {
return undefined;
}
return {
type: type_1.RType.Symbol,
location,
// remove backticks from symbol
content,
lexeme: meta.content,
info: {
fullRange: data.currentRange,
adToks: [],
fullLexeme: data.currentLexeme
}
};
}
//# sourceMappingURL=normalize-symbol.js.map