aboutsummaryrefslogtreecommitdiffhomepage
path: root/org/ao_conf_make_meta.org
blob: 4205af7d2e214182daea096c700e78d9d1a3c2d3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
#+TITLE: sdp header extract
#+AUTHOR: Ralph Amissah
#+EMAIL: ralph.amissah@gmail.com
#+STARTUP: indent
#+LANGUAGE: en
#+OPTIONS: H:3 num:nil toc:t \n:nil @:t ::t |:t ^:nil _:nil -:t f:t *:t <:t
#+OPTIONS: TeX:t LaTeX:t skip:nil d:nil todo:t pri:nil tags:not-in-toc
#+OPTIONS: author:nil email:nil creator:nil timestamp:nil
#+PROPERTY: header-args :padline no :exports code :noweb yes
#+EXPORT_SELECT_TAGS: export
#+EXPORT_EXCLUDE_TAGS: noexport
#+FILETAGS: :sdp:rel:ao:
#+TAGS: assert(a) class(c) debug(d) mixin(m) sdp(s) tangle(T) template(t) WEB(W) noexport(n)

[[./sdp.org][sdp]]  [[./][org/]]
* 0. Code Skeleton / Outline / Structure (tangles)                   :tangle:
** 1. Header Hub                                 :ao_markup_header_extract:

#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta.d
/++
  extract native/orig header return associative array<BR>

  the header is passed as text (lopped off top of a sisu markup file until the
  required first heading ^A~), determine whether is a native header or sdlang one
  with a regex check if whether it contains the "native header" required tag/field
  @title: then process accordingly as a "native header" or "sdlang header"
  converting the metadata and make instructions to a common json format used by
  program internally. Moved to associative array.
+/
template SiSUheaderExtractHub() {
  private import
    std.regex;
  private import
    ao_rgx;
  struct SiSUheaderExtractHub {
    mixin SiSUheaderExtractNative;
    mixin SiSUheaderExtractSDLang;
    auto rgx = Rgx();
    private auto SiSUheaderExtractHub(Src, DocMake)(
      Src     header_src,
      DocMake conf_doc_make_aa
    ) {
      debug(asserts){
        static assert(is(typeof(header_src)       == char[]));
        static assert(is(typeof(conf_doc_make_aa) == string[string][string]));
      }
      auto head_native = HeaderDocMetadataAndMakeNativeToAA();
      auto head_sdlang = HeaderExtractSDL();
      auto header_make_and_meta_tuple = (match(header_src, rgx.native_header_meta_title))
      ? (head_native.headerNativeToAA(header_src))
      : (head_sdlang.headerSDLangToAA(header_src, conf_doc_make_aa));
      static assert(!isTypeTuple!(header_make_and_meta_tuple));
      static assert(header_make_and_meta_tuple.length==2);
      return header_make_and_meta_tuple;
    }
  }
}
#+END_SRC

** 2a. Header Native                      :ao_markup_header_extract_native:

#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta_native.d
/++
  native headers using<br>@title:<BR>:subtitle:<BR>type tags<BR>
  extract native/orig header return associative array
+/
template SiSUheaderExtractNative() {
  private import
    std.exception,
    std.regex,
    std.utf,
    std.conv : to;
  private import
    ao_rgx;
  struct HeaderDocMetadataAndMakeNativeToAA {
    mixin SiSUregisters;
    mixin SiSUrgxInitFlags;
    mixin SiSUrgxInit;
    auto rgx = Rgx();
    enum State { off, on }
    string hm, hs;
    <<ao_markup_header_extract_native>>
  }
}
#+END_SRC

** 2b. Header SDLang                      :ao_markup_header_extract_sdlang:

#+BEGIN_SRC d :tangle ../src/sdp/ao_conf_make_meta_sdlang.d
/++
  sdlang headers<BR>
  extract sdlang header return sdlang
+/
template SiSUheaderExtractSDLang() {
  private import
    std.regex;
  private import
    ao_rgx;
  struct HeaderExtractSDL {
    mixin SiSUregisters;
    mixin SiSUrgxInit;
    auto rgx = Rgx();
    <<ao_conf_make_meta_sdl>>
  }
}
#+END_SRC

* A. sdlang to AA

#+name: ao_conf_make_meta_sdl
#+BEGIN_SRC d
private auto sdlangToAAmake(C,Tag)(C conf, Tag conf_sdlang) {
  debug(asserts){
    static assert(is(typeof(conf) == string[string][string]));
  }
  foreach (maintag, subtags; conf) {
    foreach (subtag, content; subtags) {
      if (!(conf_sdlang.maybe.tags[maintag].empty)) {
        if (!(conf_sdlang.tags[maintag][0].maybe.attributes[subtag].empty)
        && (conf_sdlang.tags[maintag][0].attributes[subtag][0].value.length > 0)) {
          debug(headersdlang) {
            writeln(conf_sdlang.tags[maintag][0].attributes[subtag][0].value);
          }
          conf[maintag][subtag] =
            to!string(conf_sdlang.tags[maintag][0].attributes[subtag][0].value);
        }
      }
    }
  }
  return conf;
}
#+END_SRC

* B. conf settings sdlang

#+name: ao_conf_make_meta_sdl
#+BEGIN_SRC d
private auto configSettingsSDLangToAAmake(Tag)(Tag conf_sdlang) {
  auto conf = sdlangToAAmake(conf_aa, conf_sdlang);
  return conf;
}
#+END_SRC

* C. conf make sdlang

#+name: ao_conf_make_meta_sdl
#+BEGIN_SRC d
private auto documentMakeSDLangToAAmake(Tag)(Tag document_make_sdlang) {
  auto dochead_make = sdlangToAAmake(make_aa, document_make_sdlang);
  /+
  /+ dochead +/
  string hm;
  string hs;
  /+ make +/
  auto dochead_make = make_aa;
  if (!(document_make_sdlang.maybe.tags["make"].empty)) {
    hm = "make";
    hs = "bold";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "breaks";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "cover_image";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "css";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "emphasis";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "footer";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "headings";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "home_button_image";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "home_button_text";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "italics";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "num_top";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "substitute";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
    hs = "texpdf_font";
    if (!(document_make_sdlang.tags[hm][0].maybe.attributes[hs].empty)
    && (document_make_sdlang.tags[hm][0].attributes[hs][0].value.length > 1)) {
      debug(headersdlang) {
        writeln(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
      }
      dochead_make[hm][hs] =
        to!string(document_make_sdlang.tags[hm][0].attributes[hs][0].value);
    }
  }
  +/
  /+
  hm = "links";
  if (!(document_make_sdlang.maybe.tags[hm].empty)) {
    /+ TODO
      stuff to fix
    +/
  }
  +/
  return dochead_make;
}
#+END_SRC

* D. header                                                          :header:
** a. header native                                           :header:native:

*** native header document metadata in associative array                  :aa:

#+name: ao_markup_header_extract_native
#+BEGIN_SRC d
auto header_metadata_and_make_aa(H,Me,Ma)(
  H  header,
  Me dochead_meta,
  Ma dochead_make
)
in {
  debug(asserts){
    static assert(is(typeof(header)       == string));
    static assert(is(typeof(dochead_meta) == string[string][string]));
    static assert(is(typeof(dochead_make) == string[string][string]));
  }
}
body {
  scope(exit) {
    destroy(header);
    destroy(dochead_meta);
    destroy(dochead_make);
  }
  if (auto t = match(header, rgx.native_header_main)) {
    char[][] header_obj_spl = split(
      cast(char[]) header,
      rgx.line_delimiter_ws_strip
    );
    auto hm = to!string(t.captures[1]);
    if (match(hm, rgx.main_headers)) {
      foreach (line; header_obj_spl) {
        if (auto m = match(line, rgx.native_header_main)) {
          if (!empty(m.captures[2])) {
            if (hm == "creator") {
              dochead_meta[hm]["author"] =
                to!string(m.captures[2]);
            } else if (hm == "title") {
              dochead_meta[hm]["main"] =
                to!string(m.captures[2]);
            } else if (hm == "publisher") {
              dochead_meta[hm]["name"] =
                to!string(m.captures[2]);
            }
          }
        } else if (auto s = match(line, rgx.native_header_sub)) {
          if (!empty(s.captures[2])) {
            auto hs = to!string(s.captures[1]);
            if ((hm == "make" )
            && (dochead_make[hm])) {
              switch (hm) {
              case "make":
                if (match(hs, rgx.native_subhead_make)) {
                  if (dochead_make[hm][hs]) {
                    dochead_make[hm][hs] = to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              default:
                break;
              }
            } else if (dochead_meta[hm]) {
              switch (hm) {
              case "creator":
                if (match(hs, rgx.native_subhead_creator)) {
                  if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "title":
                if (match(hs, rgx.native_subhead_title)) {
                  if ((hs == "subtitle")
                  && (dochead_meta[hm]["sub"])) {
                    dochead_meta[hm]["sub"] =
                      to!string(s.captures[2]);
                  } else if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "rights":
                if (match(hs, rgx.native_subhead_rights)) {
                  if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "date":
                if (match(hs, rgx.native_subhead_date)) {
                  if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "original":
                if (match(hs, rgx.native_subhead_original)) {
                  if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "classify":
                if (match(hs, rgx.native_subhead_classify)) {
                  if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "identifier":
                if (match(hs, rgx.native_subhead_identifier)) {
                  if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "notes":
                if (match(hs, rgx.native_subhead_notes)) {
                  if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "publisher":
                if (match(hs, rgx.native_subhead_publisher)) {
                  if (dochead_meta[hm][hs]) {
                    dochead_meta[hm][hs] =
                      to!string(s.captures[2]);
                  }
                } else {
                  writeln("not a valid header type:", hm, ":", hs);
                  destroy(hm);
                  destroy(hs);
                }
                break;
              case "links":
                destroy(hm);
                destroy(hs);
                break;
              default:
                break;
              }
            }
          }
        }
      }
    } else {
      writeln("not a valid header type:", hm);
    }
  }
  auto t = tuple(dochead_meta, dochead_make);
  static assert(t.length==2);
  return t;
}
#+END_SRC

*** native header extract to string object                         :string:

#+name: ao_markup_header_extract_native
#+BEGIN_SRC d
private auto native_header_extract(L,Lo,O,T)(
  L line,
  ref Lo line_occur,
  ref O an_object,
  ref T type
) {
  debug(asserts){
    static assert(is(typeof(line)       == char[]));
    static assert(is(typeof(line_occur) == int[string]));
    static assert(is(typeof(an_object)  == string[string]));
    static assert(is(typeof(type)       == int[string]));
  }
  if (matchFirst(line, rgx.native_header_make)) {   /+ matched header_make +/
    debug(header1) { /+ writeln(line); +/ }
    type["header"]      = State.on;
    type["header_make"] = State.on;
    type["header_meta"] = State.off;
    ++line_occur["header_make"];
    an_object["body_nugget"] ~= line ~= "\n";
  } else if (matchFirst(line, rgx.native_header)) { /+ matched header_metadata +/
    /+ (generic header match and not previously caught by header_make) +/
    debug(header1) { /+ writeln(line); +/ }
    type["header"]      = State.on;
    type["header_make"] = State.off;
    type["header_meta"] = State.on;
    ++line_occur["header_meta"];
    an_object["body_nugget"] ~= line ~= "\n";
  } else if (type["header_make"] == State.on
  && (line_occur["header_make"] > State.off)) {     /+ header_make flag set +/
    if (matchFirst(line, rgx.native_header_sub)) {  /+ sub-header +/
      debug(header1) { /+ writeln(line); +/ }
      ++line_occur["header_make"];
      an_object["body_nugget"] ~= line ~= "\n";
    }
  } else if (type["header_meta"] == State.on
  && (line_occur["header_meta"] > State.off)) {     /+ header_metadata flag set +/
    if (matchFirst(line, rgx.native_header_sub)) {  /+ sub-header +/
      debug(header1) { /+ writeln(line); +/ }
      ++line_occur["header_meta"];
      an_object["body_nugget"] ~= line ~= "\n";
    }
  }
  return an_object;
}
#+END_SRC

*** native header reset states                                      :reset:

#+name: ao_markup_header_extract_native
#+BEGIN_SRC d
auto header_reset_states_common(Lo,O,T)(
  ref Lo line_occur,
  ref O  an_object,
  ref T  type
) {
  debug(asserts){
    static assert(is(typeof(line_occur) == int[string]));
    static assert(is(typeof(an_object)  == string[string]));
    static assert(is(typeof(type)       == int[string]));
  }
  line_occur["header_make"] = State.off;
  line_occur["header_meta"] = State.off;
  type["header"] = State.off;
  an_object.remove("body_nugget");
  an_object.remove("is");
  an_object.remove("attrib");
}
#+END_SRC

*** hub: native header start                                          :hub:

#+name: ao_markup_header_extract_native
#+BEGIN_SRC d
private auto headerNativeToAA(Hn)(Hn src_header) {
  debug(asserts){
    static assert(is(typeof(src_header) == char[]));
  }
  auto type = flags_type_init;
  type = [
   "header"          : State.off,
   "header_make"     : State.off,
   "header_meta"     : State.off,
  ];
  string[string] an_object;
  int[string] line_occur;
  auto dochead_make = make_aa;
  auto dochead_meta = meta_aa;
  auto set_header = HeaderDocMetadataAndMakeNativeToAA();
  char[][] source_header_arr =
    split(cast(char[]) src_header, rgx.newline_eol_delimiter);
  foreach(header_line; source_header_arr) {
    if (auto m = matchFirst(header_line, rgx.comment)) {
      /+ matched comment +/
      debug(comment) {
      }
      header_reset_states_common(line_occur, an_object, type);
    } else if ((matchFirst(header_line, rgx.native_header))
    || (type["header_make"] == State.on
    && (line_occur["header_make"] > State.off))
    || (type["header_meta"] == State.on
    && (line_occur["header_meta"] > State.off))) {
      if (header_line.length == 0) {
        /+ header_make instructions (current line empty) +/
        auto dochead_metadata_and_make =
          set_header.header_metadata_and_make_aa(strip(an_object["body_nugget"]), dochead_meta, dochead_make);
        static assert(!isTypeTuple!(dochead_metadata_and_make));
        dochead_meta = dochead_metadata_and_make[0];
        dochead_make = dochead_metadata_and_make[1];
        header_reset_states_common(line_occur, an_object, type);
        type["header_make"] = State.off;
        type["header_meta"] = State.off;
        debug(headersdlang) {
          writeln(dochead_metadata_and_make);
        }
      } else {
        an_object = native_header_extract(header_line, line_occur, an_object, type);
      }
    }
  }
  auto t = tuple(
    dochead_make,
    dochead_meta,
  );
  return t;
}
#+END_SRC

** b. header sdlang                                              :header:sdl:
*** sdlang header parse and extract root Tag              :sdlang:root:tag:

#+name: ao_conf_make_meta_sdl
#+BEGIN_SRC d
final private auto headerMakeSDLang(Hs)(Hs src_header) {
  debug(asserts){
    static assert(is(typeof(src_header) == string));
  }
  scope(failure) {
    stderr.writefln(
      "%s\n%s\n%s:%s failed here:\n  src_header: %s",
      __MODULE__, __FUNCTION__,
      __FILE__, __LINE__,
      src_header,
    );
  }
  Tag sdl_root_header;
  try {
    sdl_root_header = parseSource(src_header);
  }
  catch(ParseException e) {
    stderr.writeln("SDLang problem with this document header:");
    stderr.writeln(src_header);
    // Error messages of the form:
    // myFile.sdl(5:28): Error: Invalid integer suffix.
    stderr.writeln(e.msg);
  }
  debug(sdlang) {
    writeln("header SDL:");
    writeln(sdl_root_header.toSDLDocument());
  }
  return sdl_root_header;
}
#+END_SRC

*** sdlang header get                                      :sdlang:get:src:

#+name: ao_conf_make_meta_sdl
#+BEGIN_SRC d
private auto headerSDLangGet(Hs)(Hs src_header) {
  debug(asserts){
    static assert(is(typeof(src_header) == char[]));
  }
  char[][] source_header_arr =
    split(cast(char[]) src_header, rgx.newline_eol_delimiter);
  char[] header_clean;
  // TODO
  foreach(header_line; source_header_arr) {
    if (!match(header_line, rgx.comments)) {
      header_clean ~= header_line ~ "\n";
    }
  }
  /+ get sdlang tags +/
  auto header_sdlang=headerMakeSDLang(to!string(header_clean));
  debug(sdlang) {
    writeln("--------------");
    stdout.rawWrite( header_sdlang.toSDLDocument() );
    writeln("--------------");
    Value test = header_sdlang.tags["title"][0].values[0];
    assert(test == typeid(string));
    writeln(header_sdlang.maybe.tags["title"]);
    writeln(header_sdlang.maybe.tags["title"][0].maybe.attributes["subtitle"]);
  }
  return header_sdlang; // sdlang.ast.Tag
}
#+END_SRC

*** sdlang header to associative array make sdlTag in              :sdlang:aa:

#+name: ao_conf_make_meta_sdl
#+BEGIN_SRC d
private auto headerSDLangToAAmake(Tag,Ma)(Tag header_sdlang, Ma dochead_make) {
  debug(asserts){
    static assert(is(typeof(dochead_make) == string[string][string]));
  }
  dochead_make = sdlangToAAmake(dochead_make, header_sdlang);
  auto dochead_meta = sdlangToAAmake(meta_aa, header_sdlang);
  if (dochead_meta["title"]["main"].empty) {
    dochead_meta["title"]["main"] =
      to!string(header_sdlang.maybe.tags["title"][0].values[0]); // test that this exists
  }
  if (!(dochead_meta["title"]["subtitle"].empty)
  && (dochead_meta["title"]["sub"].empty)) {
    dochead_meta["title"]["sub"] ~= dochead_meta["title"]["subtitle"];
  }
  dochead_meta["title"].remove("subtitle");
  if (dochead_meta["title"]["sub"].empty) {
    dochead_meta["title"]["full"] ~= dochead_meta["title"]["main"];
  } else {
    dochead_meta["title"]["full"] ~= format(
      "%s - %s",
      dochead_meta["title"]["main"],
      dochead_meta["title"]["sub"],
    );
  }
  dochead_meta["creator"]["author_raw"] = dochead_meta["creator"]["author"];
  string[] authors_arr;
  auto authors_raw_arr = split(dochead_meta["creator"]["author"], rgx.arr_delimiter);
  foreach (author_raw; authors_raw_arr) {
    authors_arr ~= replace(author_raw, rgx.raw_author_munge, "$2 $1");
  }
  dochead_meta["creator"]["author"] = join(authors_arr, ", ").chomp.chomp;
  auto t = tuple(dochead_make, dochead_meta);
  static assert(t.length==2);
  return t;
}
#+END_SRC

*** hub: get sdlang header and convert to associative array :hub:sdlang:aa:

#+name: ao_conf_make_meta_sdl
#+BEGIN_SRC d
private auto headerSDLangToAA(Hs,Ma)(Hs header_sdlang_src, Ma conf_doc_make_aa) {
  debug(asserts){
    static assert(is(typeof(header_sdlang_src) == char[]));
    static assert(is(typeof(conf_doc_make_aa) == string[string][string]));
  }
  auto header_sdlang_tag = headerSDLangGet(header_sdlang_src); // sdlang.ast.Tag
  auto header_aa_tuple = headerSDLangToAAmake(header_sdlang_tag, conf_doc_make_aa);
  return header_aa_tuple;
}
#+END_SRC