Navision Internal Domain-Specific Languages

I have found that working with XML, in particular in Navision, it is often a bit unnatural to look at programmatic node construction. It looks very imperative and very unnatural compared to XML itself. As described previously, I developed a codeunit to encapsulate programmatic XML construction in what could be called an XML macro-assembler Internal DSL for Navision. In essence it allows a very declarative style of construction that, behind the scenes, constructs a DOM.

The style is imperative, but it looks declarative when indented. It is quite a perculiar mix, but one that I find makes the code crystal clear and also provides additional abstraction. I call this module Xstream. It functions like a stack with pushes and pops. But the pushes and pops inject nodes into, and switches node context, on an XML DOM, behind the scenes.

with xs do begin
            set(‘title’,’I am a strange loop’);

As you can see, it looks quite like XML and it can become even more so, via quoted function names

with xs do begin
            “=”(‘title’,’I am a strange loop’);

It is not XML, but it looks quite close in some respects and it is very declarative and natural to look at, at least after a little while.
Now this may seem like an odd example for an internal DSL. – A general purpose metamodel like the XML Infoset and the XML syntax, what’s so domain-specific about that?
The truth is: not much. But it is still an example of getting closer to a different domain. The domain here is the XML Infoset and it’s syntactic form. And because W3C XML Schemas are so prevalent, I also encoded a chunk of the W3C XML Schema datamodel as function calls as well; it means you can write expressions such as
with xs do begin
A little thing to notice is that it is not necessary with all these pops at the end in this case, as the DOM behind the scenes is working on nodes and a cursor node and a node is always closed. It is only necessary to pop when you want to add something to a higher context in the hierarchy.

So this was a small example of the kind of “tricks” you can pull in Navision, if you really want to twist and pervert the language.

About xosfaere

Software Developer
This entry was posted in Declarative, Infoset and tagged , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s