diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2016-09-24 17:02:48 +0000 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2016-09-24 17:02:48 +0000 |
commit | 7d3417bf20295c6bec7fd611d3d3bc0fdce255ef (patch) | |
tree | 45b9df9b17033ebe5669bc69b7bacb7698794260 /src/examples/simpleSQL.py | |
parent | 026e21eca624a5dab19e12890a86bd50470d32b8 (diff) | |
download | pyparsing-git-7d3417bf20295c6bec7fd611d3d3bc0fdce255ef.tar.gz |
Updated some examples to more current pyparsing coding methods
Diffstat (limited to 'src/examples/simpleSQL.py')
-rw-r--r-- | src/examples/simpleSQL.py | 20 |
1 files changed, 9 insertions, 11 deletions
diff --git a/src/examples/simpleSQL.py b/src/examples/simpleSQL.py index 09c028e..6cde6ce 100644 --- a/src/examples/simpleSQL.py +++ b/src/examples/simpleSQL.py @@ -7,24 +7,22 @@ #
from pyparsing import Literal, CaselessLiteral, Word, delimitedList, Optional, \
Combine, Group, alphas, nums, alphanums, ParseException, Forward, oneOf, quotedString, \
- ZeroOrMore, restOfLine, Keyword, upcaseTokens, pyparsing_common
+ ZeroOrMore, restOfLine, CaselessKeyword, pyparsing_common
# define SQL tokens
selectStmt = Forward()
-SELECT = Keyword("select", caseless=True)
-FROM = Keyword("from", caseless=True)
-WHERE = Keyword("where", caseless=True)
+SELECT, FROM, WHERE = map(CaselessKeyword, "select from where".split())
ident = Word( alphas, alphanums + "_$" ).setName("identifier")
-columnName = ( delimitedList( ident, ".", combine=True ) ).setName("column name").addParseAction(upcaseTokens)
-columnNameList = Group( delimitedList( columnName ) )
-tableName = ( delimitedList( ident, ".", combine=True ) ).setName("table name").addParseAction(upcaseTokens)
-tableNameList = Group( delimitedList( tableName ) )
+columnName = delimitedList(ident, ".", combine=True).setName("column name")
+columnName.addParseAction(pyparsing_common.upcaseTokens)
+columnNameList = Group( delimitedList(columnName))
+tableName = delimitedList(ident, ".", combine=True).setName("table name")
+tableName.addParseAction(pyparsing_common.upcaseTokens)
+tableNameList = Group(delimitedList(tableName))
whereExpression = Forward()
-and_ = Keyword("and", caseless=True)
-or_ = Keyword("or", caseless=True)
-in_ = Keyword("in", caseless=True)
+and_, or_, in_ = map(CaselessKeyword, "and or in".split())
binop = oneOf("= != < > >= <= eq ne lt le gt ge", caseless=True)
realNum = pyparsing_common.real()
|