Commit 8d001bd5 authored by Jim Fulton's avatar Jim Fulton

de-winified so that compileall would not barf

parent 8f58bce6
# this was used for debugging null productions (a nearly full sql grammar # this was used for debugging null productions (a nearly full sql grammar
# is available on request). # is available on request).
#set this to automatically rebuild the grammar. #set this to automatically rebuild the grammar.
REBUILD = 1 REBUILD = 1
MARSHALFILE = "SQLTEST.mar" MARSHALFILE = "SQLTEST.mar"
SELECTRULES = """ SELECTRULES = """
## highest level for select statement (not select for update) ## highest level for select statement (not select for update)
select-statement :: select-statement ::
@R selectR :: select-statement >> @R selectR :: select-statement >>
SELECT SELECT
from-clause from-clause
where-clause where-clause
group-by-clause group-by-clause
having-clause having-clause
## generalized to allow null from clause eg: select 2+2 ## generalized to allow null from clause eg: select 2+2
@R fromNull :: from-clause >> @R fromNull :: from-clause >>
@R fromFull :: from-clause >> FROM @R fromFull :: from-clause >> FROM
@R whereNull :: where-clause >> @R whereNull :: where-clause >>
@R whereFull :: where-clause >> WHERE @R whereFull :: where-clause >> WHERE
@R groupNull :: group-by-clause >> @R groupNull :: group-by-clause >>
@R groupFull :: group-by-clause >> GROUP BY @R groupFull :: group-by-clause >> GROUP BY
@R havingNull :: having-clause >> @R havingNull :: having-clause >>
@R havingFull :: having-clause >> HAVING @R havingFull :: having-clause >> HAVING
@R unionNull :: union-clause >> @R unionNull :: union-clause >>
@R unionFull :: union-clause >> UNION @R unionFull :: union-clause >> UNION
""" """
SELECTNONTERMS = """ SELECTNONTERMS = """
select-statement select-statement
all-distinct select-list table-reference-list all-distinct select-list table-reference-list
where-clause group-by-clause having-clause union-clause where-clause group-by-clause having-clause union-clause
maybe-order-by maybe-order-by
search-condition column-list maybe-all order-by-clause search-condition column-list maybe-all order-by-clause
column-name from-clause column-name from-clause
""" """
# of these the following need resolution # of these the following need resolution
# (select-list) (table-reference-list) # (select-list) (table-reference-list)
# (search-condition) order-by-clause (column-name) # (search-condition) order-by-clause (column-name)
SELECTKEYWORDS = """ SELECTKEYWORDS = """
SELECT FROM WHERE GROUP BY HAVING UNION DISTINCT ALL AS SELECT FROM WHERE GROUP BY HAVING UNION DISTINCT ALL AS
""" """
# test generation of the grammar # test generation of the grammar
def BuildSQLG(): def BuildSQLG():
import kjParseBuild import kjParseBuild
SQLG = kjParseBuild.NullCGrammar() SQLG = kjParseBuild.NullCGrammar()
SQLG.SetCaseSensitivity(0) SQLG.SetCaseSensitivity(0)
SQLG.Keywords(SELECTKEYWORDS) SQLG.Keywords(SELECTKEYWORDS)
SQLG.Nonterms(SELECTNONTERMS) SQLG.Nonterms(SELECTNONTERMS)
# no comments yet # no comments yet
SQLG.Declarerules(SELECTRULES) SQLG.Declarerules(SELECTRULES)
print "building" print "building"
SQLG.Compile() SQLG.Compile()
print "marshaling" print "marshaling"
outfile = open( MARSHALFILE, "w") outfile = open( MARSHALFILE, "w")
SQLG.MarshalDump(outfile) SQLG.MarshalDump(outfile)
outfile.close() outfile.close()
return SQLG return SQLG
# load function # load function
def LoadSQLG(): def LoadSQLG():
import kjParser import kjParser
print "unmarshalling" print "unmarshalling"
infile = open(MARSHALFILE, "r") infile = open(MARSHALFILE, "r")
SQLG = kjParser.UnMarshalGram(infile) SQLG = kjParser.UnMarshalGram(infile)
infile.close() infile.close()
return SQLG return SQLG
#### for testing #### for testing
if REBUILD: if REBUILD:
SQLG0 = BuildSQLG() SQLG0 = BuildSQLG()
print " rebuilt SQLG0 as compilable grammar" print " rebuilt SQLG0 as compilable grammar"
SQLG = LoadSQLG() SQLG = LoadSQLG()
print " build SQLG as reloaded grammar" print " build SQLG as reloaded grammar"
\ No newline at end of file
This diff is collapsed.
"test parses for sql grammar" "test parses for sql grammar"
test = [ test = [
"select a from x where b=c", "select a from x where b=c",
"select distinct x.a from x where x.b=c", "select distinct x.a from x where x.b=c",
"select all a from x where b=c", "select all a from x where b=c",
"select a from x, y where b=c or x.d=45", "select a from x, y where b=c or x.d=45",
"select a as k from x d, y as m where b=c", "select a as k from x d, y as m where b=c",
"select 1 as n, a from x where b=c", "select 1 as n, a from x where b=c",
"select * from x", "select * from x",
"select a from x where b=c", "select a from x where b=c",
"select a from x where not b=c or d=1 and e=5", "select a from x where not b=c or d=1 and e=5",
"select a from x where a=1 and (x.b=3 or not b=c)", "select a from x where a=1 and (x.b=3 or not b=c)",
] ]
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment