<?xml version="1.0"?>

<xs:schema 
targetNamespace="http://www.ruleml.org/0.86/xsd"
xmlns="http://www.ruleml.org/0.86/xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
>

	<xs:annotation>
		<xs:documentation xml:lang="en">
			Horn RuleML elements module.
			This is the XML Schema horn module for RuleML.
			File: horn_module.xsd
			Version: 0.86
			Last Modification: 2004-06-24
			
			This module declares the following horn RuleML elements:
			* cterm
			* _opc
			* ctor
			* plex
			
			The approach is modelled after that used in "Modularization of XHTML in XML Schema"
			WD [http://www.w3.org/TR/xhtml-m12n-schema/], which will soon be integrated with
			"Modularization of XHTML" (REC-xhtml-modularization-20010410)
			[http://www.w3.org/TR/xhtml-modularization/].
		</xs:documentation>
	</xs:annotation>

	<!--
		*** cterm ***
		content model:
		(
			( _opc, (_slot)*, (ind | var | cterm | plex)*, (_slot)* ) |
			( (_slot)*, (ind | var | cterm | plex)+, (_slot)*, _opc )
		)

		however, this is non-deterministic, so it is (equivalently) restructured as follows:

                        (
                            ( _opc,
                              (_slot)*, 
                              ( (ind | var | cterm | plex)+, (_slot)*)?
                            ) 
                          |
                            (
                               (
                                  ( (_slot)+, 
                                    ( (ind | var | cterm | plex)+, (_slot)* )?
                                  )
                                |
                                  ((ind | var | cterm | plex)+, (_slot)*)
                               ),
                               _opc
                            )
                         )

		A complex term, i.e. a logical term of the form "f(...)" where f is a constructor.

		Complex, compound, or constructor terms are usable within other cterms, plexs, and atoms.
		The cterm element uses '_opc' ("operator of constructors") role followed by a sequence
		of four kinds of arguments, surrounded by optional metaroles ('_slot'), or vice versa, much
		like atoms.

		Complex terms may have an optional 'type' attribute for term typing.
	-->	
	<xs:attributeGroup name="cterm.attlist">
		<xs:attributeGroup ref="type.attrib"/>
	</xs:attributeGroup>
	<xs:group name="cterm.content">
		<xs:choice>
			<xs:sequence>
				<xs:element ref="_opc"/>
				<xs:element ref="_slot" minOccurs="0" maxOccurs="unbounded"/>
				<xs:sequence minOccurs="0">
					<xs:choice minOccurs="1" maxOccurs="unbounded">
						<xs:element ref="ind"/>
						<xs:element ref="var"/>
						<xs:element ref="cterm"/>
						<xs:element ref="plex"/>
					</xs:choice>
					<xs:element ref="_slot" minOccurs="0" maxOccurs="unbounded"/>
				</xs:sequence>
			</xs:sequence>
			<xs:sequence>
				<xs:choice>
					<xs:sequence>
						<xs:element ref="_slot" minOccurs="1" maxOccurs="unbounded"/>
						<xs:sequence minOccurs="0">
							<xs:choice minOccurs="1" maxOccurs="unbounded">
								<xs:element ref="ind"/>
								<xs:element ref="var"/>
								<xs:element ref="cterm"/>
								<xs:element ref="plex"/>
							</xs:choice>
							<xs:element ref="_slot" minOccurs="0" maxOccurs="unbounded"/>
						</xs:sequence>
					</xs:sequence>
					<xs:sequence>
						<xs:choice minOccurs="1" maxOccurs="unbounded">
							<xs:element ref="ind"/>
							<xs:element ref="var"/>
							<xs:element ref="cterm"/>
							<xs:element ref="plex"/>
						</xs:choice>
						<xs:element ref="_slot" minOccurs="0" maxOccurs="unbounded"/>
					</xs:sequence>
				</xs:choice>
				<xs:element ref="_opc"/>
			</xs:sequence>
		</xs:choice>
	</xs:group>
	<xs:complexType name="cterm.type">
		<xs:group ref="cterm.content"/>
		<xs:attributeGroup ref="cterm.attlist"/>
	</xs:complexType>
	<xs:element name="cterm" type="cterm.type"/>

	<!--
		*** _opc ***
		content model: (ctor)
	
		A constructor operator expression (similar in spirit to _opr).

		'_opc' is usable within complex terms.  It uses a c(onstruc)tor.
	-->
	<xs:attributeGroup name="_opc.attlist"/>
	<xs:group name="_opc.content">
		<xs:sequence>
			<xs:element ref="ctor"/>
		</xs:sequence>
	</xs:group>
	<xs:complexType name="_opc.type">
		<xs:group ref="_opc.content"/>
		<xs:attributeGroup ref="_opc.attlist"/>
	</xs:complexType>
	<xs:element name="_opc" type="_opc.type"/>

	<!--
		*** ctor ***
		content model: (#PCDATA)

		A constructor, i.e. a logical function.
	-->
	<xs:attributeGroup name="ctor.attlist"/>
	<xs:group name="ctor.content">
		<xs:sequence/>
	</xs:group>
	<xs:complexType name="ctor.type" mixed="true">
		<xs:group ref="ctor.content"/>
		<xs:attributeGroup ref="ctor.attlist"/>
	</xs:complexType>
	<xs:element name="ctor" type="ctor.type"/>

	<!--
		*** plex ***
		content model: ( (_slot)*, (ind | var | cterm | plex)*, (_slot)* )

		however, this is non-deterministic, so it is (equivalently) restructured as follows:
		( (_slot)*, ( (ind | var | cterm | plex)+, (_slot)* )? )

		An unordered collection of arguments. 

		(com)plex elements are usable within complex terms, atoms and other 'plex' elements.
		(Previous to version 0.85, these were called tup(le)s - the addition of user-defined
		roles meant the term "tup" was no longer appropriate because it implies order.)

		The 'plex' element uses a sequence of four kinds of arguments surrounded by optional
		metaroles (_slot).
	-->
	<xs:attributeGroup name="plex.attlist"/>
	<xs:group name="plex.content">
		<xs:sequence>
			<xs:element ref="_slot" minOccurs="0" maxOccurs="unbounded"/>
			<xs:sequence minOccurs="0">
				<xs:choice minOccurs="1" maxOccurs="unbounded">
					<xs:element ref="ind"/>
					<xs:element ref="var"/>
					<xs:element ref="cterm"/>
					<xs:element ref="plex"/>
				</xs:choice>
				<xs:element ref="_slot" minOccurs="0" maxOccurs="unbounded"/>
			</xs:sequence>
		</xs:sequence>
	</xs:group>
	<xs:complexType name="plex.type">
		<xs:group ref="plex.content"/>
		<xs:attributeGroup ref="plex.attlist"/>
	</xs:complexType>
	<xs:element name="plex" type="plex.type"/>
	
</xs:schema>
