[Rcpp-commits] r4242 - in pkg/Rcpp: . inst src

noreply at r-forge.r-project.org noreply at r-forge.r-project.org
Tue Feb 5 12:15:10 CET 2013


Author: jjallaire
Date: 2013-02-05 12:15:10 +0100 (Tue, 05 Feb 2013)
New Revision: 4242

Modified:
   pkg/Rcpp/ChangeLog
   pkg/Rcpp/inst/NEWS.Rd
   pkg/Rcpp/src/attributes.cpp
Log:
ensure that line comments invalidate block comments when parsing for attributes

Modified: pkg/Rcpp/ChangeLog
===================================================================
--- pkg/Rcpp/ChangeLog	2013-02-04 16:56:19 UTC (rev 4241)
+++ pkg/Rcpp/ChangeLog	2013-02-05 11:15:10 UTC (rev 4242)
@@ -1,3 +1,8 @@
+2013-02-05 JJ Allaire <jj at rstudio.org>
+
+        * src/attributes.cpp : ensure that line comments invalidate block
+        comments when parsing for attributes
+
 2013-02-04 Romain Francois <romain at r-enthusiasts.com>
 
         * include/Rcpp/traits/r_type_traits.h : make the r_type_pairstring_string_tag tag

Modified: pkg/Rcpp/inst/NEWS.Rd
===================================================================
--- pkg/Rcpp/inst/NEWS.Rd	2013-02-04 16:56:19 UTC (rev 4241)
+++ pkg/Rcpp/inst/NEWS.Rd	2013-02-05 11:15:10 UTC (rev 4242)
@@ -20,6 +20,8 @@
         \item Stop with an error if the file name passed to 
         \code{sourceCpp} has spaces in it
         \item Return invisibly from void functions
+        \item Ensure that line comments invalidate block comments when
+        parsing for attributes
     }
     \item Changes in Rcpp API:
     \itemize{

Modified: pkg/Rcpp/src/attributes.cpp
===================================================================
--- pkg/Rcpp/src/attributes.cpp	2013-02-04 16:56:19 UTC (rev 4241)
+++ pkg/Rcpp/src/attributes.cpp	2013-02-05 11:15:10 UTC (rev 4242)
@@ -1245,9 +1245,21 @@
     void CommentState::submitLine(const std::string& line) {
         std::size_t pos = 0;
         while (pos != std::string::npos) {
+            
+            // check for a // which would invalidate any other token found
+            std::size_t lineCommentPos = line.find("//", pos);
+            
+            // look for the next token
             std::string token = inComment() ? "*/" : "/*";
             pos = line.find(token, pos);
+            
+            // process the comment token if found
             if (pos != std::string::npos) {
+                
+                // break if the line comment precedes the comment token
+                if (lineCommentPos != std::string::npos && lineCommentPos < pos)
+                    break;
+                
                 inComment_ = !inComment_;
                 pos += token.size();
             }



More information about the Rcpp-commits mailing list