-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_types.py
41 lines (27 loc) · 1.02 KB
/
simple_types.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""
This is the registry for all data types to know:
- How to use them in type definitions
- How to call them in function declarations / constants
- And how to work with them
"""
class SimpleType:
"""An entity to hold information about simple language type"""
def __init__(self, code: str, title: str, uppercase: str):
self.code = code
self.title = title
self.uppercase = uppercase
_simple_types = {}
def register(entity: SimpleType) -> None:
_simple_types[entity.code] = entity
def has_type(code: str) -> bool:
"""Does type with that code was registered?"""
return code in _simple_types
def get_type(code: str) -> SimpleType:
"""Get type definition by its code"""
return _simple_types[code]
register(SimpleType("int", "Int", "INT"))
register(SimpleType("string", "String", "STRING"))
register(SimpleType("long", "Long", "LONG"))
register(SimpleType("bool", "Boolean", "BOOL"))
register(SimpleType("byte", "Byte", "BYTE"))
register(SimpleType("float", "Float", "FLOAT"))