Again an Oslo session :)

By the way, I really like how Chris Anderson presents these subjects. We saw him (also together with Don Box) a couple of times, and there talks are very good. This is because they know how to wrap the message they want to spread in a very, very humorous way. (Or does Oslo make them funny, because the same applies to the “A Lap Around Oslo” by Douglas Purdy, which was also quite some fun!)
This session was about MGrammer, the Text to Data bits of Oslo.
MGrammer fits in right here:
And it’s made to transform Text input to MGraph output:
Here is a small example of an MGrammer language:
Left is the “Contact” textual data input. In the middle is the “Contact” language. To the right is the output of the language.
So what do we see within the language?
- syntax is the definition of an entity. The entry point of the language is “Main” and it defines that it contains a Contact entity.
- The Contact entity is made op of the string “Contact” followed by “:” and an Alias and the shape of this entity is the Alias contained in the Contact. Then, you see a pipe. This means that the Contact entity can also be of the following syntax:
again the string “Contact” followed by “:” and an Alias and then “-” and then a PhoneNumber and the shape will then be that the Contact contains an Alias entity and a Phone entity. - a token defines what the engine should match on. So an Alias is defined an string of A..Z and a..z
- A Digit is a character of 0..9
- A PhoneNumber consists of three Digits, then “-”, again three Digits, again “-“ and four Digits.
- The interleave defines what the language engine should discard in the input data.
It is also possible to define parameterized rules:
This looks like a function in functional programming; It states that a CommaList list of certain Element entity could be either on instance of that entity, or it is a list of that entity followed by another instance of that entity. This reminds me of my Prolog days during my study : http://en.wikibooks.org/wiki/Prolog/Lists Look for the Head Tail stuff.
When the language is ready, they compile it with mg.exe to an mgx file.
This mgx file can than be picked up by a run time and used. We were shown how this is done within Visual Studio:
It’s a bit hard to see, but here they load the mgx file from the assembly resources and create a DynamicParser instance. Then, the parser can be fed with a textual input and the input gets parsed through the language and the output is an object (this is an object, because the output of the language could mean anything, text,c#,bytes….)
Then, a GraphBuilder is created which is used to iterate over all successors (in this case Contacts) within the output. Then each Contact will get iterated and the “Alias” label will be sought and its value displayed.
So how can you use MGrammer with the CLR:
You can use a build task to transform the MGrammar language into an MGX.
You can use the MGrammarCompiler to create an MGX in memory.
You can use the DynamicParser to parse the input text data though the mgx in memory.
And you can use the IGraphBuilder to read and build MGraphs
Be the first to rate this post
- Currently 0/5 Stars.
- 1
- 2
- 3
- 4
- 5