<?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="object" />
  </start>

  <define name="object">
    <choice>
      <ref name="list" />
      <ref name="map" />
      <ref name="issue" />
      <ref name="status" />
      <ref name="priority" />
      <ref name="name" />
      <ref name="yes-no" />
      <ref name="activity" />
      <ref name="constraint" />
      <ref name="ordering" />
      <ref name="node-end-ref" />
      <ref name="end" />
      <ref name="pattern-assignment" />
      <ref name="item-var" />
      <ref name="report" />
      <ref name="report-type" />
      <ref name="chat-message" />
      <ref name="literal-document" />
      <ref name="symbol" />
      <ref name="string" />
      <ref name="integer" />
      <ref name="long" />
      <ref name="float" />
      <ref name="double" />
      <ref name="domain" />
      <ref name="variable-declaration" />
      <ref name="refinement" />
      <ref name="node-spec" />
      <ref name="plan" />
      <ref name="plan-variable-declaration" />
      <ref name="variable-scope" />
      <ref name="plan-issue" />
      <ref name="plan-issue-refinement" />
      <ref name="plan-node" />
      <ref name="plan-refinement" />
      <ref name="constrainer" />
      <ref name="plan-variable" />
    </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>

  <!--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="id">
          <ref name="name-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>

  <!--name-->

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

  <define name="name-value">
    <data type="string" />
  </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>

  <!--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="id">
          <ref name="name-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>

  <!--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>

  <!--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>

  <!--item-var-->

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

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

  <!--report-->

  <define name="report">
    <element name="report">
      <optional>
        <attribute name="report-type">
          <ref name="report-type-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>
      <interleave>
        <optional>
          <element name="text">
            <ref name="string" />
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--report-type-->

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

  <define name="report-type-value">
    <choice>
      <value>success</value>
      <value>failure</value>
      <value>progress</value>
      <value>information</value>
      <value>event</value>
    </choice>
  </define>

  <!--chat-message-->

  <define name="chat-message">
    <element name="chat-message">
      <optional>
        <attribute name="sender-id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="text">
            <ref name="string" />
          </element>
        </optional>
      </interleave>
    </element>
  </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>

  <!--symbol-->

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

  <define name="symbol-value">
    <data type="string" />
  </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>

  <!--domain-->

  <define name="domain">
    <element name="domain">
      <interleave>
        <optional>
          <element name="name">
            <ref name="string" />
          </element>
        </optional>
        <optional>
          <element name="variable-declarations">
            <element name="list">
              <zeroOrMore>
                <ref name="variable-declaration" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="refinements">
            <element name="list">
              <zeroOrMore>
                <ref name="refinement" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--variable-declaration-->

  <define name="variable-declaration">
    <element name="variable-declaration">
      <optional>
        <attribute name="name">
          <ref name="item-var-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--refinement-->

  <define name="refinement">
    <element name="refinement">
      <interleave>
        <optional>
          <element name="name">
            <ref name="string" />
          </element>
        </optional>
        <optional>
          <element name="pattern">
            <ref name="list" />
          </element>
        </optional>
        <optional>
          <element name="variable-declarations">
            <element name="list">
              <zeroOrMore>
                <ref name="variable-declaration" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="nodes">
            <element name="list">
              <zeroOrMore>
                <ref name="node-spec" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="orderings">
            <element name="list">
              <zeroOrMore>
                <ref name="ordering" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="constraints">
            <element name="list">
              <zeroOrMore>
                <ref name="constraint" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="issues">
            <element name="list">
              <zeroOrMore>
                <ref name="issue" />
              </zeroOrMore>
            </element>
          </element>
        </optional>
        <optional>
          <element name="comments">
            <ref name="string" />
          </element>
        </optional>
        <optional>
          <element name="annotations">
            <ref name="map" />
          </element>
        </optional>
      </interleave>
    </element>
  </define>

  <!--node-spec-->

  <define name="node-spec">
    <element name="node-spec">
      <optional>
        <attribute name="id">
          <ref name="name-value" />
        </attribute>
      </optional>
      <interleave>
        <optional>
          <element name="pattern">
            <ref name="list" />
          </element>
        </optional>
      </interleave>
    </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>

  <!--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>

  <!--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>

  <!--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>

  <!--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>

</grammar>
  
  
