Skip to content

Conversation

lppedd
Copy link
Contributor

@lppedd lppedd commented Jan 31, 2024

The main difference here is the use of @JvmField to avoid JVM-specific conflicts (while also avoiding JS name clashes), and the addition of ruleIndex to the reserved words.

ruleIndex has to be reserved as the generated code will already have such a property:

public open class MiniCalcFileContext : ParserRuleContext {
    override val ruleIndex: Int = Rules.MiniCalcFile
    ...

This should be merged before #166.
Closes: #162

lppedd referenced this pull request in antlr/antlr5 Jan 31, 2024

override fun getText(start: Token, stop: Token): String? =
getText(Interval.of(start.tokenIndex, stop.tokenIndex))
override fun getText(start: Token?, stop: Token?): String? =
Copy link
Member

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

Copy link
Contributor Author

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.

override val ruleIndex: Int = Rules.<struct.derivedFromName; format="cap">

<attrs:{a | public var <a>}; separator="\n">
<attrs:{a | @JvmField public var <a>}; separator="\n">
Copy link
Member

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

Copy link
Member

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?

Copy link
Contributor Author

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;
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, good

Copy link
Contributor Author

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.

@ftomassetti ftomassetti merged commit b1c6958 into Strumenta:master Feb 1, 2024
@ftomassetti
Copy link
Member

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

@lppedd lppedd deleted the refactor/codegen-backports branch February 1, 2024 13:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Predicate Reference To Token Generates Invalid Code
2 participants