mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
Cleanup for ddl2cpp (thanks, David)
This commit is contained in:
parent
af6811bb4d
commit
9bc9575723
@ -31,7 +31,7 @@ import re
|
|||||||
import os
|
import os
|
||||||
import pprint
|
import pprint
|
||||||
|
|
||||||
from pyparsing import CaselessLiteral, Literal, SkipTo, restOfLine, oneOf, ZeroOrMore, Optional, Combine, \
|
from pyparsing import CaselessLiteral, Literal, SkipTo, restOfLine, oneOf, ZeroOrMore, Optional, Combine, Suppress, \
|
||||||
WordStart, WordEnd, Word, alphas, alphanums, nums, QuotedString, nestedExpr, MatchFirst, OneOrMore, delimitedList, Or, Group
|
WordStart, WordEnd, Word, alphas, alphanums, nums, QuotedString, nestedExpr, MatchFirst, OneOrMore, delimitedList, Or, Group
|
||||||
|
|
||||||
INCLUDE = 'sqlpp11'
|
INCLUDE = 'sqlpp11'
|
||||||
@ -80,7 +80,7 @@ ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + One
|
|||||||
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlTerm.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
|
createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlTerm.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create")
|
||||||
|
|
||||||
|
|
||||||
ddl = ZeroOrMore(SkipTo(createTable, include=True))
|
ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable)
|
||||||
|
|
||||||
ddlComment = oneOf(["--", "#"]) + restOfLine
|
ddlComment = oneOf(["--", "#"]) + restOfLine
|
||||||
ddl.ignore(ddlComment)
|
ddl.ignore(ddlComment)
|
||||||
@ -131,16 +131,7 @@ print('{', file=header)
|
|||||||
|
|
||||||
tableCreations = ddl.parseFile(pathToDdl)
|
tableCreations = ddl.parseFile(pathToDdl)
|
||||||
|
|
||||||
for tableCreation in tableCreations:
|
for create in tableCreations:
|
||||||
# get the actual table parse result depending on the version of pyparsing
|
|
||||||
if isinstance(tableCreation, basestring): # Since pyparsing-2.10
|
|
||||||
continue
|
|
||||||
create = None
|
|
||||||
if tableCreation.create:
|
|
||||||
create = tableCreation.create # Before pyparsing-2.10
|
|
||||||
elif tableCreation.tableName:
|
|
||||||
create = tableCreation # Since pyparsing-2.10
|
|
||||||
|
|
||||||
sqlTableName = create.tableName
|
sqlTableName = create.tableName
|
||||||
tableClass = toClassName(sqlTableName)
|
tableClass = toClassName(sqlTableName)
|
||||||
tableMember = toMemberName(sqlTableName)
|
tableMember = toMemberName(sqlTableName)
|
||||||
|
Loading…
Reference in New Issue
Block a user