wesnoth/data/schema/schema.cfg
Celtic Minstrel 0c42cdc038
Enable translation mark validation by the schema (#5800)
- The t_string type is now a schema built-in type and no longer attempts a regex match.
- You can also specify that non-t_string types may be optionally-translatable; this case supports a regex match on the string (but note that the translation mark is not part of the match).
- Error messages involving keys with very large values ( > 128 characters) will now truncate the value.
- To account for occasional cases where the schema is intentionally violated, the --validate command-line option now automatically defines the SCHEMA_VALIDATION preprocessor define.

A key validates as type t_string if one of the following is true:
- The key is not present
- The key has at least one segment with a translation mark
- The key is blank (an empty string)

Any type other than t_string is not allowed to be translatable by default, unless you specify allow_translatable=yes in the [type] tag.

An optionally-translatable string could also be defined as a union of t_string and some other type.
2021-06-14 23:59:52 -04:00

212 lines
4.0 KiB
INI

{./macros.cfg}
[wml_schema]
[type]
name="regex"
value=".*"
[/type]
[type]
name="glob"
value=".*"
[/type]
[type]
name="string"
value=".*"
[/type]
[type]
name="id"
value="[a-zA-Z0-9_~$]+"
[/type]
[type]
name="path"
[list]
min=1
split="/"
[element]
link="id"
[/element]
[/list]
[/type]
[type]
name="path_list"
[list]
min=1
[element]
link="path"
[/element]
[/list]
[/type]
[type]
name="id_list"
[list]
min=1
[element]
link="id"
[/element]
[/list]
[/type]
[type]
name="int"
value="\d+"
[/type]
[type]
name="inf"
value="infinite"
[/type]
[type]
name="bool"
value="yes|no|true|false"
[/type]
[tag]
name="root"
min=1
[tag]
name="wml_schema"
min=1
[tag]
name="type"
max=infinite
super="wml_schema/type"
{REQUIRED_KEY name id}
{SIMPLE_KEY allow_translatable bool}
[if]
[union]
[/union]
[then]
[tag]
name="union"
min=1
[tag]
name="type"
max=infinite
super="wml_schema/type"
# Override the required name with an optional name
# Technically name is not really allowed here at all,
# but the schema can't override a supertag key with its absence.
{SIMPLE_KEY name string}
[/tag]
[/tag]
[/then]
[elseif]
[intersection]
[/intersection]
[then]
[tag]
name="intersection"
min=1
[tag]
name="type"
max=infinite
super="wml_schema/type"
# Override the required name with an optional name
# Technically name is not really allowed here at all,
# but the schema can't override a supertag key with its absence.
{SIMPLE_KEY name string}
[/tag]
[/tag]
[/then]
[/elseif]
[elseif]
[list]
[/list]
[then]
[tag]
name="list"
min=1
{DEFAULT_KEY min int 0}
{DEFAULT_KEY max int,inf infinite}
{DEFAULT_KEY split regex "\s*,\s*"}
[tag]
name="element"
max=infinite
super="wml_schema/type"
# Override the required name with an optional name
# Technically name is not really allowed here at all,
# but the schema can't override a supertag key with its absence.
{SIMPLE_KEY name string}
[/tag]
[/tag]
[/then]
[/elseif]
[elseif]
glob_on_value=*
[then]
{SIMPLE_KEY value regex}
[/then]
[/elseif]
[else]
{SIMPLE_KEY link id}
[/else]
[/if]
[/tag]
[tag]
name="tag"
min=1
{REQUIRED_KEY name glob}
{DEFAULT_KEY min int 0}
{DEFAULT_KEY max int,inf 1}
{SIMPLE_KEY super path_list}
{DEFAULT_KEY any_tag bool no}
{DEFAULT_KEY deprecated bool no}
{DEFAULT_KEY min_tags int 0}
{DEFAULT_KEY max_tags int,inf infinite}
[tag]
name="key"
max=infinite
{REQUIRED_KEY name glob}
{REQUIRED_KEY type id_list}
{DEFAULT_KEY mandatory bool no}
{SIMPLE_KEY default string}
{DEFAULT_KEY deprecated bool no}
[/tag]
{LINK_TAG "wml_schema/tag"}
[tag]
name="link"
max=infinite
{REQUIRED_KEY name path}
[/tag]
[tag]
name="switch"
max=infinite
{REQUIRED_KEY key id}
[tag]
name="case"
max=infinite
super="wml_schema/tag"
{REQUIRED_KEY value string}
{DEFAULT_KEY trigger_if_missing bool no}
[/tag]
[tag]
name="else"
super="wml_schema/tag"
[/tag]
[/tag]
[tag]
name="if"
max="infinite"
any_tag=yes
{ANY_KEY string}
[tag]
name="then"
super="wml_schema/tag"
[/tag]
[tag]
name="elseif"
max=infinite
super="wml_schema/tag"
any_tag=yes
{ANY_KEY string}
[tag]
name="then"
min=1
super="wml_schema/tag"
[/tag]
[/tag]
[tag]
name="else"
super="wml_schema/tag"
[/tag]
[/tag]
[/tag]
[/tag]
[/tag]
[/wml_schema]