Version 7 by komaz
on Nov 22, 2010 17:26.

compared with
Version 8 by komaz
on Nov 22, 2010 17:45.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (2)

View Page History
class Sample
{
StaticImports imports :=
StaticImports<|
sys::Str.spaces
sys::File.os
|>
Void main()
{
file := os("/")
prefix := spaces(4)
}
}
{noformat}

So, what we want here - the DSL source just defines a list of fully qualified static methods, and DSL plugin just creates instance methods which route to corresponding static methods:
{noformat}
class Sample
{
File os(Str str) { File.os(str) }
...
}
{noformat}

The creation of method routers and their bodies look fairly simple, but there's a problem - again, DSL plugins are called a bit too late and compiler have already generated a lot of compiler errors. Fail? No! We can do another black magic trick - go through all complier [errs|http://fantom.org/doc/compiler/Compiler#errs] and remove those which caused by undefined method:
{noformat}
newQnames := qnames.a
compiler.errs = compiler.errs.exclude { it.msg == "Unknown method '$newQname'" }
{noformat}