• R/O
  • SSH

Commit

Tags
Aucun tag

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

Révision34fd10eda4e21e8137dbd52d1882ce334efc33e5 (tree)
l'heure2022-01-02 01:02:51
AuteurAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Message de Log

implementation of 'Expressions' improved: (visitor of) single_expr is not that relevant, it can in expressions ... -- tests

Change Summary

Modification

diff -r 8508bf239c70 -r 34fd10eda4e2 Arpeggio/pytst/d2_ast/test_1_term.py
--- a/Arpeggio/pytst/d2_ast/test_1_term.py Fri Dec 31 21:32:14 2021 +0100
+++ b/Arpeggio/pytst/d2_ast/test_1_term.py Sat Jan 01 17:02:51 2022 +0100
@@ -48,7 +48,7 @@
4848 regex_variants(txt:='''R"""re__Rstr_d3"""''', expect=txt[4:-3])
4949 regex_variants(txt:='''r"""re__rstr_d3"""''', expect=txt[4:-3])
5050
51-
51+@pytest.mark.skip(reason="single_expr has no visitor -- as that is now in expressions")
5252 def test_term_as_single_expr(): # A term is **ALSO** a single_expr
5353 txt="'a string'"
5454 ast = parse(txt, grammar.single_expr)
@@ -56,6 +56,7 @@
5656 assert len(ast.value) == 1, "An expression with length==1"
5757 assert ast.value[0].value == txt[1:-1], "It's correct value should be without quotes"
5858
59+
5960 def test_term_as_expressions(): # A term is **ALSO an expressions
6061 txt="'a string'"
6162 ast = parse(txt, grammar.expressions)
diff -r 8508bf239c70 -r 34fd10eda4e2 Arpeggio/pytst/d2_ast/test_2_ID.py
--- a/Arpeggio/pytst/d2_ast/test_2_ID.py Fri Dec 31 21:32:14 2021 +0100
+++ b/Arpeggio/pytst/d2_ast/test_2_ID.py Sat Jan 01 17:02:51 2022 +0100
@@ -22,6 +22,7 @@
2222 assert ast.name == txt
2323
2424
25+@pytest.mark.skip(reason="single_expr has no visitor -- as that is now in expressions")
2526 def test_ID_as_single_expr():
2627 txt="aRef"
2728 ast = parse(txt, grammar.single_expr)
@@ -29,6 +30,7 @@
2930 assert len(ast.value) == 1, "An expression with length==1"
3031 assert ast.value[0].name == txt, "The name of the (ID of the) Expression-value is still the same"
3132
33+
3234 def test_ID_as_expressions():
3335 txt="aRef"
3436 ast = parse(txt, grammar.expressions)
diff -r 8508bf239c70 -r 34fd10eda4e2 Arpeggio/pytst/d2_ast/test_3_rule.py
--- a/Arpeggio/pytst/d2_ast/test_3_rule.py Fri Dec 31 21:32:14 2021 +0100
+++ b/Arpeggio/pytst/d2_ast/test_3_rule.py Sat Jan 01 17:02:51 2022 +0100
@@ -14,8 +14,6 @@
1414 assert id.name == name, err_message if err_message else f"Note correct name, expected {name}"
1515
1616
17-
18-
1917 def test_trivial_rule_with_2IDS():
2018 """The most simple rule has only two IDs"""
2119
@@ -31,3 +29,25 @@
3129 assert len(expr) ==1, " .. of length==1"
3230 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")
3331
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+
diff -r 8508bf239c70 -r 34fd10eda4e2 Arpeggio/visitor.py
--- a/Arpeggio/visitor.py Fri Dec 31 21:32:14 2021 +0100
+++ b/Arpeggio/visitor.py Sat Jan 01 17:02:51 2022 +0100
@@ -21,10 +21,14 @@
2121 return peg.Rule(name=children[0],expr=children[1], parse_tree=node)
2222
2323
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
3031
32+ def visit_expressions(self, node, children): # OneOrMore(single_expr), Optional( '|' , expressions )
33+ return peg.Sequence(value=children, parse_tree=node)
34+