<?xml version="1.0" encoding="utf-8"?>
<!-- <?xml-stylesheet type="text/xsl" href="" ?> -->
<grammar xmlns="http://relaxng.org/ns/structure/1.0"
         xmlns:a="http://relaxng.org/ns/compatibility/annotations/1.0"
         xmlns:xhtml="http://www.w3.org/1999/xhtml"
         xmlns:rng="http://relaxng.org/ns/structure/1.0"
         datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">

	<!-- ns="http://bluefish.openoffice.nl/ns/bflang/2.0" -->
	<a:documentation>RELAX NG flat schema for Bluefish Language Files (bflang) containing syntax highlighting and autocompletion information for the bluefish <xhtml:a href="http://bluefish.openoffice.nl">Bluefish</xhtml:a> editor.</a:documentation>

	<start>
		<element name="bflang">
			<a:documentation>The root tag of a Bluefish language file (bflang2) file. It defines the human readable name, the bflang format version and some values for the compiler, indicating how much memory should be allocated.</a:documentation>
			<attribute name="name">
				<a:documentation>Human readable name of the language defined; must be unique regarding other language files</a:documentation>
				<data type="normalizedString"/>
			</attribute>
			<attribute name="version">
				<a:documentation>Version of the bflang2 format the file complies to</a:documentation>
				<data type="decimal"/>
			</attribute>
			<optional>
				<group>
					<attribute name="contexts">
						<a:documentation>Size of the context table. This value is an indication for the compiler how much memory should be allocated. It optimises the loading speed. As illustration: contexts="100" (4.69 Kbytes)</a:documentation>
						<data type="positiveInteger"/>
					</attribute>
					<attribute name="matches">
						<a:documentation>Size of the matches table. This value is an indication for the compiler how much memory should be allocated. It optimises the loading speed. As illustration: matches="1752" (123.19 Kbytes)</a:documentation>
						<data type="positiveInteger"/>
					</attribute>
					<attribute name="table">
						<a:documentation>Size of the DFA table, compiled patterns for each contex. This value is an indication for the compiler how much memory should be allocated. It optimises the loading speed. As illustration: table="7906" (1976.50 Kbytes)</a:documentation>
						<data type="positiveInteger"/>
					</attribute>
				</group>
			</optional>
			<element name="header">
				<a:documentation>Region of the language file that is always loaded, regardless if the language is used or not.</a:documentation>
				<oneOrMore>
					<element name="mime">
					<a:documentation>Every language file should have at least one unique mime type (compared to the other language files) in order to be available to the user. There can be multiple mime tags.</a:documentation>
						<attribute name="type">
							<a:documentation>"Content Type" or "Internet Media Type" (refer to RFC 2045-2049 and the IANA)</a:documentation>
							<data type="token"/>
						</attribute>
						<empty/>
					</element><!-- mime -->
				</oneOrMore>
				<zeroOrMore>
					<choice>
						<element name="option">
							<a:documentation>Options are links to the class/notclass attribute of &lt;group&gt; elements. Enabling/disabling an option turns on/off (complete) groups.</a:documentation>
							<attribute name="name">
								<a:documentation>Option name (ID)</a:documentation>
								<data type="ID"/>
							</attribute>
							<attribute name="default">
								<a:documentation>Enable (1) or disable (0) the feature/group</a:documentation>
								<data type="boolean"/>
							</attribute>
							<optional>
								<attribute name="description">
									<a:documentation>Optional human readable description of the option (not yet used)</a:documentation>
									<data type="string"/>
								</attribute>
							</optional>
							<empty/>
						</element><!-- option -->
						<element name="highlight">
							<a:documentation>Links contexts, elements, groups and tags, that can be highlighted and that are used by multiple languages, with styles. Default styles are hardcoded.</a:documentation>
							<attribute name="name">
								<a:documentation>Highlight name (ID)</a:documentation>
								<data type="ID"/>
							</attribute>
							<attribute name="style">
								<a:documentation>Highlight style (pre-defined)</a:documentation>
								<choice>
									<value type="token">attribute</value>
									<a:documentation>(usually) SGML/XML tag attributes</a:documentation>
									<value type="token">brackets</value>
									<a:documentation>Braces, brackets and parenthesis</a:documentation>
									<value type="token">comment</value>
									<a:documentation>Comments of all styles (C-style, Shell, XML, ...)</a:documentation>
									<value type="token">function</value>
									<a:documentation>Functions in a programming language</a:documentation>
									<value type="token">keyword</value>
									<a:documentation>Programming languages keywords</a:documentation>
									<value type="token">operator</value>
									<a:documentation></a:documentation>
									<value type="token">preprocessor</value>
									<a:documentation>Programmming languages </a:documentation>
									<value type="token">special-attribute</value>
									<a:documentation></a:documentation>
									<value type="token">special-function</value>
									<a:documentation></a:documentation>
									<value type="token">special-keyword</value>
									<a:documentation></a:documentation>
									<value type="token">special-tag</value>
									<a:documentation></a:documentation>
									<value type="token">special-tag2</value>
									<a:documentation></a:documentation>
									<value type="token">special-tag3</value>
									<a:documentation></a:documentation>
									<value type="token">special-type</value>
									<a:documentation></a:documentation>
									<value type="token">special-value</value>
									<a:documentation></a:documentation>
									<value type="token">string</value>
									<a:documentation>Strings, usually inside quotation marks</a:documentation>
									<value type="token">tag</value>
									<a:documentation>(usually) SGML/XML tags</a:documentation>
									<value type="token">type</value>
									<a:documentation></a:documentation>
									<value type="token">value</value>
									<a:documentation>Value of a tag</a:documentation>
									<value type="token">variable</value>
									<a:documentation></a:documentation>
									<value type="token">warning</value>
									<a:documentation></a:documentation>
									<value type="token">special-warning</value>
									<a:documentation>used to highlight spaces</a:documentation>
								</choice>
							</attribute>
							<empty/>
						</element><!-- highlight -->
					</choice>
				</zeroOrMore>
				<empty/>
			</element><!-- header -->
			<optional>
				<element name="properties">
					<a:documentation>Language file properties.</a:documentation>
					<oneOrMore>
						<choice>
							<element name="comment">
								<a:documentation>Specify which line and block comments are possible for the smart comment function.</a:documentation>
								<attribute name="type">
									<a:documentation>Type of comment</a:documentation>
									<choice>
										<value type="token">block</value>
										<a:documentation>Block comment</a:documentation>
										<value type="token">line</value>
										<a:documentation>Line comment</a:documentation>
									</choice>
								</attribute>
								<attribute name="start">
									<a:documentation>Start-pattern of a comment</a:documentation>
									<data type="string"/>
								</attribute>
								<optional>
									<attribute name="end">
										<a:documentation>End-pattern of a block comment</a:documentation>
										<data type="string"/>
									</attribute>
								</optional>
								<optional>
									<attribute name="id">
										<a:documentation>used to set a certain comment type for a certain context.</a:documentation>
										<data type="ID">
											<param name="pattern">cm\.[a-zA-Z0-9_.]+</param>
										</data>
									</attribute>
								</optional>
								<empty/>
							</element><!-- comment -->
							<element name="smartindent">
								<a:documentation>Specify which characters (followed by a return) should increase the indenting.</a:documentation>
								<attribute name="characters">
									<a:documentation>List of characters</a:documentation>
									<data type="string"/>
								</attribute>
								<empty/>
							</element><!-- smartindent -->
							<element name="smartoutdent">
								<a:documentation>Specify which characters (followed by a return) should decrease the indenting.</a:documentation>
								<attribute name="characters">
									<a:documentation>List of characters</a:documentation>
									<data type="string"/>
								</attribute>
								<empty/>
							</element><!-- smartoutdent -->
							<element name="default_spellcheck">
								<a:documentation>Define if regions that are not highlighted will be checked by the spell checker. This is typically enabled for HTML/XML like languages, and disabled (or ignored) for all programming languages.</a:documentation>
								<oneOrMore>
									<choice>
										<attribute name="enabled" a:defaultValue="1">
											<a:documentation>Enable (1) or disable (0) the feature</a:documentation>
											<data type="boolean"/>
										</attribute>
										<attribute name="spell_decode_entities">
											<a:documentation>Enable (1) or disable (0) the feature, if the spell checker sees a word like m&amp;eacute;l it will decode the entity and try again if it is spelled correctly.</a:documentation>
											<data type="boolean" a:defaultValue="0"/>
										</attribute>
									</choice>
								</oneOrMore>
								<empty/>
							</element><!-- default_spellcheck -->
						</choice>
					</oneOrMore>
					<empty/>
				</element><!-- properties -->
			</optional>
			<element name="definition">
				<a:documentation>The region of the language file that actually defines the language. This region is only loaded when a file of this type is opened in the editor. A language definition always starts with a &lt;context&gt; tag.</a:documentation>
				<zeroOrMore>
					<ref name="bf.element.context"/>
				</zeroOrMore>
			</element><!-- definition -->
			<empty/>
		</element><!-- bflang -->
	</start>

	<define name="bf.element.context">
		<element name="context">
			<a:documentation>The most important attribute of a context are the symbols, a string of characters that are all 'symbol' characters for this context. A 'symbol' character is a character that may start or end the next match. Usually all spacing is a symbol, and in programming languages all operators are symbols. Contexts can be reused later by using an ID during definition and referencing this ID later.</a:documentation>
			<choice>
				<group>
					<attribute name="symbols">
						<a:documentation>List of characters</a:documentation>
						<data type="string"/>
					</attribute>
					<ref name="bf.attribute.highlight"/>
					<optional>
						<attribute name="id">
							<a:documentation>Context ID to reuse it later</a:documentation>
							<data type="ID">
								<param name="pattern">c\.[a-zA-Z0-9_.]+</param>
							</data>
						</attribute>
					</optional>
					<oneOrMore>
						<choice>
							<ref name="bf.element.element"/>
							<ref name="bf.element.group"/>
							<ref name="bf.element.tag"/>
						</choice>
					</oneOrMore>
				</group>
				<attribute name="idref">
					<a:documentation>ID of context to reuse (no other attributes or elements are allowed)</a:documentation>
					<data type="IDREF">
						<param name="pattern">c\.[a-zA-Z0-9_.]+</param>
					</data>
				</attribute>
			</choice>
			<optional>
				<attribute name="commentid_block">
					<a:documentation>ID of comment block to reuse, or `none`, default: inherited.</a:documentation>
					<data type="string">
						<param name="pattern">(cm\.[a-zA-Z0-9_.]+)|none</param>
					</data>
				</attribute>
			</optional>
			<optional>
				<attribute name="commentid_line">
					<a:documentation>ID of comment line to reuse, or `none`, default: inherited.</a:documentation>
					<data type="string">
						<param name="pattern">(cm\.[a-zA-Z0-9_.]+)|none</param>
					</data>
				</attribute>
			</optional>
			<empty/>
		</element><!-- context -->
	</define>

	<define name="bf.element.element">
		<element name="element">
		<a:documentation>Language element that is syntax highlighted, autocompleted or has reference information. The most important attribute is 'pattern': a keyword (e.g. a function name) or a regular expression (if attribute 'is_regex' is set to '1'). It might contain other elements, contexts, groups and references. To reuse an element it must have only the 'idref' attribute.</a:documentation>
			<choice>
				<group>
					<attribute name="pattern">
						<a:documentation>Pattern: keyword, function, string, regular expression (limited)</a:documentation>
						<data type="string"/>
					</attribute>
					<ref name="bf.attribute.autocomplete.element"/>
					<ref name="bf.attribute.autocomplete.extended"/>
					<ref name="bf.attribute.class.notclass"/>
					<ref name="bf.attribute.case_insens"/>
					<ref name="bf.attribute.highlight"/>
					<ref name="bf.attribute.is_regex"/>
					<optional>
						<choice>
							<attribute name="starts_block">
								<a:documentation>Element pattern starts a block ('1')</a:documentation>
								<data type="boolean"/>
							</attribute>
							<group>
								<attribute name="ends_block" a:defaultValue="0">
									<a:documentation>Element pattern ends a block ('1')</a:documentation>
									<data type="boolean"/>
								</attribute>
								<attribute name="blockstartelement">
									<a:documentation>ID of element containing start-pattern of block to end</a:documentation>
									<data type="IDREF">
										<param name="pattern">[et]\.[a-zA-Z0-9_.]+</param>
									</data>
								</attribute>
							</group>
						</choice>
					</optional>
					<optional>
						<attribute name="blockhighlight">
							<a:documentation>UNKNOWN / TODO</a:documentation><!-- only available with starts_block? -->
							<data type="string"/>
						</attribute>
					</optional>
					<optional>
						<attribute name="ends_context">
							<a:documentation>Number of contexts to be ended</a:documentation>
							<data type="positiveInteger"/>
						</attribute>
					</optional>
					<optional>
						<attribute name="id">
							<data type="ID">
								<a:documentation>ID to reuse element</a:documentation>
								<param name="pattern">e\.[a-zA-Z0-9_.]+</param>
							</data>
						</attribute>
					</optional>
					<optional>
						<attribute name="mayfold">
							<a:documentation>UNKNOWN / TODO</a:documentation>
							<data type="boolean" a:defaultValue="0"/>
						</attribute>
					</optional>
					<optional>
						<attribute name="tagclose_from_blockstack">
							<a:documentation>Special attribute to enable automatic closure of the generic tags only used for generic XML highlighting, and only for the element that starts the generic xml tag pattern</a:documentation>
							<data type="boolean" a:defaultValue="0"/>
						</attribute>
					</optional>
					<optional>
						<attribute name="identifier_mode">
							<a:documentation>right now there is only 1 valid mode, used for php and python functions. If you define a function in a file, that function name will autocomplete, and you can use the 'jump' function in bluefish to jump to the declaration of that function.</a:documentation>
							<data type="boolean" a:defaultValue="0"/>
						</attribute>
					</optional>		
					<zeroOrMore>
						<choice>
							<ref name="bf.element.context"/>
							<ref name="bf.element.reference"/>
						</choice>
					</zeroOrMore>
				</group>
				<attribute name="idref">
					<a:documentation>ID of element to reuse (no other attributes or elements are allowed)</a:documentation>
					<data type="IDREF">
						<param name="pattern">e\.[a-zA-Z0-9_.]+</param>
					</data>
				</attribute>
			</choice>
			<empty/>
		</element><!-- element -->
	</define>

	<define name="bf.element.group">
		<element name="group">
			<a:documentation>Group multiple tags or elements that share the same attribute values for a subset of attributes: 'attrib_autocomplete_append', 'attribhighlight', 'autocomplete', 'autocomplete_append', 'case_insens', 'class', 'highlight', 'is_regex' and/or 'notclass'. These attributes are then only set for the group tag, and not for the elements or tags immediately within this group tag.</a:documentation>
			<ref name="bf.attribute.autocomplete.attribute"/>
			<ref name="bf.attribute.autocomplete.element"/>
			<ref name="bf.attribute.autocomplete.extended"/>
			<ref name="bf.attribute.attribhighlight"/>
			<ref name="bf.attribute.case_insens"/>
			<ref name="bf.attribute.class.notclass"/>
			<ref name="bf.attribute.highlight"/>
			<ref name="bf.attribute.is_regex"/>
			<oneOrMore>
				<choice>
					<ref name="bf.element.element"/>
					<ref name="bf.element.group"/>
					<ref name="bf.element.tag"/>
				</choice>
			</oneOrMore>
			<empty/>
		</element><!-- group -->
	</define>

	<define name="bf.element.tag">
		<element name="tag">
			<a:documentation>Convenience element for SGML/XML based languages. Everything within tag is possible with a combination of multiple element and context tags.</a:documentation>
			<choice>
				<group>
					<attribute name="name">
						<a:documentation>ID of element to reuse (no other attributes or elements are allowed)</a:documentation>
						<data type="token"/>
					</attribute>
					<ref name="bf.attribute.autocomplete.attribute"/>
					<ref name="bf.attribute.autocomplete.element"/>
					<ref name="bf.attribute.autocomplete.extended"/>
					<ref name="bf.attribute.case_insens"/>
					<ref name="bf.attribute.highlight"/>
					<ref name="bf.attribute.is_regex"/>
					<optional>
						<group>
							<attribute name="attributes">
								<a:documentation>List of comma-separated attributes</a:documentation>
								<data type="string">
									<param name="pattern">[a-zA-Z0-9][a-zA-Z0-9:,-_]+</param>
								</data><!-- TODO: more like a list with commata? -->
							</attribute>
							<ref name="bf.attribute.attribhighlight"/>
						</group>
					</optional>
					<optional>
						<attribute name="id">
							<a:documentation>ID to reuse tag</a:documentation>
							<data type="ID">
								<param name="pattern">t\.[a-zA-Z0-9_.]+</param>
							</data>
						</attribute>
					</optional>
					<optional>
						<attribute name="no_close" a:defaultValue="0">
							<a:documentation>Do not automatically close the tag ('1')</a:documentation>
							<data type="boolean"/>
						</attribute>
					</optional>
					<optional>
						<attribute name="sgml_shorttag" a:defaultValue="0">
							<a:documentation>The tag does not need to be closed, like SGML Shorttags ('1'). This is currently only used in HTML for tags like &lt;br&gt;.</a:documentation>
							<data type="boolean"/>
						</attribute>
					</optional>
					<zeroOrMore>
						<choice>
							<ref name="bf.element.context"/>
							<ref name="bf.element.reference"/>
						</choice>
					</zeroOrMore>
				</group>
				<attribute name="idref">
					<data type="IDREF">
						<a:documentation>ID of tag to reuse (no other attributes or elements are allowed)</a:documentation>
						<param name="pattern">t\.[a-zA-Z0-9_.]+</param>
					</data>
				</attribute>
			</choice>
			<empty/>
		</element><!-- tag -->
	</define>

	<define name="bf.element.reference">
		<element name="reference">
		<a:documentation>The reference contains a description of elements or tags and must only contain valid PANGO markup and text according to <xhtml:a href="http://library.gnome.org/devel/pango/stable/PangoMarkupFormat.html">http://library.gnome.org/devel/pango/stable/PangoMarkupFormat.html</xhtml:a>. For the moment PANGO markup is not checked for validity!</a:documentation>
			<zeroOrMore>
				<choice>
					<text/>
					<element>
						<anyName>
							<!--<except>
								<nsName ns="http://bluefish.openoffice.nl/ns/bflang/2.0"/>
								<nsName ns="http://www.pango.org/xml/pango-markup"/>
							</except>-->
						</anyName>
						<text/>
					</element>
				</choice>
			</zeroOrMore>
			<empty/>
		</element><!-- reference -->
	</define>

	<define name="bf.attribute.autocomplete.element">
		<optional>
			<attribute name="autocomplete" a:defaultValue="0">
				<a:documentation>Enable ('1') or disable ('0') autocompletion feature for item</a:documentation>
				<data type="boolean"/>
			</attribute>
		</optional>
		<optional>
			<attribute name="autocomplete_append">
				<a:documentation>Automatically appended string to item</a:documentation>
				<data type="string"/>
			</attribute>
		</optional>
	</define>

	<define name="bf.attribute.autocomplete.attribute">
		<optional>
			<attribute name="attrib_autocomplete_append">
				<a:documentation>Automatically appended string to attribute</a:documentation>
				<data type="string"/>
			</attribute>
		</optional>
		<optional>
			<attribute name="attrib_autocomplete_backup_cursor">
				<a:documentation>Set cursor position after auto-completion of attribute back by X characters</a:documentation>
				<data type="positiveInteger"/>
			</attribute>
		</optional>
	</define>

	<define name="bf.attribute.autocomplete.extended">
		<optional>
			<attribute name="autocomplete_string">
				<a:documentation>Auto-complete regular expression with this string</a:documentation>
				<data type="string"/>
			</attribute>
		</optional>
		<optional>
			<attribute name="autocomplete_backup_cursor">
				<a:documentation>Set cursor position after auto-completion back by X characters</a:documentation>
				<data type="positiveInteger"/>
			</attribute>
		</optional>
	</define>

	<define name="bf.attribute.class.notclass">
		<optional>
			<choice>
				<attribute name="class">
					<a:documentation>Enable item if option with ID is set/enabled</a:documentation>
					<data type="IDREF"/>
				</attribute>
				<attribute name="notclass">
					<a:documentation>Disable item if option with ID is set/enabled</a:documentation>
					<data type="IDREF"/>
				</attribute>
			</choice>
		</optional>
	</define>

	<define name="bf.attribute.attribhighlight">
		<optional>
			<attribute name="attribhighlight">
				<a:documentation>Link attribute style to highlight name/ID</a:documentation>
				<data type="IDREF"/>
			</attribute>
		</optional>
	</define>

	<define name="bf.attribute.case_insens">
		<optional>
			<attribute name="case_insens" a:defaultValue="0">
				<a:documentation>Pattern is case insensitive ('1')</a:documentation>
				<data type="boolean"/>
			</attribute>
		</optional>
	</define>

	<define name="bf.attribute.highlight">
		<optional>
			<attribute name="highlight">
				<a:documentation>Link item style to highlight name/ID</a:documentation>
				<data type="IDREF"/>
			</attribute>
		</optional>
	</define>

	<define name="bf.attribute.is_regex">
		<optional>
			<attribute name="is_regex" a:defaultValue="0">
				<a:documentation>Pattern is a regular expression ('1')</a:documentation>
				<data type="boolean"/>
			</attribute>
		</optional>
	</define>

</grammar>
