summaryrefslogtreecommitdiff
path: root/data
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2015-04-15 21:37:53 +0600
committerDaniil Baturin <daniil@baturin.org>2015-04-15 21:37:53 +0600
commit6718fc61b3605f649e4ba6dead4d7642fd5609dd (patch)
treedc811c88c548d75f0816c49bd3ab4e7e9f859049 /data
parentf9aad533ee80268a5acac34179098a097968a48d (diff)
downloadvyconf-6718fc61b3605f649e4ba6dead4d7642fd5609dd.tar.gz
vyconf-6718fc61b3605f649e4ba6dead4d7642fd5609dd.zip
Simplify the interface definition schema.
1. Don't distinguish name and value constraints, they have exact same structure. 2. Don't use individual error messages for all constraints. If they work like OR, it makes little sense. 3. Move most of data from arguments to tag bodies.
Diffstat (limited to 'data')
-rw-r--r--data/schemata/interface_definition.rnc107
-rw-r--r--data/schemata/interface_definition.rng140
2 files changed, 101 insertions, 146 deletions
diff --git a/data/schemata/interface_definition.rnc b/data/schemata/interface_definition.rnc
index 5bd3437..fdecfd4 100644
--- a/data/schemata/interface_definition.rnc
+++ b/data/schemata/interface_definition.rnc
@@ -68,6 +68,47 @@ ownerAttr = attribute owner
text
}
+# Tag and leaf nodes may have constraints on their names and values
+# (respectively).
+# When multiple constraints are listed, they work as logical OR
+constraint = element constraint
+{
+ (regex | validator)+,
+ errorMessage?
+}
+
+# A constraint may be a regex pattern
+regex = element regex
+{
+ text
+}
+
+# A constraint may also use an external validator
+validator = element validator
+{
+ validatorNameAttr,
+ validatorArgumentAttr,
+ empty
+}
+
+# Validators are named
+validatorNameAttr = attribute name
+{
+ text
+}
+
+# An argument can be passed to validator, in addition to the value to be validated
+validatorArgumentAttr = attribute argument
+{
+ text
+}
+
+# When validation fails, a message can be shown
+errorMessage = element errorMessage
+{
+ text
+}
+
# Tag nodes are containers for nodes without predefined names, like network interfaces
# or user names (e.g. "interfaces ethernet eth0" or "user jrandomhacker")
# Tag nodes may contain node and leafNode elements, and also nameConstraint tags
@@ -76,21 +117,11 @@ tagNode = element tagNode
{
ownerAttr?,
nodeNameAttr,
- nameConstraint?,
helpString?,
+ constraint?,
(node | leafNode)+
}
-# Tag nodes may also contain nameConstraint tag with type and constraint
-# attributes. It provides information required to validate child name.
-nameConstraint = element nameConstraint
-{
- typeAttr,
- constraintAttr?,
- errorMessageAttr?,
- empty
-}
-
# Leaf nodes are terminal configuration nodes that can't have children,
# but can have values.
# Leaf node may contain one or more valueConstraint tags
@@ -102,65 +133,19 @@ leafNode = element leafNode
nodeNameAttr,
multiAttr?,
helpString?,
- (valueHelpString | valueConstraint)*
-}
-
-# valueConstraint tag contains information required to validate node values
-# It must have two attributes, "type" and "constraint".
-valueConstraint = element valueConstraint
-{
- typeAttr,
- constraintAttr?,
- errorMessageAttr?,
- empty
+ constraint?,
+ valueHelpString*
}
# helpString tag contains brief description of the purpose of the node
# Must have description= attribute
helpString = element helpString
{
- descriptionAttr, empty
-}
-
-# valueHelpString tag contain information about acceptable value format
-# It may be exact value in value= attribute, or a placeholder taken from
-# type specified in type= attribute
-valueHelpString = element valueHelpString
-{
- ((typeAttr, constraintAttr?) | valueAttr),
- descriptionAttr,
- empty
-}
-
-# description= attribute contains help strings for nodes
-descriptionAttr = attribute description
-{
text
}
-# value= attributes contains one of allowed values for leaf nodes
-valueAttr = attribute value
-{
- text
-}
-
-# type= attribute is used in leaf nodes and contains name of a type
-# to take value placeholder from
-typeAttr = attribute type
-{
- text
-}
-
-# constraint= attribute contains additional information for type validation,
-# used in valueContrating tags
-constraintAttr = attribute constraint
-{
- text
-}
-
-# error-message= attribute is used to override default error message
-# in nameConstraint and valueConstraint attributes
-errorMessageAttr = attribute error-message
+# valueHelpString tags contain information about acceptable value format
+valueHelpString = element valueHelpString
{
text
}
diff --git a/data/schemata/interface_definition.rng b/data/schemata/interface_definition.rng
index f502dcc..7a53182 100644
--- a/data/schemata/interface_definition.rng
+++ b/data/schemata/interface_definition.rng
@@ -88,6 +88,52 @@
<attribute name="owner"/>
</define>
<!--
+ Tag and leaf nodes may have constraints on their names and values
+ (respectively).
+ When multiple constraints are listed, they work as logical OR
+ -->
+ <define name="constraint">
+ <element name="constraint">
+ <oneOrMore>
+ <choice>
+ <ref name="regex"/>
+ <ref name="validator"/>
+ </choice>
+ </oneOrMore>
+ <optional>
+ <ref name="errorMessage"/>
+ </optional>
+ </element>
+ </define>
+ <!-- A constraint may be a regex pattern -->
+ <define name="regex">
+ <element name="regex">
+ <text/>
+ </element>
+ </define>
+ <!-- A constraint may also use an external validator -->
+ <define name="validator">
+ <element name="validator">
+ <ref name="validatorNameAttr"/>
+ <ref name="validatorArgumentAttr"/>
+ <empty/>
+ </element>
+ </define>
+ <!-- Validators are named -->
+ <define name="validatorNameAttr">
+ <attribute name="name"/>
+ </define>
+ <!-- An argument can be passed to validator, in addition to the value to be validated -->
+ <define name="validatorArgumentAttr">
+ <attribute name="argument"/>
+ </define>
+ <!-- When validation fails, a message can be shown -->
+ <define name="errorMessage">
+ <element name="errorMessage">
+ <text/>
+ </element>
+ </define>
+ <!--
Tag nodes are containers for nodes without predefined names, like network interfaces
or user names (e.g. "interfaces ethernet eth0" or "user jrandomhacker")
Tag nodes may contain node and leafNode elements, and also nameConstraint tags
@@ -100,10 +146,10 @@
</optional>
<ref name="nodeNameAttr"/>
<optional>
- <ref name="nameConstraint"/>
+ <ref name="helpString"/>
</optional>
<optional>
- <ref name="helpString"/>
+ <ref name="constraint"/>
</optional>
<oneOrMore>
<choice>
@@ -114,22 +160,6 @@
</element>
</define>
<!--
- Tag nodes may also contain nameConstraint tag with type and constraint
- attributes. It provides information required to validate child name.
- -->
- <define name="nameConstraint">
- <element name="nameConstraint">
- <ref name="typeAttr"/>
- <optional>
- <ref name="constraintAttr"/>
- </optional>
- <optional>
- <ref name="errorMessageAttr"/>
- </optional>
- <empty/>
- </element>
- </define>
- <!--
Leaf nodes are terminal configuration nodes that can't have children,
but can have values.
Leaf node may contain one or more valueConstraint tags
@@ -146,28 +176,12 @@
<optional>
<ref name="helpString"/>
</optional>
- <zeroOrMore>
- <choice>
- <ref name="valueHelpString"/>
- <ref name="valueConstraint"/>
- </choice>
- </zeroOrMore>
- </element>
- </define>
- <!--
- valueConstraint tag contains information required to validate node values
- It must have two attributes, "type" and "constraint".
- -->
- <define name="valueConstraint">
- <element name="valueConstraint">
- <ref name="typeAttr"/>
- <optional>
- <ref name="constraintAttr"/>
- </optional>
<optional>
- <ref name="errorMessageAttr"/>
+ <ref name="constraint"/>
</optional>
- <empty/>
+ <zeroOrMore>
+ <ref name="valueHelpString"/>
+ </zeroOrMore>
</element>
</define>
<!--
@@ -176,59 +190,15 @@
-->
<define name="helpString">
<element name="helpString">
- <ref name="descriptionAttr"/>
- <empty/>
+ <text/>
</element>
</define>
- <!--
- valueHelpString tag contain information about acceptable value format
- It may be exact value in value= attribute, or a placeholder taken from
- type specified in type= attribute
- -->
+ <!-- valueHelpString tags contain information about acceptable value format -->
<define name="valueHelpString">
<element name="valueHelpString">
- <choice>
- <group>
- <ref name="typeAttr"/>
- <optional>
- <ref name="constraintAttr"/>
- </optional>
- </group>
- <ref name="valueAttr"/>
- </choice>
- <ref name="descriptionAttr"/>
- <empty/>
+ <text/>
</element>
</define>
- <!-- description= attribute contains help strings for nodes -->
- <define name="descriptionAttr">
- <attribute name="description"/>
- </define>
- <!-- value= attributes contains one of allowed values for leaf nodes -->
- <define name="valueAttr">
- <attribute name="value"/>
- </define>
- <!--
- type= attribute is used in leaf nodes and contains name of a type
- to take value placeholder from
- -->
- <define name="typeAttr">
- <attribute name="type"/>
- </define>
- <!--
- constraint= attribute contains additional information for type validation,
- used in valueContrating tags
- -->
- <define name="constraintAttr">
- <attribute name="constraint"/>
- </define>
- <!--
- error-message= attribute is used to override default error message
- in nameConstraint and valueConstraint attributes
- -->
- <define name="errorMessageAttr">
- <attribute name="error-message"/>
- </define>
<!--
multi=<true|false> attribute indicates that a leaf node can have
multiple values