-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommon.py
55 lines (48 loc) · 1.21 KB
/
common.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
from enum import Enum, auto
class TokenType(Enum):
VERSION = auto()
MIN_SUP = auto()
AUTHOR = auto()
DESCRIPTION = auto()
LOG = auto()
DOC = auto()
HELP = auto()
SEMI = auto()
STRING = auto()
IDENT = auto()
LCBRACE = auto()
RCBRACE = auto()
STRUCT = auto()
SLICE = auto()
TRIGGER = auto()
TRICOND = auto()
PYARG = auto()
LPAREN = auto()
RPAREN = auto()
CONFIG = auto()
COMMAND = auto()
ARGUMENT = auto()
EOF = auto()
class TagTokenType(Enum):
VERSION = auto()
MIN_SUP = auto()
AUTHOR = auto()
DESCRIPTION = auto()
LOG = auto()
DOC = auto()
HELP = auto()
class Token:
def __init__(self, type, value=None):
if type in [
TokenType.STRING,
TokenType.IDENT,
TokenType.COMMAND,
TokenType.ARGUMENT,
] and not isinstance(value, str):
raise ValueError("This token type requires a string value")
self.type = type
self.value = value
def __str__(self):
if self.value is not None:
return f"{self.type.name}({self.value})"
return self.type.name