<?xml version="1.0" encoding="utf-8"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes">
    <start>
        <element name="program">
            <zeroOrMore>
                <element name="define">
                    <attribute name="name"><text/></attribute>
                    <attribute name="value"><text/></attribute>
                </element>
            </zeroOrMore>

            <choice>
                <group>
                    <attribute name="type">
                        <value>arb</value>
                    </attribute>

                    <element name="vertex">
                        <attribute name="file"><text/></attribute>
                        <zeroOrMore>
                            <choice>
                                <ref name="uniformContent"/>
                                <element name="attrib">
                                    <ref name="conditional"/>
                                    <attribute name="name"><text/></attribute>
                                    <attribute name="loc"><data type="integer"/></attribute>
                                </element>
                                <ref name="streamContent"/>
                            </choice>
                        </zeroOrMore>
                    </element>

                    <element name="fragment">
                        <attribute name="file"><text/></attribute>
                        <zeroOrMore>
                            <ref name="uniformContent"/>
                        </zeroOrMore>
                    </element>
                </group>

                <group>
                    <attribute name="type">
                        <value>glsl</value>
                    </attribute>

                    <zeroOrMore>
                        <element name="vertex">
                            <attribute name="file"><text/></attribute>
                            <zeroOrMore>
                                <ref name="streamContent"/>
                            </zeroOrMore>
                        </element>
                    </zeroOrMore>

                    <zeroOrMore>
                        <element name="fragment">
                            <attribute name="file"><text/></attribute>
                        </element>
                    </zeroOrMore>

                    <zeroOrMore>
                        <element name="compute">
                            <attribute name="file"><text/></attribute>
                        </element>
                    </zeroOrMore>
                </group>
            </choice>
        </element>

    </start>

    <define name="uniformContent">
        <element name="uniform">
            <ref name="conditional"/>
            <attribute name="name"><text/></attribute>
            <attribute name="loc"><data type="integer"/></attribute>
            <attribute name="type">
                <choice>
                    <value>float</value>
                    <value>vec2</value>
                    <value>vec3</value>
                    <value>vec4</value>
                    <value>mat2</value>
                    <value>mat3</value>
                    <value>mat4</value>
                    <value>sampler2D</value>
                    <value>sampler2DShadow</value>
                    <value>samplerCube</value>
                </choice>
            </attribute>
        </element>
    </define>

    <define name="streamContent">
        <element name="stream">
            <ref name="conditional"/>
            <attribute name="name">
                <choice>
                    <value>pos</value>
                    <value>normal</value>
                    <value>color</value>
                    <value>uv0</value>
                    <value>uv1</value>
                    <value>uv2</value>
                    <value>uv3</value>
                    <value>uv4</value>
                    <value>uv5</value>
                    <value>uv6</value>
                    <value>uv7</value>
                </choice>
            </attribute>
            <optional>
                <attribute name="attribute"><text/></attribute>
            </optional>
        </element>
    </define>

    <define name="conditional">
        <optional>
            <attribute name="if"><text/></attribute>
        </optional>
    </define>

</grammar>
