Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revision | b631a4bad20025b4a08decc33ac4370acdf4c8fc (tree) |
---|---|
Zeit | 2022-01-30 23:55:45 |
Autor | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
ASIS: Gowing to rewrite peg.Rules (children_as_tuple)
@@ -44,9 +44,9 @@ | ||
44 | 44 | def validate_or_raise(value): |
45 | 45 | if isinstance(value, ID): return |
46 | 46 | if not isinstance(value, str): |
47 | - raise IDError("not a str (or an ID)") | |
47 | + raise IDError(f">>{value}<<: not a str (or an ID)") | |
48 | 48 | if ID._pattern.fullmatch(value) is None: |
49 | - raise IDError("not a valid pattern") | |
49 | + raise IDError(f">>{value}<<: not a valid pattern") | |
50 | 50 | |
51 | 51 | def __init__(self, *, name, **kwargs): |
52 | 52 | super().__init__(**kwargs) |
@@ -56,24 +56,30 @@ | ||
56 | 56 | |
57 | 57 | |
58 | 58 | def _MixIn_value_attribute2xml(self, ast, parent, cls_name): |
59 | - logger.debug(f"{cls_name}2xml:: value={ast._valType(ast.value)}") | |
59 | + logger.debug(f"{cls_name}2xml:: ast={ast._valType(ast.value)}") | |
60 | 60 | ET.SubElement(parent, cls_name, value=ast.value) |
61 | 61 | |
62 | 62 | def StrTerm2xml(self, ast, parent): self._MixIn_value_attribute2xml(ast, parent, 'StrTerm') |
63 | 63 | def RegExpTerm2xml(self, ast, parent): self._MixIn_value_attribute2xml(ast, parent, 'RegExpTerm') |
64 | 64 | |
65 | 65 | def Sequence2xml(self, ast, parent) ->None: |
66 | - logger.debug(f"Sequence2xml:: value={ast._valType(ast.value)}") | |
66 | + logger.debug(f"Sequence2xml::ast={ast._valType(ast.value)}") | |
67 | 67 | seq = ET.SubElement(parent, 'Sequence') |
68 | 68 | for elm in ast.value: |
69 | - self._ast2xml(elm, seq) | |
69 | + self._ast2xml(elm, parent=seq) | |
70 | 70 | |
71 | 71 | def Rule2xml(self, ast, parent) ->None: |
72 | 72 | rule = ET.SubElement(parent, 'Rule', name=ast.name.name) |
73 | - self._ast2xml(ast.expr, rule) | |
73 | + self._ast2xml(ast.expr, parent=rule) | |
74 | + | |
75 | + def Rules2xml(self, ast, parent) ->None: | |
76 | + logger.debug(f"Rules2xml:: ast[{len(ast)}]") | |
77 | + for child in ast: | |
78 | + logger.debug(f'Rules2xml child={child}:{type(child)}') | |
79 | + self._ast2xml(child, parent=parent) | |
74 | 80 | |
75 | 81 | ############# |
76 | - def Rules2xml(self, ast, parent) ->None: ... | |
82 | + | |
77 | 83 | def Setting2xml(self, ast, parent) ->None: ... |
78 | 84 | def Settings2xml(self, ast, parent) ->None: ... |
79 | 85 | def Grammar2xml(self, ast, parent) ->None: ... |
@@ -100,5 +100,13 @@ | ||
100 | 100 | rn.assert_xml_Element(txt) |
101 | 101 | seq.assert_xml_Element(txt) |
102 | 102 | |
103 | +@pytest.mark.skip(reason="Will rewrite peg.Rules first --") | |
104 | +def test_Rules(xml_serialize): | |
105 | + r1 = peg.Rule(name='rule_1', expr=peg.Sequence(value=[peg.ID(name='id1')])) | |
106 | + r2 = peg.Rule(name='rule_2', expr=peg.Sequence(value=[peg.StrTerm(value='str2')])) | |
103 | 107 | |
108 | + txt = xml_serialize(peg.Rules(children=[r1,r2])) | |
109 | + logger.debug(f'XML:: {txt}') | |
104 | 110 | |
111 | + assert False, "not yet done" | |
112 | + |