Skip to content

Commit 80ef127

Browse files
Merge pull request #141 from riscv/140-add-optional-note-keyword-for-normative-rules
Added note keyword and added to unit test
2 parents 116d24e + b6d5467 commit 80ef127

File tree

8 files changed

+51
-6
lines changed

8 files changed

+51
-6
lines changed

schemas/common-schema.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
"summaryDesc": {
77
"description": "Short summary of the normative rule (just a few words)"
88
},
9+
"noteDesc": {
10+
"description": "A note about the normative rule"
11+
},
912
"descriptionDesc": {
1013
"description": "Comprehensive description of the normative rule (sentence, paragraph, or longer)"
1114
},

schemas/defs-schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
"type": "string",
2929
"$ref": "common-schema.json#/summaryDesc"
3030
},
31+
"note": {
32+
"type": "string",
33+
"$ref": "common-schema.json#/noteDesc"
34+
},
3135
"description": {
3236
"type": "string",
3337
"$ref": "common-schema.json#/descriptionDesc"

tests/norm-rule/expected/test-norm-rules.adoc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,9 @@
1212
| [Zicsr, ABC] | Rule Instances
1313
| inside inline a| link:test.html#norm:inline[norm:inline]
1414

15-
.1+| no_tag
15+
.2+| no_tag
1616
| Normative rule without tag/tags | Rule's 'summary' property
17+
| This normative rule has no references to the standard. This should only be used in extraordinary circumstances. | Rule's 'note' property
1718

1819
.1+| inline-with-hash
1920
| includes a hash # symbol. a| link:test.html#norm:inline-with-hash[norm:inline-with-hash]

tests/norm-rule/expected/test-norm-rules.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,10 +130,14 @@ <h3>my-chapter_name</h3>
130130
<td><a href="test.html#norm:inline">norm:inline</a></td>
131131
</tr>
132132
<tr>
133-
<td rowspan=1 id="no_tag">no_tag</td>
133+
<td rowspan=2 id="no_tag">no_tag</td>
134134
<td>Normative rule without tag/tags</td>
135135
<td>Rule's "summary" property</td>
136136
</tr>
137+
<tr>
138+
<td>This normative rule has no references to the standard. This should only be used in extraordinary circumstances.</td>
139+
<td>Rule's "note" property</td>
140+
</tr>
137141
<tr>
138142
<td rowspan=1 id="inline-with-hash">inline-with-hash</td>
139143
<td>includes a hash # symbol.</td>

tests/norm-rule/expected/test-norm-rules.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"def_filename": "tests/norm-rule/test.yaml",
2525
"chapter_name": "my-chapter_name",
2626
"summary": "Normative rule without tag/tags",
27+
"note": "This normative rule has no references to the standard. This should only be used in extraordinary circumstances.",
2728
"tags": []
2829
},
2930
{
62 Bytes
Binary file not shown.

tests/norm-rule/test.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ normative_rule_definitions:
1515
tag: "norm:inline"
1616
- name: no_tag
1717
summary: Normative rule without tag/tags
18+
note: This normative rule has no references to the standard. This should only be used in extraordinary circumstances.
1819
- name: inline-with-hash
1920
tag: "norm:inline-with-hash"
2021

tools/create_normative_rules.rb

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ class NormativeRuleDef
147147
attr_reader :def_filename # String (mandatory)
148148
attr_reader :chapter_name # String (mandatory)
149149
attr_reader :summary # String (optional - a few words)
150+
attr_reader :note # String (optional - as long as needed)
150151
attr_reader :description # String (optional - sentence, paragraph, or more)
151152
attr_reader :kind # String (optional, can be nil)
152153
attr_reader :instances # Array<String> (optional - can be empty)
@@ -167,6 +168,11 @@ def initialize(name, def_filename, chapter_name, data)
167168
fatal("Provided #{@summary.class} class for summary in normative rule #{name} but need a String") unless @summary.is_a?(String)
168169
end
169170

171+
@note = data["note"]
172+
unless @note.nil?
173+
fatal("Provided #{@note.class} class for note in normative rule #{name} but need a String") unless @note.is_a?(String)
174+
end
175+
170176
@description = data["description"]
171177
unless @description.nil?
172178
fatal("Provided #{@description.class} class for description in normative rule #{name} but need a String") unless @description.is_a?(String)
@@ -428,6 +434,7 @@ def create_normative_rules_hash(defs, tags, tag_fname2url)
428434
hash["kind"] = d.kind unless d.kind.nil?
429435
hash["instances"] = d.instances unless d.instances.empty?
430436
hash["summary"] = d.summary unless d.summary.nil?
437+
hash["note"] = d.note unless d.note.nil?
431438
hash["description"] = d.description unless d.description.nil?
432439

433440
unless d.tag_refs.nil?
@@ -720,6 +727,11 @@ def output_xlsx(filename, defs, tags)
720727
rule_def_sources.append("Rule Summary")
721728
end
722729

730+
unless d.note.nil?
731+
rule_defs.append(d.note.chomp)
732+
rule_def_sources.append("Rule Note")
733+
end
734+
723735
unless d.description.nil?
724736
rule_defs.append(d.description.chomp)
725737
rule_def_sources.append("Rule Description")
@@ -784,13 +796,19 @@ def output_adoc(filename, defs, tags, tag_fname2url)
784796
f.puts("| Rule Name | Rule Description | Origin of Description")
785797

786798
nr_defs.each do |nr|
787-
info_rows = (nr.summary.nil? ? 0 : 1) + (nr.description.nil? ? 0 : 1) +
788-
(nr.kind.nil? ? 0 : 1) + (nr.instances.empty? ? 0 : 1) + nr.tag_refs.length
799+
info_rows =
800+
(nr.summary.nil? ? 0 : 1) +
801+
(nr.note.nil? ? 0 : 1) +
802+
(nr.description.nil? ? 0 : 1) +
803+
(nr.kind.nil? ? 0 : 1) +
804+
(nr.instances.empty? ? 0 : 1) +
805+
nr.tag_refs.length
789806
row_span = (info_rows > 0) ? ".#{info_rows}+" : ""
790807

791808
f.puts("")
792809
f.puts("#{row_span}| #{nr.name}")
793810
f.puts("| #{nr.summary} | Rule's 'summary' property") unless nr.summary.nil?
811+
f.puts("| #{nr.note} | Rule's 'note' property") unless nr.note.nil?
794812
f.puts("| #{nr.description} | Rule's 'description' property") unless nr.description.nil?
795813
f.puts("| #{nr.kind} | Rule's 'kind' property") unless nr.kind.nil?
796814
f.puts('| [' + nr.instances.join(', ') + '] | Rule Instances') unless nr.instances.empty?
@@ -1001,8 +1019,13 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
10011019
f.puts(%Q{ <tbody>})
10021020

10031021
nr_defs.each do |nr|
1004-
name_row_span = (nr.summary.nil? ? 0 : 1) + (nr.description.nil? ? 0 : 1) +
1005-
(nr.kind.nil? ? 0 : 1) + (nr.instances.empty? ? 0 : 1) + nr.tag_refs.length
1022+
name_row_span =
1023+
(nr.summary.nil? ? 0 : 1) +
1024+
(nr.note.nil? ? 0 : 1) +
1025+
(nr.description.nil? ? 0 : 1) +
1026+
(nr.kind.nil? ? 0 : 1) +
1027+
(nr.instances.empty? ? 0 : 1) +
1028+
nr.tag_refs.length
10061029

10071030
row_started = true
10081031
f.puts(%Q{ <tr>})
@@ -1016,6 +1039,14 @@ def html_chapter_table(f, table_num, chapter_name, nr_defs, tags, tag_fname2url)
10161039
row_started = false
10171040
end
10181041

1042+
unless nr.note.nil?
1043+
f.puts(%Q{ <tr>}) unless row_started
1044+
f.puts(%Q{ <td>#{nr.note}</td>})
1045+
f.puts(%Q{ <td>Rule's "note" property</td>})
1046+
f.puts(%Q{ </tr>})
1047+
row_started = false
1048+
end
1049+
10191050
unless nr.description.nil?
10201051
f.puts(%Q{ <tr>}) unless row_started
10211052
f.puts(%Q{ <td>#{convert_newlines_to_html(nr.description)}</td>})

0 commit comments

Comments
 (0)