• R/O
  • SSH

Commit

Tags
Keine Tags

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

Revisioncd3f73efabaf2d7867cceab8974c70f5c575cb4a (tree)
Zeit2021-12-21 06:14:58
AutorAlbert Mietus < albert AT mietus DOT nl >
CommiterAlbert Mietus < albert AT mietus DOT nl >

Log Message

Added RegEx visitor (and tests)

Ändern Zusammenfassung

Diff

diff -r e301e7991ae1 -r cd3f73efabaf Arpeggio/pytst/d2_ast/test_1_term.py
--- a/Arpeggio/pytst/d2_ast/test_1_term.py Mon Dec 20 21:51:08 2021 +0100
+++ b/Arpeggio/pytst/d2_ast/test_1_term.py Mon Dec 20 22:14:58 2021 +0100
@@ -29,3 +29,32 @@
2929 assert isinstance(ast, peg.Terminal), "It should be a term ..."
3030 assert isinstance(ast, peg.StrTerm), "... and a str"
3131 assert ast.value == "triple string", "It's correct value should be without quotes"
32+
33+def test_regex_RE():
34+ txt='/a reg.ex/'
35+ ast = parse(txt, grammar.term)
36+ assert isinstance(ast, peg.Terminal), "It should be a term ..."
37+ assert isinstance(ast, peg.RegExpTerm), "... and a RegExp"
38+ assert ast.value == 'a reg.ex', "It's correct value should be without slahes -- note: the regex itself is a string"
39+
40+def regex_variants(txt, expect):
41+ ast = parse(txt, grammar.term)
42+ assert isinstance(ast, peg.Terminal), "It should be a term ..."
43+ assert isinstance(ast, peg.RegExpTerm), "... and a RegExp"
44+ assert ast.value == expect, "And the regex-pre/postfix should be removed from the value"
45+
46+def testregex_variants():
47+ regex_variants(txt:="""/a reg.ex/""", expect=txt[1:-1]) # Same a test_regex_RE
48+ regex_variants(txt:="""/re_slash/""", expect=txt[1:-1])
49+
50+ regex_variants(txt:="""R're__Rstr_s1'""", expect=txt[2:-1])
51+ regex_variants(txt:="""r're__rstr_s1'""", expect=txt[2:-1])
52+ regex_variants(txt:='''R"re__Rstr_d1"''', expect=txt[2:-1])
53+ regex_variants(txt:='''r"re__rstr_d1"''', expect=txt[2:-1])
54+
55+ regex_variants(txt:="""R'''re__Rstr_s3'''""", expect=txt[4:-3])
56+ regex_variants(txt:="""r'''re__rstr_s3'''""", expect=txt[4:-3])
57+ regex_variants(txt:='''R"""re__Rstr_d3"""''', expect=txt[4:-3])
58+ regex_variants(txt:='''r"""re__rstr_d3"""''', expect=txt[4:-3])
59+
60+
diff -r e301e7991ae1 -r cd3f73efabaf Arpeggio/visitor.py
--- a/Arpeggio/visitor.py Mon Dec 20 21:51:08 2021 +0100
+++ b/Arpeggio/visitor.py Mon Dec 20 22:14:58 2021 +0100
@@ -7,3 +7,6 @@
77 def visit_str_term(self, node, children):
88 ast = peg.StrTerm(value=node[1], parse_tree=node)
99 return ast
10+ def visit_regex_term(self, node, children):
11+ ast = peg.RegExpTerm(value=node[1], parse_tree=node)
12+ return ast