<?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="group-attributes">
      <ref name="type"/>
      <optional>
        <ref name="n"/>
      </optional>
    </define>
    <define name="source-rights">
      <a:documentation>All sources are TAN files, so no source rights should be declared--they're already stated</a:documentation>
      <empty/>
    </define>
    <define name="source-refs">
      <attribute name="src">
        <a:documentation>refers to the ID of one or more &lt;source&gt;s </a:documentation>
      </attribute>
    </define>
    <define name="body-group-opt">
      <zeroOrMore>
        <ref name="body-group"/>
      </zeroOrMore>
    </define>
  </include>
  <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="decl-supp-div-type">
    <element name="suppress-div-types">
      <a:documentation>marks div types in a source that should be suppressed in references. Suppressions occur shallowly. That is, it does not suppress any descendants of that div type. But if the suppression applies to a leaf div, that div and its text is effectively suppressed. </a:documentation>
      <a:documentation>Any suppression of a div type must preserve the Leaf Div Uniqueness Rule (LDUR). See main.xml#leaf_div_uniqueness_rule</a:documentation>
      <a:documentation>This element will be used seldomly, for cases where a source has a div type that is dispensable in text references. </a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <choice>
        <ref name="inclusion"/>
        <group>
          <ref name="source-refs"/>
          <ref name="div-type-ref"/>
        </group>
      </choice>
    </element>
  </define>
  <define name="decl-rename-div-n">
    <element name="rename-div-ns">
      <a:documentation>provisionally reassigns @n values for one or more sources and one or more div types. Renaming applies only to the current file. </a:documentation>
      <a:documentation>This element is especially useful for converting Roman numerals or letter numerals into Arabic numerals. See &lt;rename&gt; for syntax.</a:documentation>
      <a:documentation>This feature is strictly speaking a convenience, not a necessity. All TAN-compliant preprocessors are required to automatically detect Roman and alphabetic numbering systems and treat them as Arabic numerals. </a:documentation>
      <a:documentation>It is also useful for div types that use descriptive names for @n (such as books of the Bible), particularly for reconciling those names with a system that prevails or is preferred (e.g., "mt" to "Matt"). </a:documentation>
      <a:documentation>Note for TAN-A-div users: Although this element can reconcile simple differences, it should not be used for more complex inconsistencies that affect alignment, best handled in the &lt;body&gt; of a TAN-A-div file.</a:documentation>
      <a:documentation>For more inforrmation see main.xml#class_2_metadata</a:documentation>
      <optional>
        <ref name="ed-stamp"/>
      </optional>
      <choice>
        <ref name="inclusion"/>
        <group>
          <ref name="source-refs"/>
          <ref name="div-type-ref"/>
          <oneOrMore>
            <ref name="name-change"/>
          </oneOrMore>
        </group>
      </choice>
    </element>
  </define>
  <define name="name-change">
    <element name="rename">
      <a:documentation>indicates the name of a &lt;div&gt; @n that should be changed in a given @type, and the name to which it should be changed.</a:documentation>
      <a:documentation>There is no need to use this feature to convert Roman, alphabetic, or other numerals, which are detected and converted automatically </a:documentation>
      <attribute name="old">
        <a:documentation>provides the name of an @n to be renamed</a:documentation>
        <ref name="n-val"/>
      </attribute>
      <attribute name="new">
        <a:documentation>provides the new name for an @n that is to be renamed</a:documentation>
        <ref name="n-val"/>
      </attribute>
    </element>
  </define>
  <define name="id-option">
    <a:documentation>Option to include an internal id. Not needed in TAN-LM files.</a:documentation>
    <ref name="internal-id"/>
  </define>
  <define name="div-type-ref">
    <attribute name="div-type-ref">
      <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="tok-attr-core">
    <optional>
      <ref name="ed-stamp"/>
    </optional>
    <optional>
      <ref name="char-ref"/>
    </optional>
  </define>
  <define name="tok-regular">
    <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-LM, it normally does.</a:documentation>
      <a:documentation>&lt;tok&gt;s are two types: simple and complex.</a:documentation>
      <a:documentation>SIMPLE: &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>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). This syntax, then, allows multiple &lt;tok&gt;s to be collapsed into a single one, to save space and perhaps enhance legibility. 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>COMPLEX: There are cases where one wishes to treat more than one token, in whole or part, as a single entity. In this case, @cont should be used, and it must join &lt;tok&gt;s that have only single values for @src, @ref, and @pos. @chars may take multiple values.</a:documentation>
      <a:documentation>The behavior of &lt;tok&gt; differs from &lt;div-ref&gt;. The former is never treated as a group, whereas the latter is. For more, see &lt;div-ref&gt;.</a:documentation>
      <ref name="tok-attr-core"/>
      <ref name="tok-source-ref-opt"/>
      <ref name="pointer-to-div-range"/>
      <choice>
        <ref name="token-value-ref"/>
        <ref name="seq-pos-ref"/>
        <group>
          <ref name="token-value-ref"/>
          <ref name="seq-pos-ref"/>
        </group>
      </choice>
      <ref name="tok-cert-opt"/>
    </element>
  </define>
  <define name="tok-source-ref-opt">
    <ref name="source-refs"/>
  </define>
  <define name="tok-cert-opt">
    <ref name="cert-opt"/>
  </define>
  <define name="tok-sequence">
    <ref name="tok-with-src-and-cont"/>
    <zeroOrMore>
      <ref name="tok-with-cont-but-no-src"/>
    </zeroOrMore>
    <ref name="tok-without-cont-or-src"/>
  </define>
  <define name="tok-sequence-attr-core">
    <ref name="tok-attr-core"/>
    <ref name="pointer-to-div-item"/>
    <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-with-src-and-cont">
    <element name="tok">
      <ref name="tok-sequence-attr-core"/>
      <ref name="source-ref"/>
      <ref name="continuation-opt"/>
      <optional>
        <ref name="cert-claim"/>
      </optional>
    </element>
  </define>
  <define name="tok-with-cont-but-no-src">
    <element name="tok">
      <ref name="tok-sequence-attr-core"/>
      <ref name="continuation-opt"/>
    </element>
  </define>
  <define name="tok-without-cont-or-src">
    <element name="tok">
      <ref name="tok-sequence-attr-core"/>
    </element>
  </define>
  <define name="cert-opt">
    <optional>
      <ref name="cert-claim"/>
    </optional>
  </define>
  <define name="pointer-to-div-range">
    <a:documentation>   Pointer (link) to a div in a TAN-T(EI) file</a:documentation>
    <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;. </a:documentation>
      <a:documentation>It is assumed that any simple reference that has fewer @n values than preceding simple references has been truncated. The abbreviated form will be checked before the form actually stated. 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. 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. Permits regular expressions.</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="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="item-pos-ref">
    <attribute name="pos">
      <ref name="item-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>
  <define name="continuation-opt">
    <ref name="continuation"/>
  </define>
  <define name="continuation">
    <attribute name="cont">
      <a:documentation>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.</a:documentation>
      <a:documentation>This feature is useful in &lt;tok&gt; for rejoining the portion of a word split across two &lt;div&gt;s, or for uniting into a single linguistic token multiple tokens separated by the tokenization process, e.g., "pom pom". </a:documentation>
      <a:documentation>This feature is useful in &lt;div-ref&gt; for creating groups of references that cannot be expressed in a single &lt;div-ref&gt;  </a:documentation>
      <data type="boolean">
        <param name="pattern">true|1</param>
      </data>
    </attribute>
  </define>
</grammar>
