This repository was archived by the owner on Mar 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsyntax.py
More file actions
77 lines (53 loc) · 1.32 KB
/
syntax.py
File metadata and controls
77 lines (53 loc) · 1.32 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
from dataclasses import dataclass
from dataclasses import field
from numpy import integer
from typing import List
from typing import Type
@dataclass
class SyntaxTerm:
pass
@dataclass
class SyntaxNumber(SyntaxTerm):
value: integer
value_type: Type = field(init=False)
def __post_init__(self):
self.value_type = type(self.value)
assert issubclass(
self.value_type, integer
), self.value_type
@dataclass
class SyntaxIdentifier(SyntaxTerm):
name: str
@dataclass
class SyntaxComment(SyntaxTerm):
text: str
@dataclass
class SyntaxBlock(SyntaxTerm):
statements: List["SyntaxStatement"]
@dataclass
class SyntaxStatement:
terms: List[SyntaxTerm]
@dataclass
class SyntaxExpression(SyntaxStatement):
pass
@dataclass
class SyntaxBinding(SyntaxStatement):
bindings: List[SyntaxIdentifier]
@dataclass
class SyntaxAssignment(SyntaxBinding):
pass
@dataclass
class SyntaxModification(SyntaxBinding):
pass
@dataclass
class SyntaxMethodDefinition(SyntaxStatement):
binding: SyntaxIdentifier
definition_block: SyntaxBlock
def __init__(
self,
binding: SyntaxIdentifier,
definition: SyntaxStatement,
):
super().__init__(terms=[])
self.binding = binding
self.definition_block = SyntaxBlock([definition])