Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Révision | 9480be9594159eb5e13343b2941028be9da36756 (tree) |
---|---|
l'heure | 2022-01-03 08:01:50 |
Auteur | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
Now, UnorderedGroup also works
@@ -2,6 +2,7 @@ | ||
2 | 2 | """Base class for all Castle ATS nodes""" |
3 | 3 | |
4 | 4 | def __init__(self, *, parse_tree=None, **kwargs): |
5 | + assert len(kwargs)==0, "Do not call 'Object' with kwargs (caller is wrong)" | |
5 | 6 | super().__init__(**kwargs) |
6 | 7 | self._parse_tree = parse_tree |
7 | 8 |
@@ -62,7 +62,10 @@ | ||
62 | 62 | |
63 | 63 | |
64 | 64 | class Group(Expression):pass # abstract -- Do not use for a '(' ...')' group, that's a Sequence!! |
65 | -class UnorderedGroup(Group):pass # It looks like a Quantity, but is a group | |
65 | +class UnorderedGroup(Group): # It looks like a Quantity, but is a group | |
66 | + def __init__(self, *, expr=None, **kwargs): | |
67 | + super().__init__(**kwargs) | |
68 | + self.expr = expr | |
66 | 69 | |
67 | 70 | |
68 | 71 | class Quantity(Expression): # abstract |
@@ -85,7 +88,6 @@ | ||
85 | 88 | |
86 | 89 | class OrderedChoice(Expression):pass # It a an set of alternatives |
87 | 90 | |
88 | - | |
89 | 91 | class Optional(Quantity):pass |
90 | 92 | class ZeroOrMore(Quantity):pass |
91 | 93 | class OneOrMore(Quantity):pass |
@@ -36,3 +36,21 @@ | ||
36 | 36 | assert_ID(ngrp[0][0], 'A') |
37 | 37 | assert_ID(ngrp[0][1], 'B') |
38 | 38 | |
39 | + | |
40 | +def test_unordered_group(): | |
41 | + txt = "R <- ( A B )# ;" | |
42 | + | |
43 | + ast = parse(txt, grammar.rule) | |
44 | + assert_ID(ast.name, 'R') | |
45 | + | |
46 | + grp = ast.expr | |
47 | + assert len(grp)==1, "There should be only one expr; ..." | |
48 | + assert isinstance(grp[0], peg.UnorderedGroup), " ... the UnorderedGroup" | |
49 | + | |
50 | + exp = grp[0].expr | |
51 | + assert len(exp)==2, "The UnorderedGroup should have 2 elements .." | |
52 | + assert isinstance(exp, peg.Sequence), "... in a sequence" | |
53 | + | |
54 | + assert_ID(exp[0], 'A') | |
55 | + assert_ID(exp[1], 'B') | |
56 | + |