[Aptitude-svn-commit] r3705 - in branches/aptitude-0.3/aptitude: . doc/en src/generic

Daniel Burrows dburrows at costa.debian.org
Fri Aug 5 06:05:51 UTC 2005


Author: dburrows
Date: Fri Aug  5 06:05:46 2005
New Revision: 3705

Modified:
   branches/aptitude-0.3/aptitude/ChangeLog
   branches/aptitude-0.3/aptitude/doc/en/aptitude.xml
   branches/aptitude-0.3/aptitude/src/generic/matchers.cc
   branches/aptitude-0.3/aptitude/src/generic/matchers.h
Log:
Make the pattern matching language handle whitespace quite a bit differently: it delimits bare strings rather than being included in them.

Modified: branches/aptitude-0.3/aptitude/ChangeLog
==============================================================================
--- branches/aptitude-0.3/aptitude/ChangeLog	(original)
+++ branches/aptitude-0.3/aptitude/ChangeLog	Fri Aug  5 06:05:46 2005
@@ -1,5 +1,11 @@
 2005-08-04  Daniel Burrows  <dburrows at debian.org>
 
+	* doc/en/aptitude.xml, src/generic/matchers.cc, src/generic/matchers.h:
+
+	  Make the matching language whitespace-insensitive: to include
+	  literal whitespace, you must now place it between double quotes
+	  or tilde-escape it.
+
 	* src/generic/matchers.h, src/load_grouppolicy.cc, src/pkg_grouppolicy.h:
 
 	  Total rewrite of the load_grouppolicy code, and a few interface

Modified: branches/aptitude-0.3/aptitude/doc/en/aptitude.xml
==============================================================================
--- branches/aptitude-0.3/aptitude/doc/en/aptitude.xml	(original)
+++ branches/aptitude-0.3/aptitude/doc/en/aptitude.xml	Fri Aug  5 06:05:46 2005
@@ -3270,6 +3270,29 @@
       </para>
 
       <para>
+	Normally, <quote>whitespace</quote> -- that is, space
+	characters, tabs, and so on -- separates terms but is
+	otherwise ignored by &aptitude;.  To include whitespace (or
+	other special characters) in a term, you can either place a
+	tilde in front of it (as in <literal>Debian~
+	Project</literal>) or place quotation marks around it (as in
+	<literal>"Debian Project"</literal> or even <literal>Debian"
+	"Project</literal>).  Inside a quoted string, the backslash
+	character (<quote>\</quote>) can be used to cancel the special
+	meaning of the quotation mark: for instance,
+	<literal>~d"\"email"</literal> will match any package whose
+	description contains a quotation mark followed immediately by
+	<literal>email</literal>.
+	<footnote>
+	  <para>
+	    The backslash escapes <literal>\\</literal>,
+	    <literal>\n</literal>, and <literal>\t</literal> are also
+	    available.
+	  </para>
+	</footnote>
+      </para>
+
+      <para>
 	The following types of terms are available:
       </para>
 

Modified: branches/aptitude-0.3/aptitude/src/generic/matchers.cc
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/matchers.cc	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/matchers.cc	Fri Aug  5 06:05:46 2005
@@ -22,18 +22,19 @@
 //
 //  CONDITION := CONDITION-LIST
 //  CONDITION-LIST := CONDITION-AND-GROUP '|' CONDITION-LIST
-//                 := CONDITION-AND-GROUP
+//                 |  CONDITION-AND-GROUP
 //  CONDITION-AND-GROUP := CONDITION-ATOM CONDITION-AND-GROUP
 //                      := CONDITION-ATOM
 //  CONDITION-ATOM := '(' CONDITION-LIST ')'
-//                 := '!' CONDITION-ATOM
-//                 := '~'field-id [string]
-//                 := string
+//                 |  '!' CONDITION-ATOM
+//                 |  '~'field-id <string>
+//                 |  <string>
 
 #include "matchers.h"
 #include "apt.h"
 #include "tags.h"
 #include "tasks.h"
+#include "util.h"
 
 #include "../aptitude.h"
 
@@ -1556,9 +1557,13 @@
 			 const string::const_iterator &end,
 			 const vector<const char *> &terminators)
 {
-  std::string rval="";
+  std::string rval;
   bool done=false;
 
+  // Strip leading whitespace.
+  while(start != end && isspace(*start))
+    ++start;
+
   do
     {
       while(start != end &&
@@ -1567,12 +1572,54 @@
 	    *start != '!' &&
 	    *start != '~' &&
 	    *start != '|' &&
+	    *start != '"' &&
+	    !isspace(*start) &&
 	    !terminate(start, end, terminators))
 	{
 	  rval += *start;
 	  ++start;
 	}
 
+      if(start != end && *start == '"')
+	{
+	  ++start;
+
+	  while(start != end && *start != '"')
+	    {
+	      if(*start == '\\')
+		{
+		  ++start;
+		  if(start != end)
+		    {
+		      switch(*start)
+			{
+			case 'n':
+			  rval += '\n';
+			  break;
+			case 't':
+			  rval += '\t';
+			  break;
+			default:
+			  rval += *start;
+			  break;
+			}
+		      ++start;
+		    }
+		}
+	      else
+		{
+		  rval += *start;
+		  ++start;
+		}
+	    }
+
+	  if(start == end)
+	    throw CompilationException(_("Unterminated literal string after %s"), rval.c_str());
+
+	  assert(*start == '"');
+	  ++start;
+	}
+
       // We quit because we ran off the end of the string or saw a
       // metacharacter.  If the latter case and it was a tilde-escape,
       // add the escaped character to the string and continue.
@@ -1582,7 +1629,8 @@
 
 	  if(next == '(' || next == ')' ||
 	     next == '!' || next == '~' ||
-	     next == '|')
+	     next == '|' || next == '"' ||
+	     isspace(next))
 	    {
 	      rval += next;
 	      start += 2;
@@ -1635,9 +1683,12 @@
 	}
       else if(*start == '~')
 	{
-	  if(start + 1 == end)
+	  ++start;
+	  while(start != end && isspace(*start))
+	    ++start;
+
+	  if(start == end)
 	    {
-	      ++start;
 	      if(!search_descriptions)
 		return new pkg_name_matcher("~");
 	      else
@@ -1651,11 +1702,13 @@
 	    }
 	  else
 	    {
-	      ++start;
 	      const char search_flag = *start;
 
 	      ++start;
 
+	      while(start != end && isspace(*start))
+		++start;
+
 	      switch(search_flag)
 		// Nested switch statements, mmmm...
 		// Ok, there really is a reason here.  For all of the match
@@ -1708,13 +1761,18 @@
 
 		    string::const_iterator nextstart = start;
 
+
 		    while(nextstart != end && isalpha(*nextstart) &&
 			  !terminate(nextstart, end, terminators))
 		      ++nextstart;
 
+		    while(nextstart != end && isspace(*nextstart))
+		      ++nextstart;
+
 		    if(nextstart != end && *nextstart == ':')
 		      {
 			string tname(start, nextstart);
+			stripws(tname);
 
 			start = nextstart;
 			++start;
@@ -1895,8 +1953,7 @@
       else
 	rval = auto_ptr<pkg_matcher>(new pkg_and_matcher(rval.release(), atom.release()));
 
-      while(start != end && isspace(*start) &&
-	    !terminate(start, end, terminators))
+      while(start != end && isspace(*start))
 	++start;
     }
 
@@ -1914,7 +1971,7 @@
   auto_ptr<pkg_matcher> grp(parse_and_group(start, end, terminators,
 					    search_descriptions));
 
-  while(start != end && isspace(*start) && !terminate(start, end, terminators))
+  while(start != end && isspace(*start))
     ++start;
 
   while(start != end && *start != ')' && !terminate(start, end, terminators))
@@ -1959,6 +2016,9 @@
       auto_ptr<pkg_matcher> rval(parse_condition_list(start, end, terminators,
 						      search_descriptions));
 
+      while(start != end && isspace(*start))
+	++start;
+
       if(require_full_parse && start != end)
 	throw CompilationException(_("Unexpected ')'"));
       else

Modified: branches/aptitude-0.3/aptitude/src/generic/matchers.h
==============================================================================
--- branches/aptitude-0.3/aptitude/src/generic/matchers.h	(original)
+++ branches/aptitude-0.3/aptitude/src/generic/matchers.h	Fri Aug  5 06:05:46 2005
@@ -67,9 +67,10 @@
  *
  *  \param start the beginning of the range to parse
  *  \param end the end of the range to parse
- *  \param terminators a set of characters whose presence at the top
+ *  \param terminators a list of strings whose presence at the top
  *                     syntactic level should cause the parse to
- *                     terminate.
+ *                     terminate.  It is assumed that none of these
+ *                     strings contain whitespace.
  *  \param search_descriptions if \b true, then strings without an
  *                     explicit pattern escape will be used to search
  *                     both names and descriptions rather than



More information about the Aptitude-svn-commit mailing list