Hey all, I have used Kotlin a bit here and there, ...
# dsl
b
Hey all, I have used Kotlin a bit here and there, but never really stuck my nose into the DSL opportunities. I have an existing, small custom DSL (perhaps close to a simplified haskell), whose main purpose is to provide a tiny, restrictive language (~40 functions). Is it possible either syntactically, or at compile time, to place heavy restrictions on the allowable functionality within a kotlin DSL? Thus for example, could I prevent basic string manipulation, except through my own pre-defined string manipulation functions? (I suspect this is partially in contrast to typical kotlin/DSL goals, but lack the experience.) Any tips/pointers to related work greatly appreciated. My googling so far has not led to any results.
g
You probably can restrict some functions if run your DSL with custom ScriptDefinition from Kotlin Scripting
At least it was planned, but not sure about current status
b
interesting as it discusses explicit white/black-listing support.
Thanks
g
anyway, I believe kotlin scripting and JSR-223 are the only real ways to add some language restrictions
Maybe custom class loader also may help
b
I was also going to look into both java/kotlin online compilation, and what degree of function/symbol whitelisting I could manually apply. But language support would be obviously far simpler 🙂
Perhaps class loading time would be simpler, but that might lose the benefit of being able to report exactly where a symbol whitelist violation occurs? Not sure, as I have never worked in compile/load layers in jvm.
g
language support
What do you mean? You cannot just limit arbitrary Kotlin code in some DSL, it would break a lot of things, so scripting is much better way to do that instead
b
Perhaps a naive interpretation of the scripting support — that it provides an alternative form of the language which explicitly includes this functionality, thus “language support”.
I don’t have enough context to understand the assertion that it would break a lot of things within ordinary kotlin/DSL context. Care to enlighten me? 😄
g
dsl doesn’t limit the language or existing classpath
b
I know it does not by default. I was trying to understand whether such restrictions could be added/manufactured.
What would be the breakage of doing such things?
g
What kind thing? limit what can be called inside of custom DSL?
b
Yep, for example, could I prevent basic string manipulation, except through my own pre-defined string manipulation functions?
g
Yes, but what is use case of it as for general usage feature of the language?
b
quarantining sensitive data — restricted DSL can provide that nominally, kotlin based DSL is what I was examining to understand what’s possible
g
if you running not trusted code you should use scripting API and JVM JSR-223, this is exactly why it created
e
I’m gonna echo @gildor and say scripting will get you far but the advanced stuff you’re looking for might be covered by compiler plugins.
g
Yes, compiler plugin may be a solution, but it's definitely not a simple one
b
Just saw this response — I have the same sense, that compiler level gives me more. I will dig into the scripting soon though to get a better sense of what it does and doesn’t do.
Thanks for the thoughts!