Commit e7fa05a251e0fe746b9524e94b42b5093c4714bf

Authored by totoro
1 parent c20e8ff6

add comment to main entry of Alternative. This comment exists to explain the ma…

…in goal of the alternative and located on top of the alternative
Showing 1 changed file with 31 additions and 15 deletions   Show diff stats
types/ds_types.anubis
... ... @@ -30,7 +30,7 @@ public type Bool_List:
30 30 list.
31 31  
32 32 public type DS_Comment:
33   - none,
  33 + no_comment,
34 34 comment(String comment).
35 35  
36 36 public type DS_Component:
... ... @@ -61,7 +61,7 @@ public define DS_Component
61 61 DS_Anubis_Type anb_type,
62 62 String name
63 63 )=
64   - component(list, anb_type, name, none).
  64 + component(list, anb_type, name, no_comment).
65 65  
66 66 public define DS_Component
67 67 /* Default constructor helper without Bool_List means 'none'
... ... @@ -71,7 +71,7 @@ public define DS_Component
71 71 DS_Anubis_Type anb_type,
72 72 String name
73 73 )=
74   - component(none, anb_type, name, none).
  74 + component(none, anb_type, name, no_comment).
75 75  
76 76  
77 77 public type DS_Alternative:
... ... @@ -82,7 +82,8 @@ public type DS_Alternative:
82 82 ),
83 83 //alternative
84 84 alternative(
85   - String alt_name, //Name of the alternative
  85 + String alt_name, //Name of the alternative
  86 + DS_Comment comment, //main comment of the alternative if need
86 87 List(DS_Component) components //list of components of that alternative
87 88 ).
88 89  
... ... @@ -93,8 +94,17 @@ public define DS_Alternative
93 94 (
94 95 String alt_name
95 96 )=
96   - enum(alt_name, none).
97   -
  97 + enum(alt_name, no_comment).
  98 +
  99 +public define DS_Alternative
  100 + alternative
  101 + (
  102 + String alt_name, //Name of the alternative
  103 + List(DS_Component) components //list of components of that alternative
  104 + )=
  105 + alternative(alt_name, no_comment, components)
  106 +.
  107 +
98 108 public type DS_Type:
99 109 ds_type(
100 110 String type_name,
... ... @@ -139,8 +149,8 @@ define List(Extern_type)
139 149 [h . t] then
140 150 if h is
141 151 {
142   - enum(_ , _) then extract_extern_type(t, so_far)
143   - alternative(_, components) then
  152 + enum(_ , _) then extract_extern_type(t, so_far)
  153 + alternative(_, _, components) then
144 154 extract_extern_type(t, extract_extern_type(components, so_far))
145 155 }
146 156 }
... ... @@ -186,7 +196,7 @@ public define String
186 196 )=
187 197 if comment is
188 198 {
189   - none then "",
  199 + no_comment then "",
190 200 comment(_str) then "//"+_str
191 201 }
192 202 .
... ... @@ -239,8 +249,8 @@ define Int
239 249 [h . t] then
240 250 with name = if h is
241 251 {
242   - enum(name, _) then name,
243   - alternative(name, _) then name
  252 + enum(name, _) then name,
  253 + alternative(name, _, _) then name
244 254 },
245 255 alternative_name_max_length(t, max(current_length, length(name)))
246 256 }
... ... @@ -276,7 +286,7 @@ define Int
276 286 with current = if h is
277 287 {
278 288 enum(name, _) then length(name),
279   - alternative(name, components) then component_type_max_length(components, 0)
  289 + alternative(name, _, components) then component_type_max_length(components, 0)
280 290 },
281 291 alternative_type_max_length(t, max(current, so_far_length))
282 292 }
... ... @@ -311,8 +321,8 @@ define Int
311 321 [h . t] then
312 322 with current = if h is
313 323 {
314   - enum(_, _) then 0,
315   - alternative(_, components) then component_name_max_length(components, 0)
  324 + enum(_, _) then 0,
  325 + alternative(_, _, components) then component_name_max_length(components, 0)
316 326 },
317 327 alternative_type_name_max_length(t, max(current, so_far_length))
318 328 }
... ... @@ -336,7 +346,13 @@ public define String
336 346 enum(name, _comment) then prefix + fill(name+(if is_empty(t) then "" else ","), type_length + name_length+2) + dump(_comment) +
337 347 dump_DS_Alternative_list(t, type_length, alt_name_length, name_length),
338 348  
339   - alternative(name, components) then prefix + name+"("+
  349 + alternative(name, comment, components) then
  350 + //if comment exists, add it first
  351 + (if comment != no_comment then
  352 + prefix + dump(comment) +"\n"
  353 + else
  354 + "")+
  355 + prefix + name+"("+
340 356 dump(components, true, type_length, name_length)+(if is_empty(t) then "" else ",")+
341 357 dump_DS_Alternative_list(t, type_length, alt_name_length, name_length)
342 358 }
... ...