Grammar-Kit icon indicating copy to clipboard operation
Grammar-Kit copied to clipboard

Allow generating Kotlin code instead of Java

Open mar-v-in opened this issue 6 years ago • 2 comments

With Kotlin becoming a major language with the JetBrains platform, it would only make sense if language plugins would be entirely in Kotlin as well.

As a first step, it should be possible to (optionally) use the Kotlins J2K to convert the generated Java code to Kotlin. Converting the code to Kotlin will directly help with certain issues in the Kotlin compiler when it comes to Kotlin/Java compatibility, allowing for more developers to use Kotlin for language plugins.

At some point one would probably prefer to directly generate Kotlin code, so it becomes easy to make use of Kotlins language features...

mar-v-in avatar Mar 15 '19 23:03 mar-v-in

One big advantage would be using sealed classes/interfaces in an or rule: foo ::= bar | baz | a At the moment, you have to use this:

if (foo.bar != null) { 
  foo.bar!! 
} else if (foo.baz != null) {
  foo.baz!!
} else { 
  foo.a!! 
}

This would be nice:

when (foo) {
  is Foo.Bar -> foo.bar
  is Foo.Baz -> foo.baz
  is Foo.A -> foo.a
}

hfhbd avatar Jul 19 '22 10:07 hfhbd

@hfhbd That would be great indeed, luckily this isn't unique to Kotlin. I'd love your input on my proposal to add this to Java, so it can be utilized in all JVM languages. https://github.com/JetBrains/Grammar-Kit/issues/305

brokenhappy avatar Nov 15 '22 09:11 brokenhappy