From bcd7341476e785a99e1c509950baac0aea9ec726 Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Thu, 9 Jun 2016 19:18:15 +0300 Subject: [PATCH 1/2] fix formatting --- scripts/ddl2cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 20855442..6f4d4454 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -161,16 +161,16 @@ def ddlWord(string): def ddlFunctionWord(string): return CaselessLiteral(string) + OneOrMore("(") + ZeroOrMore(" ") + OneOrMore(")") -ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) +ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) negativeSign = Literal('-') -ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) -ddlTerm = Word(alphas, alphanums + "_$") -ddlName = Or([ddlTerm, ddlString]) +ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) +ddlTerm = Word(alphas, alphanums + "_$") +ddlName = Or([ddlTerm, ddlString]) ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull") ddlDefaultValue = ddlWord("DEFAULT").setResultsName("hasDefaultValue") ddlAutoValue = ddlWord("AUTO_INCREMENT").setResultsName("hasAutoValue") -ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") +ddlColumnComment = Group(ddlWord("COMMENT") + ddlString).setResultsName("comment") ddlConstraint = Or([ ddlWord("CONSTRAINT"), ddlWord("PRIMARY"), @@ -179,7 +179,7 @@ ddlConstraint = Or([ ddlWord("INDEX"), ddlWord("UNIQUE"), ]) -ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) +ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create") From 3d2dae9bb177d750520f566166cab5e2c5779f0e Mon Sep 17 00:00:00 2001 From: strangeqargo <“strangeqargo@gmail.com”> Date: Thu, 9 Jun 2016 19:19:37 +0300 Subject: [PATCH 2/2] fixed --- scripts/ddl2cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/scripts/ddl2cpp b/scripts/ddl2cpp index 6f4d4454..c93ac643 100755 --- a/scripts/ddl2cpp +++ b/scripts/ddl2cpp @@ -164,7 +164,7 @@ def ddlFunctionWord(string): ddlString = Or([QuotedString("'"), QuotedString("\"", escQuote='""'), QuotedString("`")]) negativeSign = Literal('-') ddlNum = Combine(Optional(negativeSign) + Word(nums + ".")) -ddlTerm = Word(alphas, alphanums + "_$") +ddlTerm = Word(alphanums + "_$") ddlName = Or([ddlTerm, ddlString]) ddlArguments = "(" + delimitedList(Or([ddlString, ddlTerm, ddlNum])) + ")" ddlNotNull = Group(ddlWord("NOT") + ddlWord("NULL")).setResultsName("notNull") @@ -181,7 +181,7 @@ ddlConstraint = Or([ ]) ddlColumn = Group(Optional(ddlConstraint).setResultsName("isConstraint") + OneOrMore(MatchFirst([ddlNotNull, ddlAutoValue, ddlDefaultValue, ddlFunctionWord("NOW"), ddlTerm, ddlNum, ddlColumnComment, ddlString, ddlArguments]))) createTable = Group(ddlWord("CREATE") + ddlWord("TABLE") + ddlName.setResultsName("tableName") + "(" + Group(delimitedList(ddlColumn)).setResultsName("columns") + ")").setResultsName("create") - +#ddlString.setDebug(True) #uncomment to debug pyparsing ddl = ZeroOrMore(Suppress(SkipTo(createTable, False)) + createTable)