Feature: AST transformers#19
Conversation
Add testing module (empty for now)
|
|
||
|
|
||
| @dataclass | ||
| class GenericErrorNode(Node, ErrorNode): |
There was a problem hiding this comment.
What is the difference between ErrorNode and GenericErrorNode?
There was a problem hiding this comment.
In Kolasu, ErrorNode is an interface and GenericErrorNode a concrete class. I ported the same hierarchy even though in Python we could just use ErrorNode.
| return isinstance(decl_type, type) and issubclass(decl_type, Node) | ||
|
|
||
|
|
||
| class Concept(ABCMeta): |
There was a problem hiding this comment.
With LionWeb we may want to introduce Concept with a close but perhaps different meaning
There was a problem hiding this comment.
Do we have a corresponding Concept in Kolasu?
There was a problem hiding this comment.
For now Concept does not exist in Kolasu
There was a problem hiding this comment.
No, at least not explicitly. In Kolasu the concept is implicitly defined by extension methods using reflection. We could have done the same in Pylasu, but the IDE doesn't give any support for Python extension methods, so it's better to be more explicit if possible.
| from pylasu.model import Node | ||
|
|
||
|
|
||
| def assert_asts_are_equal(expected: Node, actual: Node, context: str = "<root>", consider_position: bool = False): |
There was a problem hiding this comment.
No, this is a work in progress, I opened the PR just to have a high-level view of the changes
|
|
||
|
|
||
| @dataclass | ||
| class GenericNode(Node): |
There was a problem hiding this comment.
In an experiment I am working on (based on Kolasu), I add a sort of annotation on "normal" nodes to mark them as placeholder for something we do not know how to translate yet. In this way I can create a node of the type that fit the hierarchy. In Python this may be less of an issue, given it is dynamic.
Perhaps this generic node could contain a reference to the thing that we do not know how to translate. That could be useful for debugging
There was a problem hiding this comment.
Indeed the GenericNode has its origin set to the transformation source, this is ported exactly from Kolasu
ftomassetti
left a comment
There was a problem hiding this comment.
I just added some minor comments, as I am not a Python expert
|
This is now good to go I think, I've ported all the necessary stuff from Kolasu. |
| flake8 tests --config tests/.flake8 --count --show-source --statistics | ||
| - name: Generate test parser | ||
| run: java -cp ../antlr-4.10.1-complete.jar org.antlr.v4.Tool -Dlanguage=Python3 -visitor -o simple_lang SimpleLangLexer.g4 SimpleLangParser.g4 | ||
| - name: Generate test parsers |
There was a problem hiding this comment.
Would it be useful to put these into a script, so that it can be used also when running tests locally?
There was a problem hiding this comment.
Yes, it makes sense
| def test_identitiy_transformer(self): | ||
| prop = PropertyRef("statements") | ||
| transformer = ASTTransformer() | ||
| transformer.register_node_factory(CU, CU).with_child(prop, prop) |
There was a problem hiding this comment.
Is this different from an IdentityTransformer?
There was a problem hiding this comment.
Yes because it has a child. This is ported as-is from Kolasu.
| DisplayIntStatement(value=456)]) | ||
| transformed_cu = transformer.transform(cu) | ||
| self.assertEqual(cu, transformed_cu) | ||
| # assertTrue { transformed_cu.hasValidParents() } |
There was a problem hiding this comment.
We may want to uncomment or remove
There was a problem hiding this comment.
I've opened a separate issue to port hasValidParents noting that this test will have to be enabled.
|
+1 |
Ported from Kolasu, not yet as well-tested as in Kolasu (we're missing some infrastructure)