@@ -1165,7 +1165,7 @@ namespace attributes {
1165
1165
1166
1166
// Now read into a list of strings (which we can pass to regexec)
1167
1167
// First read into a std::deque (which will handle lots of append
1168
- // operations efficiently) then copy into an R chracter vector
1168
+ // operations efficiently) then copy into an R character vector
1169
1169
std::deque<std::string> lines;
1170
1170
readLines (buffer, &lines);
1171
1171
lines_ = Rcpp::wrap (lines);
@@ -1420,6 +1420,7 @@ namespace attributes {
1420
1420
1421
1421
// Establish the text to parse for the signature
1422
1422
std::string signature = parseSignature (lineNumber);
1423
+ std::cerr << " -------------------------------- SourceFileAttributesParser::parseFunction 10" << std::endl << signature << std::endl;
1423
1424
if (signature.empty ()) {
1424
1425
rcppExportNoFunctionFoundWarning (lineNumber); // #nocov
1425
1426
return Function (); // #nocov
@@ -1429,6 +1430,7 @@ namespace attributes {
1429
1430
// (bail with an empty result if we can't find them)
1430
1431
std::string::size_type endParenLoc = signature.find_last_of (' )' );
1431
1432
std::string::size_type beginParenLoc = signature.find_first_of (' (' );
1433
+ std::cerr << " -------------------------------- SourceFileAttributesParser::parseFunction 20" << std::endl << beginParenLoc << std::endl << endParenLoc << std::endl;
1432
1434
if (endParenLoc == std::string::npos ||
1433
1435
beginParenLoc == std::string::npos ||
1434
1436
endParenLoc < beginParenLoc) {
@@ -1481,6 +1483,8 @@ namespace attributes {
1481
1483
std::string argsText = signature.substr (beginParenLoc + 1 ,
1482
1484
endParenLoc-beginParenLoc-1 );
1483
1485
std::vector<std::string> args = parseArguments (argsText);
1486
+ for (auto arg: args)
1487
+ std::cerr << " -------------------------------- SourceFileAttributesParser::parseFunction 30" << std::endl << arg << std::endl;
1484
1488
for (std::vector<std::string>::const_iterator it =
1485
1489
args.begin (); it != args.end (); ++it) {
1486
1490
@@ -1588,44 +1592,66 @@ namespace attributes {
1588
1592
std::vector<std::string> SourceFileAttributesParser::parseArguments (
1589
1593
const std::string& argText) {
1590
1594
1595
+ std::cerr << " -------------------------------- SourceFileAttributesParser::SourceFileAttributesParser::parseArguments 1" << std::endl << argText << std::endl;
1591
1596
int templateCount = 0 ;
1592
1597
int parenCount = 0 ;
1593
- bool insideQuotes = false ;
1598
+ bool endOfArg = false ;
1594
1599
std::string currentArg;
1595
1600
std::vector<std::string> args;
1601
+ char quote = 0 ;
1596
1602
char prevChar = 0 ;
1597
- for (std::string::const_iterator
1598
- it = argText.begin (); it != argText.end (); ++it) {
1603
+ typedef std::string::const_iterator it_t ;
1604
+ for (it_t it = argText.begin (); it != argText.end (); ++it) {
1605
+
1606
+ endOfArg = false ;
1607
+
1608
+ // Store current character
1599
1609
char ch = *it;
1600
1610
1601
- if (ch == ' "' && prevChar != ' \\ ' ) {
1602
- insideQuotes = !insideQuotes;
1603
- }
1611
+ // Ignore quoted strings and character values in single quotes
1612
+ if ( ! quote && (ch == ' "' || ch == ' \' ' ))
1613
+ quote = ch;
1614
+ else if (quote && ch == quote && prevChar != ' \\ ' )
1615
+ quote = 0 ;
1604
1616
1605
- if ((ch == ' ,' ) &&
1617
+ std::cerr << " -------------------------------- SourceFileAttributesParser::SourceFileAttributesParser::parseArguments 10" << std::endl << " '" << prevChar << " ' '" << ch << " ' #" << quote << " #" << std::endl;
1618
+ // Detect end of argument declaration
1619
+ if ( ! quote &&
1620
+ (ch == ' ,' ) &&
1606
1621
(templateCount == 0 ) &&
1607
- (parenCount == 0 ) &&
1608
- !insideQuotes) {
1622
+ (parenCount == 0 )) {
1609
1623
args.push_back (currentArg);
1610
1624
currentArg.clear ();
1611
- continue ;
1612
- } else {
1613
- currentArg.push_back (ch);
1614
- switch (ch) {
1615
- case ' <' :
1616
- templateCount++;
1617
- break ;
1618
- case ' >' :
1619
- templateCount--;
1620
- break ;
1621
- case ' (' :
1622
- parenCount++; // #nocov
1623
- break ; // #nocov
1624
- case ' )' :
1625
- parenCount--; // #nocov
1626
- break ; // #nocov
1625
+ endOfArg = true ;
1626
+ }
1627
+
1628
+ std::cerr << " -------------------------------- SourceFileAttributesParser::SourceFileAttributesParser::parseArguments 20" << std::endl << endOfArg << std::endl;
1629
+ if ( ! endOfArg) {
1630
+
1631
+ // Append current character if not a space at start
1632
+ if ( ! currentArg.empty () || ch != ' ' )
1633
+ currentArg.push_back (ch);
1634
+
1635
+ // Count use of potentially enclosed brackets
1636
+ if ( ! quote) {
1637
+ switch (ch) {
1638
+ case ' <' :
1639
+ templateCount++;
1640
+ break ;
1641
+ case ' >' :
1642
+ templateCount--;
1643
+ break ;
1644
+ case ' (' :
1645
+ parenCount++; // #nocov
1646
+ break ; // #nocov
1647
+ case ' )' :
1648
+ parenCount--; // #nocov
1649
+ break ; // #nocov
1650
+ }
1627
1651
}
1628
1652
}
1653
+ std::cerr << " -------------------------------- SourceFileAttributesParser::SourceFileAttributesParser::parseArguments 30" << std::endl << templateCount << " " << parenCount << std::endl;
1654
+ std::cerr << " -------------------------------- SourceFileAttributesParser::SourceFileAttributesParser::parseArguments 40" << std::endl << currentArg << std::endl;
1629
1655
1630
1656
prevChar = ch;
1631
1657
}
0 commit comments