>b's YML 2
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

206 lines
5.5 KiB

5 years ago
  1. // the YML homepage
  2. include homepage.en.yhtml2
  3. page "YML – Why a Markup Language?!" {
  4. h1 > Introduction
  5. h2 > What is YML?
  6. p >>
  7. Well, it's the idea not to need to define a grammar first when you want to use a
  8. ¬http://en.wikipedia.org/wiki/Domain_Specific_Language Domain Specific Language¬.
  9. For that purpose, YML is being translated into XML. Let's make an example.
  10. >>
  11. p >>
  12. Everything which comes close to a C like language, parses without a grammar
  13. definition:
  14. >>
  15. p > This:
  16. Code
  17. ||
  18. template< class T > T max(T a, T b);
  19. ||
  20. p > Parses to:
  21. Code
  22. ||
  23. <?xml version='1.0' encoding='UTF-8'?>
  24. <template>
  25. <generic>
  26. <class/>
  27. <T/>
  28. </generic>
  29. <T>
  30. <max>
  31. <parm>
  32. <T/>
  33. <a/>
  34. </parm>
  35. <parm>
  36. <T/>
  37. <b/>
  38. </parm>
  39. </max>
  40. </T>
  41. </template>
  42. ||
  43. p >>
  44. Instead of defining grammars, you test out and play around until the
  45. results are matching your needs. If the resulting tree does not fit
  46. what you're expecting, change it by patching the grammar with `code > decl`:
  47. >>
  48. p > This:
  49. Code
  50. ||
  51. module A {
  52. interface B {
  53. attribute long n;
  54. };
  55. };
  56. ||
  57. p > Parses to:
  58. Code
  59. ||
  60. <?xml version='1.0' encoding='UTF-8'?>
  61. <module>
  62. <A>
  63. <interface>
  64. <B>
  65. <attribute>
  66. <long>
  67. <n/>
  68. </long>
  69. </attribute>
  70. </B>
  71. </interface>
  72. </A>
  73. </module>
  74. ||
  75. p >>
  76. This does not look like what we want. So we tell YML that
  77. we have a module name after the module, an interface name after
  78. the interface and type and name after the attribute:
  79. >>
  80. p > This:
  81. Code
  82. ||
  83. decl module @name;
  84. decl interface @name;
  85. decl attribute @type @name;
  86. module A {
  87. interface B {
  88. attribute long n;
  89. };
  90. };
  91. ||
  92. p > Parses to:
  93. Code
  94. ||
  95. <?xml version='1.0' encoding='UTF-8'?>
  96. <module name="A">
  97. <interface name="B">
  98. <attribute type="long" name="n"/>
  99. </interface>
  100. </module>
  101. ||
  102. h2 id=what > What can I do with YML?
  103. p > With YML you can:
  104. ul {
  105. li p > use a C-like ¬http://en.wikipedia.org/wiki/Domain-specific_language DSL¬ without writing a grammar first
  106. li p > generate code out of this ¬http://en.wikipedia.org/wiki/Domain-specific_language DSL¬ using ¬yslt YSLT¬
  107. 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¬
  108. li p > generate code out of any XML based language like ¬http://en.wikipedia.org/wiki/Scalable_Vector_Graphics SVG¬ using ¬yslt YSLT¬
  109. 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
  110. li p > replace bad designed and complicated XML languages with simpler C-like ones
  111. li p > ... and much more.
  112. }
  113. h2 id=howitworks > How it works: Replacing angle brackets with some Python
  114. p > Just writing down what I wanted to have instead of XML for a sample:
  115. Code ||
  116. <list name="List of goods">
  117. <head>
  118. <columTitle>
  119. Goods
  120. </columnTitle>
  121. <columnTitle>
  122. Price
  123. </columnTitle>
  124. </head>
  125. <row>
  126. <value>
  127. Beer
  128. </value>
  129. <value>
  130. 20
  131. </value>
  132. </row>
  133. <row>
  134. <value>
  135. Wine
  136. </value>
  137. <value>
  138. 30
  139. </value>
  140. </row>
  141. </list>
  142. ||
  143. p > Something like that should be more easy, say, like this:
  144. Code ||
  145. list "List of goods" {
  146. head title "Goods", title "Price";
  147. row value "Beer", value 20;
  148. row value "Wine", value 30;
  149. }
  150. ||
  151. h2 id=ylanguages > Y Languages
  152. p >>
  153. The latter is what I call an Y language – a language specified in YML. How could this be
  154. achieved? Well, what's to do? To have the required information, how to build XML from the
  155. script above, we need:
  156. >>
  157. ul {
  158. li >>
  159. the information, that “list of goods” is an attribute named «name», while «Goods» is
  160. the text value of a tag
  161. >>
  162. li > «title» shout be written out as «columnTitle»
  163. }
  164. p > How to do that? Let's invent a simple definition language for that information:
  165. Code ||
  166. decl list(name);
  167. decl title alias columnTitle;
  168. ||
  169. p > Here you can ¬samples/list.yml2 download the complete list sample¬.
  170. div id=bottom > ¬#top ^Top^¬ ¬programming >> Using YML 2¬ ¬index.en.yhtml2 (source)¬
  171. }