Strumenta / antlr-kotlin

Support for Kotlin as a target for ANTLR 4
Apache License 2.0
221 stars 47 forks source link

Improve nullability support for generated parsers #142

Closed lppedd closed 7 months ago

lppedd commented 7 months ago

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 the ContextTokenGetterDecl and ContextRuleGetterDecl template parts.
Note that the generated methods now start with get* instead of find*.

The missing part is for TokenDecl. We would have to use the lateinit modifier, but I'm still unsure if it's appropriate.

lppedd commented 7 months ago

@ftomassetti let me know what you think about this.

lppedd commented 7 months ago

The missing part is for TokenDecl. We would have to use the lateinit modifier, but I'm still unsure if it's appropriate.

This can't be done at all, as it's then impossible to check if a lateinit variable has been initialized or not.

ftomassetti commented 7 months ago

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

lppedd commented 7 months ago

@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.

ftomassetti commented 7 months ago

Thank you for your answers. Merging