Error tolerant ASTs in Kolasu 1.6 #306
Replies: 1 comment 2 replies
-
I would consider solve this problem through a compiler plugin. The rationale is that in Kolasu 1.6 we plan to use a compiler plugin for several features (observability of features, auto-setting parents, and possibly generating languages and concepts). The idea is that, for each AST class we would create a corresponding Error class:
We would be able to use the The advantage is that:
The problem is that, if the AST is used without checking for errors we could get the InvalidASTException exception inadvertently.
And based on that fact it has errors or not we could decide not to process the AST further with components that full expect a correct AST (for example an interpreter). |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
When creating an AST we would like to support two use-cases that are difficult to reconcile:
For example, we would like ASTs to be strictly defined:
When writing an interpreter we want to be sure that left and right are present in each AdditionExpr, so that we can write code such as:
On the other hand when parsing an incorrect piece of code we do not want to completely fail but to build a partial AST, which is still useful to support editors, to perform code analysis, etc. This would typically be done by making classes less strict:
Which in turn requires to use nullability checks in all the places.
And what about assigning a left value to indicate that some Expr could ot be recognized? How could we represent that?
For this problem we looked into various alternatives, discussed today in the Tech Meeting:
Below the authors will illustrate their ideas so that we can discuss them and pick one solution
Beta Was this translation helpful? Give feedback.
All reactions