User:Bayo/script
From UFO:AI
UFO:AI scripts, inside .ufo
files, are used to define most of the content of the game.
Yet, there is no global parser for this kind of files. Each node type use is own code to read one by one token and use them like it want. Then here some construction rules, scripts should respect to unify our scripts. It was not created from scratch, but from script legacy, with patch here and there to avoid most of ambiguous construction.
This grammar is already used by our Eclipse plugin, to parse and validate scripts.
Contents
Grammar
UFOSCRIPT := NODE* NODE := TYPE IDENTIFIER? BLOCK | TYPE IDENTIFIER? LIST | TYPE VALUE BLOCK := '{' NODE* '}' LIST := '(' VALUE* ')' VALUE := NUMBER | QUOTED_STRING | NAMED_CONST | IDENTIFIER ---- TYPE := [a-z]+ IDENTIFIER := [a-z][a-zA-Z0-9/\-_\.]+ NUMBER := [0-9.]+ QUOTED_STRING := '"' -> '"' NAMED_CONST := [A-Z][A-Z_]*
This grammar is simplified to stay readable. But some construction are not allowed, like identified node with an identifier as value.
Values
NUMBER | A number, like 6 , or 56.2
|
---|---|
QUOTED_STRING | Any kind of content between to double quotes. It support common C escaping, like \n , \" . Many composite types are also quoted, for example "2.5 4.0 2.5" which is a 3D vector; or "1 0 0 0.5" which can be a red color with some transparency.
|
NAMED_CONST | A named constant provided by the game. It must be in full upper case, for example EMPL_PILOT , and usualy there is only a set of available values. It should be always used when a value is hardcoded into the game (instead of a quoted string).
|
IDENTIFIER | As value, a reference to an identifier node somewhere from the script. It support |
Structure
Block
A block contains sub nodes.
List
A list contains a list of values.
It can't contains a block or a list.