-
Notifications
You must be signed in to change notification settings - Fork 53
Fix code generation by partially backporting ANTLR5 changes #167
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
Fix code generation by partially backporting ANTLR5 changes #167
Conversation
Signed-off-by: Federico Tomassetti <[email protected]>
|
||
override fun getText(start: Token, stop: Token): String? = | ||
getText(Interval.of(start.tokenIndex, stop.tokenIndex)) | ||
override fun getText(start: Token?, stop: Token?): String? = |
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.
Could this be moved to TokenStream? Or become an extension method for TokenStream? In this way we would avoid the duplication we have in UnbufferedTokenStream
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.
@ftomassetti we could, but the better approach imo is to stick with simple code that is aligned with ANTLR4 Java, and ANTLR5, even if there is a small amount of duplication.
antlr-kotlin-runtime/src/commonMain/kotlin/org/antlr/v4/kotlinruntime/atn/ATNDeserializer.kt
Show resolved
Hide resolved
override val ruleIndex: Int = Rules.<struct.derivedFromName; format="cap"> | ||
|
||
<attrs:{a | public var <a>}; separator="\n"> | ||
<attrs:{a | @JvmField public var <a>}; separator="\n"> |
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.
This change may break existing code, which I think is acceptable, but I just wonder if it could make sense to first replicate the tests we have in ANTLR 5, so that we are more confident this change will work on all platforms before introducing it
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.
Also, this avoid the platform clash on the JVM, but does it work also on other platforms?
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.
This change may break existing code
I think that's not something you have to take into account, as I really doubt a Java consumer is using this Kotlin target.
so that we are more confident this change will work on all platforms before introducing it
I have tested with code specifically written to reproduce conflicting signatures, and all supported platforms compiled and run correctly.
Also, this avoid the platform clash on the JVM, but does it work also on other platforms?
The problem is specific to the JVM. In JS/TS you end up with code similar to:
class Example {
get foo(): number;
getFoo(): string;
}
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.
Ok, good
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.
@piacenti ahh no, this is what I did test, your case is a new one.
I will do a new release. I think that some time in the near future we should move to 1.0, as this code seems performing well, pass all tests, and be used in production by several companies, so the current version number is deceitful |
The main difference here is the use of
@JvmField
to avoid JVM-specific conflicts (while also avoiding JS name clashes), and the addition ofruleIndex
to the reserved words.ruleIndex
has to be reserved as the generated code will already have such a property:This should be merged before #166.
Closes: #162