As far as I know it's impossible at the moment to implement it as you want (I would be happy to be proven wrong). I also faced this issue, when I was creating my small DSL for injection. But I have realized, that even if you can't have 2 variables between 2 identifiers, you still can have three identifiers between them. It looks like this:
variable1 method constant method variable2
which is the same as:
variable1.method(constant).method(variable2)
With this I was able to come up with very nice DSL that looks like this:
by default defaultDb and identified by 'remote
'remote is by default defaultDb
You can find more examples of it's usage in this spec:
https://github.com/OlegIlyenko/scaldi/blob/48f7e4186cf7eb441116087003d7f45f16e0ac6c/src/test/scala/scaldi/InjectableSpec.scala#L47
It's implementation can be found here:
https://github.com/OlegIlyenko/scaldi/blob/master/src/main/scala/scaldi/Injectable.scala
I used ByWord
and IdentifiedWord
class types as method arguments. For example:
def is(by: ByWord) = and(by)
Which leaves possibility, that users of the library will extend ByWorld
class and generally can provide their own ByWorld
implementations. Now when I think about this, I find it not very nice. Better solution would be to create singelton objects for the constant words and then use their type like this:
object by
def is(byWord: by.type) = and(by)
This generally restricts argument to only one possible by
word instance.