<?xml version="1.0" encoding="utf-8"?>

<!--
	description: "Eiffel Xace RelaxNG specification"
	system: "Gobo Eiffel Xace"
	copyright: "Copyright (c) 2003-2017, Berend de Boer and others"
	license: "MIT License"
	date: "$Date$"
	revision: "$Revision$"
-->

<grammar
	xmlns="http://relaxng.org/ns/structure/1.0"
	xmlns:xsd="http://www.w3.org/2001/XMLSchema"
	datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

	<!-- An Xace file defines either a library or a system -->
	<start>

		<choice>
			<ref name="library"/>
			<ref name="system"/>
		</choice>

	</start>


	<!-- Definition for <library/> follows -->
	<define name="library">
		<element name="library">
			<attribute name="name"/>
			<optional>
				<attribute name="prefix"/>
			</optional>
			<optional>
				<ref name="description"/>
			</optional>
			<ZeroOrMore>
				<choice>
					<ref name="option"/>
					<ref name="cluster"/>
					<ref name="mount"/>
				</choice>
			</ZeroOrMore>
		</element>
	</define>


	<!-- Definition for <system/> follows -->
	<define name="system">
		<element name="system">
			<attribute name="name"/>
			<optional>
				<ref name="description"/>
			</optional>
			<ZeroOrMore> <!-- use if/unless flags to enable/disable just one -->
				<element name="root">
					<optional>
						attribute name="class"/>
					</optional>
					<optional>
						<attribute name="creation"/>
					</optional>
				</element>
			</ZeroOrMore>
			<ZeroOrMore>
				<choice>
					<ref name="option"/>
					<ref name="cluster"/>
					<ref name="mount"/>
				</choice>
			</ZeroOrMore>
		</element>
	</define>


	<!-- Elements used in both libraries and systems -->
	<define name="description">
		<element name="description">
			<text/>
		</element>
	</define>

	<define name="cluster">
		<element name="cluster">
			<attribute name="name"/>
			<optional>
				<attribute name="prefix"/>
			</optional>
			<optional>
				<attribute name="relative"><data type="boolean"/></attribute>
			</optional>
			<optional>
				<attribute name="location"/>
			</optional>
			<ref name="ifUnless"/>
			<zeroOrMore>
				<choice>
					<ref name="option"/>
					<ref name="cluster"/>
					<ref name="class"/>
					<ref name="mount"/>
				</choice>
			</zeroOrMore>
		</element>
	</define>

	<define name="class">
		<element name="class">
			<attribute name="name"/>
			<ref name="ifUnless"/>
			<zeroOrMore>
				<choice>
					<ref name="option"/>
					<ref name="feature"/>
				</choice>
			</zeroOrMore>
		</element>
	</define>

	<define name="feature">
		<element name="feature">
			<attribute name="name"/>
			<ref name="ifUnless"/>
			<zeroOrMore>
				<ref name="option"/>
			</zeroOrMore>
		</element>
	</define>

	<define name="mount">
		<element name="mount">
			<attribute name="location"/>
			<optional>
				<attribute name="prefix"/>
			</optional>
			<ref name="ifUnless"/>
		</element>
	</define>

	<define name="option">
		<element name="option">
			<optional>
				<attribute name="name"/>
				<attribute name="value"/>
			</optional>
			<ref name="ifUnless"/>
			<zeroOrMore>
				<ref name="option"/>
			</zeroOrMore>
		</element>
	</define>

	<!-- if and unless attributes can be used on most elements -->
	<define name="ifUnless">
		<optional>
			<choice>
				<attribute name="if"/>
				<attribute name="unless"/>
			</choice>
		</optional>
	</define>

</grammar>
