--- simpleSQL-1.4.11.py 2008-04-19 20:39:03.000000000 -0500 +++ simpleSQL.py 2008-04-19 20:47:25.000000000 -0500 @@ -7,7 +7,7 @@ # from pyparsing import Literal, CaselessLiteral, Word, Upcase, delimitedList, Optional, \ Combine, Group, alphas, nums, alphanums, ParseException, Forward, oneOf, quotedString, \ - ZeroOrMore, restOfLine, Keyword + ZeroOrMore, restOfLine, Keyword, ErrStop, ParseFatalException def test( str ): print str,"->" @@ -17,7 +17,7 @@ print "tokens.columns =", tokens.columns print "tokens.tables =", tokens.tables print "tokens.where =", tokens.where - except ParseException, err: + except (ParseException, ParseFatalException), err: print " "*err.loc + "^\n" + err.msg print err print @@ -59,10 +59,11 @@ # define the grammar selectStmt << ( selectToken + - ( '*' | columnNameList ).setResultsName( "columns" ) + + ( '*' | columnNameList )( "columns" ) + fromToken + tableNameList.setResultsName( "tables" ) + - Optional( Group( CaselessLiteral("where") + whereExpression ), "" ).setResultsName("where") ) + Optional( Group( CaselessLiteral("where") + + ErrStop(whereExpression)), "" ).setResultsName("where") ) simpleSQL = selectStmt @@ -84,7 +85,7 @@ test( "Select A from Sys.dual where a in ('RED','GREEN','BLUE')" ) test( "Select A from Sys.dual where a in ('RED','GREEN','BLUE') and b in (10,20,30)" ) test( "Select A,b from table1,table2 where table1.id eq table2.id -- test out comparison operators" ) - +test( "select * from table1 where a b" ) """ Test output: >pythonw -u simpleSQL.py @@ -138,5 +139,10 @@ Expected '*' Expected '*' (7), (1,8) +select * from table1 where a b + ^ +Expected '=' +Expected '=' (at char 29), (line:1, col:30) + >Exit code: 0