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
|
#############################################################################
##
#W getdtd.g GAPDoc Frank Lübeck
##
##
#Y Copyright (C) 2000, Frank Lübeck, Lehrstuhl D für Mathematik,
#Y RWTH Aachen
##
## This is a utility file for the GAPDoc package, which reads
## gapdoc.dtd, creates the content of `GAPDOCDTDINFO' and writes it to
## `GAPDocDtdInfo.g'. (Because we don't have a dtd-parser.)
##
## This is not read by the package and only used when gapdoc.dtd is
## changed.
##
#Revision.getdtd.g :=
# some hacks instead of writing a dtd-parser
dtd := StringFile("gapdoc.dtd");;
pos := PositionSublist(dtd, "<!ELEMENT");
elementdecs := [];
while pos <> fail do
pos2 := Position(dtd, '>', pos);
Add(elementdecs, dtd{[pos+10..pos2-1]});
pos := pos2;
pos := PositionSublist(dtd, "<!ELEMENT", pos);
od;
elements := [];
elementcontents := rec();
for a in elementdecs do
wds := WordsString(a);
Add(elements, wds[1]);
elementcontents.(wds[1]) := Set(wds{[2..Length(wds)]});
od;
pos := PositionSublist(dtd, "% InnerText");
pos2 := Position(dtd, '>', pos);
innertxt := WordsString(dtd{[pos+13..pos2]});
txt := Concatenation(innertxt, [ "Enum", "List", "Table" ]);
ssent := [ "Subsection", "ManSection" ];
for x in elements do
if "InnerText" in elementcontents.(x) then
elementcontents.(x) :=
Concatenation(Difference(elementcontents.(x), ["InnerText"]), innertxt);
fi;
if "Text" in elementcontents.(x) then
elementcontents.(x) :=
Set(Concatenation(Difference(elementcontents.(x), ["Text"]), txt));
fi;
if "SubsectionEnt" in elementcontents.(x) then
elementcontents.(x) :=
Set(Concatenation(Difference(elementcontents.(x), ["SubsectionEnt"]),
ssent));
fi;
od;
pos := PositionSublist(dtd, "<!ATTLIST");
elementatts := [];
while pos <> fail do
pos2 := Position(dtd, '>', pos);
Add(elementatts, dtd{[pos+10..pos2-1]});
pos := pos2;
pos := PositionSublist(dtd, "<!ATTLIST", pos);
od;
elementattributes := rec();
for a in elementatts do
wds := WordsString(a);
elementattributes.(wds[1]) := wds{[2..Length(wds)]};
od;
DTDINFO := [];
for x in elements do
rr := rec(name := x);
atr := [];
ati := [];
if IsBound(elementattributes.(x)) then
a := elementattributes.(x);
for i in [1..Length(a)-2] do
if not a[i] in ["IMPLIED","REQUIRED","CDATA"] then
jj := i+2;
while not a[jj] in ["IMPLIED","REQUIRED"] do
jj := jj+1;
od;
if a[jj] = "IMPLIED" then
Add(ati, a[i]);
fi;
if a[jj] = "REQUIRED" then
Add(atr, a[i]);
fi;
fi;
od;
fi;
rr.attr := Set(Concatenation(ati, atr));
rr.reqattr := Set(atr);
a := elementcontents.(x);
if "PCDATA" in a then
rr.type := "mixed";
elif "EMPTY" in a then
rr.type := "empty";
else
rr.type := "elements";
fi;
if rr.type in ["mixed", "elements"] then
rr.content := a;
fi;
Add(DTDINFO, rr);
od;
PrintTo("GAPDocDtdInfo.g","GAPDOCDTDINFO:=",DTDINFO,";\n");
s:=StringFile("GAPDocDtdInfo.g");
s:=Filtered(s, x-> not x in WHITESPACE);
Add(s,'\n');
FileString("GAPDocDtdInfo.g",s);
Read("GAPDocDtdInfo.g");
Print(GAPDOCDTDINFO);
|