1.1 --- a/sqlliterals/regexp.py Sat Jun 02 19:41:22 2007 +0200
1.2 +++ b/sqlliterals/regexp.py Sat Jun 02 20:03:42 2007 +0200
1.3 @@ -1,12 +1,41 @@
1.4 #!/usr/bin/env python
1.5
1.6 +"""
1.7 +A regular expression implementation of SQL statement tokenisation.
1.8 +
1.9 +Copyright (C) 2007 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This library is free software; you can redistribute it and/or
1.12 +modify it under the terms of the GNU Lesser General Public
1.13 +License as published by the Free Software Foundation; either
1.14 +version 2.1 of the License, or (at your option) any later version.
1.15 +
1.16 +This library is distributed in the hope that it will be useful,
1.17 +but WITHOUT ANY WARRANTY; without even the implied warranty of
1.18 +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1.19 +Lesser General Public License for more details.
1.20 +
1.21 +You should have received a copy of the GNU Lesser General Public
1.22 +License along with this library; if not, write to the Free Software
1.23 +Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
1.24 +"""
1.25 +
1.26 import re
1.27 -query = re.compile("(?P<non_literal>[^']+)|(?P<literal>'(?:[^']|(?:''))*')")
1.28 +
1.29 +region_expr = re.compile("(?P<non_literal>[^']+)|(?P<literal>'(?:[^']|(?:''))*')")
1.30
1.31 def parseString(s):
1.32 +
1.33 + """
1.34 + Parse the string 's' and return a list of regions, with the first element
1.35 + being a non-literal region, the next element being a literal region, and
1.36 + with subsequent elements repeating this pattern. Note that the first region
1.37 + may be an empty string.
1.38 + """
1.39 +
1.40 regions = []
1.41 first = 1
1.42 - for match in query.finditer(s):
1.43 + for match in region_expr.finditer(s):
1.44 non_literal, literal = match.groups()
1.45 if first and literal:
1.46 regions.append("")