-
Notifications
You must be signed in to change notification settings - Fork 47
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve nullability support for generated parsers #142
Conversation
@ftomassetti let me know what you think about this. |
This can't be done at all, as it's then impossible to check if a |
} | ||
is ErrorNode -> return t.toString() | ||
is TerminalNode -> return t.symbol.text!! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we write something along the lines of:
t.symbol.text ?: throw IllegalStateException("Token symbol text should not be null")
Wouldn't it be null for EOF?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that's better, I'll commit the change.
|
||
if (symbol != null) { | ||
return symbol.text!! | ||
when (t) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we factor out the return?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We cannot as that's a non-local return (when
inside of an if
). Will be supported starting from Kotlin 2.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, wrong answer. We cannot, as it requires an else
branch to return something. We don't want that, we want it to continue over the rest of the method, as it was doing with if-elseif.
It looks good, but it is difficult to assess if the code work. I assume tests guarantee that to some extent. I just added minor comments |
@ftomassetti haven't changed much so everything still work as before. The "issue" here is the change in generated method names. This is a breaking change basically. |
Thank you for your answers. Merging |
Improves type nullability support in generated parsers, and solves a part of #84.
In this case we are checking for the
optional
property - injected by the ANTLR code generator - on theContextTokenGetterDecl
andContextRuleGetterDecl
template parts.Note that the generated methods now start with
get*
instead offind*
.The missing part is for
TokenDecl
. We would have to use thelateinit
modifier, but I'm still unsure if it's appropriate.