Re: [groovy-user] DSL Help
Hello,
I managed to get something working by doing the following:
def csvFromImpl = { ... }
def propertiesFromImpl = { ... }
def csv = { c ->
String.metaClass.from = csvFromImpl
c()
}
def properties = { c ->
String.metaClass.from = propertiesFromImpl
c()
}
Then when I called either the csv or properties methods, using the
"str".from invoked the relevant implementation. There are a few issues with
this thougj; one is thread safty , another is I'm not sure how perfomant
this would be. Any thoughts?
Thanks
Mark
Guillaume Laforge-2 wrote:
>
> Both method calls you're showing here would call the same method
> from(String), and there's no magic way of dispatching to different
> methods... unless you do the dispatching logic yourself inside that
> method -- at least, nothing comes to mind for such a scenario.
> So I'd advise to delegate to different implementations for your logic.
>
> On Sun, Feb 28, 2010 at 00:51, zronph <mbarrett.mark@...> wrote:
>>
>> Hello there. I'm attempting to implement a DSL for the first time and am
>> having a few troubles.
>>
>> Basically the I want to implement it so that based on the context that a
>> method was called a different implementation would be called. For example
>> consider the following code:
>>
>> "person1".from "people.csv" // select the column 'person1' from the csv
>> file
>> "property1".from "propertiesFile.properties" // read the property
>> 'peroperty1' from the properties file
>>
>> Is there any way to define a context such as CsvContext and
>> PropertiesContext, and depending how/where the from function was called
>> it
>> was use the relevant implementation?
>>
>> Also, if anyone knows of any good resources for DSLs I'd much appreciate
>> a
>> link :)
>>
>> Thanks for any help
>>
>> Mark
>> --
>> View this message in context:
>> http://old.nabble.com/DSL-Help-tp27732033p27732033.html
>> Sent from the groovy - user mailing list archive at Nabble.com.
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>> http://xircles.codehaus.org/manage_email
>>
>>
>>
>
>
>
> --
> Guillaume Laforge
> Groovy Project Manager
> Head of Groovy Development at SpringSource
> http://www.springsource.com/g2one
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
> http://xircles.codehaus.org/manage_email
>
>
>
>
--
--
View this message in context: http://old.nabble.com/DSL-Help-tp27732033p27742979.html
Sent from the groovy - user mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email