Here is a syntax description of the Crystal Space world file format.
As you can see from the syntax there are still a few things that
are inconsistent and redundant (some things are exactly the same but
still need a different way of being represented). This will be
fixed in future.

-----------------------------------------------------------------------------

Basic syntax elements:

  <from..to>	is a numeric range. For example, <0..1> is a number
		between 0 and 1.
  <number>	a general number
  <pos-number>	a general positive number
  <name>	a name identifier
  <integer>	a general integer
  <pos-integer>	a positive integer (> 0)

List of numbers:

  <number-list> ::= <number> { ',' <number> }

Boolean values:

  <yes> ::= 'yes' | 'true' | 'on' | '1'
  <no> ::= 'no' | 'false' | 'off' | '0'
  <yes-no> ::= <yes> | <no>

-----------------------------------------------------------------------------
Color description:

  <red> ::= <0..1>
  <green> ::= <0..1>
  <blue> ::= <0..1>
  <color> ::= <red> ',' <green> ',' <blue>

-----------------------------------------------------------------------------
Vectors and coordinates. Note that the z-axis points forward, the y-axis
points upwards and the x-axis points to the right.

  <x> ::= <number>
  <y> ::= <number>
  <z> ::= <number>
  <vector-2d> ::= <x> ',' <z>
  <vector-3d> ::= <x> ',' <y> ',' <z>
  <coordinate> ::= <vector-3d>
  <coordinate-2d> ::= <vector-2d>

-----------------------------------------------------------------------------
Various names of objects:

  <sector-name> ::= <name>
  <thing-name> ::= <name>
  <thingtpl-name> ::= <name>
  <plane-name> ::= <name>
  <col-name> ::= <name>
  <script-name> ::= <name>
  <lightx-name> ::= <name>
  <texture-name> ::= <name>
  <polygon-name> ::= <name>
  <sprite-name> ::= <name>
  <spritetpl-name> ::= <name>

-----------------------------------------------------------------------------
Various attributes and numbers:

  <max-textures-nr> ::= <pos-integer>
  <radius> ::= <pos-number>
  <texture-length> ::= <pos-number>
  <height-nr> ::= <number>
  <alpha-nr> ::= '0' | '25' | '50' | '75'
  <angle> ::= <number>
  <light-index> ::= '0' | <pos-integer>
  <vertex-index> ::= '0' | <pos-integer>

-----------------------------------------------------------------------------
Various basic objects:

  <vertex> ::= 'VERTEX' '(' <coordinate> ')'

  <light> ::= 'LIGHT' '(' <coordinate> ':' <radius> ',' <color> ',' <dynamic-flag> ')'
  <dynamic-flag> ::= '0' | '1'

  <texture> ::= 'TEXTURE' '(' <texture-name> ')'
  <ceil-texture> ::= 'CEIL_TEXTURE' '(' <texture-name> ')'
  <floor-texture> ::= 'FLOOR_TEXTURE' '(' <texture-name> ')'
  <texnr> ::= 'TEXNR' '(' <texture-name> ')'

  <texlen> ::= 'LEN' '(' <texture-length> ')'
  <texture-scale> ::= 'TEXTURE_SCALE' '(' <texture-length> ')'

  <lightx> ::= 'LIGHTX' '(' <lightx-name> ')'

  <activate> ::= 'ACTIVATE' '(' <script-name> ')'
  <trigger> ::= 'TRIGGER' '(' <trigger-type> ',' <script-name> ')'
  <trigger-type> ::= 'activate'

  <bsp> ::= 'BSP' '(' ')'

  <plane> ::= 'PLANE' '(' <plane-name> ')'

  <tex-lighting> ::= 'TEXTURE_LIGHTING' '(' <yes-no> ')'
  <tex-mipmap> ::= 'TEXTURE_MIPMAP' '(' <yes-no> ')'
  <lighting> ::= 'LIGHTING' '(' <yes-no> ')'
  <mipmap> ::= 'MIPMAP' '(' <yes-no> ')'

  <dim> ::= 'DIM' '(' <x> ',' <y> ',' <z> ')'
  <height> ::= 'HEIGHT' '(' <height-nr> ')'
  <floor-height> ::= 'FLOOR_HEIGHT' '(' <height-nr> ')'

  <alpha> ::= 'ALPHA' '(' <alpha-nr> ')'

  <vector> ::= 'V' '(' <vector-3d> ')'

  <identity-matrix> ::= 'IDENTITY'
  <rotation-x-matrix> ::= 'ROT_X' '(' <angle> ')'
  <rotation-y-matrix> ::= 'ROT_Y' '(' <angle> ')'
  <rotation-z-matrix> ::= 'ROT_Z' '(' <angle> ')'
  <rotation-matrix-comp> ::= <rotation-x-matrix> | <rotation-y-matrix> | <rotation-z-matrix>
  <rotation-matrix> ::= 'ROT' '(' { <rotation-matrix-comp> } ')'
  <mult-matrix> ::= <number>
  <normal-matrix> ::= <vector-3d> ',' <vector-3d> ',' <vector-3d>
  <matrix> ::= 'MATRIX '(' <identity-matrix> | <rotation-matrix> | <mult-matrix> | <normal-matrix> ')'

-----------------------------------------------------------------------------
Various components:

  <plane-orig> ::= 'ORIG' '(' <vector-3d> ')'
  <plane-first> ::= 'FIRST' '(' <vector-3d> ')'
  <plane-second> ::= 'SECOND' '(' <vector-3d> ')'
  <plane-first-len> ::= 'FIRST_LEN' '(' <texture-length> ')'
  <plane-second-len> ::= 'SECOND_LEN' '(' <texture-length> ')'

  <polytext-comp> ::= <plane-orig> | <plane-first-len> | <plane-first> | <plane-second-len> |
		    <plane-second> | <matrix> | <vector> | <texlen> | <plane>
  <polygon-texture> ::= 'TEXTURE' '(' { <polytext-comp> } ')'

  <portal> ::= 'PORTAL' '(' <sector-name> ')'

  <warp-comp> ::= <matrix> | <vector>
  <warp> ::= 'WARP' '(' { <warp-comp> } ')'

  <move-comp> ::= <matrix> | <vector>
  <move2> ::= 'MOVE' '(' { <move-comp> } ')'
  <move> ::= 'MOVE' '(' <matrix> <vector> ')'

  <floor> ::= 'FLOOR' '(' '(' <coordinate> ')' '(' <coodinate> ')' '(' <coordinate> ')' '(' <coordinate> ')' ')'
  <ceiling> ::= 'CEILING' '(' '(' <coordinate> ')' '(' <coodinate> ')' '(' <coordinate> ')' '(' <coordinate> ')' ')'
  <floor-ceil> ::= 'FLOOR_CEILING' '(' '(' <coordinate-2d> ')' '(' <coodinate-2d> ')' '(' <coordinate-2d> ')' '(' <coordinate-2d> ')' ')'

-----------------------------------------------------------------------------
A polygon:

The list of vertices is a list of vertex indices. These indices are
relative to the list of vertices of the parent object (a sector,
thing or thing template). The first vertex in the parent object has
index 0. The vertices of a polygon must be defined in clock-wise
ordering as seen from a position from where you want the polygon to
be visible.

  <vertices> ::= 'VERTICES' '(' <vertex-index> { ',' <vertex-index> } ')'

  <polygon-comp> ::= <texnr> | <lighting> | <mipmap> | <portal> | <warp> |
		   <lightx> | <polygon-texture> | <vertices> | <alpha>
  <polygon> ::= 'POLYGON' <polygon-name> '(' { <polygon-comp> } ')'

-----------------------------------------------------------------------------
Polygon templates:

  <polygon-tpl-comp> ::= <texnr> | <lighting> | <mipmap> | <polygon-texture> | <vertices>
  <polygon-template> ::= 'POLYGON' <polygon-name> '(' { <polygon-tpl-comp> } ')'

-----------------------------------------------------------------------------
Uniform dynamic light:

  <lightx-type> ::= <number>
  <lightx-period> ::= <number>
  <lightx-dp> ::= <number>
  <lightx-intensity> ::= <number>
  <lightx-di> ::= <number>

  <lightx-description> ::= <lightx-type> ',' <lightx-period> ',' <lightx-dp> ',' <lightx-intensity> ','
			 <lightx-di>
  <lightx-act> ::= 'ACTIVE' '(' <number> ')'
  <lightx-prim-act> ::= 'PRIMARY_ACTIVE' '(' <lightx-description> ')'
  <lightx-sec-act> ::= 'SECONDARY_ACTIVE' '(' <lightx-description> ')'
  <lightx-bec-act> ::= 'BECOMING_ACTIVE' '(' <lightx-description> ')'
  <lightx-prim-inact> ::= 'PRIMARY_INACTIVE' '(' <lightx-description> ')'
  <lightx-sec-inact> ::= 'SECONDARY_INACTIVE' '(' <lightx-description> ')'
  <lightx-bec-inact> ::= 'BECOMING_INACTIVE' '(' <lightx-description> ')'
  <lightx-stateless> ::= 'STATELESS' '(' <number> ')'

  <lightx-desc-comp> ::= <lightx-act> | <lightx-prim-act> | <lightx-sec-act> | <lighx-bec-act> |
		  <lightx-prim-inact> | <lightx-sec-inact> | <lightx-bec-inact> | <lightx-stateless>
  <lightx-desc> ::= 'LIGHTX' <lightx-name> '(' { <lightx-desc-comp> } ')'

-----------------------------------------------------------------------------
A collection object:

  <col-thing> ::= 'THING' '(' <thing-name> ')'
  <col-collection> ::= 'COLLECTION' '(' <col-name> ')'
  <col-light> ::= 'LIGHT' '(' <sector-name> ',' <light-index> ')'
  <col-sector> ::= 'SECTOR' '(' <sector-name> ')'
  <col-trigger> ::= 'TRIGGER' '(' <obj-name> ',' <trigger-type> '->' <script-name> ')'

  <collection-comp> ::= <col-thing> | <col-collection> | <col-light> | <col-trigger> | <col-sector>
  <collection> ::= 'COLLECTION' <col-name> '(' { <collection-comp> } ')'

-----------------------------------------------------------------------------
A texture description:

  <transparent> ::= 'TRANSPARENT' '(' <color> ')'
  <filter> ::= 'FILTER' '(' ... ')'

  <texture-desc-comp> ::= <transparent> | <filter>
  <texture-desc> ::= 'TEXTURE' '(' { <texture-desc-comp> } ')'

-----------------------------------------------------------------------------
A script:

  <script> ::= 'SCRIPT' <script-name> '(' <script-language> ':' <script-description> ')'

-----------------------------------------------------------------------------
Things and objects:

  <template> ::= 'TEMPLATE' '(' <thingtpl-name> ')'

  <thing-comp> ::= <vertex> | <polygon> | <texnr> | <texlen> | <lightx> |
		  <activate> | <trigger> | <bsp> | <move2> | <template>
  <thing> ::= 'THING' <thing-name> '(' { <thing-comp> } ')'

  <sixface-comp> ::= <move2> | <texture-scale> | <texture> | <ceil-texture> |
		   <dim> | <height> | <floor-height> | <floor-ceil> | <floor-texture> |
		   <floor> | <ceiling> | <trigger> | <activate>
  <sixface> ::= 'SIXFACE' <thing-name> '(' { <sixface-comp> } ')'

-----------------------------------------------------------------------------
Thing and object templates:

  <thing-tpl-comp> ::= <vertex> | <polygon-template> | <texnr> | <texlen> | <move>
  <thing-template> ::= 'THING' <thingtpl-name> '(' { <thing-tpl-comp> } ')'

  <sixface-tpl-comp> ::= <move> | <texture-scale> | <texture> |
		       <ceil-texture> | <dim> | <height> | <floor-height> | <floor-ceil> |
		       <floor-texture> | <floor> | <ceiling>
  <sixface-template> ::= 'SIXFACE' <thingtpl-name> '(' { <sixface-tpl-comp> } ')'

-----------------------------------------------------------------------------
Sprites:

  <u> ::= <number>
  <v> ::= <number>
  <texel> ::= 'TEXEL' '(' <u> ',' <v> ')'
  <v1> ::= <number>
  <v2> ::= <number>
  <v3> ::= <number>
  <sprite-triangle> ::= 'TRIANGLE' '(' <v1> ',' <v2> ',' <v3> ')'
  <sprite-frame> ::= 'FRAME' '(' { <vector> } ')'

  <sprite-tpl-comp> ::= <texnr> | <texel> | <sprite-frame> | <sprite-triangle>
  <sprite-template> ::= 'SPRITE' <spritetpl-name> '(' { <sprite-tpl-comp> } ')'

  <sp-template> ::= 'TEMPLATE' '(' <spritetpl-name> ')'
  <start-frame> ::= 'FRAME' '(' <number> ')'
  <sprite-comp> ::= <move2> | <sp-template> | <start-frame>
  <sprite> ::= 'SPRITE' <sprite-name> '(' { <sprite-comp> } ')'

-----------------------------------------------------------------------------
Sectors and rooms:

  <tex-comp> ::= <texture> | <plane> | <texlen>
  <tex> ::= 'TEX' '(' { <tex-comp> } ')'

  <portal-poly> ::= 'POLYGON' '(' <polygon-name> ')'
  <portal-sector> ::= 'SECTOR' '(' <sector-name> ')'
  <room-portal-comp> ::= <portal-poly> | <portal-sector> | <alpha> | <warp>
  <room-portal> ::= 'PORTAL' '(' { <room-portal-comp> ) ')'

  <split-direction> ::= 'VER' | 'HOR'
  <split-list> ::= <number-list>
  <split> ::= 'SPLIT' '(' <polygon-name> ',' <split-direction> '(' <split-list> ')' ')'

  <sector-comp> ::= <vertex> | <polygon> | <texnr> | <texlen> | <lightx> |
		  <activate> | <trigger> | <bsp> | <thing> | <sixface> | <light> |
		  <sprite>
  <sector> ::= 'SECTOR' <sector-name> '(' { <sector-comp> } ')'

  <room-comp> ::= <tex-lighting> | <tex-mipmap> | <texture-scale> | <texture> |
		<tex> | <ceil-texture> | <floor-texture> | <lightx> | <light> |
		<dim> | <height> | <floor-height> | <floor-ceil> | <floor> | <ceiling> |
		<sixface> | <thing> | <room-portal> | <split> | <trigger> | <activate> |
		<bsp> | <move> | <sprite>
  <room> ::= 'ROOM' <sector-name> '(' { <room-comp> } ')'

-----------------------------------------------------------------------------
Descriptions for all textures:

  <max-textures> ::= 'MAX_TEXTURES' '(' <max-textures-nr> ')'
  <textures-comp> ::= <max-textures> | <texture-desc>
  <textures> ::= 'TEXTURES' '(' { <textures-comp> } ')'

-----------------------------------------------------------------------------
Plane description:

  <plane-desc-comp> ::= <plane-orig> | <plane-first-len> | <plane-first> | <plane-second-len> |
		      <plane-second> | <matrix> | <vector>
  <plane-desc> ::= 'PLANE' <plane-name> '(' { <plane-desc-comp> } ')'

-----------------------------------------------------------------------------
The World:

  <world-comp> ::= <textures> | <sector> | <room> | <thing-template> |
		 <sixface-template> | <sprite-template> | <plane-desc> |
		 <collection> | <script> | <lightx-desc>
  <world> ::= 'WORLD' '(' { <world-comp> } ')'

-----------------------------------------------------------------------------


