Commit af5ed046 authored by Dave Kuhlman's avatar Dave Kuhlman

Merged in mustafa_cosar/generateds (pull request #36)

Generate uppercase enumerations
parents 50f2b2e7 e77d9827
......@@ -257,6 +257,14 @@ Namespacedef = ''
NoNameSpaceDefs = False
CleanupNameList = [(re.compile('[-:.]'), '_')]
PythonIdentifierRegex = re.compile('^[_A-Za-z][_A-Za-z0-9]*$')
UppercaseEnums = True
NameSeparationRegexList = [
re.compile("(.)([A-Z][a-z]+)"),
re.compile("(.)([0-9]+)"),
re.compile("([0-9])([a-zA-Z])"),
re.compile("([a-z])([A-Z])")
]
NonAlphaNumRegex = re.compile(r"\W+")
NamespacesDict = {}
SchemaNamespaceDict = {}
......@@ -6675,7 +6683,17 @@ def generateFromTree(wrt, prefix, elements, processed):
def generateSimpleTypes(wrt, prefix, simpleTypeDict):
global UppercaseEnums
def value2Uppercase(value):
if UppercaseEnums:
# This will turn a string 'fooBar123' to 'foo_Bar_123'
for regex in NameSeparationRegexList:
value = regex.sub(r"\1_\2", value)
value = value.upper()
value = NonAlphaNumRegex.sub("", value)
return value
def validateIdentifier(name):
name = value2Uppercase(name)
validPythonIdentifier = True
if not PythonIdentifierRegex.match(name):
# it may start with a digit
......
......@@ -727,18 +727,18 @@ def _cast(typ, value):
class RelationType(object):
down='down'
add='add'
DOWN='down'
ADD='add'
class RelationType2(object):
up='up'
subtract='subtract'
UP='up'
SUBTRACT='subtract'
class RelationType3(object):
right='right'
divide='divide'
RIGHT='right'
DIVIDE='divide'
class SpecialDate(GeneratedsSuper):
......
......@@ -727,10 +727,10 @@ def _cast(typ, value):
class ArrayTypes(object):
float_='float'
int='int'
Name='Name'
token='token'
FLOAT='float'
INT='int'
NAME='Name'
TOKEN='token'
class people(GeneratedsSuper):
......
......@@ -727,10 +727,10 @@ def _cast(typ, value):
class ArrayTypes(object):
float_='float'
int='int'
Name='Name'
token='token'
FLOAT='float'
INT='int'
NAME='Name'
TOKEN='token'
class people(GeneratedsSuper):
......
......@@ -727,10 +727,10 @@ def _cast(typ, value):
class ArrayTypes(object):
float_='float'
int='int'
Name='Name'
token='token'
FLOAT='float'
INT='int'
NAME='Name'
TOKEN='token'
class tomato_people(GeneratedsSuper):
......
......@@ -727,18 +727,18 @@ def _cast(typ, value):
class RelationType(object):
down='down'
add='add'
DOWN='down'
ADD='add'
class RelationType2(object):
down='down'
add='add'
DOWN='down'
ADD='add'
class RelationType3(object):
down='down'
add='add'
DOWN='down'
ADD='add'
class SpecialDate(GeneratedsSuper):
......
......@@ -933,7 +933,7 @@ class GenTest(unittest.TestCase):
diffs = list(diffs)
if diffs:
diffs = ''.join(diffs[2:12])
self.fail("Files differed:\n{}".format(diffs))
self.fail("Files '{}' and '{}' differed:\n{}".format(left, right, diffs))
def remove(self, filename):
if False:
......
......@@ -729,10 +729,10 @@ def _cast(typ, value):
class ArrayTypes(object):
float_='float'
int='int'
Name='Name'
token='token'
FLOAT='float'
INT='int'
NAME='Name'
TOKEN='token'
class peopleType(GeneratedsSuper):
......
......@@ -727,10 +727,10 @@ def _cast(typ, value):
class token_enum_st(object):
float_='float'
int='int'
Name='Name'
token='token'
FLOAT='float'
INT='int'
NAME='Name'
TOKEN='token'
class containerType(GeneratedsSuper):
......
......@@ -727,10 +727,10 @@ def _cast(typ, value):
class token_enum_st(object):
float_='float'
int='int'
Name='Name'
token='token'
FLOAT='float'
INT='int'
NAME='Name'
TOKEN='token'
class containerType(GeneratedsSuper):
......
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