Homogeneous/Reflective APIs #22
ftomassetti
started this conversation in
General
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I think that it would be useful to provide some form of homogenous/reflective API, similar to what is available in EMF or JavaParser.
By homogeneous/reflective APIs, I mean some APIs that given a node, can permit to access a definition of that node type. That definition should list all the features of that node (i.e., its structure). For example, given a node representing a sum, I should get to know that the type of the node is SumContext and a node of type SumContext is supposed to have one child left of type Expression and a child right of type Expression.
These APIs permit writing generic algorithms, very useful for serialization/deserialization, for example.
Currently in ANTLR 4 we use reflection to get something similar, but reflection has its disadvantages and it is not available on all platforms. Also, it requires some work to the user. For targets for which we do not have reflection, sometimes we parse the grammar and generate some file that we use to get that data. I think we can make the life of users easier by providing these APIs out of the box.
In practice I would imagine that each Context class could have a method called
getConcept
/getStructure
and that method would return an object describing the structure of that kind of node. I believe the implementation effort would be reduced.Beta Was this translation helpful? Give feedback.
All reactions