Castle: The best Real-Time/Embedded/HighTech language EVER. Attempt 2
修訂 | 4c63a33e26c27a7c97af4d8d65db179a09b3686f (tree) |
---|---|
時間 | 2021-12-20 06:21:15 |
作者 | Albert Mietus < albert AT mietus DOT nl > |
Commiter | Albert Mietus < albert AT mietus DOT nl > |
moved visitor-class from test to visitor.py (PegVisitor)
@@ -1,23 +1,18 @@ | ||
1 | 1 | import pytest |
2 | 2 | |
3 | 3 | import grammar |
4 | +import visitor | |
4 | 5 | import arpeggio |
5 | 6 | |
6 | 7 | import sys; sys.path.append("./../AST/") ; sys.path.append("./../../AST/") |
7 | 8 | from castle import peg # has the AST clases |
8 | 9 | |
9 | 10 | |
10 | -class DemoVisitor(arpeggio.PTNodeVisitor): | |
11 | - def visit_str_term(self, node, children): | |
12 | - ast = peg.StrTerm(value=node[1], parse_tree=node) | |
13 | - return ast | |
14 | - | |
15 | - | |
16 | 11 | def parse(txt, rule): |
17 | 12 | parser = arpeggio.ParserPython(rule) |
18 | 13 | pt = parser.parse(txt) |
19 | 14 | assert pt.position_end == len(txt), "Did not parse all input"# JTBS |
20 | - ast = arpeggio.visit_parse_tree(pt, DemoVisitor()) | |
15 | + ast = arpeggio.visit_parse_tree(pt, visitor.PegVisitor()) | |
21 | 16 | return ast |
22 | 17 | |
23 | 18 | def test_simple_str(): |
@@ -37,4 +32,3 @@ | ||
37 | 32 | assert ast.value == "triple string", "It's correct value should be without quotes" |
38 | 33 | assert ast.position == 0, "The term's position includes the quotes ..." |
39 | 34 | assert ast.position_end == len(txt), " ... on both ends." |
40 | - |
@@ -0,0 +1,9 @@ | ||
1 | +import arpeggio | |
2 | + | |
3 | +import sys; sys.path.append("./../AST/") ; sys.path.append("./../../AST/") | |
4 | +from castle import peg # has the AST clases | |
5 | + | |
6 | +class PegVisitor(arpeggio.PTNodeVisitor): | |
7 | + def visit_str_term(self, node, children): | |
8 | + ast = peg.StrTerm(value=node[1], parse_tree=node) | |
9 | + return ast |