cassandra-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eev...@apache.org
Subject svn commit: r1095149 - /cassandra/branches/cassandra-0.8/drivers/py/cqlsh
Date Tue, 19 Apr 2011 17:53:38 GMT
Author: eevans
Date: Tue Apr 19 17:53:38 2011
New Revision: 1095149

URL: http://svn.apache.org/viewvc?rev=1095149&view=rev
Log:
teach cqlsh to ignore comments

Patch by eevans; reviewed by gdusbabek for CASSANDRA-2488

Modified:
    cassandra/branches/cassandra-0.8/drivers/py/cqlsh

Modified: cassandra/branches/cassandra-0.8/drivers/py/cqlsh
URL: http://svn.apache.org/viewvc/cassandra/branches/cassandra-0.8/drivers/py/cqlsh?rev=1095149&r1=1095148&r2=1095149&view=diff
==============================================================================
--- cassandra/branches/cassandra-0.8/drivers/py/cqlsh (original)
+++ cassandra/branches/cassandra-0.8/drivers/py/cqlsh Tue Apr 19 17:53:38 2011
@@ -64,12 +64,33 @@ class Shell(cmd.Cmd):
         
         self.statement = StringIO()
         self.color = color
+        self.in_comment = False
     
     def reset_statement(self):
         self.set_prompt(Shell.default_prompt)
         self.statement.truncate(0)
         
     def get_statement(self, line):
+        if self.in_comment:
+            if "*/" in line:
+                fragment = line[line.index("*/")+2:]
+                if fragment.strip():
+                    line = fragment
+                    self.in_comment = False
+                else:
+                    self.in_comment = False
+                    self.set_prompt(Shell.default_prompt)
+                    return None
+            else:
+                return None
+        
+        if "/*" in line and (not self.in_comment):
+            self.in_comment = True
+            self.set_prompt(Shell.continue_prompt)
+            if line.lstrip().index("/*") != 0:
+                self.statement.write(line[:line.lstrip().index("/*")])
+            return None
+        
         self.statement.write("%s\n" % line)
             
         if not line.endswith(";"):
@@ -82,8 +103,14 @@ class Shell(cmd.Cmd):
             self.reset_statement()
 
     def default(self, arg):
-        if not arg.strip(): return
-        statement = self.get_statement(arg)
+        def scrub_oneline_comments(s):
+            res = re.sub(r'\/\*.*\*\/', '', s)
+            res = re.sub(r'--.*$', '', res)
+            return res
+        
+        input = scrub_oneline_comments(arg)
+        if not input.strip(): return
+        statement = self.get_statement(input)
         if not statement: return
         
         cursor = self.conn.cursor()



Mime
View raw message