Loading...

rhino-tools-dev@googlegroups.com

[Prev] Thread [Next]  |  [Prev] Date [Next]

[rhino-tools-dev] Rhino DSL - Nested Blocks Howard van Rooijen Thu Feb 02 15:07:30 2012

Hi,

I’ve just finished DSLs in Boo & have really enjoyed it. I wish I’d
made the time to read it a few years ago.

I’m trying to write a little DSL for a pet project – but I keep a wall
– that I don’t quite understand.

I want to create a DSL that has the following syntax:

create_setting @MySetting:
        site_url "http://mysite/":
                listening_on "192.168.100.10:80"
        site_url "https://mysite/":
                listening_on "192.168.100.10:443"
        on_environment @MyEnvironment

The problem is the nested block statement.

The template is fairly standard:

public void CreateSetting(string name, Func<string> block)
{
    this.settingName = name;
    block();
}

public string ListeningOn(string ip)
{
    return ip;
}

public void OnEnvironment(string environment)
{
    this.environmentName = environment;
}

public void SiteUrl(string url, Func<string> block)
{
    var listenAddress = block();
    this.bindings.Add(new Uri(url), listenAddress);
}

The problem I’m hitting is that

var listenAddress = block();

always returns null. If I decompile Boo’s cached assembly – it’s plain
to see that the delegate method returns void


using CompilerGenerated;
using DslSample;
using System;

[Serializable]
public class Settings : SettingsTemplate
{
  public Settings()
  {
    base.\u002Ector();
  }

  public virtual void Prepare()
  {
    this.CreateSetting("MySetting", \u0024adaptor\u0024__Settings
\u0024callable0\u00243_21__\u0024Func.Adapt(new __Settings
\u0024callable0\u00243_21__(this.\u0024Prepare\u0024closure\u00241)));
  }

  internal void \u0024Prepare\u0024closure\u00241()
  {
    this.SiteUrl("http://mysite/", \u0024adaptor\u0024__Settings
\u0024callable0\u00243_21__\u0024Func.Adapt(new __Settings
\u0024callable0\u00243_21__(this.\u0024\u0024Prepare\u0024closure
\u00241\u0024closure\u00242)));
    this.SiteUrl("https://mysite/", \u0024adaptor\u0024__Settings
\u0024callable0\u00243_21__\u0024Func.Adapt(new __Settings
\u0024callable0\u00243_21__(this.\u0024\u0024Prepare\u0024closure
\u00241\u0024closure\u00243)));
    this.OnEnvironment("MyEnvironment");
  }

  internal void \u0024\u0024Prepare\u0024closure\u00241\u0024closure
\u00242()
  {
    this.ListeningOn("192.168.100.10:80");
  }

  internal void \u0024\u0024Prepare\u0024closure\u00241\u0024closure
\u00243()
  {
    this.ListeningOn("192.168.100.10:443");
  }
}


but the question is – how can I get it to return a value so that I can
chain the methods together?

I’ve got a small sample should you need it: 
http://dl.dropbox.com/u/5892928/DSLSample.7z

Many thanks for any help.

Howard van Rooijen

-- 
You received this message because you are subscribed to the Google Groups 
"Rhino Tools Dev" group.
To post to this group, send email to [EMAIL PROTECTED]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rhino-tools-dev?hl=en.