<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         ns="http://jelix.org/ns/urls/1.0"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"
         >

   <start>
      <element name="urls">
         <oneOrMore>
            <ref name="entrypoint" />
         </oneOrMore>
      </element>
   </start>


   <define name="entrypoint">
      <choice>
         <element>
            <choice>
               <name>classicentrypoint</name>
               <name>xmlrpcentrypoint</name>
               <name>jsonrpcentrypoint</name>
               <name>rdfentrypoint</name>
               <name>xmlentrypoint</name>
               <name>xulentrypoint</name>
               <name>cssentrypoint</name>
            </choice>
            <ref name="entrypoint.common" />
         </element>
         <element name="entrypoint">
            <attribute name="type">
               <choice><value>classic</value>
                  <value>xmlrpc</value>
                  <value>jsonrpc</value>
                  <value>rdf</value>
                  <value>xml</value>
                  <value>xul</value>
                  <value>css</value>
               </choice>
            </attribute>
            <ref name="entrypoint.common" />
         </element>
      </choice>
   </define>

   <define name="entrypoint.common">
      <attribute name="name"/>
      <optional><attribute name="default"><data type="boolean"/></attribute></optional>
      <optional><attribute name="https"><data type="boolean"/></attribute> </optional>
      <optional><attribute name="noentrypoint"><data type="boolean"/></attribute> </optional>
      <zeroOrMore>
         <choice>
            <ref name="url.module.dedicated" />
            <ref name="url" />
            <ref name="url.handler" />
         </choice>
      </zeroOrMore>
   </define>

   <define name="url">
      <element name="url">
         <ref name="url.common" />
         <attribute name="action" />
         <optional>
            <attribute name="actionoverride" />
         </optional>
         <optional>
            <attribute name="pathinfo" />
            <zeroOrMore>
               <ref name="param" />
            </zeroOrMore>
         </optional>
         <zeroOrMore>
            <ref name="static" />
         </zeroOrMore>
         <optional> <attribute name="optionalTrailingSlash"><data type="boolean"/></attribute> </optional>
      </element>
   </define>

   <define name="url.module.dedicated">
      <element name="url">
         <ref name="url.common" />
         <optional>
            <attribute name="include" />
         </optional>
         <empty/>
      </element>
   </define>

   <define name="url.handler">
      <element name="url">
         <ref name="url.common" />
         <optional>
            <attribute name="action" />
            <optional>
               <attribute name="actionoverride" />
            </optional>
         </optional>
         <optional>
            <attribute name="pathinfo" />
         </optional>
         <attribute name="handler" />
         <empty/>
      </element>
   </define>

   <define name="url.common">
      <attribute name="module" />
      <optional> <attribute name="noentrypoint"><data type="boolean"/></attribute> </optional>
      <optional> <attribute name="https"><data type="boolean"/></attribute> </optional>
   </define>

   <define name="param">
      <element name="param">
         <attribute name="name" />
         <optional>
            <choice>
               <attribute name="type">
                  <choice>
                     <value>string</value>
                     <value>char</value>
                     <value>letter</value>
                     <value>number</value>
                     <value>int</value>
                     <value>integer</value>
                     <value>digit</value>
                     <value>date</value>
                     <value>year</value>
                     <value>month</value>
                     <value>day</value>
                  </choice>
               </attribute>
               <attribute name="regexp"/>
            </choice>
         </optional>
         <optional><attribute name="escape"><data type="boolean"/></attribute></optional>
         <empty />
      </element>
   </define>

   <define name="static">
      <element name="static">
         <attribute name="name" />
         <attribute name="value" />
         <optional>
            <attribute name="type">
               <choice>
                  <value>lang</value>
                  <value>locale</value>
               </choice>
            </attribute>
         </optional>
         <empty />
      </element>
   </define>

</grammar>