Skip to content

Commit

Permalink
Created the optional parameter "list"
Browse files Browse the repository at this point in the history
Other minor improvements and updates in wmlvalidator
  • Loading branch information
macabeus authored and Elvish-Hunter committed Mar 22, 2016
1 parent aeb2dc6 commit 2eeac02
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
19 changes: 10 additions & 9 deletions data/schema.cfg
@@ -1,8 +1,7 @@
#textdomain wesnoth
[schema]
identifier="re ^[a-zA-Z0-9_ ]+$"
identifierlist="re ^([a-zA-Z0-9_ ]+,)*[a-zA-Z0-9_ ]+$"
string="re ^[\d\w\s]*$"
string="re ^[ -~]+$"
integer="re ^(\+|-)?[0-9]+$"
float="re ^(\+|-)?[0-9]+(\.[0-9]*)?$"
boolean="enum true,false,yes,no,on,off"
Expand All @@ -16,7 +15,6 @@
# All possible root elements
_about="repeated about"
_advanced_preference="repeated advanced_preference"
_ais="required ais"
_binary_path="repeated binary_path"
_campaign="repeated campaign"
_fonts="optional fonts"
Expand All @@ -29,6 +27,8 @@
_textdomain="repeated textdomain"
_theme="repeated theme"
_units="optional units"
_section="optional section"
_topic="repeated topic" # TODO: De algum jeito, tem que dizer que depende do 'section'
[/root]

[about]
Expand Down Expand Up @@ -87,9 +87,9 @@
abbrev="required identifier translatable"
define="required identifier" #TODO: maybe require it to be uppercase?
description="required string translatable"
difficulties="required string" #TODO: should be a list of identifiers, same maybe as above
difficulties="required string list"
difficulty_descriptions="required string" #TODO: this one's especially complicated
extra_defines="optional string" #TODO: should be a list of identifiers, maybe uppercase?
extra_defines="optional string list"
first_scenario="required identifier"
icon="optional path"
id="required string"
Expand All @@ -111,14 +111,15 @@
id="forbidden identifier"
inherit="optional boolean"
[/female:unit_type]
interval="re ^(\d+|\d+-\d+)$"
[font]
codepoints="required string" #TODO: should be a list of integers
codepoints="required interval list"
name="required path"
[/font]
[fonts]
_font="repeated font"

order="required string" #TODO: should be a list of paths
order="required string list" #TODO: should be a list of paths
[/fonts]
# this is a list of path:integer
flag_image_type="re ^((([a-zA-Z0-9_\-.+]+/)*[a-zA-Z0-9_\-.+]+):[0-9]+,)*(([a-zA-Z0-9_\-.+]+/)*[a-zA-Z0-9_\-.+]+):[0-9]+$"
Expand Down Expand Up @@ -262,7 +263,7 @@
sort_sections="optional boolean"
sort_topics="optional sort_topics_type"
title="required string translatable"
topics="optional string" # TODO: list of identifiers
topics="optional string list"
[/section]
#[terrain_graphics]
# #subtags here
Expand Down Expand Up @@ -321,7 +322,7 @@
_variation="repeated variation"

#TODO: make [base_unit] do its job
advances_to="optional identifierlist" #should be required
advances_to="optional identifier list" #should be required
alignment="optional alignments" # required
cost="optional integer" # required
description="optional string translatable"
Expand Down
12 changes: 10 additions & 2 deletions data/tools/wmlvalidator
Expand Up @@ -59,12 +59,20 @@ class Validator:
elif attribute.freq == wmlgrammar.FORBIDDEN and nummatches > 0:
print "(%s:%d) Attribute '[%s] %s' should not appear. It appears %d times" % (node.file, node.line, verbosename, attribute.name, nummatches)
for match in matches:
if not attribute.validate(match.data):
print "(%s:%d) Attribute '[%s] %s's value should be %s, found: %s" % (node.file, node.line, verbosename, attribute.name, attribute.type, match.data)
if 'translatable' in attribute.optionals and match.is_translatable() == False:
print "(%s:%d) Attribute '[%s] %s's value is translatable, but haven't _ at the beginning" % (node.file, node.line, verbosename, attribute.name)
elif 'translatable' not in attribute.optionals and match.is_translatable() == True:
print "(%s:%d) Attribute '[%s] %s's value isn't translatable, but have a _ at the beginning" % (node.file, node.line, verbosename, attribute.name)
if 'list' in attribute.optionals:
pos = 1
for i in match.data.split(","):
if i[0] == ' ': i = i[1:]
if not attribute.validate(i):
print "(%s:%d) Attribute '[%s] %s's value in list should be %s, found at position %d: %s" % (node.file, node.line, verbosename, attribute.name, attribute.type, pos, i)
pos += 1
else:
if not attribute.validate(match.data):
print "(%s:%d) Attribute '[%s] %s's value should be %s, found: %s" % (node.file, node.line, verbosename, attribute.name, attribute.type, match.data)
node.remove(match) # Get rid of these so we can see what's left
for attribute in node.get_all_text():
print "(%s:%d) Attribute '[%s] %s' found, which has no meaning there" % (node.file, node.line, verbosename, attribute.name)
Expand Down

0 comments on commit 2eeac02

Please sign in to comment.