Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
Revision | 34fd10eda4e21e8137dbd52d1882ce334efc33e5 (tree) |
---|---|
Zeit | 2022-01-02 01:02:51 |
Autor | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
@@ -48,7 +48,7 @@ | ||
48 | 48 | regex_variants(txt:='''R"""re__Rstr_d3"""''', expect=txt[4:-3]) |
49 | 49 | regex_variants(txt:='''r"""re__rstr_d3"""''', expect=txt[4:-3]) |
50 | 50 | |
51 | - | |
51 | +@pytest.mark.skip(reason="single_expr has no visitor -- as that is now in expressions") | |
52 | 52 | def test_term_as_single_expr(): # A term is **ALSO** a single_expr |
53 | 53 | txt="'a string'" |
54 | 54 | ast = parse(txt, grammar.single_expr) |
@@ -56,6 +56,7 @@ | ||
56 | 56 | assert len(ast.value) == 1, "An expression with length==1" |
57 | 57 | assert ast.value[0].value == txt[1:-1], "It's correct value should be without quotes" |
58 | 58 | |
59 | + | |
59 | 60 | def test_term_as_expressions(): # A term is **ALSO an expressions |
60 | 61 | txt="'a string'" |
61 | 62 | ast = parse(txt, grammar.expressions) |
@@ -22,6 +22,7 @@ | ||
22 | 22 | assert ast.name == txt |
23 | 23 | |
24 | 24 | |
25 | +@pytest.mark.skip(reason="single_expr has no visitor -- as that is now in expressions") | |
25 | 26 | def test_ID_as_single_expr(): |
26 | 27 | txt="aRef" |
27 | 28 | ast = parse(txt, grammar.single_expr) |
@@ -29,6 +30,7 @@ | ||
29 | 30 | assert len(ast.value) == 1, "An expression with length==1" |
30 | 31 | assert ast.value[0].name == txt, "The name of the (ID of the) Expression-value is still the same" |
31 | 32 | |
33 | + | |
32 | 34 | def test_ID_as_expressions(): |
33 | 35 | txt="aRef" |
34 | 36 | ast = parse(txt, grammar.expressions) |
@@ -14,8 +14,6 @@ | ||
14 | 14 | assert id.name == name, err_message if err_message else f"Note correct name, expected {name}" |
15 | 15 | |
16 | 16 | |
17 | - | |
18 | - | |
19 | 17 | def test_trivial_rule_with_2IDS(): |
20 | 18 | """The most simple rule has only two IDs""" |
21 | 19 |
@@ -31,3 +29,25 @@ | ||
31 | 29 | assert len(expr) ==1, " .. of length==1" |
32 | 30 | assert_ID(expr[0], txt.split()[2], "The single element of the expression is an ID (the 2nd) -- which name is the 3 part of the txt") |
33 | 31 | |
32 | + | |
33 | +def test_rule_with_ID_and_terms(): | |
34 | + txt = """aRule <- 'aStr' aCross /regexp/ ;""" | |
35 | + ast = parse(txt, grammar.rule) | |
36 | + | |
37 | + assert isinstance(ast, peg.Rule), "It should be an ID" | |
38 | + assert_ID(ast.name, txt.split()[0], "The name of a rule is a ID with the left-side ID as name") | |
39 | + | |
40 | + expr = ast.expr; | |
41 | + assert isinstance(expr, peg.Expression), "The expression is an Expression ..." | |
42 | + assert isinstance(expr, peg.Sequence), " .. and a Sequence .." | |
43 | + assert len(expr) == 3, " .. of length==3" | |
44 | + | |
45 | + assert isinstance(expr[0], peg.StrTerm) | |
46 | + assert expr[0].value == 'aStr' | |
47 | + | |
48 | + assert_ID(expr[1], "aCross") | |
49 | + | |
50 | + assert isinstance(expr[2], peg.RegExpTerm) | |
51 | + assert expr[2].value == 'regexp' | |
52 | + | |
53 | + |
@@ -21,10 +21,14 @@ | ||
21 | 21 | return peg.Rule(name=children[0],expr=children[1], parse_tree=node) |
22 | 22 | |
23 | 23 | |
24 | - def visit_single_expr(self, node, children): # [ rule_crossref, term, group, predicate ] Optional([ '?' , '*' , '+' , '#' ])) | |
25 | - if len(children) == 1: # No optional part | |
26 | - ast = peg.Sequence(value=children, parse_tree=node) | |
27 | - else: | |
28 | - assert NotImplementedError("To Do: visit_single_expr with optional part") # XXX | |
29 | - return ast | |
24 | +# def visit_single_expr(self, node, children): # [ rule_crossref, term, group, predicate ] Optional([ '?' , '*' , '+' , '#' ])) | |
25 | +# if len(children) == 1: # No optional part | |
26 | +# #ast = peg.Sequence(value=children, parse_tree=node) | |
27 | +# return super().visit__default__(node, children) | |
28 | +# else: | |
29 | +# assert NotImplementedError("To Do: visit_single_expr with optional part") # XXX | |
30 | +# return ast | |
30 | 31 | |
32 | + def visit_expressions(self, node, children): # OneOrMore(single_expr), Optional( '|' , expressions ) | |
33 | + return peg.Sequence(value=children, parse_tree=node) | |
34 | + |