claudio@46: ## What is YML? claudio@46: claudio@46: 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@46: claudio@46: Everything which comes close to a C like language, parses without a grammar definition: claudio@46: claudio@46: This: claudio@46: claudio@46: template< class T > T max(T a, T b); claudio@46: claudio@46: Parses to: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: 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@46: claudio@46: This: claudio@46: claudio@46: module A { claudio@46: interface B { claudio@46: attribute long n; claudio@46: }; claudio@46: }; claudio@46: claudio@46: Parses to: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: 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@46: claudio@46: This: claudio@46: claudio@46: decl module @name; claudio@46: decl interface @name; claudio@46: decl attribute @type @name; claudio@46: claudio@46: module A { claudio@46: interface B { claudio@46: attribute long n; claudio@46: }; claudio@46: }; claudio@46: claudio@46: Parses to: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: What can I do with YML? claudio@46: claudio@46: With YML you can: claudio@46: claudio@46: * use a C-like DSL without writing a grammar first claudio@46: * generate code out of this DSL using YSLT claudio@46: * generate code out of UML using YSLT on XMI claudio@46: * generate code out of any XML based language like SVG using YSLT claudio@46: * define a wiki like language in just a few lines like YHTML does claudio@46: * replace bad designed and complicated XML languages with simpler C-like ones claudio@46: * ... and much more. claudio@46: claudio@46: How it works: Replacing angle brackets with some Python claudio@46: claudio@46: Just writing down what I wanted to have instead of XML for a sample: claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: Goods claudio@46: claudio@46: claudio@46: Price claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: Beer claudio@46: claudio@46: claudio@46: 20 claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: Wine claudio@46: claudio@46: claudio@46: 30 claudio@46: claudio@46: claudio@46: claudio@46: claudio@46: Something like that should be more easy, say, like this: claudio@46: claudio@46: list "List of goods" { claudio@46: head title "Goods", title "Price"; claudio@46: row value "Beer", value 20; claudio@46: row value "Wine", value 30; claudio@46: } claudio@46: claudio@46: ### Y Languages claudio@46: claudio@46: 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@46: claudio@46: * the information, that “list of goods” is an attribute named `name`, while `Goods` is the text value of a tag claudio@46: * `title` shout be written out as `columnTitle` claudio@46: claudio@46: How to do that? Let's invent a simple definition language for that information: claudio@46: claudio@46: decl list(name); claudio@46: decl title alias columnTitle;