summaryrefslogtreecommitdiffhomepage
path: root/dlang/src/read/report_unknown.d
blob: 2f817020d80b38b33cde6f751feed047d76a2cbb (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
module read.report_unknown;

import std.algorithm : sort;
import std.array : array;
import std.stdio : writeln, writefln;
import ocda.model;

/+ ↓ say what was read and not understood.
     This is what makes the reader usable as a check on the format
     specification: a reader that ignores what it does not know is
     conforming, but one that cannot say what it ignored cannot tell you
     whether the specification it was written from was complete. Silence
     and understanding look the same from outside.
+/
void reportUnknown(ref OcdaDocument doc) {
  if (!doc.unknown.any) {
    writeln("\nread and understood: every property, block and line was known");
    return;
  }
  writeln("\nread and NOT understood:");
  if (doc.unknown.property.length > 0) {
    writeln("  properties ignored (", doc.unknown.property.length, " distinct):");
    foreach (name; doc.unknown.property.keys.sort) {
      writefln("    .%-26s %8d", name, doc.unknown.property[name]);
    }
  }
  if (doc.unknown.block.length > 0) {
    writeln("  blocks ignored (", doc.unknown.block.length, " distinct):");
    foreach (name; doc.unknown.block.keys.sort) {
      writefln("    @%-26s %8d", name, doc.unknown.block[name]);
    }
  }
  if (doc.unknown.line.length > 0) {
    writeln("  lines of no known shape, by first character:");
    foreach (c; doc.unknown.line.keys.sort) {
      writefln("    %-27s %8d", "\"" ~ c ~ "\"", doc.unknown.line[c]);
    }
  }
  writeln("  (ignoring these is conforming within a major version;",
    " the count is so that it is not silent)");
}