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