Beispiel #1
0
create_keyspace.setParseAction(ParseActionSimple('CREATE KEYSPACE'))

# Comments
# It would be nice to remove comments in the lexing stage, except that
# they are not part of the language that cassandra understands: they are
# part of cqlsh. Instead mark them as special chunks and skip them in
# the executor. This means that comments may only appear between
# statements.
comment = Regex('(--|//)[^\n]*') + lineEnd

comment.setParseAction(ParseActionSimple('COMMENT'))

cql = OneOrMore(ctable | alter | update | insert | create_keyspace | comment)

cql.enablePackrat()
cql.parseWithTabs()


class CqlChunk(object):
    def __init__(self, src, chunk_type, info, start, end):
        self.src = src
        self.chunk_type = chunk_type
        self.info = info
        self.start = start
        self.end = end
    def body(self):
        return self.src[self.start:self.end].strip()
    def is_update(self):
        return self.chunk_type == 'UPDATE'
    def is_comment(self):