vb@0: // the YML homepage vb@0: vb@0: include homepage.en.yhtml2 vb@0: vb@0: page "YML – Why a Markup Language?!" { vb@0: h1 > Introduction vb@0: vb@0: h2 > What is YML? vb@0: vb@0: p >> vb@0: Well, it's the idea not to need to define a grammar first when you want to use a vb@0: ¬http://en.wikipedia.org/wiki/Domain_Specific_Language Domain Specific Language¬. vb@0: For that purpose, YML is being translated into XML. Let's make an example. vb@0: >> vb@0: vb@0: p >> vb@0: Everything which comes close to a C like language, parses without a grammar vb@0: definition: vb@0: >> vb@0: vb@0: p > This: vb@0: vb@0: Code vb@0: || vb@0: template< class T > T max(T a, T b); vb@0: || vb@0: vb@0: p > Parses to: vb@0: vb@0: Code vb@0: || vb@0: vb@0: vb@0: || vb@0: vb@0: p >> vb@0: Instead of defining grammars, you test out and play around until the vb@0: results are matching your needs. If the resulting tree does not fit vb@0: what you're expecting, change it by patching the grammar with `code > decl`: vb@0: >> vb@0: vb@0: p > This: vb@0: vb@0: Code vb@0: || vb@0: module A { vb@0: interface B { vb@0: attribute long n; vb@0: }; vb@0: }; vb@0: || vb@0: vb@0: p > Parses to: vb@0: vb@0: Code vb@0: || vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: || vb@0: vb@0: p >> vb@0: This does not look like what we want. So we tell YML that vb@0: we have a module name after the module, an interface name after vb@0: the interface and type and name after the attribute: vb@0: >> vb@0: vb@0: p > This: vb@0: vb@0: Code vb@0: || vb@0: decl module @name; vb@0: decl interface @name; vb@0: decl attribute @type @name; vb@0: vb@0: module A { vb@0: interface B { vb@0: attribute long n; vb@0: }; vb@0: }; vb@0: || vb@0: vb@0: p > Parses to: vb@0: vb@0: Code vb@0: || vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: vb@0: || vb@0: vb@0: h2 id=what > What can I do with YML? vb@0: vb@0: p > With YML you can: vb@0: vb@0: ul { vb@0: li p > use a C-like ¬http://en.wikipedia.org/wiki/Domain-specific_language DSL¬ without writing a grammar first vb@0: li p > generate code out of this ¬http://en.wikipedia.org/wiki/Domain-specific_language DSL¬ using ¬yslt YSLT¬ vb@0: li p > generate code out of ¬http://en.wikipedia.org/wiki/Unified_Modeling_Language UML¬ using ¬yslt YSLT¬ on ¬http://en.wikipedia.org/wiki/XML_Metadata_Interchange XMI¬ vb@0: li p > generate code out of any XML based language like ¬http://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG¬ using ¬yslt YSLT¬ vb@0: li p > define a ¬http://en.wikipedia.org/wiki/Wiki wiki¬ like language in just a few lines like ¬http://fdik.org/yml/programming#wiki YHTML¬ does vb@0: li p > replace bad designed and complicated XML languages with simpler C-like ones vb@0: li p > ... and much more. vb@0: } vb@0: vb@0: h2 id=howitworks > How it works: Replacing angle brackets with some Python vb@0: vb@0: p > Just writing down what I wanted to have instead of XML for a sample: vb@0: vb@0: Code || vb@0: vb@0: vb@0: vb@0: Goods vb@0: vb@0: vb@0: Price vb@0: vb@0: vb@0: vb@0: vb@0: Beer vb@0: vb@0: vb@0: 20 vb@0: vb@0: vb@0: vb@0: vb@0: Wine vb@0: vb@0: vb@0: 30 vb@0: vb@0: vb@0: vb@0: || vb@0: vb@0: p > Something like that should be more easy, say, like this: vb@0: vb@0: Code || vb@0: list "List of goods" { vb@0: head title "Goods", title "Price"; vb@0: row value "Beer", value 20; vb@0: row value "Wine", value 30; vb@0: } vb@0: || vb@0: vb@0: h2 id=ylanguages > Y Languages vb@0: vb@0: p >> vb@0: The latter is what I call an Y language – a language specified in YML. How could this be vb@0: achieved? Well, what's to do? To have the required information, how to build XML from the vb@0: script above, we need: vb@0: >> vb@0: vb@0: ul { vb@0: li >> vb@0: the information, that “list of goods” is an attribute named «name», while «Goods» is vb@0: the text value of a tag vb@0: >> vb@0: li > «title» shout be written out as «columnTitle» vb@0: } vb@0: vb@0: p > How to do that? Let's invent a simple definition language for that information: vb@0: vb@0: Code || vb@0: decl list(name); vb@0: decl title alias columnTitle; vb@0: || vb@0: vb@0: p > Here you can ¬samples/list.yml2 download the complete list sample¬. vb@0: vb@0: div id=bottom > ¬#top ^Top^¬ ¬programming >> Using YML 2¬ ¬index.en.yhtml2 (source)¬ vb@0: }