Custom .NET DSL
Posted
by Dmitriy Nagirnyak
on Stack Overflow
See other posts from Stack Overflow
or by Dmitriy Nagirnyak
Published on 2010-05-17T12:17:09Z
Indexed on
2010/05/17
12:20 UTC
Read the original article
Hit count: 421
Hi,
I am thinking about implementing a templating engine using only the plain C#/.NET 4 syntax with the benefit of static typing.
Then on top of that templating language we could create Domain Specific Languages (let's say HTML4, XHTML, HTML5, RSS, Atom, Multipart Emails and so on).
One of the best DSLs in .NET 4 (if not only one) is SharpDOM. It implements HTML-specific DSL.
Looking at SharpDOM, I am really impressed of what you can do using .NET (4).
So I believe there are some not-so-well-known ways for implementing custom DSLs in .NET 4. Possibly not as well as in Ruby, but still.
So my the question would be: what are the C# (4) specific syntax features that can be used for implementing custom DSLs?
Examples I can think of right now:
// HTML - doesn't look tooo readable :)
div(clas: "head",
ul(clas: "menu", id: "main-menu", () => {
foreach(var item in allItems) {
li(item.Name)
}
}) // See how much noise it has with all the closing brackets?
)
// Plain text (Email or something) - probably too simple
Line("Dear {0}", user.Name);
Line("You have been kicked off from this site");
For me it is really hard to come up with the syntax with least amount of noise.
Please NOTE that I am not talking about another language (Boo, IronRuby etc), neither I am not talking about different templating engines (NHaml, Spark, StringTemplate etc).
Thanks,
Dmitriy.
© Stack Overflow or respective owner