Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revision | a2721885306dc506be570dfbc8d1253f93587943 (tree) |
---|---|
Zeit | 2022-02-16 06:21:12 |
Autor | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
Sequence is now a list of children; test d1/d2 work. More work is needed
@@ -125,15 +125,14 @@ | ||
125 | 125 | """An expression with Quantification; like optional, or repetition. The subclasses defines which Quantification""" |
126 | 126 | |
127 | 127 | |
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 | |
134 | 132 | |
135 | 133 | 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 | + | |
137 | 136 | |
138 | 137 | class OrderedChoice(MixIn_children_tuple, Expression): # A | B | C | ... the order is relevant |
139 | 138 | """OC: A _tuple_ of alternative expressions""" |
@@ -91,7 +91,7 @@ | ||
91 | 91 | # OneOrMore(single_expr) |
92 | 92 | def visit_sequence(self, node, children) -> peg.Sequence: |
93 | 93 | 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) | |
95 | 95 | |
96 | 96 | |
97 | 97 | def visit_predicate(self, node, children): |
@@ -35,7 +35,7 @@ | ||
35 | 35 | |
36 | 36 | def assert_Seq(ast, length=None, ids=None): |
37 | 37 | 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()" | |
39 | 39 | if length: |
40 | 40 | assert len(ast) == length, f" ... of specified length=={length}" |
41 | 41 | if ids: |
@@ -55,5 +55,5 @@ | ||
55 | 55 | ast = parse(txt, grammar.expression) |
56 | 56 | # result is same a above |
57 | 57 | 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" |
@@ -29,5 +29,5 @@ | ||
29 | 29 | ast = parse(txt, grammar.expression) |
30 | 30 | |
31 | 31 | 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") |
@@ -25,16 +25,14 @@ | ||
25 | 25 | def test_seq_of_two_as_expression(): |
26 | 26 | txt = "A B" |
27 | 27 | ast = parse(txt, grammar.expression) |
28 | + logger.debug(f'seq2expr:: ast={ast}:{type(ast).__name__}') | |
29 | + assert_Seq(ast, length=2, ids=('A', 'B')) | |
28 | 30 | |
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" | |
31 | 31 | |
32 | 32 | def test_seq_of_three_as_expression(): |
33 | 33 | txt = "A B C" |
34 | 34 | 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')) | |
38 | 36 | |
39 | 37 | |
40 | 38 | def test_seq_of_three_with_quantification(): |