• R/O
  • SSH

Commit

Tags
Keine Tags

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

Revision937f62a25c9654fa389ade623863ae6d59fd0f04 (tree)
Zeit2022-02-16 06:51:05
AutorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

Merged: Sequence is now a list/tuple of children; ._value is gone

Ändern Zusammenfassung

Diff

diff -r 002223ee76a7 -r 937f62a25c96 Makefile
--- a/Makefile Mon Feb 14 22:38:45 2022 +0100
+++ b/Makefile Tue Feb 15 22:51:05 2022 +0100
@@ -16,10 +16,10 @@
1616
1717 python-demo:
1818 @echo Running all 'dem*.py' python-files
19- for d in `find demos -type f -iname \*.py `; do echo "=== $$d ==="; python $$d; echo "=========="; done
19+ export PYTHONPATH=`pwd`; for d in `find demos -type f -iname \*.py `; do echo "=== $$d ==="; python $$d; echo "=========="; done
2020
2121 pytest-demo:
22- pytest -s demos
22+ PYTHONPATH=`pwd` pytest -s demos
2323
2424
2525 missing_visitor: castle/readers/parser/grammar.py
diff -r 002223ee76a7 -r 937f62a25c96 castle/ast/ast2xml.py
--- a/castle/ast/ast2xml.py Mon Feb 14 22:38:45 2022 +0100
+++ b/castle/ast/ast2xml.py Tue Feb 15 22:51:05 2022 +0100
@@ -57,9 +57,9 @@
5757 def RegExpTerm2xml(self, ast, parent): self._MixIn_value_attribute2xml(ast, parent, 'RegExpTerm')
5858
5959 def Sequence2xml(self, ast, parent) ->None:
60- logger.debug(f"Sequence2xml::ast={ast._valType(ast.value)}")
60+ logger.debug(f"Sequence2xml::ast={ast._valType(ast._children)}")
6161 seq = ET.SubElement(parent, 'Sequence')
62- for elm in ast.value:
62+ for elm in ast:
6363 self._ast2xml(elm, parent=seq)
6464
6565 def Rule2xml(self, ast, parent) ->None:
diff -r 002223ee76a7 -r 937f62a25c96 castle/ast/peg.py
--- a/castle/ast/peg.py Mon Feb 14 22:38:45 2022 +0100
+++ b/castle/ast/peg.py Tue Feb 15 22:51:05 2022 +0100
@@ -44,13 +44,13 @@
4444 logger.debug(f'{self._typeName(self)}.MixIn_children_tuple:: children[{len(children)}]:=' +
4545 ('[[' +', '.join(f'{c}:{type(c).__name__}' for c in children) + ']]') if isinstance(children, list) else f's>>{children}<<')
4646 super().__init__(**kwargs)
47- self._childeren = tuple(children)
47+ self._children = tuple(children)
4848
4949 def __len__(self):
50- return len(self._childeren)
50+ return len(self._children)
5151 def __getitem__(self, key):
52- return self._childeren[key]
53- def __iter__(self): return self._childeren.__iter__()
52+ return self._children[key]
53+ def __iter__(self): return self._children.__iter__()
5454
5555
5656 ##
@@ -125,21 +125,20 @@
125125 """An expression with Quantification; like optional, or repetition. The subclasses defines which Quantification"""
126126
127127
128-class Sequence(MixIn_value_attribute, Expression):
129- """A _list_ of expressions; can be of length=1"""
130- # __init__ (see MixIn) sets self._value; assuming it is a list
131-
132- def __len__(self): return len(self._value)
133- def __getitem__(self, n): return self._value[n]
128+#class Sequence(MixIn_value_attribute, Expression):
129+class Sequence(MixIn_children_tuple, Expression):
130+ """A sequence of expressions; can be of length=1"""
131+ # __init__ (see MixIn) sets self._children; assuming it is a list
134132
135133 def __str__(self): # mostly for debugging
136- return "Seq{{" + " ; ".join(f"{c}" for c in self._value) + "}}" # XXX ToDo: _value -> children
134+ return "Seq{{" + " ; ".join(f"{c}" for c in self) + "}}"
135+
137136
138137 class OrderedChoice(MixIn_children_tuple, Expression): # A | B | C | ... the order is relevant
139138 """OC: A _tuple_ of alternative expressions"""
140139
141140 def __str__(self): # mostly for debugging
142- return "OC{{" + " | ".join(f"{c}" for c in self._childeren) + "}}"
141+ return "OC{{" + " | ".join(f"{c}" for c in self._children) + "}}"
143142
144143 class Optional(Quantity):pass
145144 class ZeroOrMore(Quantity):pass
diff -r 002223ee76a7 -r 937f62a25c96 castle/readers/parser/visitor.py
--- a/castle/readers/parser/visitor.py Mon Feb 14 22:38:45 2022 +0100
+++ b/castle/readers/parser/visitor.py Tue Feb 15 22:51:05 2022 +0100
@@ -91,7 +91,7 @@
9191 # OneOrMore(single_expr)
9292 def visit_sequence(self, node, children) -> peg.Sequence:
9393 logger.debug(f'visit_sequence::{self._logstr_node_children(node, children)}')
94- return peg.Sequence(value=children, parse_tree=node)
94+ return peg.Sequence(children=children, parse_tree=node)
9595
9696
9797 def visit_predicate(self, node, children):
diff -r 002223ee76a7 -r 937f62a25c96 pytst/ast/XML_serialization/__init__.py
--- a/pytst/ast/XML_serialization/__init__.py Mon Feb 14 22:38:45 2022 +0100
+++ b/pytst/ast/XML_serialization/__init__.py Tue Feb 15 22:51:05 2022 +0100
@@ -12,7 +12,7 @@
1212 e1 = peg.ID(name=self.n1)
1313 e2 = peg.StrTerm(value=self.v2)
1414 e3 = peg.RegExpTerm(value=self.v3)
15- self.seq = peg.Sequence(value=[e1, e2, e3])
15+ self.seq = peg.Sequence(children=[e1, e2, e3])
1616 def assert_xml_Element(self, txt):
1717 assert_xml_Element(txt, tag='.//Sequence')
1818 assert_xml_Element(txt, tag='.//ID', name=self.n1)
diff -r 002223ee76a7 -r 937f62a25c96 pytst/ast/XML_serialization/test_1_simpleXML.py
--- a/pytst/ast/XML_serialization/test_1_simpleXML.py Mon Feb 14 22:38:45 2022 +0100
+++ b/pytst/ast/XML_serialization/test_1_simpleXML.py Tue Feb 15 22:51:05 2022 +0100
@@ -30,7 +30,7 @@
3030
3131 def test_Sequence_1(xml_serialize):
3232 e1 = peg.ID(name='ID_1')
33- txt= xml_serialize(peg.Sequence(value=[e1]))
33+ txt= xml_serialize(peg.Sequence(children=[e1]))
3434 logger.debug(f'XML:: {txt}')
3535 assert_xml_Element(txt, tag='Sequence')
3636 assert_xml_Element(txt, tag='.//ID', name='ID_1')
@@ -48,7 +48,7 @@
4848 def test_Rule_1ID(xml_serialize):
4949 rule_name = "RuleName"
5050 xref = "cross_ref"
51- expr = peg.Sequence(value=[peg.ID(name=xref)])
51+ expr = peg.Sequence(children=[peg.ID(name=xref)])
5252
5353 txt = xml_serialize(peg.Rule(name=peg.ID(name=rule_name), expr=expr))
5454 logger.debug(f'XML:: {txt}')
@@ -69,8 +69,8 @@
6969
7070
7171 def test_Rules(xml_serialize):
72- r1 = peg.Rule(name=peg.ID(name='rule_1'), expr=peg.Sequence(value=[peg.ID(name='id1')]))
73- r2 = peg.Rule(name=peg.ID(name='rule_2'), expr=peg.Sequence(value=[peg.StrTerm(value='str2')]))
72+ r1 = peg.Rule(name=peg.ID(name='rule_1'), expr=peg.Sequence(children=[peg.ID(name='id1')]))
73+ r2 = peg.Rule(name=peg.ID(name='rule_2'), expr=peg.Sequence(children=[peg.StrTerm(value='str2')]))
7474
7575 txt = xml_serialize(peg.Rules(children=[r1,r2]))
7676 logger.debug(f'XML:: {txt}')
diff -r 002223ee76a7 -r 937f62a25c96 pytst/readers/parser/d2_ast/__init__.py
--- a/pytst/readers/parser/d2_ast/__init__.py Mon Feb 14 22:38:45 2022 +0100
+++ b/pytst/readers/parser/d2_ast/__init__.py Tue Feb 15 22:51:05 2022 +0100
@@ -35,7 +35,7 @@
3535
3636 def assert_Seq(ast, length=None, ids=None):
3737 assert isinstance(ast, peg.Sequence)
38- assert isinstance(ast, peg.Expression), "A sequence is aslo an Expression()"
38+ assert isinstance(ast, peg.Expression), "A sequence is also an Expression()"
3939 if length:
4040 assert len(ast) == length, f" ... of specified length=={length}"
4141 if ids:
diff -r 002223ee76a7 -r 937f62a25c96 pytst/readers/parser/d2_ast/test_1_term.py
--- a/pytst/readers/parser/d2_ast/test_1_term.py Mon Feb 14 22:38:45 2022 +0100
+++ b/pytst/readers/parser/d2_ast/test_1_term.py Tue Feb 15 22:51:05 2022 +0100
@@ -55,5 +55,5 @@
5555 ast = parse(txt, grammar.expression)
5656 # result is same a above
5757 assert isinstance(ast, peg.Expression), "A (str)term is also an Expression"
58- assert len(ast.value) == 1, "An expression with length==1"
59- assert ast.value[0].value == txt[1:-1], "It's correct value should be without quotes"
58+ assert len(ast) == 1, "with a lengt of 1 -- note: use: ``len(sequence)`` not ``len(sequence._children)``!!"
59+ assert ast[0].value == txt[1:-1], "It's correct value should be without quotes"
diff -r 002223ee76a7 -r 937f62a25c96 pytst/readers/parser/d2_ast/test_2_ID.py
--- a/pytst/readers/parser/d2_ast/test_2_ID.py Mon Feb 14 22:38:45 2022 +0100
+++ b/pytst/readers/parser/d2_ast/test_2_ID.py Tue Feb 15 22:51:05 2022 +0100
@@ -29,5 +29,5 @@
2929 ast = parse(txt, grammar.expression)
3030
3131 assert isinstance(ast, peg.Expression), "A crossref is also an Expression"
32- assert len(ast.value) == 1, "An expression with length==1"
33- assert_ID(ast.value[0], name=txt, err_message= "The name of the (ID of the) Expression-value is still the same")
32+ assert len(ast) == 1, "An expression with length==1"
33+ assert_ID(ast[0], name=txt, err_message= "The name of the (ID of the) Expression-value is still the same")
diff -r 002223ee76a7 -r 937f62a25c96 pytst/readers/parser/d2_ast/test_3_Seq.py
--- a/pytst/readers/parser/d2_ast/test_3_Seq.py Mon Feb 14 22:38:45 2022 +0100
+++ b/pytst/readers/parser/d2_ast/test_3_Seq.py Tue Feb 15 22:51:05 2022 +0100
@@ -25,16 +25,14 @@
2525 def test_seq_of_two_as_expression():
2626 txt = "A B"
2727 ast = parse(txt, grammar.expression)
28+ logger.debug(f'seq2expr:: ast={ast}:{type(ast).__name__}')
29+ assert_Seq(ast, length=2, ids=('A', 'B'))
2830
29- assert_Seq(ast, 2, ids=('A', 'B'))
30- assert isinstance(ast.value, list), "It will be an `arpeggio.SemanticActionResult` which is a subclass of list"
3131
3232 def test_seq_of_three_as_expression():
3333 txt = "A B C"
3434 ast = parse(txt, grammar.expression)
35-
36- assert_Seq(ast, 3, ids=('A', 'B', 'C'))
37- assert isinstance(ast.value, list), "It will be an `arpeggio.SemanticActionResult` which is a subclass of list"
35+ assert_Seq(ast, length=3, ids=('A', 'B', 'C'))
3836
3937
4038 def test_seq_of_three_with_quantification():