DMD 1.005 release
Yauheni Akhotnikau
eao197 at intervale.ru
Wed Feb 7 01:39:59 PST 2007
On Wed, 07 Feb 2007 06:20:51 +0300, Walter Bright
<newshound at digitalmars.com> wrote:
> What it's for is to:
>
> 1) import data for a string constant
> 2) import code that's in DSL (Domain Specific Language), not D, form.
Can you provide some examples of DSL the new D feature is intended for?
For example, what if I want to implement something like to RubyOnRails
ActiveRecord DSL
(http://api.rubyonrails.org/files/vendor/rails/activerecord/README.html)?
This is an ordinal Ruby code:
class Account < ActiveRecord::Base
validates_presence_of :subdomain, :name, :email_address, :password
validates_uniqueness_of :subdomain
validates_acceptance_of :terms_of_service, :on => :create
validates_confirmation_of :password, :email_address, :on => :create
end
I may wish to translate it in the following D fragment (with an exception
that in D I must explicitly describe all table fields):
mixin( DActiveRecord!(
`class Account
field subdomain varchar(20)
field name varchar(100)
field email_address varchar(255)
field password varchar(32)
field term_of_service int
validates_presence_of subdomain, name, email_address, password
validates_uniqueness_of subdomain
validates_acceptance_of terms_of_service, on => create
validates_confirmation_of password, email_address, on => create
end` ) );
The template DActiveRecord must parse DSL string at compile time and
produce another string with Account class implementation in D. With all
necessary symantic analysis and constraints (for example, it is impossible
to use name of field in 'validate_presence_of' if it isn't described as
'field').
Do you think this task can be done with D templates at complile time?
--
Regards,
Yauheni Akhotnikau
More information about the Digitalmars-d-announce
mailing list