RELAX NG Schema for AntWeave XRefFilter output pipeline data
Author: Hugh Field-Richards
Date: 2015-08-11T13:11

This is the RELAX NG schema for the output of the XRefFilter stage of the AntWeave Ant task pipeline processor. It defines the XML available for users to extend AntWeave by writing their own filters.

The documentation is designed to be processed by the rng2xhtml.xsl pretty-printing processor and is how the file is seen via a Web browser.

Schematron
Declare schematron namespace : aw:http://www.hsfr.org.uk/Schema/AntWeave

Root

Schema Root
start
element : aw:file
optional
attribute : filter
Any text
<start>
   <element name="aw:file">
      <optional>
         <attribute name="filter">
            <text/>
         </attribute>
      </optional>
      <ref name="XRefFilter.chunks"/>
   </element>
</start>

List of Chunks

The file consists of an ordered list of chunks and definitions.

define : XRefFilter.chunks
oneOrMore
choice
element : aw:chunk
choice
oneOrMore
refcode.lines
oneOrMore
reftext.lines
element : aw:definitions
refdefinitions
<define name="XRefFilter.chunks">
   <oneOrMore>
      <choice>
         <element name="aw:chunk">
            <ref name="chunk.attributes"/>
            <choice>
               <oneOrMore>
                  <ref name="code.lines"/>
               </oneOrMore>
               <oneOrMore>
                  <ref name="text.lines"/>
               </oneOrMore>
            </choice>
         </element>
         <element name="aw:definitions">
            <ref name="definitions"/>
         </element>
      </choice>
   </oneOrMore>
</define>

Definition Chunk

define : definitions
attribute : chunk
data : NCName
choice
interleave
optional
element : aw:usedIn
zeroOrMore
refwhere
zeroOrMore
element : aw:define
attribute : var
zeroOrMore
refwhere
<define name="definitions">
   <attribute name="chunk">
      <data type="NCName"/>
   </attribute>
   <choice>
      <interleave>
         <optional>
            <element name="aw:usedIn">
               <zeroOrMore>
                  <ref name="where"/>
               </zeroOrMore>
            </element>
         </optional>
         <zeroOrMore>
            <element name="aw:define">
               <attribute name="var"/>
               <zeroOrMore>
                  <ref name="where"/>
               </zeroOrMore>
            </element>
         </zeroOrMore>
      </interleave>
   </choice>
</define>

Where definition is referenced

define : where
element : aw:where
attribute : ref
data : integer
<define name="where">
   <element name="aw:where">
      <attribute name="ref">
         <data type="integer"/>
      </attribute>
   </element>
</define>

Chunk attributes

Chunk attributes define the exact nature of that chunk. Some attributes are required and some must be unique. The Schematron checks on the validity of the attributes.

define : chunk.attributes
Schematron
Check appropriate attributes for either documentation and code
Context : “aw:chunk
If condition “@type = 'code' and not ( @hash )
then output: Code chunks must have associated hash.
Schematron
Check appropriate attributes for either documentation and code
Context : “aw:chunk
If condition “@type = 'code' and not ( @name )
then output: Code chunks must have associated name.
Schematron
Check appropriate attributes for either documentation and code
Context : “aw:chunk
If condition “@type = 'code' and not ( @id )
then output: Code chunks must have associated id.
Schematron
Element 'aw:chunk' must have unique 'id' attribute
Context : “aw:chunk/@code
if not condition “count(//@id[. = current()]) = 1
then output: Id not unique!
attribute : type
choice
value = "documentation"
value = "code"
optional
attribute : hash
data : NCName
optional
attribute : id
data : integer
optional
attribute : name
<define name="chunk.attributes">
   <sch:pattern name="Check appropriate attributes for either documentation and code">
      <sch:rule context="aw:chunk">
         <sch:report test="@type = 'code' and not ( @hash )">Code chunks must have associated hash.</sch:report>
      </sch:rule>
   </sch:pattern>
   <sch:pattern name="Check appropriate attributes for either documentation and code">
      <sch:rule context="aw:chunk">
         <sch:report test="@type = 'code' and not ( @name )">Code chunks must have associated name.</sch:report>
      </sch:rule>
   </sch:pattern>
   <sch:pattern name="Check appropriate attributes for either documentation and code">
      <sch:rule context="aw:chunk">
         <sch:report test="@type = 'code' and not ( @id )">Code chunks must have associated id.</sch:report>
      </sch:rule>
   </sch:pattern>
   <sch:pattern name="Element 'aw:chunk' must have unique 'id' attribute">
      <sch:rule context="aw:chunk/@code">
         <sch:assert test="count(//@id[. = current()]) = 1">Id not unique!</sch:assert>
      </sch:rule>
   </sch:pattern>
   <attribute name="type">
      <choice>
         <value>documentation</value>
         <value>code</value>
      </choice>
   </attribute>
   <ref name="common.attributes"/>
   <optional>
      <attribute name="hash">
         <data type="NCName"/>
      </attribute>
   </optional>
   <optional>
      <attribute name="id">
         <data type="integer"/>
      </attribute>
   </optional>
   <optional>
      <attribute name="name"/>
   </optional>
</define>

Common attributes

define : common.attributes
attribute : file
data : NCName
attribute : line
data : integer
<define name="common.attributes">
   <attribute name="file">
      <data type="NCName"/>
   </attribute>
   <attribute name="line">
      <data type="integer"/>
   </attribute>
</define>

Simple documentation text line

This has a single attribute defining the original source line number.

define : text.lines
element : aw:text
attribute : line
data : integer
Any text
<define name="text.lines">
   <element name="aw:text">
      <attribute name="line">
         <data type="integer"/>
      </attribute>
      <text/>
   </element>
</define>

Code line

The hash attribute is a unique number based on the name attribute. The latter is the chunk name in the original NoWeb source (the text between the double angle brackets).

define : code.lines
element : aw:code
attribute : hash
data : NCName
attribute : ref
Any text
oneOrMore
choice
interleave
refcode.token
refcode.include
<define name="code.lines">
   <element name="aw:code">
      <ref name="common.attributes"/>
      <attribute name="hash">
         <data type="NCName"/>
      </attribute>
      <attribute name="ref">
         <text/>
      </attribute>
      <oneOrMore>
         <choice>
            <interleave>
               <ref name="code.token"/>
               <ref name="code.separator"/>
               <ref name="code.variable"/>
               <ref name="code.include"/>
            </interleave>
         </choice>
      </oneOrMore>
   </element>
</define>
define : code.token
element : aw:token
Any text
<define name="code.token">
   <element name="aw:token">
      <text/>
   </element>
</define>
define : code.separator
element : aw:separator
Any text
<define name="code.separator">
   <element name="aw:separator">
      <text/>
   </element>
</define>
define : code.variable
element : aw:variable
Any text
<define name="code.variable">
   <element name="aw:variable">
      <text/>
   </element>
</define>

Code Include

used to include another file (generally used only by tangle).

define : code.include
element : aw:include
attribute : file
data : NCName
attribute : hash
data : NCName
attribute : line
data : integer
attribute : ref
Any text
<define name="code.include">
   <element name="aw:include">
      <attribute name="file">
         <data type="NCName"/>
      </attribute>
      <attribute name="hash">
         <data type="NCName"/>
      </attribute>
      <attribute name="line">
         <data type="integer"/>
      </attribute>
      <attribute name="ref"/>
      <text/>
   </element>
</define>