<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" ns="http://www.aiai.ed.ac.uk/project/ix/" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

  <start>
    <ref name="plan" />
  </start>

  <define name="object">
    <choice>
      <ref name="list" />
      <ref name="map" />
      <ref name="plan" />
      <ref name="plan-variable-declaration" />
      <ref name="name" />
      <ref name="symbol" />
      <ref name="variable-scope" />
      <ref name="plan-issue" />
      <ref name="issue" />
      <ref name="status" />
      <ref name="priority" />
      <ref name="yes-no" />
      <ref name="plan-issue-refinement" />
      <ref name="plan-node" />
      <ref name="activity" />
      <ref name="plan-refinement" />
      <ref name="constrainer" />
      <ref name="pattern-assignment" />
      <ref name="plan-variable" />
      <ref name="constraint" />
      <ref name="ordering" />
      <ref name="node-end-ref" />
      <ref name="end" />
      <ref name="literal-document" />
      <ref name="string" />
      <ref name="integer" />
      <ref name="long" />
      <ref name="float" />
      <ref name="double" />
    </choice>
  </define>

  <define name="list">
    <element name="list">
      <zeroOrMore>
        <ref name="object" />
      </zeroOrMore>
    </element>
  </define>

  <define name="map">
    <element name="map">
      <zeroOrMore>
        <element name="map-entry">
          <element name="key">
            <ref name="object" />
          </element>
          <element name="value">
            <ref name="object" />
          </element>
        </element>
      </zeroOrMore>
    </element>
  </define>

  <!--plan-->

  <define name="plan">
    <element name="plan">
      <interleave>
        <optional>
          <element name="plan-variable-declarations">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-variable-declaration" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="plan-issues">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-issue" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="plan-issue-refinements">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-issue-refinement" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="plan-nodes">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-node" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="plan-refinements">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-refinement" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="constraints">
            <element name="list">
              <zeroOrMore>
                <ref name="constrainer" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="world-state">
            <element name="list">
              <zeroOrMore>
                <ref name="pattern-assignment" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--plan-variable-declaration-->

  <define name="plan-variable-declaration">
    <element name="plan-variable-declaration">
      <optional>
        <attribute name="id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="name">
          <ref name="symbol-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="scope">
          <ref name="variable-scope-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--name-->

  <define name="name">
    <element name="name">
      <ref name="name-value" />
    </element>
  </define>

  <define name="name-value">
    <data type="string" />
  </define>

  <!--symbol-->

  <define name="symbol">
    <element name="symbol">
      <ref name="symbol-value" />
    </element>
  </define>

  <define name="symbol-value">
    <data type="string" />
  </define>

  <!--variable-scope-->

  <define name="variable-scope">
    <element name="variable-scope">
      <ref name="variable-scope-value" />
    </element>
  </define>

  <define name="variable-scope-value">
    <choice>
      <value>local</value>
      <value>global</value>
    </choice>
  </define>

  <!--plan-issue-->

  <define name="plan-issue">
    <element name="plan-issue">
      <optional>
        <attribute name="id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="expansion">
          <ref name="name-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="issue">
            <ref name="issue" />
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--issue-->

  <define name="issue">
    <element name="issue">
      <optional>
        <attribute name="status">
          <ref name="status-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="priority">
          <ref name="priority-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="sender-id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="ref">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="report-back">
          <ref name="yes-no-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="pattern">
            <ref name="list" />
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--status-->

  <define name="status">
    <element name="status">
      <ref name="status-value" />
    </element>
  </define>

  <define name="status-value">
    <choice>
      <value>blank</value>
      <value>complete</value>
      <value>executing</value>
      <value>possible</value>
      <value>impossible</value>
      <value>n/a</value>
    </choice>
  </define>

  <!--priority-->

  <define name="priority">
    <element name="priority">
      <ref name="priority-value" />
    </element>
  </define>

  <define name="priority-value">
    <choice>
      <value>lowest</value>
      <value>low</value>
      <value>normal</value>
      <value>high</value>
      <value>highest</value>
    </choice>
  </define>

  <!--yes-no-->

  <define name="yes-no">
    <element name="yes-no">
      <ref name="yes-no-value" />
    </element>
  </define>

  <define name="yes-no-value">
    <choice>
      <value>yes</value>
      <value>no</value>
    </choice>
  </define>

  <!--plan-issue-refinement-->

  <define name="plan-issue-refinement">
    <element name="plan-issue-refinement">
      <optional>
        <attribute name="id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="expands">
          <ref name="name-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="plan-variable-declarations">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-variable-declaration" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="plan-issues">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-issue" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--plan-node-->

  <define name="plan-node">
    <element name="plan-node">
      <optional>
        <attribute name="id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="expansion">
          <ref name="name-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="activity">
            <ref name="activity" />
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--activity-->

  <define name="activity">
    <element name="activity">
      <optional>
        <attribute name="status">
          <ref name="status-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="priority">
          <ref name="priority-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="sender-id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="ref">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="report-back">
          <ref name="yes-no-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="pattern">
            <ref name="list" />
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--plan-refinement-->

  <define name="plan-refinement">
    <element name="plan-refinement">
      <optional>
        <attribute name="id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="expands">
          <ref name="name-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="plan-variable-declarations">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-variable-declaration" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="plan-nodes">
            <element name="list">
              <zeroOrMore>
                <ref name="plan-node" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="constraints">
            <element name="list">
              <zeroOrMore>
                <ref name="constrainer" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--constrainer-->

  <define name="constrainer">
    <choice>
      <ref name="constraint" />
      <ref name="ordering" />
    </choice>
  </define>

  <!--pattern-assignment-->

  <define name="pattern-assignment">
    <element name="pattern-assignment">
      <interleave>
        <optional>
          <element name="pattern">
            <ref name="list" />
          </element>
        </optional>
        <optional>
          <element name="value">
            <ref name="object" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--plan-variable-->

  <define name="plan-variable">
    <element name="plan-variable">
      <optional>
        <attribute name="id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="name">
          <ref name="symbol-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--constraint-->

  <define name="constraint">
    <element name="constraint">
      <optional>
        <attribute name="type">
          <ref name="symbol-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="relation">
          <ref name="symbol-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="sender-id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="parameters">
            <ref name="list" />
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--ordering-->

  <define name="ordering">
    <element name="ordering">
      <interleave>
        <optional>
          <element name="from">
            <ref name="node-end-ref" />
          </element>
        </optional>
        <optional>
          <element name="to">
            <ref name="node-end-ref" />
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--node-end-ref-->

  <define name="node-end-ref">
    <element name="node-end-ref">
      <optional>
        <attribute name="end">
          <ref name="end-value" />
        </attribute>
      </optional>
      <optional>
        <attribute name="node">
          <ref name="name-value" />
        </attribute>
      </optional>
    </element>
  </define>

  <!--end-->

  <define name="end">
    <element name="end">
      <ref name="end-value" />
    </element>
  </define>

  <define name="end-value">
    <choice>
      <value>begin</value>
      <value>end</value>
    </choice>
  </define>

  <!--literal-document-->

  <define name="literal-document">
    <element name="literal-document">
      <ref name="anyXML" />
    </element>
  </define>

  <define name="anyXML">
    <element>
      <anyName />
      <zeroOrMore>
        <choice>
          <attribute>
            <anyName />
          </attribute>
          <text />
          <ref name="anyXML" />
        </choice>
      </zeroOrMore>
    </element>
  </define>

  <!--string-->

  <define name="string">
    <element name="string">
      <ref name="string-value" />
    </element>
  </define>

  <define name="string-value">
    <text />
  </define>

  <!--integer-->

  <define name="integer">
    <element name="integer">
      <ref name="integer-value" />
    </element>
  </define>

  <define name="integer-value">
    <data type="int" />
  </define>

  <!--long-->

  <define name="long">
    <element name="long">
      <ref name="long-value" />
    </element>
  </define>

  <define name="long-value">
    <data type="long" />
  </define>

  <!--float-->

  <define name="float">
    <element name="float">
      <ref name="float-value" />
    </element>
  </define>

  <define name="float-value">
    <data type="float" />
  </define>

  <!--double-->

  <define name="double">
    <element name="double">
      <ref name="double-value" />
    </element>
  </define>

  <define name="double-value">
    <data type="double" />
  </define>

</grammar>
  
  
