Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revisão | 96da5581ccbe5bd47c30d3a31f55fc4be50cb71c (tree) |
---|---|
Hora | 2022-01-03 07:43:33 |
Autor | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
groups (normal ones) do work
@@ -61,7 +61,7 @@ | ||
61 | 61 | self.settings = settings |
62 | 62 | |
63 | 63 | |
64 | -class Group(Expression):pass # abstract | |
64 | +class Group(Expression):pass # abstract -- Do not use for a '(' ...')' group, that's a Sequence!! | |
65 | 65 | class UnorderedGroup(Group):pass # It looks like a Quantity, but is a group |
66 | 66 | |
67 | 67 |
@@ -0,0 +1,38 @@ | ||
1 | +import pytest | |
2 | +import logging;logger = logging.getLogger(__name__) | |
3 | + | |
4 | +import grammar | |
5 | +from castle import peg # has the AST classes | |
6 | + | |
7 | +from . import parse, assert_ID | |
8 | + | |
9 | +def test_simple_group(): | |
10 | + txt = "R <- ( A B ) ;" | |
11 | + | |
12 | + ast = parse(txt, grammar.rule) | |
13 | + assert_ID(ast.name, 'R') | |
14 | + | |
15 | + grp = ast.expr | |
16 | + assert len(grp)==1, "There should be only one expr; the group" | |
17 | + assert isinstance(grp[0], peg.Sequence) | |
18 | + | |
19 | + assert_ID(grp[0][0], 'A') | |
20 | + assert_ID(grp[0][1], 'B') | |
21 | + | |
22 | +def test_nested_group(): | |
23 | + txt = "R <- ( ( A B ) ) ;" | |
24 | + | |
25 | + ast = parse(txt, grammar.rule) | |
26 | + assert_ID(ast.name, 'R') | |
27 | + | |
28 | + grp = ast.expr | |
29 | + assert len(grp)==1, "There should be only one expr; the group" | |
30 | + assert isinstance(grp[0], peg.Sequence) | |
31 | + | |
32 | + ngrp = grp[0] | |
33 | + assert len(ngrp)==1 | |
34 | + assert isinstance(ngrp[0], peg.Sequence) | |
35 | + | |
36 | + assert_ID(ngrp[0][0], 'A') | |
37 | + assert_ID(ngrp[0][1], 'B') | |
38 | + |
@@ -34,7 +34,7 @@ | ||
34 | 34 | n = children[0].name |
35 | 35 | except AttributeError: |
36 | 36 | n = str(children[0]) |
37 | - logger.warning(f'visit_single_expr==1:: {n}:{type(children[0])}') | |
37 | + logger.debug(f'visit_single_expr==1:: {n}:{type(children[0])}') | |
38 | 38 | return children[0] |
39 | 39 | elif len(children) == 2: # Optional part |
40 | 40 | logger.debug(f'visit_single_expr==2:: {children[0]}, {children[1]}') |