mirror of
https://github.com/rbock/sqlpp11.git
synced 2024-11-16 04:47:18 +08:00
ddl2cpp: Require word breaks when parsing SQL keywords.
This commit is contained in:
parent
8797dfd79e
commit
43fa5c445c
@ -45,7 +45,8 @@ ddlString = (
|
||||
ddlTerm = pp.Word(pp.alphas + "_", pp.alphanums + "_.$")
|
||||
ddlName = pp.Or([ddlTerm, ddlString, pp.Combine(ddlString + "." + ddlString), pp.Combine(ddlTerm + ddlString)])
|
||||
ddlOperator = pp.Or(
|
||||
map(pp.CaselessLiteral, ["+", "-", "*", "/", "<", "<=", ">", ">=", "=", "%", "DIV"])
|
||||
map(pp.CaselessLiteral, ["+", "-", "*", "/", "<", "<=", ">", ">=", "=", "%"]),
|
||||
pp.CaselessKeyword("DIV")
|
||||
)
|
||||
|
||||
ddlBracedExpression = pp.Forward()
|
||||
@ -162,44 +163,44 @@ def initDllParser():
|
||||
# Column and constraint parsers
|
||||
|
||||
ddlBoolean = pp.Or(
|
||||
map(pp.CaselessLiteral, sorted(ddlBooleanTypes, reverse=True))
|
||||
map(pp.CaselessKeyword, sorted(ddlBooleanTypes, reverse=True))
|
||||
).setParseAction(pp.replaceWith("boolean"))
|
||||
|
||||
ddlInteger = pp.Or(
|
||||
map(pp.CaselessLiteral, sorted(ddlIntegerTypes, reverse=True))
|
||||
map(pp.CaselessKeyword, sorted(ddlIntegerTypes, reverse=True))
|
||||
).setParseAction(pp.replaceWith("integer"))
|
||||
|
||||
ddlSerial = (
|
||||
pp.Or(map(pp.CaselessLiteral, sorted(ddlSerialTypes, reverse=True)))
|
||||
pp.Or(map(pp.CaselessKeyword, sorted(ddlSerialTypes, reverse=True)))
|
||||
.setParseAction(pp.replaceWith("integer"))
|
||||
.setResultsName("hasAutoValue")
|
||||
)
|
||||
|
||||
ddlFloatingPoint = pp.Or(
|
||||
map(pp.CaselessLiteral, sorted(ddlFloatingPointTypes, reverse=True))
|
||||
map(pp.CaselessKeyword, sorted(ddlFloatingPointTypes, reverse=True))
|
||||
).setParseAction(pp.replaceWith("floating_point"))
|
||||
|
||||
ddlText = pp.Or(
|
||||
map(pp.CaselessLiteral, sorted(ddlTextTypes, reverse=True))
|
||||
map(pp.CaselessKeyword, sorted(ddlTextTypes, reverse=True))
|
||||
).setParseAction(pp.replaceWith("text"))
|
||||
|
||||
|
||||
ddlBlob = pp.Or(
|
||||
map(pp.CaselessLiteral, sorted(ddlBlobTypes, reverse=True))
|
||||
map(pp.CaselessKeyword, sorted(ddlBlobTypes, reverse=True))
|
||||
).setParseAction(pp.replaceWith("blob"))
|
||||
|
||||
ddlDate = (
|
||||
pp.Or(map(pp.CaselessLiteral, sorted(ddlDateTypes, reverse=True)))
|
||||
pp.Or(map(pp.CaselessKeyword, sorted(ddlDateTypes, reverse=True)))
|
||||
.setParseAction(pp.replaceWith("day_point"))
|
||||
.setResultsName("warnTimezone")
|
||||
)
|
||||
|
||||
ddlDateTime = pp.Or(
|
||||
map(pp.CaselessLiteral, sorted(ddlDateTimeTypes, reverse=True))
|
||||
map(pp.CaselessKeyword, sorted(ddlDateTimeTypes, reverse=True))
|
||||
).setParseAction(pp.replaceWith("time_point"))
|
||||
|
||||
ddlTime = pp.Or(
|
||||
map(pp.CaselessLiteral, sorted(ddlTimeTypes, reverse=True))
|
||||
map(pp.CaselessKeyword, sorted(ddlTimeTypes, reverse=True))
|
||||
).setParseAction(pp.replaceWith("time_of_day"))
|
||||
|
||||
ddlUnknown = pp.Word(pp.alphanums).setParseAction(pp.replaceWith("UNKNOWN"))
|
||||
@ -217,19 +218,19 @@ def initDllParser():
|
||||
| ddlUnknown
|
||||
)
|
||||
|
||||
ddlUnsigned = pp.CaselessLiteral("UNSIGNED").setResultsName("isUnsigned")
|
||||
ddlUnsigned = pp.CaselessKeyword("UNSIGNED").setResultsName("isUnsigned")
|
||||
ddlDigits = "," + pp.Word(pp.nums)
|
||||
ddlWidth = ddlLeft + pp.Word(pp.nums) + pp.Optional(ddlDigits) + ddlRight
|
||||
ddlTimezone = (
|
||||
(pp.CaselessLiteral("with") | pp.CaselessLiteral("without"))
|
||||
+ pp.CaselessLiteral("time")
|
||||
+ pp.CaselessLiteral("zone")
|
||||
(pp.CaselessKeyword("with") | pp.CaselessKeyword("without"))
|
||||
+ pp.CaselessKeyword("time")
|
||||
+ pp.CaselessKeyword("zone")
|
||||
)
|
||||
|
||||
ddlNotNull = pp.Group(
|
||||
pp.CaselessLiteral("NOT") + pp.CaselessLiteral("NULL")
|
||||
pp.CaselessKeyword("NOT") + pp.CaselessKeyword("NULL")
|
||||
).setResultsName("notNull")
|
||||
ddlDefaultValue = pp.CaselessLiteral("DEFAULT").setResultsName("hasDefaultValue")
|
||||
ddlDefaultValue = pp.CaselessKeyword("DEFAULT").setResultsName("hasDefaultValue")
|
||||
|
||||
ddlAutoKeywords = [
|
||||
"AUTO_INCREMENT",
|
||||
@ -242,7 +243,7 @@ def initDllParser():
|
||||
"BIGSERIAL",
|
||||
"GENERATED",
|
||||
]
|
||||
ddlAutoValue = pp.Or(map(pp.CaselessLiteral, sorted(ddlAutoKeywords, reverse=True)))
|
||||
ddlAutoValue = pp.Or(map(pp.CaselessKeyword, sorted(ddlAutoKeywords, reverse=True)))
|
||||
|
||||
ddlConstraintKeywords = [
|
||||
"CONSTRAINT",
|
||||
@ -256,7 +257,7 @@ def initDllParser():
|
||||
"PERIOD",
|
||||
]
|
||||
ddlConstraint = pp.Group(
|
||||
pp.Or(map(pp.CaselessLiteral, sorted(ddlConstraintKeywords, reverse=True)))
|
||||
pp.Or(map(pp.CaselessKeyword, sorted(ddlConstraintKeywords, reverse=True)))
|
||||
+ ddlExpression
|
||||
).setResultsName("isConstraint")
|
||||
|
||||
@ -268,25 +269,25 @@ def initDllParser():
|
||||
+ pp.ZeroOrMore(
|
||||
ddlUnsigned("isUnsigned")
|
||||
| ddlNotNull("notNull")
|
||||
| pp.CaselessLiteral("null")
|
||||
| pp.CaselessKeyword("null")
|
||||
| ddlAutoValue("hasAutoValue")
|
||||
| ddlDefaultValue("hasDefaultValue")
|
||||
| pp.Suppress(pp.OneOrMore(pp.Or(map(pp.CaselessLiteral, sorted(ddlConstraintKeywords, reverse=True)))))
|
||||
| pp.Suppress(pp.OneOrMore(pp.Or(map(pp.CaselessKeyword, sorted(ddlConstraintKeywords, reverse=True)))))
|
||||
| pp.Suppress(ddlExpression)
|
||||
)
|
||||
)
|
||||
|
||||
# CREATE TABLE parser
|
||||
ddlIfNotExists = pp.Group(
|
||||
pp.CaselessLiteral("IF") + pp.CaselessLiteral("NOT") + pp.CaselessLiteral("EXISTS")
|
||||
pp.CaselessKeyword("IF") + pp.CaselessKeyword("NOT") + pp.CaselessKeyword("EXISTS")
|
||||
).setResultsName("ifNotExists")
|
||||
ddlOrReplace = pp.Group(
|
||||
pp.CaselessLiteral("OR") + pp.CaselessLiteral("REPLACE")
|
||||
pp.CaselessKeyword("OR") + pp.CaselessKeyword("REPLACE")
|
||||
).setResultsName("orReplace")
|
||||
ddlCreateTable = pp.Group(
|
||||
pp.CaselessLiteral("CREATE")
|
||||
pp.CaselessKeyword("CREATE")
|
||||
+ pp.Suppress(pp.Optional(ddlOrReplace))
|
||||
+ pp.CaselessLiteral("TABLE")
|
||||
+ pp.CaselessKeyword("TABLE")
|
||||
+ pp.Suppress(pp.Optional(ddlIfNotExists))
|
||||
+ ddlName.setResultsName("tableName")
|
||||
+ ddlLeft
|
||||
|
Loading…
Reference in New Issue
Block a user