Skip to content

Commit

Permalink
teach cqlsh to ignore comments
Browse files Browse the repository at this point in the history
Patch by eevans; reviewed by gdusbabek for CASSANDRA-2488


git-svn-id: https://svn.apache.org/repos/asf/cassandra/branches/cassandra-0.8@1095149 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Eric Evans committed Apr 19, 2011
1 parent 41f83a1 commit 2f43dc3
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions drivers/py/cqlsh
Original file line number Diff line number Diff line change
Expand Up @@ -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(";"):
Expand All @@ -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()
Expand Down

0 comments on commit 2f43dc3

Please sign in to comment.