1
1
Fork
You've already forked yml2
0
>b's YML 2
  • Python 72.8%
  • Vim Script 24.3%
  • CSS 1.6%
  • Makefile 1.3%
Find a file
2024年03月06日 00:32:58 +01:00
samples ... 2019年01月29日 11:23:36 +01:00
vim/syntax correcting «...» problems in parantheses 2016年08月21日 08:50:09 +02:00
yml2 fileinput.input: no longer use mode="rU" which is no longer supported; switch to mode="r" in other forgotten cases; new release 2023年02月02日 17:09:08 +01:00
.gitignore grammar in own file 2021年04月08日 14:37:11 +02:00
features.en.yhtml2 feature: include from *pointer 2021年04月08日 15:17:25 +02:00
format.css initial commit 2016年07月11日 23:15:28 +02:00
gpl-2.0.txt initial commit 2016年07月11日 23:15:28 +02:00
heading.en.yhtml2 switch to codeberg repo 2024年03月06日 00:32:58 +01:00
hello.en.yhtml2 initial commit 2016年07月11日 23:15:28 +02:00
homepage.en.yhtml2 initial commit 2016年07月11日 23:15:28 +02:00
index.en.yhtml2 initial commit 2016年07月11日 23:15:28 +02:00
Makefile updating documentation 2021年04月08日 21:11:30 +02:00
MANIFEST.in Add setup.py, setup.cfg and MANIFEST.in. 2020年03月17日 11:05:51 +01:00
programming.en.yhtml2 initial commit 2016年07月11日 23:15:28 +02:00
README.md Add a README. 2018年09月04日 17:09:43 +02:00
setup.cfg fileinput.input: no longer use mode="rU" which is no longer supported; switch to mode="r" in other forgotten cases; new release 2023年02月02日 17:09:08 +01:00
setup.py Add setup.py, setup.cfg and MANIFEST.in. 2020年03月17日 11:05:51 +01:00
toolchain.en.yhtml2 fix path handling on Windows 2023年02月07日 00:15:08 +01:00
yml2c taking Lucas update into a new release 2023年05月25日 12:51:43 +02:00
yml2proc taking Lucas update into a new release 2023年05月25日 12:51:43 +02:00
yslt.en.yhtml2 changing URL because W3C changed 2023年02月02日 16:52:40 +01:00

What is YML?

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.

Everything which comes close to a C like language, parses without a grammar definition:

This:

template< class T > T max(T a, T b);

Parses to:

<?xml version='1.0' encoding='UTF-8'?>
<template>
 <generic>
 <class/>
 <T/>
 </generic>
 <T>
 <max>
 <parm>
 <T/>
 <a/>
 </parm>
 <parm>
 <T/>
 <b/>
 </parm>
 </max>
 </T>
</template>

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:

This:

module A {
 interface B {
 attribute long n;
 };
};

Parses to:

<?xml version='1.0' encoding='UTF-8'?>
<module>
 <A>
 <interface>
 <B>
 <attribute>
 <long>
 <n/>
 </long>
 </attribute>
 </B>
 </interface>
 </A>
</module>

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:

This:

decl module @name;
decl interface @name;
decl attribute @type @name;
module A {
 interface B {
 attribute long n;
 };
};

Parses to:

<?xml version='1.0' encoding='UTF-8'?>
<module name="A">
 <interface name="B">
 <attribute type="long" name="n"/>
 </interface>
</module>

What can I do with YML?

With YML you can:

  • use a C-like DSL without writing a grammar first
  • generate code out of this DSL using YSLT
  • generate code out of UML using YSLT on XMI
  • generate code out of any XML based language like SVG using YSLT
  • define a wiki like language in just a few lines like YHTML does
  • replace bad designed and complicated XML languages with simpler C-like ones
  • ... and much more.

How it works: Replacing angle brackets with some Python

Just writing down what I wanted to have instead of XML for a sample:

<list name="List of goods">
 <head>
 <columTitle>
 Goods
 </columnTitle>
 <columnTitle>
 Price
 </columnTitle>
 </head>
 <row>
 <value>
 Beer
 </value>
 <value>
 20
 </value>
 </row>
 <row>
 <value>
 Wine
 </value>
 <value>
 30
 </value>
 </row>
</list>

Something like that should be more easy, say, like this:

list "List of goods" {
 head title "Goods", title "Price";
 row value "Beer", value 20;
 row value "Wine", value 30;
}

Y Languages

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:

  • the information, that "list of goods" is an attribute named name, while Goods is the text value of a tag
  • title shout be written out as columnTitle

How to do that? Let's invent a simple definition language for that information:

decl list(name);
decl title alias columnTitle;