From: jim@... Date: 2005-02-16T06:24:45+09:00 Subject: Re: Ruby as a domain specific language? * cnmaclean@hotmail.com [2005-02-16 05:49:56 +0900]: > In our current (proprietary) language, it's something like this: > > Define File 1234 > Name = "My File" > Parent = 5678 > DataItem = "DataItem 1", Decimal, 10 bytes > DataItem = "DataItem 2", Hex, 10 bytes > > Currently, the format is almost entirely declarative. You can't have > any logic (e.g. determining the second data item based on the contents > of the first), and there's only a very primitive and limited form of > variables. Doing some new means extending the language definition. > > I'd also like (if possible) to allow declaring files hierarchically, so > that I can define File 1234 in the scope of 5678. > > As I said, I'm also just looking for general articles/mailings etc. on > using Ruby as a domain-specific language - examples, showing what's > possible/allowed etc. Sorry, but I don't know of any write-ups on this. However, it was a hot topic at the last Ruby Conf, and I bet we see at least one presentation on this at the next Ruby Conf. Maybe I can help with some examples, or better yet, write your example in a Ruby DSL form. define_file 1234 do |f| f.name "My File" f.parent 5678 f.data_item "DataItem 1", Decimal, 10.bytes f.data_item "DataItem 2", Hex, 10.bytes end Here, we have defined #name, #parent and #data_item as methods. As these are constructed, references can be constructed to give you the 'smarts' that you are looking for. With these smarts, we can to do programmatical things like iteration: define_file 5678 do |f| f.name "Parent File" f.parent 1 f.data_item :inherit_from_parent f.children { |child| child.do_whatever } end -- Jim Freeze Code Red. Code Ruby