How to define DSL over C #

For a small overnight project, I would like to write a validation component that could be used in a .NET application to perform the usual and tedious validation of an object, props, and message conditions.

My first idea was to dump all this validation setup logic into an XML config file and provide a fluid interface for people who would like to have it in code.

Since I would like to provide something that can actually be used, I thought about providing a specialized DSL (domain specific language). The question is, what tools should I use for this?

I was thinking about parsing it by hand using a regex. But personally, I would like to have something more ... useful.

So what would you suggest?

+2


source to share


8 answers


If you're looking specifically at DSL, check out the ANTLR project . We have used it at my company quite successfully in the past.



+1


source


It sounds like you are talking about implementing one of the .NET 4.0 features, code contracts .



So, I believe VS.Net 2010 will be my recommended tool.

+5


source


The thing with DSls is that they are rarely effective in isolation. To be useful for writing real software, you really need to be able to embed the DSL inside the host language. Compare, for example, how Linq works against plain SQL. Another good example is XML literal in VB. Both allow you to write real code in general-purpose PL and combine it with simpler declarative DSL code.

The result is something much more powerful than standalone SQL or a simple XML editor.

The downside to this, unfortunately, is that neither C # nor VB offer any metaprogramming functionality, so the only way for mainstream .net developers to do this is to create their own language. If this is something you are doing just for fun, you can modify the mono C # compiler to add the functions of interest to the language. Another alternative might be trying ruby. It has flexible syntax that allows you to get away with a lot of craziness. Personally, however, I would prefer the hacky C # approach.

0


source


You might want to check out Creating Domain Languages ​​in Boo (Boo is a CLR language, concepts should carry over to C #). Sample project Simple state machine .

0


source


Take a look at Oslo from Microsoft, not sure if it does what you want, but I know you can create parser DSLs and specify grammars and create a class library that can parse data based on grammar.

Read more about the "M" language and how to use it here

0


source


Why so far away? Start by using generics and a free interface. Start simple and work it through some production. If the friction is too much when dealing with a fluid interface, take a look at using DSL.

0


source


You can try using the DSL Tools for Visual Studio.

0


source


You should have a look at the Irony project at http://irony.codeplex.com/

0


source







All Articles