Expanded the gui schema a bit

This commit is contained in:
Alexander van Gessel 2010-02-21 05:40:21 +01:00
parent f254942d7c
commit 8c627a2b15
2 changed files with 120 additions and 14 deletions

View file

@ -1,12 +1,53 @@
[schema]
identifier="re ^[a-z_]+$"
identifier="re ^[a-zA-Z_]+$"
# slash-separated filenames
path="re ^([a-z0-9\-.+]+/)*[a-z0-9\-.+]+$"
# for non-negative geometry
unsigned="re ^[0-9]+$"
halign="enum left,right,center"
valign="enum top,bottom,center"
[root]
_gui="required gui" # or repeated? maybe we need a new 'at least one' type
[/root]
# This is possibly specific to [window] [resolution] [grid] [row] [column]
[column]
border_size="optional unsigned"
grow_factor="optional unsigned"
#TODO: possible other stuff
# A column should contain exactly one widget
# How are we going to define that, if at all?
_button="optional button"
_horizontal_listbox="optional horizontal_listbox"
_horizontal_scrollbar="optional horizontal_scrollbar"
_image="optional image"
_label="optional label"
_listbox="optional listbox"
_menubar="optional menubar"
_minimap="optional minimap"
_multi_page="optional multi_page"
_panel="optional panel"
_repeating_button="optional repeating_button"
_scroll_label="optional scroll_label"
_scrollbar_panel="optional scrollbar_panel"
_slider="optional slider"
_spacer="optional spacer"
_stacked_widget="optional stacked_widget"
_text_box="optional text_box"
_password_box="optional password_box"
_toggle_button="optional toggle_button"
_toggle_panel="optional toggle_panel"
_tree_view="optional tree_view"
_vertical_scrollbar="optional vertical_scrollbar"
_grid="optional grid"
[/column]
# This is possibly specific to [window] [resolution] [grid]
[grid]
_row="repeated row"
[/grid]
[gui]
_settings="required settings"
@ -39,16 +80,81 @@
id="required identifier"
description="required string"
[/gui]
[label:widget]
wrap="optional boolean"
[/label:widget]
[panel:widget]
_resolution="repeated panel-resolution"
[/panel:widget]
[panel-resolution:resolution]
bottom_border="optional unsigned"
left_border="optional unsigned"
right_border="optional unsigned"
top_border="optional unsigned"
_background="optional state_definition"
_foreground="optional state_definition"
[/panel-resolution:resolution]
# This is possibly specific to [window] [resolution] [grid] [row]
[row]
grow_factor="optional unsigned"
_column="repeated column"
[/row]
[settings]
double_click_time="required integer"
help_show_time="optional integer"
popup_show_delay="optional integer"
popup_show_time="optional integer"
repeat_button_repeat_time="optional integer"
double_click_time="required unsigned"
help_show_time="optional unsigned"
popup_show_delay="optional unsigned"
popup_show_time="optional unsigned"
repeat_button_repeat_time="optional unsigned"
sound_button_click="optional path"
sound_toggle_button_click="optional path"
sound_toggle_panel_click="optional path"
sound_slider_adjust="optional path"
[/settings]
[state_definition]
_draw="required draw"
[/state_definition]
[window:widget]
_resolution="repeated window-resolution"
[/window:widget]
[window-resolution:panel-resolution]
_grid="optional grid" #TODO: check if it's actually required
_linked_group="repeated linked_group"
automatic_placement="optional boolean"
click_dismiss="optional boolean"
definition="optional identifier"
height="optional string" # A formula that returns unsigned
horizontal_placement="optional halign"
maximum_height="optional unsigned"
maximum_width="optional unsigned"
vertical_placement="optional valign"
width="optional string" # A formula that returns unsigned
window_height="optional unsigned"
window_width="optional unsigned"
x="optional string" # A formula that returns unsigned
y="optional string" # A formula that returns unsigned
[/window-resolution:panel-resolution]
# Base things that are only derived from
[resolution]
default_height="optional unsigned"
default_width="optional unsigned"
max_height="optional unsigned"
max_width="optional unsigned"
min_height="optional unsigned"
min_width="optional unsigned"
text_extra_height="optional unsigned"
text_extra_width="optional unsigned"
text_font_size="optional unsigned"
window_height="optional unsigned"
window_width="optional unsigned"
text_font_style="optional string" #TODO: this is an enum
[/resolution]
[widget]
id="required identifier"
description="required string"
[/widget]
[/schema]

View file

@ -52,32 +52,32 @@ class Validator:
matches = node.get_texts(attribute.name)
nummatches = len(matches)
if attribute.freq == wmlgrammar.REQUIRED and nummatches != 1:
print "Attribute '[%s] %s' should appear exactly once, not %d times" % (verbosename, attribute.name, nummatches)
print "(%s:%d) Attribute '[%s] %s' should appear exactly once, not %d times" % (node.file, node.line, verbosename, attribute.name, nummatches)
elif attribute.freq == wmlgrammar.OPTIONAL and nummatches > 1:
print "Attribute '[%s] %s' should appear at most once, not %d times" % (verbosename, attribute.name, nummatches)
print "(%s:%d) Attribute '[%s] %s' should appear at most once, not %d times" % (node.file, node.line, verbosename, attribute.name, nummatches)
elif attribute.freq == wmlgrammar.FORBIDDEN and nummatches > 0:
print "Attribute '[%s] %s' should not appear. It appears %d times" % (verbosename, attribute.name, nummatches)
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 "Attribute '[%s] %s's value should be %s, found: %s" % (verbosename, attribute.name, attribute.type, 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 "Attribute '[%s] %s' found, which has no meaning there" % (verbosename, attribute.name)
print "(%s:%d) Attribute '[%s] %s' found, which has no meaning there" % (node.file, node.line, verbosename, attribute.name)
# Validate the elements
for element in schema.get_elements():
matches = node.get_subs(element.name)
nummatches = len(matches)
if element.freq == wmlgrammar.REQUIRED and nummatches != 1:
print "Element '[%s] [%s]' should appear exactly once, not %d times" % (verbosename, element.name, nummatches)
print "(%s:%d) Element '[%s] [%s]' should appear exactly once, not %d times" % (node.file, node.line, verbosename, element.name, nummatches)
elif element.freq == wmlgrammar.OPTIONAL and nummatches > 1:
print "Element '[%s] [%s]' should appear at most once, not %d times" % (verbosename, element.name, nummatches)
print "(%s:%d) Element '[%s] [%s]' should appear at most once, not %d times" % (node.file, node.line, verbosename, element.name, nummatches)
for match in matches:
self.validate(match, depth+1, element.subname)
node.remove(match)
for element in node.get_all_subs():
print "Element '[%s] [%s]' found, which has no meaning there" % (verbosename, element.name)
print "(%s:%d) Element '[%s] [%s]' found, which has no meaning there" % (node.file, node.line, verbosename, element.name)
# Do we want to do this?
if False:
print "Attempting to validate [%s] anyway" % element.name