• R/O
  • SSH

提交

标签
No 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

修订版a2721885306dc506be570dfbc8d1253f93587943 (tree)
时间2022-02-16 06:21:12
作者Albert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

Sequence is now a list of children; test d1/d2 work. More work is needed

更改概述

差异

diff -r 541186bd35ed -r a2721885306d castle/ast/peg.py
--- a/castle/ast/peg.py Tue Feb 15 21:47:51 2022 +0100
+++ b/castle/ast/peg.py Tue Feb 15 22:21:12 2022 +0100
@@ -125,15 +125,14 @@
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._childeren; 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"""
diff -r 541186bd35ed -r a2721885306d castle/readers/parser/visitor.py
--- a/castle/readers/parser/visitor.py Tue Feb 15 21:47:51 2022 +0100
+++ b/castle/readers/parser/visitor.py Tue Feb 15 22:21:12 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 541186bd35ed -r a2721885306d pytst/readers/parser/d2_ast/__init__.py
--- a/pytst/readers/parser/d2_ast/__init__.py Tue Feb 15 21:47:51 2022 +0100
+++ b/pytst/readers/parser/d2_ast/__init__.py Tue Feb 15 22:21:12 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 541186bd35ed -r a2721885306d pytst/readers/parser/d2_ast/test_1_term.py
--- a/pytst/readers/parser/d2_ast/test_1_term.py Tue Feb 15 21:47:51 2022 +0100
+++ b/pytst/readers/parser/d2_ast/test_1_term.py Tue Feb 15 22:21:12 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 541186bd35ed -r a2721885306d pytst/readers/parser/d2_ast/test_2_ID.py
--- a/pytst/readers/parser/d2_ast/test_2_ID.py Tue Feb 15 21:47:51 2022 +0100
+++ b/pytst/readers/parser/d2_ast/test_2_ID.py Tue Feb 15 22:21:12 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 541186bd35ed -r a2721885306d pytst/readers/parser/d2_ast/test_3_Seq.py
--- a/pytst/readers/parser/d2_ast/test_3_Seq.py Tue Feb 15 21:47:51 2022 +0100
+++ b/pytst/readers/parser/d2_ast/test_3_Seq.py Tue Feb 15 22:21:12 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():