Skip to content

Commit a5e5b8f

Browse files
author
Fábio
authored
Make the YAML details: section more flexible (#393)
Closes #366
1 parent 193fe11 commit a5e5b8f

File tree

3 files changed

+59
-49
lines changed

3 files changed

+59
-49
lines changed

scripts/YaML.md

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ n/a
5656
- `altvalue` must be an ISO-C standard preprocessor replacement list. If specified, then will be contained within the `#else` conditional block.
5757
- `ordinal` will be used to override the default order (in which they appear) the macro appears within its section; `default="1000"`
5858
- `version` will be used to define the minimum API version in which the macro will appear; `default="1.0"` This will also affect the order in which the macro appears within its section.
59-
* A macro may take the following optional sequence of scalars or scalars to sequences: {`details`}
60-
- `detail` will be used as the macro's detailed comment
59+
* A macro may take the following optional field which can be a scalar, a sequence of scalars or scalars to sequences: {`details`}
60+
- `details` will be used as the macro's detailed comment
6161

6262
<table>
6363
<tr><th>YaML</th><th>C\C++</th><th>Python</th></tr>
@@ -147,8 +147,8 @@ n/a
147147
- `altvalue` must be an ISO-C standard identifier. If specified, then will be contained within the `#else` conditional block.
148148
- `ordinal` will be used to override the default order (in which they appear) the typedef appears within its section; `default="1000"`
149149
- `version` will be used to define the minimum API version in which the typedef will appear; `default="1.0"` This will also affect the order in which the typedef appears within its section and class.
150-
* A typedef may take the following optional sequence of scalars or scalars to sequences: {`details`}
151-
- `detail` will be used as the typedef's detailed comment
150+
* A typedef may take the following optional field which can be a scalar, a sequence of scalars or scalars to sequences: {`details`}
151+
- `details` will be used as the typedef's detailed comment
152152

153153
<table>
154154
<tr><th>YaML</th><th>C</th><th>C++</th><th>Python</th></tr>
@@ -244,8 +244,8 @@ std::function<void(void*)> ur_callback_t;
244244
- `condition` will be used as a C/C++ preprocessor `#if` conditional expression
245245
- `ordinal` will be used to override the default order (in which they appear) the handles appears within its section; `default="1000"`
246246
- `version` will be used to define the minimum API version in which the handles will appear; `default="1.0"` This will also affect the order in which the handles appears within its section.
247-
* A handle may take the following optional sequence of scalars or scalars to sequences: {`details`}
248-
- `detail` will be used as the handle's detailed comment
247+
* A handle may take the following optional field which can be a scalar, a sequence of scalars or scalars to sequences: {`details`}
248+
- `details` will be used as the handle's detailed comment
249249

250250
<table>
251251
<tr><th>YaML</th><th>C</th><th>C++</th><th>Python</th></tr>
@@ -330,8 +330,8 @@ class ur_name_handle_t(c_void_p):
330330
- An etor may take the following optional scalar field: {`value`, `version`}
331331
+ `value` must be an ISO-C standard identifier
332332
+ `version` will be used to define the minimum API version in which the etor will appear; `default="1.0"` This will also affect the order in which the etor appears within the enum.
333-
* An enum may take the following optional sequence of scalars or scalars to sequences: {`details`}
334-
- `detail` will be used as the enum's detailed comment
333+
* An enum may take the following optional field which can be a scalar, a sequence of scalars or scalars to sequences: {`details`}
334+
- `details` will be used as the enum's detailed comment
335335

336336
<table>
337337
<tr><th>YaML</th><th>C</th><th>C++</th><th>Python</th></tr>
@@ -470,8 +470,8 @@ class ur_name_flags_v(IntEnum):
470470
+ `init` will be used to initialize the C++ struct|union member's value
471471
+ `init` must be an ISO-C standard identifier or literal
472472
+ `version` will be used to define the minimum API version in which the member will appear; `default="1.0"` This will also affect the order in which the member appears within the struct|union.
473-
* A struct|union may take the following optional sequence of scalars or scalars to sequences: {`details`}
474-
- `detail` will be used as the struct|union's detailed comment
473+
* A struct|union may take the following optional field which can be a scalar, a sequence of scalars or scalars to sequences: {`details`}
474+
- `details` will be used as the struct|union's detailed comment
475475

476476
<table>
477477
<tr><th>YaML</th><th>C</th><th>C++</th><th>Python</th></tr>
@@ -615,12 +615,13 @@ class ur_name_t(Structure):
615615
- if `class` is specified and the function is not `decl: static`, then the first param **must** be the handle associated with the class
616616
* A function may take the following optional sequence of scalars: {`analogue`}
617617
- `analogue` will be used as the function's remarks comment
618-
* A function may take the following optional sequence of scalars or scalars to sequences: {`details`, `returns`}
619-
- `detail` will be used as the function's detailed comment
620-
- `return` will be used as the function's returns comment
621-
- `return` must be an etor of `$x_result_t`
622-
- `return` defaults are generated by parsing the function's params' description annotations
623-
- `return` may contain a sequence of custom validation layer code blocks
618+
* A function may take the following optional sequence of scalars or scalars to sequences: {`returns`}
619+
- `returns` will be used as the function's returns comment
620+
- `returns` must be an etor of `$x_result_t`
621+
- `returns` defaults are generated by parsing the function's params' description annotations
622+
- `returns` may contain a sequence of custom validation layer code blocks
623+
* A function may take the following optional field which can be a scalar, a sequence of scalars or scalars to sequences: {`details`}
624+
- `details` will be used as the function's detailed comment
624625

625626
<table>
626627
<tr><th>YaML</th><th>C</th><th>C++</th><th>Python</th></tr>
@@ -729,8 +730,8 @@ _urClsNameFnName_t = CFUNCTYPE( ur_result_t, ur_cls_handle_t, c_ulong, POINTER(c
729730
- The first member must be the handle associated with the class; the `name` must be `"handle"`
730731
- If `owner` is specified, then the second member must be the pointer to the owner
731732
- The next member may be the `_desc_t` used to create the object; the `name` must be `"desc"`
732-
* A class may take the following optional sequence of scalars or scalars to sequences: {`details`}
733-
- `detail` will be used as the class's detailed comment
733+
* A class may take the following optional field which can be a scalar, a sequence of scalars or scalars to sequences: {`details`}
734+
- `details` will be used as the class's detailed comment
734735

735736
<table>
736737
<tr><th>YaML</th><th>C++</th></tr>

scripts/parse_specs.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -171,23 +171,25 @@ def __validate_handle(d, key, tags):
171171

172172
def __validate_details(d):
173173
if 'details' in d:
174-
if not isinstance(d['details'], list):
175-
raise Exception("'details' must be a sequence: '%s'"%type(d['details']))
176-
177-
for i, item in enumerate(d['details']):
178-
prefix = "'details'[%s] "%i
179-
if isinstance(item, dict):
180-
for key in item:
181-
if not isinstance(key, str):
182-
raise Exception(prefix+"must be a string: '%s'"%type(key))
183-
184-
for j, val in enumerate(item[key]):
185-
prefix2 = prefix[:-1]+"[%s] "%j
186-
if not isinstance(val, str):
187-
raise Exception(prefix2+"must be a string: '%s'"%type(val))
188-
189-
elif not isinstance(item, str):
190-
raise Exception(prefix+"must be a string: '%s'"%type(item))
174+
175+
if not (isinstance(d['details'], list) or isinstance(d['details'], str)):
176+
raise Exception("'details' must be a string or a sequence")
177+
178+
if isinstance(d['details'], list):
179+
for i, item in enumerate(d['details']):
180+
prefix = "'details'[%s] "%i
181+
if isinstance(item, dict):
182+
for key in item:
183+
if not isinstance(key, str):
184+
raise Exception(prefix+"must be a string: '%s'"%type(key))
185+
186+
for j, val in enumerate(item[key]):
187+
prefix2 = prefix[:-1]+"[%s] "%j
188+
if not isinstance(val, str):
189+
raise Exception(prefix2+"must be a string: '%s'"%type(val))
190+
191+
elif not isinstance(item, str):
192+
raise Exception(prefix+"must be a string: '%s'"%type(item))
191193

192194
def __validate_etors(d, tags):
193195
if 'etors' not in d:

scripts/templates/helper.py

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -780,23 +780,30 @@ def make_details_lines(namespace, tags, obj):
780780
lines.append("")
781781
lines.append("@details")
782782

783-
for item in obj['details']:
784-
if isinstance(item, dict):
785-
for key, values in item.items():
786-
prologue = " -"
787-
for line in split_line(subt(namespace, tags, key, True), 70):
788-
lines.append("%s %s"%(prologue, line))
789-
prologue = " "
790-
for val in values:
791-
prologue = " +"
792-
for line in split_line(subt(namespace, tags, val, True), 66):
783+
# If obj['details'] is a list of bullet points, add the bullet point formatting to the lines.
784+
if isinstance(obj['details'], list):
785+
for item in obj['details']:
786+
if isinstance(item, dict):
787+
for key, values in item.items():
788+
prologue = " -"
789+
for line in split_line(subt(namespace, tags, key, True), 70):
793790
lines.append("%s %s"%(prologue, line))
794-
prologue = " "
795-
else:
796-
prologue = " -"
797-
for line in split_line(subt(namespace, tags, item, True), 70):
791+
prologue = " "
792+
for val in values:
793+
prologue = " +"
794+
for line in split_line(subt(namespace, tags, val, True), 66):
795+
lines.append("%s %s"%(prologue, line))
796+
prologue = " "
797+
else:
798+
prologue = " -"
799+
for line in split_line(subt(namespace, tags, item, True), 70):
798800
lines.append("%s %s"%(prologue, line))
799801
prologue = " "
802+
# If obj['details'] is a string, then assume that it's already correctly formatted using markdown.
803+
else:
804+
for line in obj['details'].splitlines(False):
805+
lines.append(subt(namespace, tags, line, True))
806+
800807
if 'analogue' in obj:
801808
lines.append("")
802809
lines.append("@remarks")

0 commit comments

Comments
 (0)