diff options
author | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2016-09-24 17:02:48 +0000 |
---|---|---|
committer | ptmcg <ptmcg@9bf210a0-9d2d-494c-87cf-cfb32e7dff7b> | 2016-09-24 17:02:48 +0000 |
commit | 6316cc5922201d5157a3eedc92c319c99e7a8579 (patch) | |
tree | 45b9df9b17033ebe5669bc69b7bacb7698794260 /src/examples/simpleSQL.py | |
parent | 7495b8f797419780718394a8597d493e9e839f06 (diff) | |
download | pyparsing-6316cc5922201d5157a3eedc92c319c99e7a8579.tar.gz |
Updated some examples to more current pyparsing coding methods
git-svn-id: svn://svn.code.sf.net/p/pyparsing/code/trunk@442 9bf210a0-9d2d-494c-87cf-cfb32e7dff7b
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()
|