metaconf tranformations

Michal Moskal malekith at pld.org.pl
Mon Jun 4 13:02:33 CEST 2001


Ehlo,

I refined Lukasz's idea about xml->config translation.
What we need is :
 1) validation
 2) descriptions
 3) transformation
It seems to be good idea that everything will go into
a single file, as validation is close to writing descriptions
and/or error messages, and transformation requires validated
document, and it is more obvious what you can expect from validated
document if transformation is so close to validation.

Anyway: waiting for comments.

And, I can write parser for files like this.

<?xml version="1.0"?>
<config>
 <!-- desc tags could be used by some kind of UI, or
      to generate default .xml config, with lots of
      comments -->
 <desc>
  Configuration of LILO bootloader.
 </desc>
 <desc lang=pl>
  Konfiguracja booloadera LILO.
 </desc>
 <output>
  <method>single-file</method>
  <target>/etc/lilo.conf</target>
  <options>trim-spaces</options>
 </output>
 <input>
  <!-- structure of tags here roughly follows structure of
       config .xml file -->
  <conf>
   <tag>rc-boot</tag>
   <order>global, image</order>
   
   <conf>
    <tag>global</tag>
    <desc>
     Global parameters
    </desc>
    <!-- <global> doesn't have order, as it's not important,
         except, that 'SELF' comes first, but it is the default. -->
    <output>
     #lilo.conf generated at $(date)
     prompt
    </output>
    
    <conf>
     <tag>timeout</tag>
     <desc>
      Timeout before booting default system in seconds.
     </desc>
     <regexp>\d+</regexp>
     <output>
      <!-- as in XSL, . is caption of current xml entity.
           in global, above one could use %{timeout},
	   here, to refer to global/boot, one could use
	   %{../boot} -->
      timeout=%{.}0
     </output>
    </conf>
    
    <conf>
     <tag>boot</tag>
     <desc>
      Partition to boot from.
     </desc>
     <regexp>/dev/[hs]d[a-z]</regexp>
     <output>
      boot = %{.}
     </output>
    </conf>
    
    <conf>
     <tag>default</tag>
     <desc>
      Default system to boot.
     </desc>
     <output>
      $(test "%{.}" = "" || echo "default = %{.}")
     </output>
    </conf>
   </conf> <!-- global -->

   <conf-loop>
    <tag>image</tag>
    <desc>
     Description of particular OS' images.
    </desc>
    <order>SELF, kernel, root</order>
    <output>
     # %{type} Image.
    </output>
    
    <conf>
     <tag>type</tag>
     <desc>
      Type of system to boot.
     </desc>
     <one-of>
      <value>
       <name>Linux</name>
       <desc>
        Linux system, with kernel paramter.
       </desc>
      </value>
      <value>
       <name>BSD</name>
       <desc>
        (Net|Open|Free)BSD system, with own bootloader.
       </desc>
      </value>
     </one-of>
    </conf>

    <conf>
     <tag>kernel</tag>
     <desc>
      Kernel image to boot.
     </desc>
     <cond>
      <sh>test "%{../type}" = "Linux"</sh>
      <then>
       <!-- regexps are always matched against entire string.
            i.e. /.* bahaves as ^/.*$ -->
       <regexp>/.*</regexp>
       <output>
        image = %{.}
       </output>
      </then>
      <else>
       <error>kernel not allowed on non-Linux</error>
      </else>
     </cond>
    </conf>
    
    <conf>
     <tag>root</tag>
     <regexp>/dev/[hs]d[a-z]\d+</regexp>
     <cond>
      <sh>test "%{../type}" = "Linux"</sh>
      <then>
       <output>
        root = %{.}
       </output>
      </then>
      <else>
       <output>
        other = %{.}
       </output>
      </else>
     </cond>
    </conf>

    <conf>
     <tag>label</tag>
     <!-- cannot be empty -->
     <regexp>.+</regexp>
     <output>
      label = %{.}
     </output>
    </conf>
    
    <!-- ... -->
   </conf-loop> <!-- image -->
  </conf> <!-- rc-boot -->
 </input>
</config>

-- 
: Michal ``,/\/\,       '' Moskal    | |            : GCS {C,UL}++++$
:          |    |alekith      @    |)|(| . org . pl : {E--, W, w-,M}-
:                                  |                : {b,e>+}++ !tv h
: Current project:  http://aleph-0.dhs.org/ywindow/ : PLD Team member



More information about the pld-devel-en mailing list