Skip to content

Commit 8c8bc0d

Browse files
committed
Add documentation
Signed-off-by: Michael Carroll <[email protected]>
1 parent 5cda363 commit 8c8bc0d

File tree

1 file changed

+17
-11
lines changed

1 file changed

+17
-11
lines changed

tools/xmlschema.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
from typing import List, Dict, Tuple, Optional
2525

2626

27+
# Mapping between "type" values found in SDF files to the corresponding
28+
# XSD standard datatypes as defined by https://www.w3.org/TR/xmlschema11-2/
2729
SDF_TYPES_TO_XSD_STD_TYPES = {
2830
"bool": "boolean",
2931
"char": "char",
@@ -35,18 +37,21 @@
3537
"unsigned long": "unsignedLong",
3638
}
3739

40+
# Mapping between "required" values found in SDF files to the corresponding
41+
# minOccurs and maxOccurs found in XSD
3842
SDF_REQUIRED_TO_MIN_MAX_OCCURS: Dict[str, Tuple[str, str]] = {
39-
"0": ("0", "1"),
40-
"1": ("1", "1"),
41-
"+": ("1", "unbounded"),
42-
"*": ("0", "unbounded"),
43-
"-1": ("0", "unbounded"),
43+
"0": ("0", "1"), # Required: 0, (minOccurs: 0, maxOccurs: 1)
44+
"1": ("1", "1"), # Required: 1, (minOccurs: 1, maxOccurs: 1)
45+
"+": ("1", "unbounded"), # Required: +, (minOccurs: 1, maxOccurs: inf)
46+
"*": ("0", "unbounded"), # Required: *, (minOccurs: 0, maxOccurs: inf)
47+
"-1": ("0", "unbounded"), # Required: -1, (minOccurs: 0, maxOccurs: inf)
4448
}
4549

4650

4751
def indent_lines(lines: List[str], indent: int) -> List[str]:
4852
"""
49-
Indent a group of lines by a set number of spaces
53+
Indent a list of xml lines group of lines by a number (indent) of spaces
54+
5055
"""
5156
return [" " * indent + line for line in lines]
5257

@@ -60,15 +65,16 @@ def get_attribute(element: ElementTree.Element, attrib: str) -> Optional[str]:
6065

6166
def is_std_type(sdf_type: str) -> bool:
6267
"""
63-
Check if sdf_type is a known XSD standard type
68+
Check if sdf_type is a known XSD standard type.
69+
Return true if the sdf_type is in the set of known types, false otherwise.
6470
"""
6571
return sdf_type in SDF_TYPES_TO_XSD_STD_TYPES
6672

6773

6874
def xsd_type_string(sdf_type: str) -> Optional[str]:
6975
"""
70-
If sdf_type is a known XSD standard type, return it.
71-
Otherwise, return None
76+
Check if xsd_type is a known XSD standard type.
77+
If it is, return 'xsd:' + type, None otherwise.
7278
"""
7379
if is_std_type(sdf_type):
7480
xsd_type = SDF_TYPES_TO_XSD_STD_TYPES[sdf_type]
@@ -272,9 +278,9 @@ def print_xsd(element: ElementTree.Element, sdf_root_dir: str) -> List[str]:
272278

273279

274280
def process(input_file_sdf: str, sdf_dir: str) -> List[str]:
275-
'''
281+
"""
276282
Produce an XSD file from an input SDF file
277-
'''
283+
"""
278284
lines = []
279285
tree = ElementTree.parse(input_file_sdf)
280286
root = tree.getroot()

0 commit comments

Comments
 (0)