• R/O
  • SSH

Commit

Tags
Aucun tag

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2


Commit MetaInfo

Révision2698c678f331b930955b06d039dcccce32f48ca3 (tree)
l'heure2022-02-08 23:30:23
AuteurAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Message de Log

AST-2-XML: UnorderedGroup works. Refactored log and renamed aux-class: StdSequence_withAsserts

Change Summary

Modification

diff -r 5661f00112da -r 2698c678f331 castle/ast/ast2xml.py
--- a/castle/ast/ast2xml.py Mon Feb 07 22:02:05 2022 +0100
+++ b/castle/ast/ast2xml.py Tue Feb 08 15:30:23 2022 +0100
@@ -9,7 +9,7 @@
99
1010 class XML_Serialize(serialization.Serialize):
1111 def serialize(self, ast) -> str:
12- logger.debug(f"ast={ast._valType(ast)}")
12+ logger.debug(f"serialize:: ast={ast._valType(ast)}")
1313
1414 tree = self._ast2xml(ast)
1515 return ET.tostring(tree, encoding="unicode")
@@ -21,7 +21,7 @@
2121
2222 method_name = f'{type(ast).__name__}2xml'
2323 visitor = getattr(self, method_name, None)
24- logger.debug(f'visitor={visitor}')
24+ logger.debug(f'_ast2xml:: visitor={visitor}')
2525
2626 if visitor:
2727 visitor(ast=ast, parent=parent) # Grow the tree
@@ -31,7 +31,7 @@
3131
3232
3333 def ID2xml(self, ast, parent) ->None:
34- logger.debug(f"ast={ast._valType(ast)} parent={parent} ast.name={ast.name}")
34+ logger.debug(f"ID2xml:: ast={ast._valType(ast)} parent={parent} ast.name={ast.name}")
3535 ET.SubElement(parent, 'ID', name=ast.name)
3636
3737
@@ -71,12 +71,19 @@
7171 logger.debug(f'Rules2xml type(child)={type(child)}')
7272 self._ast2xml(child, parent=parent)
7373
74+ def UnorderedGroup2xml(self, ast, parent) ->None:
75+ g = ET.SubElement(parent, 'UnorderedGroup')
76+ self._ast2xml(ast.expr, g)
77+
7478 #############
7579
76-# def Setting2xml(self, ast, parent) ->None: ...
77-# def Settings2xml(self, ast, parent) ->None: ...
80+## def Setting2xml(self, ast, parent) ->None:
81+## logger.debug(f"Setting2xml:: ast[{len(ast)}]")
82+## ET.SubElement(parent, 'Setting', name=ast.name, value=ast.value)
83+
84+## def Settings2xml(self, ast, parent) ->None: ...
7885 # def Grammar2xml(self, ast, parent) ->None: ...
79-# def UnorderedGroup2xml(self, ast, parent) ->None: ...
86+
8087 # def Quantity2xml(self, ast, parent) ->None: ...
8188
8289 # def OrderedChoice2xml(self, ast, parent) ->None: ...
diff -r 5661f00112da -r 2698c678f331 pytst/ast/XML_serialization/test_1_simpleXML.py
--- a/pytst/ast/XML_serialization/test_1_simpleXML.py Mon Feb 07 22:02:05 2022 +0100
+++ b/pytst/ast/XML_serialization/test_1_simpleXML.py Tue Feb 08 15:30:23 2022 +0100
@@ -5,7 +5,7 @@
55 from castle.ast import peg, serialization
66
77
8-class Sequence:
8+class StdSequence_withAsserts:
99 def __init__(self):
1010 self.n1, self.v2, self.v3 = 'ID_1', 'str_2', 'regexp_3'
1111 e1 = peg.ID(name=self.n1)
@@ -22,6 +22,12 @@
2222 def assert_xml_Element(txt, tag,
2323 version="0.0",
2424 **attribs,):
25+ """Partially verify an xml-string; focusing on 'tag' -- a real tag, or a (limited) XPATH-expression.
26+
27+ This `tag` (expression) should result in a single hit!. *Use e.g `[0]` as suffix to select one from a list*.
28+ Pass ``key=value`` **attribs** to verify the found tag has those attribs and values
29+ """
30+
2531 tree = ET.fromstring(txt)
2632 if version:
2733 assert tree.attrib['version'] == version
@@ -65,7 +71,7 @@
6571
6672
6773 def test_Sequence_3(xml_serialize):
68- seq = Sequence()
74+ seq = StdSequence_withAsserts()
6975 txt= xml_serialize(seq.seq)
7076 logger.debug(f'XML:: {txt}')
7177
@@ -87,7 +93,7 @@
8793
8894 def test_Rule_Sequence(xml_serialize):
8995 rule_name = "Rule_Sequence"
90- seq = Sequence()
96+ seq = StdSequence_withAsserts()
9197
9298 txt = xml_serialize(peg.Rule(name=peg.ID(name=rule_name), expr=seq.seq))
9399 logger.debug(f'XML:: {txt}')
@@ -110,3 +116,11 @@
110116
111117 assert tree.findall('.//Rule[1]')[0].attrib['name'] == 'rule_1'
112118 assert tree.findall('.//Rule[2]//StrTerm')[0].attrib['value'] == 'str2'
119+
120+def test_UnorderedGroup(xml_serialize):
121+ seq = StdSequence_withAsserts()
122+ txt = xml_serialize(peg.UnorderedGroup(expr=seq.seq))
123+ logger.debug(f'XML:: {txt}')
124+
125+ assert_xml_Element(txt, 'UnorderedGroup')
126+ seq.assert_xml_Element(txt)