Hi, I’m creating a kotlin library and I’d need to...
# announcements
g
Hi, I’m creating a kotlin library and I’d need to create a lot of functions. Is there a way to get (programatically) all keywords used in kotlin? I’ll need to escape then with backticks `. One example is the
continue
keyword that should become ``continue`` when I escape.
e
Programmatically - no. But you can copy a list from this page: https://kotlinlang.org/docs/reference/keyword-reference.html
g
Oh, thanks, this will help 😉
m
You can’t resolve them programmatically because Kotlin is not able to introspect its own grammar. Probably LISP can.
g
I’ve created a list here (https://gist.github.com/Danilo-Araujo-Silva/95040cd8bc63af841187a9c261527354) in case someone else needs something like that
e
That’s a weird mix. You only need to back-tick hard-keywords. E.g, you can safely have
val data = 123
without any backticks, but you cannot have
val val = 123
m
@elizarov this is a interesting distinction, what makes an hard-keyword? Why doesn’t “data” need to be quoted?
e
It’s the first thing written on the page I’ve linked to:
Hard Keywords
The following tokens are always interpreted as keywords and cannot be used as identifiers:
m
I missed that page sorry, I didn’t imagine there was this distinction, thanks