Parse an attribute from the vector returned by regmatches
| 1329 | |
| 1330 | // Parse an attribute from the vector returned by regmatches |
| 1331 | Attribute SourceFileAttributesParser::parseAttribute( |
| 1332 | const std::vector<std::string>& match, |
| 1333 | int lineNumber) { |
| 1334 | // Attribute name |
| 1335 | std::string name = match[1]; |
| 1336 | |
| 1337 | // Warn if this is an unknown attribute |
| 1338 | if (!isKnownAttribute(name)) { |
| 1339 | attributeWarning("Unrecognized attribute Rcpp::" + name, // #nocov |
| 1340 | lineNumber); // #nocov |
| 1341 | } |
| 1342 | |
| 1343 | // Extract params if we've got them |
| 1344 | std::vector<Param> params; |
| 1345 | std::string paramsText = match[2]; |
| 1346 | if (!paramsText.empty()) { |
| 1347 | |
| 1348 | // we know from the regex that it's enclosed in parens so remove |
| 1349 | // trim before we do this just in case someone updates the regex |
| 1350 | // to allow for whitespace around the call |
| 1351 | trimWhitespace(¶msText); |
| 1352 | |
| 1353 | paramsText = paramsText.substr(1, paramsText.size()-2); |
| 1354 | |
| 1355 | // parse the parameters |
| 1356 | params = parseParameters(paramsText); |
| 1357 | } |
| 1358 | |
| 1359 | // Extract function signature if this is a function attribute |
| 1360 | // and it doesn't appear at the end of the file |
| 1361 | Function function; |
| 1362 | |
| 1363 | // special handling for export and init |
| 1364 | if (name == kExportAttribute || name == kInitAttribute) { |
| 1365 | |
| 1366 | // parse the function (unless we are at the end of the file in |
| 1367 | // which case we print a warning) |
| 1368 | if ((lineNumber + 1) < lines_.size()) |
| 1369 | function = parseFunction(lineNumber + 1); |
| 1370 | else |
| 1371 | rcppExportWarning("No function found", lineNumber); // #nocov |
| 1372 | |
| 1373 | // validate parameters |
| 1374 | for (std::size_t i=0; i<params.size(); i++) { |
| 1375 | |
| 1376 | std::string name = params[i].name(); // #nocov start |
| 1377 | std::string value = params[i].value(); |
| 1378 | |
| 1379 | // un-named parameter that isn't the first parameter |
| 1380 | if (value.empty() && (i > 0)) { |
| 1381 | rcppExportWarning("No value specified for parameter '" + |
| 1382 | name + "'", |
| 1383 | lineNumber); |
| 1384 | } |
| 1385 | // parameter that isn't name or rng |
| 1386 | else if (!value.empty() && |
| 1387 | (name != kExportName) && |
| 1388 | (name != kExportRng) && |
nothing calls this directly
no test coverage detected