README.md
author Volker Birk <vb@pep-project.org>
Tue, 15 Dec 2020 11:29:51 +0100
changeset 68 26120af11afd
parent 46 41d7a6c0e7f3
permissions -rw-r--r--
do not need this
46
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     1
## What is YML?
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     2
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     3
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.
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     4
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     5
Everything which comes close to a C like language, parses without a grammar definition:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     6
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     7
This:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     8
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
     9
    template< class T > T max(T a, T b);
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    10
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    11
Parses to:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    12
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    13
    <?xml version='1.0' encoding='UTF-8'?>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    14
    <template>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    15
      <generic>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    16
        <class/>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    17
        <T/>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    18
      </generic>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    19
      <T>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    20
        <max>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    21
          <parm>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    22
            <T/>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    23
            <a/>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    24
          </parm>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    25
          <parm>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    26
            <T/>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    27
            <b/>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    28
          </parm>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    29
        </max>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    30
      </T>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    31
    </template>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    32
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    33
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`:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    34
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    35
This:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    36
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    37
    module A {
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    38
        interface B {
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    39
            attribute long n;
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    40
        };
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    41
    };
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    42
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    43
Parses to:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    44
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    45
    <?xml version='1.0' encoding='UTF-8'?>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    46
    <module>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    47
      <A>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    48
        <interface>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    49
          <B>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    50
            <attribute>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    51
              <long>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    52
                <n/>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    53
              </long>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    54
            </attribute>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    55
          </B>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    56
        </interface>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    57
      </A>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    58
    </module>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    59
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    60
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:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    61
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    62
This:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    63
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    64
    decl module @name;
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    65
    decl interface @name;
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    66
    decl attribute @type @name;
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    67
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    68
    module A {
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    69
        interface B {
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    70
            attribute long n;
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    71
        };
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    72
    };
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    73
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    74
Parses to:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    75
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    76
    <?xml version='1.0' encoding='UTF-8'?>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    77
    <module name="A">
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    78
      <interface name="B">
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    79
        <attribute type="long" name="n"/>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    80
      </interface>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    81
    </module>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    82
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    83
What can I do with YML?
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    84
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    85
With YML you can:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    86
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    87
  * use a C-like DSL without writing a grammar first
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    88
  * generate code out of this DSL using YSLT
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    89
  * generate code out of UML using YSLT on XMI
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    90
  * generate code out of any XML based language like SVG using YSLT
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    91
  * define a wiki like language in just a few lines like YHTML does
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    92
  * replace bad designed and complicated XML languages with simpler C-like ones
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    93
  * ... and much more.
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    94
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    95
How it works: Replacing angle brackets with some Python
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    96
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    97
Just writing down what I wanted to have instead of XML for a sample:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    98
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
    99
    <list name="List of goods">
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   100
        <head>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   101
            <columTitle>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   102
                Goods
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   103
            </columnTitle>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   104
            <columnTitle>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   105
                Price
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   106
            </columnTitle>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   107
        </head>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   108
        <row>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   109
            <value>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   110
                Beer
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   111
            </value>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   112
            <value>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   113
                20
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   114
            </value>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   115
        </row>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   116
        <row>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   117
            <value>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   118
                Wine
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   119
            </value>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   120
            <value>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   121
                30
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   122
            </value>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   123
        </row>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   124
    </list>
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   125
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   126
Something like that should be more easy, say, like this:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   127
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   128
    list "List of goods" {
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   129
        head title "Goods", title "Price";
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   130
        row value "Beer", value 20;
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   131
        row value "Wine", value 30;
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   132
    }
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   133
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   134
### Y Languages
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   135
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   136
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:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   137
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   138
  * the information, that “list of goods” is an attribute named `name`, while `Goods` is the text value of a tag
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   139
  * `title` shout be written out as `columnTitle`
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   140
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   141
How to do that? Let's invent a simple definition language for that information:
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   142
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   143
    decl list(name);
41d7a6c0e7f3 Add a README.
Claudio Luck <claudio.luck@pep.foundation>
parents:
diff changeset
   144
    decl title alias columnTitle;