• 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évisionbea0d751eb50f252c484e09867ac7daeaeffe832 (tree)
l'heure2021-12-21 07:48:17
AuteurAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Message de Log

Term is ALSO an single_expr and ALSO an expressions. TODO visitor +peg for more complex cases

Change Summary

Modification

diff -r cd3f73efabaf -r bea0d751eb50 AST/castle/_base.py
--- a/AST/castle/_base.py Mon Dec 20 22:14:58 2021 +0100
+++ b/AST/castle/_base.py Mon Dec 20 23:48:17 2021 +0100
@@ -22,7 +22,7 @@
2222
2323 @staticmethod
2424 def validate_or_raise(value):
25- if not isinstance(value, str):
25+ if not isinstance(value, (ID, str)):
2626 raise IDError("not a str of ID")
2727 if ID._pattern.fullmatch(value) is None:
2828 raise IDError("not a valid pattern")
diff -r cd3f73efabaf -r bea0d751eb50 AST/castle/peg.py
--- a/AST/castle/peg.py Mon Dec 20 22:14:58 2021 +0100
+++ b/AST/castle/peg.py Mon Dec 20 23:48:17 2021 +0100
@@ -65,7 +65,14 @@
6565
6666 class ManyExpression(Expression): pass # abstract
6767 class Group(Expression):pass
68-class Sequence(Expression):pass
68+
69+class Sequence(Expression):
70+ """A "list of expressions; can be of length=1"""
71+ def __init__(self, *, value=None, **kwargs):
72+ super().__init__(**kwargs)
73+ self.value=value
74+
75+
6976 class OrderedChoice(Expression):pass
7077 class Predicate(Expression): pass # abstract
7178
diff -r cd3f73efabaf -r bea0d751eb50 Arpeggio/pytst/d2_ast/test_1_term.py
--- a/Arpeggio/pytst/d2_ast/test_1_term.py Mon Dec 20 22:14:58 2021 +0100
+++ b/Arpeggio/pytst/d2_ast/test_1_term.py Mon Dec 20 23:48:17 2021 +0100
@@ -43,7 +43,7 @@
4343 assert isinstance(ast, peg.RegExpTerm), "... and a RegExp"
4444 assert ast.value == expect, "And the regex-pre/postfix should be removed from the value"
4545
46-def testregex_variants():
46+def test_regex_variants():
4747 regex_variants(txt:="""/a reg.ex/""", expect=txt[1:-1]) # Same a test_regex_RE
4848 regex_variants(txt:="""/re_slash/""", expect=txt[1:-1])
4949
@@ -58,3 +58,19 @@
5858 regex_variants(txt:='''r"""re__rstr_d3"""''', expect=txt[4:-3])
5959
6060
61+def test_term_as_single_expr(): # A term is **ALSO** a single_expr
62+ txt="'a string'"
63+ ast = parse(txt, grammar.single_expr)
64+ assert isinstance(ast, peg.Expression), "A (str)term is also an Expression"
65+ assert len(ast.value) == 1, "An expression with length==1"
66+ assert ast.value[0].value == txt[1:-1], "It's correct value should be without quotes"
67+
68+def test_term_as_expressions(): # A term is **ALSO an expressions
69+ txt="'a string'"
70+ ast = parse(txt, grammar.expressions)
71+ # result is same a above
72+ assert isinstance(ast, peg.Expression), "A (str)term is also an Expression"
73+ assert len(ast.value) == 1, "An expression with length==1"
74+ assert ast.value[0].value == txt[1:-1], "It's correct value should be without quotes"
75+
76+
diff -r cd3f73efabaf -r bea0d751eb50 Arpeggio/visitor.py
--- a/Arpeggio/visitor.py Mon Dec 20 22:14:58 2021 +0100
+++ b/Arpeggio/visitor.py Mon Dec 20 23:48:17 2021 +0100
@@ -10,3 +10,10 @@
1010 def visit_regex_term(self, node, children):
1111 ast = peg.RegExpTerm(value=node[1], parse_tree=node)
1212 return ast
13+ def visit_single_expr(self, node, children): # [ rule_crossref, term, group, predicate ] Optional([ '?' , '*' , '+' , '#' ]))
14+ if len(children) == 1: # No optional part
15+ ast = peg.Sequence(value=children, parse_tree=node)
16+ else:
17+ assert NotImplementedError("To Do: visit_single_expr with optional part")
18+
19+ return ast