-
Notifications
You must be signed in to change notification settings - Fork 0
/
tokens.py
32 lines (27 loc) · 857 Bytes
/
tokens.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
import enum
class TokenType(enum.Enum):
WHTSPC = 0
OPERATOR = 1
KEYWORD = 2
IDENTIFIER = 3
COMMENT = 4
NUMBER = 5
SYS_TASK = 6
COMP_DIRECTIVE = 7
STRING = 8
DEFAULT = 9 # Used for detecting errors during debugging
EMPTY_STRING = 10 # Used for detecting errors during debugging
class Token:
''' The wrapper class for raw verilog tokens '''
def __init__(self,content,token_type):
''' The constructor
Params:
content (str) : the character content of the token
token_type (TokenType) : one of the values on the enum token_type
'''
self.content = content
self.token_type = token_type
def info(self):
return f"type: <{self.token_type}>, content: <{self.content}>"
def to_string(self):
return self.content