mapres 3.dev7__tar.gz → 3.dev8__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {mapres-3.dev7/src/mapres.egg-info → mapres-3.dev8}/PKG-INFO +1 -1
- {mapres-3.dev7 → mapres-3.dev8}/pyproject.toml +1 -1
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/parser.py +30 -10
- {mapres-3.dev7 → mapres-3.dev8/src/mapres.egg-info}/PKG-INFO +1 -1
- {mapres-3.dev7 → mapres-3.dev8}/LICENSE +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/README.md +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/setup.cfg +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/__init__.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/ast.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/cache.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/datamap.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/evaluator.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/exceptions.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/layers.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/maps/__init__.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/maps/color.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/maps/time.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/resolver.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres/tokenizer.py +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres.egg-info/SOURCES.txt +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres.egg-info/dependency_links.txt +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres.egg-info/requires.txt +0 -0
- {mapres-3.dev7 → mapres-3.dev8}/src/mapres.egg-info/top_level.txt +0 -0
|
@@ -12,22 +12,23 @@ class Parser:
|
|
|
12
12
|
self.i = 0
|
|
13
13
|
self.n = len(tokens)
|
|
14
14
|
|
|
15
|
-
def peek(self, k=0) -> Token | None:
|
|
15
|
+
def peek(self, k: int = 0) -> Token | None:
|
|
16
16
|
idx = self.i + k
|
|
17
17
|
return self.tokens[idx] if idx < self.n else None
|
|
18
18
|
|
|
19
|
-
def advance(self, k=1):
|
|
19
|
+
def advance(self, k: int = 1) -> None:
|
|
20
20
|
self.i += k
|
|
21
21
|
|
|
22
|
-
def expect(self, type_: TokenType):
|
|
22
|
+
def expect(self, type_: TokenType) -> Token:
|
|
23
23
|
tok = self.peek()
|
|
24
24
|
if tok is None or tok.type != type_:
|
|
25
25
|
raise ParserError(f"Expected {type_}, got {tok}")
|
|
26
26
|
self.advance()
|
|
27
27
|
return tok
|
|
28
28
|
|
|
29
|
+
# top-level template parse
|
|
29
30
|
def parse(self) -> TemplateNode:
|
|
30
|
-
children = []
|
|
31
|
+
children: list[Node] = []
|
|
31
32
|
while self.peek() is not None:
|
|
32
33
|
tok = self.peek()
|
|
33
34
|
if tok.type is TokenType.TEXT:
|
|
@@ -37,6 +38,23 @@ class Parser:
|
|
|
37
38
|
children.append(self.parse_token())
|
|
38
39
|
return TemplateNode(children)
|
|
39
40
|
|
|
41
|
+
# nested template parse (for IDENT(...))
|
|
42
|
+
def parse_until(self, stop_types: tuple[TokenType, ...]) -> TemplateNode:
|
|
43
|
+
children: list[Node] = []
|
|
44
|
+
while True:
|
|
45
|
+
tok = self.peek()
|
|
46
|
+
if tok is None or tok.type in stop_types:
|
|
47
|
+
break
|
|
48
|
+
|
|
49
|
+
if tok.type is TokenType.TEXT:
|
|
50
|
+
children.append(TextNode(tok.value))
|
|
51
|
+
self.advance()
|
|
52
|
+
else:
|
|
53
|
+
children.append(self.parse_token())
|
|
54
|
+
|
|
55
|
+
return TemplateNode(children)
|
|
56
|
+
|
|
57
|
+
# dispatch by opening delimiter
|
|
40
58
|
def parse_token(self) -> Node:
|
|
41
59
|
tok = self.peek()
|
|
42
60
|
|
|
@@ -60,21 +78,23 @@ class Parser:
|
|
|
60
78
|
|
|
61
79
|
raise ParserError(f"Unexpected token {tok}")
|
|
62
80
|
|
|
63
|
-
#
|
|
64
|
-
|
|
65
|
-
def _parse_ident_or_call(self, closing_type, syntax_name: str) -> Node:
|
|
81
|
+
# core pattern: IDENT or IDENT(arg)
|
|
82
|
+
def _parse_ident_or_call(self, closing_type: TokenType, syntax_name: str) -> Node:
|
|
66
83
|
ident_tok = self.expect(TokenType.IDENT)
|
|
67
84
|
name = ident_tok.value
|
|
68
85
|
|
|
69
|
-
#
|
|
86
|
+
# IDENT(arg)
|
|
70
87
|
if self.peek() and self.peek().type is TokenType.LPAREN:
|
|
71
88
|
self.advance() # consume '('
|
|
72
|
-
|
|
89
|
+
|
|
90
|
+
# parse only until RPAREN
|
|
91
|
+
arg = self.parse_until((TokenType.RPAREN,))
|
|
92
|
+
|
|
73
93
|
self.expect(TokenType.RPAREN)
|
|
74
94
|
self.expect(closing_type)
|
|
75
95
|
return CallNode(name=name, arg=arg, syntax=syntax_name)
|
|
76
96
|
|
|
77
|
-
#
|
|
97
|
+
# IDENT
|
|
78
98
|
self.expect(closing_type)
|
|
79
99
|
return IdentNode(name=name, syntax=syntax_name)
|
|
80
100
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|