Skip to content
Snippets Groups Projects
Commit 7b5b5794 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

Sgml imported

Rev: tutorial/Wmml.pmod:1.7
parent de2a5803
No related branches found
No related tags found
No related merge requests found
#include "types.h" #include "types.h"
impoert Sgml;
static private int verify_any(SGML data, string in) static private int verify_any(SGML data, string in)
{ {
...@@ -239,7 +240,7 @@ multiset reserved_c = ...@@ -239,7 +240,7 @@ multiset reserved_c =
"void","while" "void","while"
>); >);
object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved) object(Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
{ {
int p,e; int p,e;
int tabindented=-1; int tabindented=-1;
...@@ -273,9 +274,9 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved) ...@@ -273,9 +274,9 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
string id=x[p..--e]; string id=x[p..--e];
if(reserved[id]) if(reserved[id])
ret+=({ Sgml.Tag("ex_keyword",([]), pos+e, ({ id }) ) }); ret+=({ Tag("ex_keyword",([]), pos+e, ({ id }) ) });
else else
ret+=({ Sgml.Tag("ex_identifier",([]), pos+e, ({ id }) ) }); ret+=({ Tag("ex_identifier",([]), pos+e, ({ id }) ) });
break; break;
} }
...@@ -285,7 +286,7 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved) ...@@ -285,7 +286,7 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
while(x[++e]!='\'') while(x[++e]!='\'')
if(x[e]=='\\') if(x[e]=='\\')
e++; e++;
ret+=({ Sgml.Tag("ex_string",([]), pos+e, ({ x[p..e]}) ) }); ret+=({ Tag("ex_string",([]), pos+e, ({ x[p..e]}) ) });
break; break;
case '"': case '"':
...@@ -294,12 +295,12 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved) ...@@ -294,12 +295,12 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
if(x[e]=='\\') if(x[e]=='\\')
e++; e++;
ret+=({ Sgml.Tag("ex_string",([]), pos+e, ({ x[p..e] }) ) }); ret+=({ Tag("ex_string",([]), pos+e, ({ x[p..e] }) ) });
break; break;
case '\n': case '\n':
if(tabindented!=-1) if(tabindented!=-1)
ret+=({ Sgml.Tag("ex_br", ([]), pos+e) }); ret+=({ Tag("ex_br", ([]), pos+e) });
if(tabindented) if(tabindented)
{ {
...@@ -320,17 +321,17 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved) ...@@ -320,17 +321,17 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
while(x[e+1..e+1]=="\t") while(x[e+1..e+1]=="\t")
{ {
ret+=({ ret+=({
Sgml.Tag("ex_indent", ([]), pos+e), Tag("ex_indent", ([]), pos+e),
Sgml.Tag("ex_indent", ([]), pos+e), Tag("ex_indent", ([]), pos+e),
Sgml.Tag("ex_indent", ([]), pos+e), Tag("ex_indent", ([]), pos+e),
Sgml.Tag("ex_indent", ([]), pos+e), Tag("ex_indent", ([]), pos+e),
}); });
e++; e++;
} }
while(x[e+1..e+2]==" ") while(x[e+1..e+2]==" ")
{ {
ret+=({ Sgml.Tag("ex_indent", ([]), pos+e) }); ret+=({ Tag("ex_indent", ([]), pos+e) });
e+=2; e+=2;
} }
break; break;
...@@ -341,7 +342,7 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved) ...@@ -341,7 +342,7 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
p=e++; p=e++;
while(x[e]!='\n') e++; while(x[e]!='\n') e++;
e--; e--;
ret+=({ Sgml.Tag("ex_comment",([]), pos+e, ({ x[p..e]}) ) }); ret+=({ Tag("ex_comment",([]), pos+e, ({ x[p..e]}) ) });
break; break;
} }
...@@ -350,7 +351,7 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved) ...@@ -350,7 +351,7 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
p=e++; p=e++;
while(x[e..e+1]!="*/") e++; while(x[e..e+1]!="*/") e++;
e++; e++;
ret+=({ Sgml.Tag("ex_comment",([]), pos+e, ({ x[p..e]}) ) }); ret+=({ Tag("ex_comment",([]), pos+e, ({ x[p..e]}) ) });
break; break;
} }
...@@ -361,17 +362,27 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved) ...@@ -361,17 +362,27 @@ object(Sgml.Tag) parse_pike_code(string x, int pos, multiset(string) reserved)
ret+=({ "" }); ret+=({ "" });
} }
return Sgml.Tag("example",([]),pos,ret); return Tag("example",([]),pos,ret);
} }
string classbase;
string name_to_link(string x) string name_to_link(string x)
{ {
return replace(x,({"->","->"}),({".","."})); return replace(x,({"->","->"}),({".","."}));
} }
SGML make_concrete_wmml(SGML data) SGML metadata=({});
class Wmml
{
SGML metadata;
SGML toc_data;
SGML index_data;
SGML data;
};
SGML low_make_concrete_wmml(SGML data,
string classbase,
string *current)
{ {
if(!data) return 0; if(!data) return 0;
SGML ret=({}); SGML ret=({});
...@@ -384,32 +395,47 @@ SGML make_concrete_wmml(SGML data) ...@@ -384,32 +395,47 @@ SGML make_concrete_wmml(SGML data)
}else{ }else{
switch(tag->tag) switch(tag->tag)
{ {
case "head":
metadata+=tag->data;
continue;
case "include": case "include":
ret+=make_concrete_wmml(Sgml.group(Sgml.lex(Stdio.read_file(tag->params->file),tag->params->file))); {
string filename=tag->params->file;
SGML tmp=group(lex(Stdio.read_file(filename),filename));
ret+=low_make_concrete_wmml(tmp,classbase);
continue; continue;
}
case "section":
case "chapter": case "chapter":
case "preface": case "preface":
case "introduction": case "introduction":
case "section":
case "table":
case "appendix": case "appendix":
switch(tag->t)
{
tag->params->number=current*".";
current[-1]=(string)(1+(int)current[-1]);
}
case "table":
case "image": case "image":
case "illustration": case "illustration":
if(tag->params->name) if(tag->params->name)
{ {
TAG t=Sgml.Tag(tag->tag, TAG t=Tag(tag->tag,
tag->params, tag->params,
tag->pos, tag->pos,
tag->data=make_concrete_wmml(tag->data), tag->data=low_make_concrete_wmml(tag->data,
current,
classbase),
tag->file); tag->file);
ret+=({ ret+=({
Sgml.Tag("anchor", Tag("anchor",
(["name":tag->params->name,"type":tag->tag]), (["name":tag->params->name,"type":tag->tag]),
tag->pos, tag->pos,
({ ({ t }))
t
}))
}); });
continue; continue;
} }
...@@ -426,8 +452,8 @@ SGML make_concrete_wmml(SGML data) ...@@ -426,8 +452,8 @@ SGML make_concrete_wmml(SGML data)
classbase+="."+tag->params->name; classbase+="."+tag->params->name;
} }
ret+=({ ret+=({
Sgml.Tag("anchor",(["name":classbase,"type":tag->tag]),tag->pos, Tag("anchor",(["name":classbase,"type":tag->tag]),tag->pos,
make_concrete_wmml(tag->data)) low_make_concrete_wmml(tag->data))
}); });
classbase=tmp; classbase=tmp;
continue; continue;
...@@ -448,19 +474,19 @@ SGML make_concrete_wmml(SGML data) ...@@ -448,19 +474,19 @@ SGML make_concrete_wmml(SGML data)
case "nb": title="nota bene"; break; case "nb": title="nota bene"; break;
case "syntax": case "syntax":
case "example": case "example":
args=({Sgml.Tag("tt",([]),tag->pos,tag->data)}); args=({Tag("tt",([]),tag->pos,tag->data)});
break; break;
case "see": case "see":
{ {
title="see also"; title="see also";
SGML tmp=({}); SGML tmp=({});
foreach(replace(Sgml.get_text(args),({" ","\n"}),({"",""}))/",",string name) foreach(replace(get_text(args),({" ","\n"}),({"",""}))/",",string name)
{ {
tmp+=({ tmp+=({
Sgml.Tag("link",(["to":name_to_link(name)]),tag->pos, Tag("link",(["to":name_to_link(name)]),tag->pos,
({ ({
Sgml.Tag("tt",([]),tag->pos,({name})), Tag("tt",([]),tag->pos,({name})),
})), })),
", " ", "
}); });
...@@ -474,9 +500,9 @@ SGML make_concrete_wmml(SGML data) ...@@ -474,9 +500,9 @@ SGML make_concrete_wmml(SGML data)
} }
} }
title=upper_case(title); title=upper_case(title);
ret+=make_concrete_wmml( ret+=low_make_concrete_wmml(
({ ({
Sgml.Tag("man_title",(["title":title]),tag->pos,args), Tag("man_title",(["title":title]),tag->pos,args),
})); }));
continue; continue;
} }
...@@ -494,15 +520,15 @@ SGML make_concrete_wmml(SGML data) ...@@ -494,15 +520,15 @@ SGML make_concrete_wmml(SGML data)
fullname=classbase+"."+tag->params->name; fullname=classbase+"."+tag->params->name;
break; break;
} }
ret+=make_concrete_wmml(({ ret+=low_make_concrete_wmml(({
Sgml.Tag("anchor",(["name":name_to_link(fullname), Tag("anchor",(["name":name_to_link(fullname),
"type":"method",]),tag->pos, "type":"method",]),tag->pos,
({ ({
Sgml.Tag("dl",([]),tag->pos, Tag("dl",([]),tag->pos,
({ ({
Sgml.Tag("man_title",(["title":upper_case(tag->tag)]),tag->pos, Tag("man_title",(["title":upper_case(tag->tag)]),tag->pos,
({ ({
Sgml.Tag("tt",([]),tag->pos,({fullname})), Tag("tt",([]),tag->pos,({fullname})),
" - ", " - ",
tag->params->title, tag->params->title,
}) })
...@@ -513,7 +539,7 @@ SGML make_concrete_wmml(SGML data) ...@@ -513,7 +539,7 @@ SGML make_concrete_wmml(SGML data)
) )
})), })),
"\n", "\n",
Sgml.Tag("hr"), Tag("hr"),
})); }));
continue; continue;
} }
...@@ -534,10 +560,10 @@ SGML make_concrete_wmml(SGML data) ...@@ -534,10 +560,10 @@ SGML make_concrete_wmml(SGML data)
continue; continue;
} }
} }
ret+=({Sgml.Tag(tag->tag, ret+=({Tag(tag->tag,
tag->params, tag->params,
tag->pos, tag->pos,
make_concrete_wmml(tag->data), low_make_concrete_wmml(tag->data),
tag->file)}); tag->file)});
} }
} }
...@@ -708,7 +734,7 @@ static private SGML low_collect_toc(mixed *data, ...@@ -708,7 +734,7 @@ static private SGML low_collect_toc(mixed *data,
t->params->number=prefix+(string)current[-1]; t->params->number=prefix+(string)current[-1];
ret+=({ ret+=({
Sgml.Tag("section_toc", Tag("section_toc",
t->params, t->params,
t->pos, t->pos,
low_collect_toc(t->data, low_collect_toc(t->data,
...@@ -724,7 +750,7 @@ static private SGML low_collect_toc(mixed *data, ...@@ -724,7 +750,7 @@ static private SGML low_collect_toc(mixed *data,
t->params->number=(string)chapters; t->params->number=(string)chapters;
ret+=({ ret+=({
Sgml.Tag("chapter_toc", Tag("chapter_toc",
t->params, t->params,
t->pos, t->pos,
low_collect_toc(t->data, low_collect_toc(t->data,
...@@ -741,7 +767,7 @@ static private SGML low_collect_toc(mixed *data, ...@@ -741,7 +767,7 @@ static private SGML low_collect_toc(mixed *data,
t->params->number=sprintf("%c",appendices); t->params->number=sprintf("%c",appendices);
ret+=({ ret+=({
Sgml.Tag("appendix_toc", Tag("appendix_toc",
t->params, t->params,
t->pos, t->pos,
low_collect_toc(t->data, low_collect_toc(t->data,
...@@ -758,7 +784,7 @@ static private SGML low_collect_toc(mixed *data, ...@@ -758,7 +784,7 @@ static private SGML low_collect_toc(mixed *data,
t->params->number="preface"; t->params->number="preface";
ret+=({ ret+=({
Sgml.Tag("preface_toc", Tag("preface_toc",
t->params, t->params,
t->pos, t->pos,
low_collect_toc(t->data, low_collect_toc(t->data,
...@@ -774,7 +800,7 @@ static private SGML low_collect_toc(mixed *data, ...@@ -774,7 +800,7 @@ static private SGML low_collect_toc(mixed *data,
t->params->number="introduction"; t->params->number="introduction";
ret+=({ ret+=({
Sgml.Tag("introduction_toc", Tag("introduction_toc",
t->params, t->params,
t->pos, t->pos,
low_collect_toc(t->data, low_collect_toc(t->data,
...@@ -787,7 +813,7 @@ static private SGML low_collect_toc(mixed *data, ...@@ -787,7 +813,7 @@ static private SGML low_collect_toc(mixed *data,
case "table-of-contents": case "table-of-contents":
t->params->number=t->tag; t->params->number=t->tag;
ret+=({ ret+=({
Sgml.Tag(t->tag+"_toc", Tag(t->tag+"_toc",
t->params, t->params,
t->pos) t->pos)
}); });
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment