1.1 --- a/sqlliterals/pyparser.py Sat Jun 02 19:41:22 2007 +0200
1.2 +++ b/sqlliterals/pyparser.py Sat Jun 02 20:03:42 2007 +0200
1.3 @@ -1,12 +1,45 @@
1.4 #!/usr/bin/env python
1.5
1.6 +"""
1.7 +A pyparsing 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 from pyparsing import *
1.27
1.28 +try:
1.29 + ParserElement.enablePackrat()
1.30 +except AttributeError:
1.31 + pass
1.32 +
1.33 +# Classes and functions.
1.34 +
1.35 class Grammar:
1.36 +
1.37 + """
1.38 + A convenience class whose objects enforce grouping and naming of grammar
1.39 + rules.
1.40 + """
1.41 +
1.42 def __setattr__(self, name, value):
1.43 self.__dict__[name] = Group(value).setResultsName(name)
1.44
1.45 -g = Grammar()
1.46 +g = grammar = Grammar()
1.47
1.48 g.non_literal = OneOrMore(CharsNotIn("'"))
1.49 g.value = ZeroOrMore(Or([Literal("''"), CharsNotIn("'")]))
1.50 @@ -15,6 +48,9 @@
1.51 g.query.leaveWhitespace()
1.52
1.53 def parseString(s):
1.54 +
1.55 + "Return a pyparsing result object from the parsing of the string 's'."
1.56 +
1.57 return g.query.parseString(s)
1.58
1.59 # vim: tabstop=4 expandtab shiftwidth=4