mapres 3.dev18__py3-none-any.whl → 3.dev19__py3-none-any.whl
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/datamap.py +2 -1
- mapres/evaluator.py +15 -4
- {mapres-3.dev18.dist-info → mapres-3.dev19.dist-info}/METADATA +1 -1
- {mapres-3.dev18.dist-info → mapres-3.dev19.dist-info}/RECORD +7 -7
- {mapres-3.dev18.dist-info → mapres-3.dev19.dist-info}/WHEEL +0 -0
- {mapres-3.dev18.dist-info → mapres-3.dev19.dist-info}/licenses/LICENSE +0 -0
- {mapres-3.dev18.dist-info → mapres-3.dev19.dist-info}/top_level.txt +0 -0
mapres/datamap.py
CHANGED
|
@@ -101,7 +101,8 @@ def datamap(_cls=None, *, syntax=None, mode=None, recursive=None,
|
|
|
101
101
|
def wrap(cls):
|
|
102
102
|
cls.__syntax__ = syntax
|
|
103
103
|
cls.__mode__ = mode
|
|
104
|
-
cls.__recursive__ = recursive
|
|
104
|
+
cls.__recursive__ = recursive if recursive is not None else False
|
|
105
|
+
# cls.__recursive__ = recursive
|
|
105
106
|
cls.__missing_key__ = missing_key or 'error'
|
|
106
107
|
cls.__ignore_delimiters__ = ignore_delimiters or False
|
|
107
108
|
|
mapres/evaluator.py
CHANGED
|
@@ -14,45 +14,54 @@ class Evaluator:
|
|
|
14
14
|
self.ctx = ctx or {}
|
|
15
15
|
self._seen = set() # cycle detection
|
|
16
16
|
|
|
17
|
+
# public api
|
|
17
18
|
def evaluate(self, node):
|
|
18
19
|
return self._eval(node)
|
|
19
20
|
|
|
21
|
+
# internal dispatch
|
|
20
22
|
def _eval(self, node):
|
|
21
23
|
if isinstance(node, TemplateNode):
|
|
22
24
|
return self._eval_template(node)
|
|
25
|
+
|
|
23
26
|
if isinstance(node, TextNode):
|
|
24
27
|
return node.text
|
|
28
|
+
|
|
25
29
|
if isinstance(node, IdentNode):
|
|
26
30
|
return self._eval_ident(node)
|
|
31
|
+
|
|
27
32
|
if isinstance(node, CallNode):
|
|
28
33
|
return self._eval_call(node)
|
|
34
|
+
|
|
29
35
|
raise EvaluationError(f'Unknown AST node: {node}')
|
|
30
36
|
|
|
37
|
+
# template
|
|
31
38
|
def _eval_template(self, node: TemplateNode):
|
|
32
39
|
parts = []
|
|
33
40
|
for child in node.children:
|
|
34
41
|
parts.append(self._eval(child))
|
|
35
42
|
out = ''.join(parts)
|
|
36
43
|
|
|
37
|
-
# recursion disabled for now
|
|
44
|
+
# recursion disabled for now (Mapres 2–style behavior)
|
|
38
45
|
return out
|
|
39
46
|
|
|
47
|
+
# identifier
|
|
40
48
|
def _eval_ident(self, node: IdentNode):
|
|
41
49
|
name = node.name
|
|
42
50
|
|
|
51
|
+
# cycle detection
|
|
43
52
|
if name in self._seen:
|
|
44
53
|
raise EvaluationError(f"Cycle detected in identifier '{name}'")
|
|
45
54
|
self._seen.add(name)
|
|
46
55
|
|
|
47
56
|
parts = name.split('.')
|
|
48
57
|
|
|
49
|
-
# ctx first
|
|
58
|
+
# 1. ctx first
|
|
50
59
|
val = self._lookup_hierarchical(self.ctx, parts)
|
|
51
60
|
if val is not None:
|
|
52
61
|
self._seen.remove(name)
|
|
53
62
|
return str(val)
|
|
54
63
|
|
|
55
|
-
# syntax-bound maps
|
|
64
|
+
# 2. syntax-bound maps
|
|
56
65
|
for m in self.layerstack.all_maps():
|
|
57
66
|
if getattr(m, '__syntax__', None) not in (None, node.syntax):
|
|
58
67
|
continue
|
|
@@ -66,6 +75,7 @@ class Evaluator:
|
|
|
66
75
|
self._seen.remove(name)
|
|
67
76
|
raise MissingKeyError(name)
|
|
68
77
|
|
|
78
|
+
# call (nested token)
|
|
69
79
|
def _eval_call(self, node: CallNode):
|
|
70
80
|
outer = node.name
|
|
71
81
|
|
|
@@ -96,6 +106,7 @@ class Evaluator:
|
|
|
96
106
|
self._seen.remove(outer)
|
|
97
107
|
raise MissingKeyError(f'{outer}({arg_value})')
|
|
98
108
|
|
|
109
|
+
# helpers
|
|
99
110
|
def _map_to_dict(self, m):
|
|
100
111
|
if hasattr(m, 'as_map'):
|
|
101
112
|
return m.as_map()
|
|
@@ -113,7 +124,7 @@ class Evaluator:
|
|
|
113
124
|
cur = cur[p]
|
|
114
125
|
return cur
|
|
115
126
|
|
|
116
|
-
# recursion helpers now
|
|
127
|
+
# recursion helpers now effectively disabled
|
|
117
128
|
def _has_recursive_maps(self):
|
|
118
129
|
return False
|
|
119
130
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
mapres/__init__.py,sha256=t23ofM-wzpPByYi1rEQonxyU1yyza4ZzwwHDZUa5QqA,1010
|
|
2
2
|
mapres/ast.py,sha256=6PcMkwtNHYD8xEkdyzDgn_mRTj1ZaWSyuHZK3BtXiuo,427
|
|
3
3
|
mapres/cache.py,sha256=hbvsoc6Qw3RhWAEfOOpKHtC7i9EomoUgWzyd4dnH71w,333
|
|
4
|
-
mapres/datamap.py,sha256=
|
|
5
|
-
mapres/evaluator.py,sha256=
|
|
4
|
+
mapres/datamap.py,sha256=ZTLRBtUCxB9_OTsMk9jEHt_ib9W98iJUlNuOxvJXgt4,5332
|
|
5
|
+
mapres/evaluator.py,sha256=pLvGORfd2qe0gRdnrhz3pHp-whh9WP4ktYxm8EONdCE,3822
|
|
6
6
|
mapres/exceptions.py,sha256=D2XKnrMkZDyUXQt2PmaKbj08FObWU00yXKGHwNpjvww,222
|
|
7
7
|
mapres/layers.py,sha256=sFc1eUOBg2BoB2cBXIleq8RMYcg5GZpUoCnGh-uKN6U,1380
|
|
8
8
|
mapres/parser.py,sha256=8XLCzYosvh81bN-Jddc1AM4w0X7bsHnBzmA8sq5_72w,4018
|
|
@@ -11,8 +11,8 @@ mapres/tokenizer.py,sha256=js0S1s8MkltdQoH5V1cLjdY0fFqZoGqmtP_OhEJEM6M,6539
|
|
|
11
11
|
mapres/maps/__init__.py,sha256=lIRRfem1Fw4iynuwUQ7BY5qrC4fbJKxqLivao2_Dtm4,239
|
|
12
12
|
mapres/maps/color.py,sha256=noRTGFNo9xLl5YEhX0tttV6i_oDAiptXmRVnkr5EzwM,1348
|
|
13
13
|
mapres/maps/time.py,sha256=TyncycYoIGVZWps32qWlFy2a2hTayvZWVHu9uh2nid8,2050
|
|
14
|
-
mapres-3.
|
|
15
|
-
mapres-3.
|
|
16
|
-
mapres-3.
|
|
17
|
-
mapres-3.
|
|
18
|
-
mapres-3.
|
|
14
|
+
mapres-3.dev19.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
15
|
+
mapres-3.dev19.dist-info/METADATA,sha256=3TALs5m0rP4P0WyctslQvZwyTH0QNo3d1oQLvOuAVDU,1476
|
|
16
|
+
mapres-3.dev19.dist-info/WHEEL,sha256=K260EYznzXsJYBQGqmI8VTxEdiZYNvDZwW9cBh9-_MA,91
|
|
17
|
+
mapres-3.dev19.dist-info/top_level.txt,sha256=5LMVQqJdtyjxfzv7wJBOZ-360m0Yc79w_-Y7s3n6cTw,7
|
|
18
|
+
mapres-3.dev19.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|