<?xml version='1.0' encoding='UTF-8' ?>
<!-- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - +
 |                                                                           |
 | MLML is published under the GNU General Public Licence                    |
 |   (see http://www.gnu.org/licenses/licenses.html#GPL).                    |
 |                                                                           |
 | A copy of the licence agreement (gpl.txt) must be part of any             |
 |   redistribution of any form.                                             |
 |                                                                           |
 | MLML was created by Martin Klang <mars@pingdynasty.com>.                  |
 |                                                                           |
 | For more information about MLML please see:                               |
 |   http://www.o-xml.org/projects/mlml.html                                 |
 |                                                                           |
 +- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -->
<schema xmlns="http://www.w3.org/2001/XMLSchema"
	xmlns:mlml="http://www.o-xml.org/namespace/mlml/"
	targetNamespace="http://www.o-xml.org/namespace/mlml/"
	elementFormDefault="qualified"
	attributeFormDefault="unqualified">

  <!-- instruction declaration -->
  <element name="instruction">
    <complexType>
      <sequence>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
	<element ref="mlml:param" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
    </complexType>
  </element>

  <!-- statement (instruction reference) -->
  <element name="statement">
    <complexType>
      <sequence>
	<element name="param" type="mlml:expression" minOccurs="0" maxOccurs="unbounded"/>
	<element ref="mlml:body" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
    </complexType>
  </element>

  <!-- type reference (recursive, for parameterised types) -->
  <complexType name="typeref">
    <sequence>
      <element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
    </sequence>
    <attribute name="ref" type="mlml:Name" use="required"/>
  </complexType>

  <!-- type declaration -->
  <element name="type">
    <complexType>
      <sequence>
	<element name="modifier" type="mlml:modref" minOccurs="0" maxOccurs="unbounded"/>
	<element ref="mlml:param" minOccurs="0" maxOccurs="unbounded"/>
	<element name="parent" type="mlml:typeref" minOccurs="0" maxOccurs="unbounded"/>
	<element ref="mlml:variable" minOccurs="0" maxOccurs="unbounded"/>
	<element ref="mlml:function" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
      <attribute name="access" type="mlml:Access" use="optional"/>
    </complexType>
  </element>

  <!-- modifier declaration -->
  <element name="modifier">
    <complexType>
      <attribute name="name" type="mlml:Name" use="required"/>
    </complexType>
  </element>

  <!-- modifier reference -->
  <complexType name="modref">
    <attribute name="ref" type="mlml:Name" use="required"/>
  </complexType>

  <!-- variable declaration -->
  <element name="variable">
    <complexType>
      <sequence>
	<element name="modifier" type="mlml:modref" minOccurs="0" maxOccurs="unbounded"/>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
      <attribute name="access" type="mlml:Access" use="optional"/>
      <attribute name="id" type="ID" use="optional"/>
    </complexType>
  </element>

  <!-- variable reference -->
  <element name="reference">
    <complexType>
      <sequence>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
      <attribute name="refid" type="IDREF" use="optional"/>
    </complexType>
  </element>

  <!-- literal (constant value) -->
  <element name="literal">
    <complexType>
      <sequence>
	<element name="modifier" type="mlml:modref" minOccurs="0" maxOccurs="unbounded"/>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
	<element name="value" type="string" minOccurs="1" maxOccurs="1"/>
      </sequence>
    </complexType>
  </element>

  <!-- param declaration -->
  <element name="param">
    <complexType>
      <sequence>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
    </complexType>
  </element>

  <!-- function declaration -->
  <element name="function">
    <complexType>
      <sequence>
	<element name="modifier" type="mlml:modref" minOccurs="0" maxOccurs="unbounded"/>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
	<element ref="mlml:param" minOccurs="0" maxOccurs="unbounded"/>
	<element ref="mlml:body" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
      <attribute name="access" type="mlml:Access" use="optional"/>
    </complexType>
  </element>

  <!-- function call -->
  <element name="call">
    <complexType>
      <sequence>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
	<element name="target" type="mlml:expression" minOccurs="0" maxOccurs="1"/>
	<element ref="mlml:param" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
    </complexType>
  </element>

  <!-- operator declaration -->
  <element name="operator">
    <complexType>
      <sequence>
	<element name="modifier" type="mlml:modref" minOccurs="0" maxOccurs="unbounded"/>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
	<element ref="mlml:param" minOccurs="0" maxOccurs="unbounded"/>
	<element ref="mlml:body" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
      <attribute name="access" type="mlml:Access" use="optional"/>
    </complexType>
  </element>

  <!-- operation -->
  <element name="operation">
    <complexType>
      <sequence>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
	<element name="param" type="mlml:expression" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
    </complexType>
  </element>

  <!-- function/statement body declaration -->
  <element name="body">
    <complexType>
      <sequence>
	<group ref="mlml:instruction" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="lang" type="mlml:Name" use="optional"/>
    </complexType>
  </element>

  <element name="return">
    <complexType>
      <sequence>
	<element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
	<group ref="mlml:instruction" minOccurs="0" maxOccurs="1"/>
      </sequence>
    </complexType>
  </element>

  <element name="unit">
    <complexType>
      <sequence>
	<group ref="mlml:declaration" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
    </complexType>
  </element>

  <element name="module">
    <complexType>
      <sequence>
	<group ref="mlml:declaration" minOccurs="0" maxOccurs="unbounded"/>
      </sequence>
      <attribute name="name" type="mlml:Name" use="required"/>
    </complexType>
  </element>

  <group name="declaration">
    <choice>
      <element ref="mlml:module"/>
      <element ref="mlml:type"/>
      <element ref="mlml:function"/>
      <element ref="mlml:variable"/>
      <element ref="mlml:statement"/>
      <element ref="mlml:operator"/>
      <any namespace="##other" processContents="lax"/>
    </choice>
  </group>

  <group name="instruction">
    <choice>
      <element ref="mlml:instruction"/>
      <group ref="mlml:expression"/>
      <any namespace="##other" processContents="lax"/>
    </choice>
  </group>

  <group name="expression">
    <choice>
      <element ref="mlml:call"/>
      <element ref="mlml:reference"/>
      <element ref="mlml:literal"/>
      <element ref="mlml:operation"/>
      <!--      <element ref="mlml:throw"/> -->
      <element ref="mlml:return"/>
      <any namespace="##other" processContents="lax"/>
    </choice>
  </group>

  <complexType name="expression">
    <sequence>
      <element name="type" type="mlml:typeref" minOccurs="0" maxOccurs="1"/>
      <group ref="mlml:expression" minOccurs="0" maxOccurs="unbounded"/>
    </sequence>
    <attribute name="name" type="mlml:Name" use="optional"/>
  </complexType>
  
  <simpleType name="Access">
    <restriction base="NMTOKEN">
      <enumeration value="public"/>
      <enumeration value="protected"/>
      <enumeration value="private"/>
      <enumeration value="package"/>
      <enumeration value="system"/>
    </restriction>
  </simpleType>

  <simpleType name="Name">
    <restriction base="Name"/>
  </simpleType>

</schema>

