diff options
author | Daniil Baturin <daniil@baturin.org> | 2015-04-16 04:56:38 +0600 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2015-04-16 04:56:38 +0600 |
commit | dd2fc4d0d4b675220a6d66d5b4f57c10bfa25793 (patch) | |
tree | 493ac8a585ce94eba207f50275eaca184d0a93ae | |
parent | 2adde14d0f096a1b38f94a8673ad9aa13a1ef4bc (diff) | |
download | vyconf-dd2fc4d0d4b675220a6d66d5b4f57c10bfa25793.tar.gz vyconf-dd2fc4d0d4b675220a6d66d5b4f57c10bfa25793.zip |
Group node properties and children into their own tags.
Make order of elements unimportant.
Remove unused references.
-rw-r--r-- | data/examples/interface_definition_sample.xml | 32 | ||||
-rw-r--r-- | data/schemata/interface_definition.rnc | 61 | ||||
-rw-r--r-- | data/schemata/interface_definition.rng | 182 |
3 files changed, 155 insertions, 120 deletions
diff --git a/data/examples/interface_definition_sample.xml b/data/examples/interface_definition_sample.xml index e77240b..fe22e17 100644 --- a/data/examples/interface_definition_sample.xml +++ b/data/examples/interface_definition_sample.xml @@ -1,15 +1,29 @@ <?xml version="1.0"?> <interfaceDefinition extends="system"> <node name="login"> - <tagNode name="user"> - <helpString>User name</helpString> - <constraint> - <regex>[a-z][a-zA-Z0-9]+</regex> - <errorMessage>User name must start with a letter and consist of letters and digits</errorMessage> - </constraint> - <leafNode name="full-name"> - <helpString>User full name</helpString> + <children> + <tagNode name="user"> + <properties> + <helpString>User name</helpString> + <constraint> + <regex>[a-z][a-zA-Z0-9]+</regex> + <errorMessage>User name must start with a letter and consist of letters and digits</errorMessage> + </constraint> + </properties> + <children> + <leafNode name="full-name"> + <properties> + <helpString>User full name</helpString> + </properties> + </leafNode> + </children> + </tagNode> + <leafNode name="hostname"> + <properties> + <helpString>System hostname</helpString> + <valueHelpString>text</valueHelpString> + </properties> </leafNode> - </tagNode> + </children> </node> </interfaceDefinition> diff --git a/data/schemata/interface_definition.rnc b/data/schemata/interface_definition.rnc index a20207b..d28d06d 100644 --- a/data/schemata/interface_definition.rnc +++ b/data/schemata/interface_definition.rnc @@ -34,15 +34,23 @@ extendsAttr = attribute extends text } -# Extends tag defines path prepended to the nodes -extends = element extends +# Normal and tag nodes may have children +children = element children { - path + (node | tagNode | leafNode)+ } -path = attribute path +# Nodes may have properties +# For simplicity, any property is allowed in any node, +# but whether they are used or not is implementation-defined +properties = element properties { - text + helpString?, + constraint?, + + # These are meaningful only for leaf nodes + valueHelpString?, + (multi | valueless)? } # node tag may contain node, leafNode, or tagNode tags @@ -50,10 +58,8 @@ path = attribute path # other nodes and must not have values node = element node { - ownerAttr?, - nodeNameAttr, - helpString?, - (node | tagNode | leafNode)* + (ownerAttr? & nodeNameAttr), + (properties? & children? ) } # All nodes must have "name" attribute @@ -74,7 +80,7 @@ ownerAttr = attribute owner # When multiple constraints are listed, they work as logical OR constraint = element constraint { - (regex | validator)+, + (regex | validator)+ & errorMessage? } @@ -87,8 +93,7 @@ regex = element regex # A constraint may also use an external validator validator = element validator { - validatorNameAttr, - validatorArgumentAttr, + (validatorNameAttr & validatorArgumentAttr), empty } @@ -116,11 +121,8 @@ errorMessage = element errorMessage # They must not contain other tag nodes tagNode = element tagNode { - ownerAttr?, - nodeNameAttr, - helpString?, - constraint?, - (node | leafNode)+ + (ownerAttr? & nodeNameAttr), + (properties? & children ) } # Leaf nodes are terminal configuration nodes that can't have children, @@ -132,10 +134,19 @@ tagNode = element tagNode leafNode = element leafNode { nodeNameAttr, - multiAttr?, - helpString?, - constraint?, - valueHelpString* + properties +} + +# Some leaf nodes may have more than one value +multi = element multi +{ + empty +} + +# Some leaf nodes may not have values (e.g. enable/disable flags) +valueless = element valueless +{ + empty } # helpString tag contains brief description of the purpose of the node @@ -150,11 +161,3 @@ valueHelpString = element valueHelpString { text } - -# multi=<true|false> attribute indicates that a leaf node can have -# multiple values -# If not present, treated as "false" -multiAttr = attribute multi -{ - xsd:boolean -} diff --git a/data/schemata/interface_definition.rng b/data/schemata/interface_definition.rng index 7a53182..bc55542 100644 --- a/data/schemata/interface_definition.rng +++ b/data/schemata/interface_definition.rng @@ -1,5 +1,5 @@ <?xml version="1.0" encoding="UTF-8"?> -<grammar xmlns="http://relaxng.org/ns/structure/1.0" datatypeLibrary="http://www.w3.org/2001/XMLSchema-datatypes"> +<grammar xmlns="http://relaxng.org/ns/structure/1.0"> <!-- interface_definition.rnc: VyConf reference tree XML grammar @@ -25,55 +25,82 @@ http://relaxng.org/compact-tutorial-20030326.htm (unless converted to XML, then just RELAX-NG :) --> - <!-- - Interface definition starts with interfaceDefinition tag that may contain node tags - It also may contain "extends" tags, if nodes must be appended to certain path - --> + <!-- Interface definition starts with interfaceDefinition tag that may contain node tags --> <start> <element name="interfaceDefinition"> - <zeroOrMore> - <ref name="extends"/> - </zeroOrMore> - <ref name="nodeList"/> - </element> - </start> - <define name="nodeList"> - <element name="nodeList"> + <optional> + <ref name="extendsAttr"/> + </optional> <zeroOrMore> <ref name="node"/> </zeroOrMore> </element> + </start> + <!-- + Interface definitions may extend other definitions + In this case you specify a whitespace-separated path + --> + <define name="extendsAttr"> + <attribute name="extends"/> </define> - <!-- Extends tag defines path prepended to the nodes --> - <define name="extends"> - <element name="extends"> - <ref name="path"/> + <!-- Normal and tag nodes may have children --> + <define name="children"> + <element name="children"> + <oneOrMore> + <choice> + <ref name="node"/> + <ref name="tagNode"/> + <ref name="leafNode"/> + </choice> + </oneOrMore> </element> </define> - <define name="path"> - <attribute name="path"/> - </define> <!-- - node tag may contain node, leafNode, or tagNode tags - Those are intermediate configuration nodes that may only contain - other nodes and must not have values + Nodes may have properties + For simplicity, any property is allowed in any node, + but whether they are used or not is implementation-defined --> - <define name="node"> - <element name="node"> + <define name="properties"> + <element name="properties"> <optional> - <ref name="ownerAttr"/> + <ref name="helpString"/> </optional> - <ref name="nodeNameAttr"/> <optional> - <ref name="helpString"/> + <ref name="constraint"/> </optional> - <zeroOrMore> + <optional> + <!-- These are meaningful only for leaf nodes --> + <ref name="valueHelpString"/> + </optional> + <optional> <choice> - <ref name="node"/> - <ref name="tagNode"/> - <ref name="leafNode"/> + <ref name="multi"/> + <ref name="valueless"/> </choice> - </zeroOrMore> + </optional> + </element> + </define> + <!-- + node tag may contain node, leafNode, or tagNode tags + Those are intermediate configuration nodes that may only contain + other nodes and must not have values + --> + <define name="node"> + <element name="node"> + <interleave> + <optional> + <ref name="ownerAttr"/> + </optional> + <ref name="nodeNameAttr"/> + </interleave> + <interleave> + <optional> + <ref name="properties"/> + </optional> + <optional> + <ref name="children"/> + </optional> + </interleave> </element> </define> <!-- All nodes must have "name" attribute --> @@ -94,15 +121,17 @@ --> <define name="constraint"> <element name="constraint"> - <oneOrMore> - <choice> - <ref name="regex"/> - <ref name="validator"/> - </choice> - </oneOrMore> - <optional> - <ref name="errorMessage"/> - </optional> + <interleave> + <oneOrMore> + <choice> + <ref name="regex"/> + <ref name="validator"/> + </choice> + </oneOrMore> + <optional> + <ref name="errorMessage"/> + </optional> + </interleave> </element> </define> <!-- A constraint may be a regex pattern --> @@ -114,8 +143,10 @@ <!-- A constraint may also use an external validator --> <define name="validator"> <element name="validator"> - <ref name="validatorNameAttr"/> - <ref name="validatorArgumentAttr"/> + <interleave> + <ref name="validatorNameAttr"/> + <ref name="validatorArgumentAttr"/> + </interleave> <empty/> </element> </define> @@ -141,22 +172,18 @@ --> <define name="tagNode"> <element name="tagNode"> - <optional> - <ref name="ownerAttr"/> - </optional> - <ref name="nodeNameAttr"/> - <optional> - <ref name="helpString"/> - </optional> - <optional> - <ref name="constraint"/> - </optional> - <oneOrMore> - <choice> - <ref name="node"/> - <ref name="leafNode"/> - </choice> - </oneOrMore> + <interleave> + <optional> + <ref name="ownerAttr"/> + </optional> + <ref name="nodeNameAttr"/> + </interleave> + <interleave> + <optional> + <ref name="properties"/> + </optional> + <ref name="children"/> + </interleave> </element> </define> <!-- @@ -170,18 +197,19 @@ <define name="leafNode"> <element name="leafNode"> <ref name="nodeNameAttr"/> - <optional> - <ref name="multiAttr"/> - </optional> - <optional> - <ref name="helpString"/> - </optional> - <optional> - <ref name="constraint"/> - </optional> - <zeroOrMore> - <ref name="valueHelpString"/> - </zeroOrMore> + <ref name="properties"/> + </element> + </define> + <!-- Some leaf nodes may have more than one value --> + <define name="multi"> + <element name="multi"> + <empty/> + </element> + </define> + <!-- Some leaf nodes may not have values (e.g. enable/disable flags) --> + <define name="valueless"> + <element name="valueless"> + <empty/> </element> </define> <!-- @@ -199,14 +227,4 @@ <text/> </element> </define> - <!-- - multi=<true|false> attribute indicates that a leaf node can have - multiple values - If not present, treated as "false" - --> - <define name="multiAttr"> - <attribute name="multi"> - <data type="boolean"/> - </attribute> - </define> </grammar> |