claudio@56: ## What is YML?
claudio@56:
claudio@56: Well, it's the idea not to need to define a grammar first when you want to use a Domain Specific Language. For that purpose, YML is being translated into XML. Let's make an example.
claudio@56:
claudio@56: Everything which comes close to a C like language, parses without a grammar definition:
claudio@56:
claudio@56: This:
claudio@56:
claudio@56: template< class T > T max(T a, T b);
claudio@56:
claudio@56: Parses to:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56: Instead of defining grammars, you test out and play around until the results are matching your needs. If the resulting tree does not fit what you're expecting, change it by patching the grammar with `decl`:
claudio@56:
claudio@56: This:
claudio@56:
claudio@56: module A {
claudio@56: interface B {
claudio@56: attribute long n;
claudio@56: };
claudio@56: };
claudio@56:
claudio@56: Parses to:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56: This does not look like what we want. So we tell YML that we have a module name after the module, an interface name after the interface and type and name after the attribute:
claudio@56:
claudio@56: This:
claudio@56:
claudio@56: decl module @name;
claudio@56: decl interface @name;
claudio@56: decl attribute @type @name;
claudio@56:
claudio@56: module A {
claudio@56: interface B {
claudio@56: attribute long n;
claudio@56: };
claudio@56: };
claudio@56:
claudio@56: Parses to:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56: What can I do with YML?
claudio@56:
claudio@56: With YML you can:
claudio@56:
claudio@56: * use a C-like DSL without writing a grammar first
claudio@56: * generate code out of this DSL using YSLT
claudio@56: * generate code out of UML using YSLT on XMI
claudio@56: * generate code out of any XML based language like SVG using YSLT
claudio@56: * define a wiki like language in just a few lines like YHTML does
claudio@56: * replace bad designed and complicated XML languages with simpler C-like ones
claudio@56: * ... and much more.
claudio@56:
claudio@56: How it works: Replacing angle brackets with some Python
claudio@56:
claudio@56: Just writing down what I wanted to have instead of XML for a sample:
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56: Goods
claudio@56:
claudio@56:
claudio@56: Price
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56: Beer
claudio@56:
claudio@56:
claudio@56: 20
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56: Wine
claudio@56:
claudio@56:
claudio@56: 30
claudio@56:
claudio@56:
claudio@56:
claudio@56:
claudio@56: Something like that should be more easy, say, like this:
claudio@56:
claudio@56: list "List of goods" {
claudio@56: head title "Goods", title "Price";
claudio@56: row value "Beer", value 20;
claudio@56: row value "Wine", value 30;
claudio@56: }
claudio@56:
claudio@56: ### Y Languages
claudio@56:
claudio@56: The latter is what I call an Y language – a language specified in YML. How could this be achieved? Well, what's to do? To have the required information, how to build XML from the script above, we need:
claudio@56:
claudio@56: * the information, that “list of goods” is an attribute named `name`, while `Goods` is the text value of a tag
claudio@56: * `title` shout be written out as `columnTitle`
claudio@56:
claudio@56: How to do that? Let's invent a simple definition language for that information:
claudio@56:
claudio@56: decl list(name);
claudio@56: decl title alias columnTitle;