3030# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3131
3232import sys
33+ from enum import Enum
3334import BaseType
3435
35- class EnumerationId (object ):
36- """
37- EXPRESS definition:
38- ===================
39- An enumeration data type has as its domain an ordered set of names. The names represent
40- values of the enumeration data type. These names are designated by enumeration_ids and are
41- referred to as enumeration items.
42- """
43- pass
44-
45- class ENUMERATION (object ):
36+ class ENUMERATION (Enum ):
4637 """
4738 EXPRESS definition:
4839 ===================
@@ -57,51 +48,17 @@ class ENUMERATION(object):
5748 (ahead,
5849 behind);
5950 END_TYPE; -- ahead_or_behind
51+
52+ Scoping and visibility of ENUMERATIONS is similar in EXPRESS and Python
6053
61- is implemented in python with the line:
62- >>> ahead_of_behind = ENUMERATION('ahead','behind', the_current_scope)
63- >>> ahead_or_behind.ahead
64- >>> ahead_of_behind.behind
65-
66- And, if and only if ahead and/or behind are not in scope (e.g. they are not entity names,
67- and/or many enums define the same enumeration identifier):
68- >>> ahead
69- >>> behind
54+ Enum implemented as per Standard Library / PEP 435
55+ >>> ahead_or_behind = ENUMERATION('ahead_or_behind', 'ahead behind')
56+ >>> race_position = ahead_or_behind.ahead
57+ >>> if race_position == ahead_or_behind.ahead:
58+ ... # do stuff!
7059 """
71- def __init__ (self ,* kargs ,** args ):
72- # first defining the scope
73- if args .has_key ('scope' ):
74- self ._scope = args ['scope' ]
75- else :
76- self ._scope = None
77- # store passed enum identifiers
78- self ._enum_id_names = list (kargs )
79- self ._enum_ids = []
80- # we create enums id from names, and create attributes
81- # for instance, from the identifier name 'ahead',
82- # we create an attribute ahead with which is a new
83- # instance of EnumerationId
84- for enum_id_name in self ._enum_id_names :
85- setattr (self ,enum_id_name ,EnumerationId ())
86- # we store this new attributes to the enum_ids list, which
87- # will be accessed by the type checker with the get_enum_ids method
88- self ._enum_ids .append (self .__getattribute__ (enum_id_name ))
89- #
90- # Then we check if the enums names can be added to the current scope:
91- # if the name is already in the scope, then another enums id or select
92- # has the same name -> we do nothing, enums will be called
93- # with ahead_of_behind.ahead or ahead_or_behind.behind.
94- # otherwise, they can be called as only ahead or behind
95- # Note: since ENUMERATIONS are defined *before* entities, if an entity
96- # has the same name as an enum id, it will replace it in the current scope.
97- #
98- for enum_id_name in self ._enum_id_names :
99- if not vars (self ._scope ).has_key (enum_id_name ):
100- vars (self ._scope )[enum_id_name ] = self .__getattribute__ (enum_id_name )
101-
102- def get_enum_ids (self ):
103- return self ._enum_ids
104-
60+ pass
61+
10562class SELECT (object ):
10663 """ A select data type has as its domain the union of the domains of the named data types in
10764 its select list. The select data type is a generalization of each of the named data types in its
0 commit comments