<?xml version="1.0" encoding="UTF-8"?>
<grammar xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0" xmlns:ns1="tag:textalign.net,2015:ns" xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
  <include href="TAN-core.rng" ns="tag:textalign.net,2015:ns">
    <define name="definition-non-core">
      <interleave>
        <ref name="definition-class-2"/>
        <ref name="definition-non-class-2"/>
      </interleave>
    </define>
    <define name="alter-statement">
      <zeroOrMore>
        <ref name="alter-element"/>
      </zeroOrMore>
    </define>
    <define name="alter-non-core">
      <ref name="alter-class-2"/>
      <ref name="alter-non-class-2"/>
    </define>
    <define name="alter-condition">
      <ref name="action-condition"/>
    </define>
    <define name="action-condition-attributes">
      <ref name="sources-ref"/>
      <optional>
        <ref name="div-type-ref"/>
      </optional>
    </define>
    <define name="body-content-non-core">
      <interleave>
        <ref name="body-content-class-2"/>
        <ref name="body-content-non-class-2"/>
      </interleave>
    </define>
    <define name="sources-ref">
      <a:documentation>All sources are TAN files, so no source rights should be declared--they're already stated</a:documentation>
      <attribute name="src">
        <a:documentation>refers to the ID of one or more &lt;source&gt;s </a:documentation>
      </attribute>
    </define>
  </include>
  <define name="definition-class-2">
    <interleave>
      <zeroOrMore>
        <ref name="defn-tok-def"/>
      </zeroOrMore>
      <zeroOrMore>
        <ref name="defn-group-type"/>
      </zeroOrMore>
    </interleave>
  </define>
  <define name="definition-non-class-2">
    <empty/>
  </define>
  <define name="alter-class-2">
    <zeroOrMore>
      <ref name="alt-skip"/>
    </zeroOrMore>
    <zeroOrMore>
      <ref name="alt-rename"/>
    </zeroOrMore>
    <zeroOrMore>
      <ref name="alt-equate"/>
    </zeroOrMore>
    <zeroOrMore>
      <ref name="alt-reassign"/>
    </zeroOrMore>
  </define>
  <define name="alter-non-class-2">
    <empty/>
  </define>
  <define name="body-content-class-2">
    <empty/>
  </define>
  <define name="body-content-non-class-2">
    <empty/>
  </define>
  <define name="source-ref">
    <attribute name="src">
      <a:documentation>refers to the ID of only one &lt;source&gt;</a:documentation>
      <data type="NCName"/>
    </attribute>
  </define>
  <define name="alt-skip">
    <element name="skip">
      <a:documentation>marks parts of a source that have been ignored or should be skipped, either shallowly (default) or deeply.</a:documentation>
      <a:documentation>Note, the shallow skip of a &lt;div&gt; may result in the source with leaf divs that have the same reference, breaking the Leaf Div Uniqueness Rule (LDUR). See main.xml#leaf_div_uniqueness_rule</a:documentation>
      <a:documentation>This element is useful for ignoring extraneous divs, e.g., where a source has introduced divs that do not exist in other versions of the same work. For example, a transcription may group the topmost divisions of a text into parts, or may adopt superfluous divisions (e.g., introducing a &lt;div&gt; for chapter in the New Testament book Philemon, which does not have more than one chapter, and can be identified purely by verse).  </a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <choice>
        <ref name="inclusion"/>
        <group>
          <optional>
            <ref name="shallow-option"/>
          </optional>
          <optional>
            <choice>
              <ref name="n"/>
              <ref name="pointer-to-div-item"/>
              <ref name="div-type-ref"/>
            </choice>
          </optional>
        </group>
      </choice>
    </element>
  </define>
  <define name="alt-rename">
    <element name="rename">
      <a:documentation>provisionally reassigns values of @n's in class 1 sources, or their calculated ref value, to another value.</a:documentation>
      <a:documentation>Values of @n will be renamed before attempting to rename references. Only the first renaming match will be applied.</a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <choice>
        <ref name="inclusion"/>
        <choice>
          <ref name="simple-rename"/>
          <ref name="complex-rename"/>
        </choice>
      </choice>
    </element>
  </define>
  <define name="simple-rename">
    <choice>
      <group>
        <ref name="n"/>
        <ref name="new-name"/>
      </group>
      <group>
        <ref name="pointer-to-div-item"/>
        <ref name="new-ref-name"/>
      </group>
    </choice>
  </define>
  <define name="complex-rename">
    <choice>
      <ref name="n"/>
      <ref name="pointer-to-div-range"/>
    </choice>
    <choice>
      <ref name="increment"/>
      <ref name="new-name"/>
    </choice>
  </define>
  <define name="increment">
    <attribute name="by">
      <a:documentation>specifies an amount by which an series of @n values or the last component in a series of @ref values should be incremented or decremented.</a:documentation>
      <data type="integer"/>
    </attribute>
  </define>
  <define name="new-name">
    <attribute name="new">
      <a:documentation>provides the new name for an @n or reference that is to be renamed</a:documentation>
    </attribute>
  </define>
  <define name="new-ref-name">
    <attribute name="new">
      <a:documentation>provides the new ref for a &lt;div&gt; that is to be renamed</a:documentation>
      <ref name="div-item-ref"/>
    </attribute>
  </define>
  <define name="alt-equate">
    <element name="equate">
      <a:documentation>declares an ad hoc equivalence between works or @n values.</a:documentation>
      <a:documentation>This is useful for handling sources that have not used the the same &lt;IRI&gt;s in defining works that you believe to be equivalent, or for associating values of @n that should be treated as synonymous.</a:documentation>
      <a:documentation>Equating is transitive and greedy. If work A is defined with &lt;IRI&gt; X, work B with &lt;IRI&gt;s X and Y, and work C with only &lt;IRI&gt; Y, then works A and C will be automatically equated.</a:documentation>
      <a:documentation>This element does not imply that the works are necessarily one and the same, or than the @n values are the same. It merely states that, for the purposes of this alignment, they should be treated as equivalent.</a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <choice>
        <ref name="inclusion"/>
        <ref name="n"/>
      </choice>
    </element>
  </define>
  <define name="alt-reassign">
    <element name="reassign">
      <a:documentation>identifies word fragments that should be moved from one ref to another</a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <choice>
        <ref name="inclusion"/>
        <group>
          <oneOrMore>
            <ref name="tok-ref-range"/>
          </oneOrMore>
          <ref name="target-div-ref"/>
        </group>
      </choice>
    </element>
  </define>
  <define name="target-div-ref">
    <element name="to">
      <a:documentation>indicates a ref to which the preceding &lt;tok&gt;s should be moved.</a:documentation>
      <ref name="pointer-to-div-item"/>
    </element>
  </define>
  <define name="id-option">
    <a:documentation>Option to include an internal id. Not needed in TAN-A-lm files.</a:documentation>
    <ref name="internal-xml-id"/>
  </define>
  <define name="shallow-option">
    <attribute name="shallow">
      <a:documentation>indicates whether skipping should be done shallowly (default) or deeply</a:documentation>
      <data type="boolean"/>
    </attribute>
  </define>
  <!-- div references -->
  <define name="div-type-ref">
    <attribute name="div-type">
      <a:documentation>is used by class-2 files to point to one or more &lt;div-type&gt;s in class-1 files. Permits multiple values separated by spaces.</a:documentation>
    </attribute>
  </define>
  <define name="div-ref-range">
    <element name="div-ref">
      <a:documentation>refers to one or more &lt;div&gt;s.</a:documentation>
      <a:documentation>&lt;div-ref&gt;s are expanded against @src/@work and @ref. That is, a &lt;div-ref&gt; points to every div of every source cited.</a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <ref name="pointer-to-div-range"/>
    </element>
  </define>
  <!-- token references -->
  <define name="tok-single-selector-attributes">
    <choice>
      <ref name="token-value-ref"/>
      <ref name="item-pos-ref"/>
      <group>
        <ref name="token-value-ref"/>
        <ref name="item-pos-ref"/>
      </group>
    </choice>
  </define>
  <define name="tok-mult-selector-attributes">
    <choice>
      <ref name="token-value-ref"/>
      <ref name="seq-pos-ref"/>
      <group>
        <ref name="token-value-ref"/>
        <ref name="seq-pos-ref"/>
      </group>
    </choice>
  </define>
  <define name="tok-ref">
    <choice>
      <ref name="tok-ref-item"/>
      <ref name="tok-ref-group"/>
      <ref name="tok-ref-range"/>
    </choice>
  </define>
  <define name="tok-ref-item">
    <element name="tok">
      <a:documentation>identifies one or more words or word fragments. Used by class 2 files to make assertions about specific words. </a:documentation>
      <a:documentation>In TAN-A-div and TAN-A-tok files, &lt;tok&gt; has no linguistic connotations; in TAN-A-lm, it normally does.</a:documentation>
      <a:documentation>&lt;tok&gt;s that are restricted to a single token, or a portion of a single token. This is the normal behavior of &lt;tok&gt;. Multiple values in @src, @ref, and @pos will result in expansion across all values. But multiple values of @chars are taken to refer to the constituent parts of a single &lt;tok&gt; and so no expansion occurs on @chars.</a:documentation>
      <a:documentation>This syntax allows multiple &lt;tok&gt;s to be collapsed into a single one, to save space and perhaps enhance legibility. For example, a &lt;tok&gt; with 2 values for @src, 3 for @ref, 4 for @pos, and 5 for @chars will result in a &lt;tok&gt; that points to 24 tokens, each of which is filtered to the same five characters (by position, not content). Put another way, &lt;tok src="X" ref="a" pos="1"/&gt; and &lt;tok src="X" ref="a" pos="2"/&gt; is always identical to &lt;tok src="X" ref="a" pos="1-2"/&gt;</a:documentation>
      <a:documentation>If you wish to treat multiple word fragments as a single token, use &lt;group&gt;.</a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <ref name="tok-sources-ref-opt"/>
      <ref name="pointer-to-div-range"/>
      <ref name="tok-mult-selector-attributes"/>
      <ref name="tok-cert-opt"/>
      <optional>
        <ref name="char-ref"/>
      </optional>
    </element>
  </define>
  <define name="tok-ref-group">
    <element name="group">
      <a:documentation>groups references that should be treated as a single passage.</a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <choice>
        <ref name="inclusion"/>
        <group>
          <ref name="group-attributes"/>
          <oneOrMore>
            <ref name="tok-ref-item"/>
          </oneOrMore>
        </group>
      </choice>
    </element>
  </define>
  <define name="tok-ref-range">
    <element name="tok">
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <ref name="pointer-to-div-item"/>
      <choice>
        <ref name="tok-mult-selector-attributes"/>
        <ref name="tok-range-selector"/>
      </choice>
    </element>
  </define>
  <define name="tok-range-selector">
    <element name="from">
      <a:documentation>points to a single token that is the start of a range of tokens to be selected</a:documentation>
      <ref name="tok-single-selector-attributes"/>
    </element>
    <element name="to">
      <a:documentation>points to a single token that is the end of a range of tokens to be selected</a:documentation>
      <ref name="tok-single-selector-attributes"/>
    </element>
  </define>
  <define name="tok-sources-ref-opt">
    <ref name="sources-ref"/>
  </define>
  <define name="tok-cert-opt">
    <optional>
      <ref name="cert-claim"/>
    </optional>
  </define>
  <define name="pointer-to-div-range">
    <attribute name="ref">
      <a:documentation>lists references to one or more &lt;div&gt;s. It consists of one or more simple references joined by commas or hyphens. A simple reference is a string value that points to a single &lt;div&gt;, e.g., "1 1". </a:documentation>
      <a:documentation>Truncation is allowed. For example, 1 1 - 3 will be interpreted first as 1 1 through 1 3; if that is invalid, it will be interpeted as 1 1 through 3. Other examples: '2.4 - 7, 9', 'iv 7 - 9'</a:documentation>
      <a:documentation>In a range with members of uneven depth, those &lt;div&gt;s that are closest to the shallowest member are retrieved. For example, 2 - 3 2 2 might fetch 2, 3 1, 3 2 1, 3 2 2 (and not 3 or 3 1 1).</a:documentation>
      <a:documentation>For more, see main.xml#class_2_body </a:documentation>
      <ref name="div-range-ref"/>
    </attribute>
  </define>
  <define name="pointer-to-div-item">
    <attribute name="ref">
      <ref name="div-item-ref"/>
    </attribute>
  </define>
  <define name="token-value-ref">
    <attribute name="val">
      <a:documentation>specifies a particular word token by means of its string value. Treated as a constrained regular expression (the expression must match the entire token, case-sensitive).</a:documentation>
      <a:documentation>For more see main.xml#attr_pos_and_val</a:documentation>
      <data type="string">
        <param name="pattern">.+</param>
      </data>
    </attribute>
  </define>
  <define name="item-pos-ref">
    <attribute name="pos">
      <a:documentation>lists one items, specified through Arabic numerals and the keyword 'last' or 'last-X' (where X is a valid number).</a:documentation>
      <a:documentation>Examples: '1', 'last', 'last-3 - last-1'</a:documentation>
      <a:documentation>For more see main.xml#attr_pos_and_val</a:documentation>
      <ref name="item-picker"/>
    </attribute>
  </define>
  <define name="seq-pos-ref">
    <attribute name="pos">
      <a:documentation>lists one or more items, specified through Arabic numerals and the keyword 'last' or 'last-X' (where X is a valid number), joined with commas or hyphens.</a:documentation>
      <a:documentation>Examples: '1', 'last', 'last-3 - last-1', '1, 3, 5, 7 - 11, last-8, last'</a:documentation>
      <a:documentation>For more see main.xml#attr_pos_and_val</a:documentation>
      <ref name="seq-picker"/>
    </attribute>
  </define>
  <define name="char-ref">
    <attribute name="chars">
      <a:documentation>list of one or more characters, specified through Arabic numerals, the keyword 'last' or 'last-X' (where X is a valid number), joined with commas or hyphens.</a:documentation>
      <a:documentation>Examples: '1', 'last', 'last-3 - last-1', '1, 3, 5, 7 - 11, last-8, last'</a:documentation>
      <ref name="seq-picker"/>
    </attribute>
  </define>
</grammar>
<!--
  continuation-opt = continuation
  continuation =
     
     ## indicates whether the current element is continued by the next one and to be treated as a single one. Value must be 1 or true, implied by the very presence of the attribute. If you wish to decare it to be false, delete the attribute altogether.
-->
<!--    ## This feature is useful in <tok> for rejoining the portion of a word split across two <div>s, or for uniting into a single linguistic token multiple tokens separated by the tokenization process, e.g., "pom pom". -->
<!--
     ## This feature is useful in <div-ref> for creating groups of references that cannot be expressed in a single <div-ref>  
     attribute cont {
         xsd:boolean { pattern = "true|1" }
     }
-->
