:- compiler_options([ciao_directives]). :- export rewrite_command/4. :- import error_message/2, list_concat/2,xsbdoc_warning/1 from ciaoaux. :- import member/2 from basics. :- import typeindex/5, texinfo_escape_ats_etc/2 from autodocformats. :- import rewrite_docstring/4 from autodoc. %% --------------------------------------------------------------------------- :- comment(rewrite_command(Format,Command,Indices,NewCommand), "Defines the translation between the special commands which can appear in strings inside assertions and the formatting target. @var{Indices} is a list of index names (the indices to be generated)."). :- pred rewrite_command(Format,Command,Indices,NewCommand) : (Format=texinfo,stringcommand(Command), list(Indices,atom)) => string(NewCommand) # "Defines the translation between the special commands which can appear in strings inside assertions and texinfo.". %% --------------------------------------------------------------------------- %% Commands with special translation %% Concept definition index entry rewrite_command(texinfo,A,B,C):- rewrite_texinfo_command(A,B,C). ascii_blank_lines(0,"") :- !. ascii_blank_lines(N,[0'\n | R]) :- N1 is N-1, ascii_blank_lines(N1,R). %% --------------------------------------------------------------------------- :- pred rewrite_command(Format,Command,Indices,NewCommand) : (Format=html,stringcommand(Command), list(Indices,atom)) => string(NewCommand) # "Defines the translation between the special commands which can appear in strings inside assertions and html. This is still somewhat incomplete.". %% --------------------------------------------------------------------------- rewrite_command(html,A,B,C):- rewrite_html_command(A,B,C). html_blank_lines(0,"") :- !. html_blank_lines(N,[0'<,0'B,0'R,0'>,0' |R]) :- N1 is N-1, html_blank_lines(N1,R). %% --------------------------------------------------------------------------- :- pred rewrite_command(Format,Command,Indices,NewCommand) : (Format=ascii,stringcommand(Command), list(Indices,atom)) => string(NewCommand) # "Defines the translation between the special commands which can appear in strings inside assertions and ascii.". %% --------------------------------------------------------------------------- rewrite_command(ascii,A,B,C):- rewrite_ascii_command(A,B,C). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% rewrite_texinfo_command(index(RBody),Indices,NewAll) :- !, rewrite_docstring(texinfo,Indices,RBody,Body), ( ( member(concept,Indices); Indices=[all] ), typeindex(concept,Index,_,_,_) -> list_concat([ "\n@", Index, " ", Body ], T0 ) ; T0 = [] ), ( ( member(global,Indices); Indices=[all] ), typeindex(global,UIndex,_,_,_) -> list_concat([ T0, "\n@", UIndex, " ", Body ], T1) ; T1 = T0), list_concat([ T1,"\n@emph{", Body, "}" ], NewAll). %% Concept definition index entry (NOT including the body in-line) rewrite_texinfo_command(cindex(RBody),Indices,NewAll) :- !, rewrite_docstring(texinfo,Indices,RBody,Body), ( ( member(concept,Indices); Indices=[all] ), typeindex(concept,Index,_,_,_) -> list_concat([ "\n@", Index, " ", Body ], T0 ) ; T0 = [] ), ( ( member(global,Indices); Indices=[all] ), typeindex(global,UIndex,_,_,_) -> list_concat([ T0, "\n@", UIndex, " ", Body ], T1) ; T1 = T0), list_concat([ T1, "\n" ], NewAll). %% Reference to concept (NOT emphasized, goes only to global) rewrite_texinfo_command(concept(RBody),Indices,NewAll) :- !, %% Concepts should appear only once in the concept index rewrite_docstring(texinfo,Indices,RBody,Body), ( ( member(global,Indices); Indices=[all] ), typeindex(global,UIndex,_,_,_) -> list_concat([ "\n@", UIndex, " ", Body ], T0) ; T0 = []), list_concat([ T0, "\n", Body ], NewAll). %% Predicate/Application/Property/Type/Operator/Library/File/etc. references rewrite_texinfo_command(Command,Indices,NewAll) :- Command =.. [Type,RBody], codetype(Type), !, rewrite_docstring(texinfo,Indices,RBody,Body), ( ( member(global,Indices); Indices=[all] ), typeindex(global,UIndex,_,_,_) -> list_concat([ "\n@", UIndex, " ", Body, "\n" ],T1) ; T1 = []), list_concat( [ T1, "@code{", Body, "}" ], NewAll). rewrite_texinfo_command(section(RBody),Indices,NewAll) :- !, rewrite_docstring(texinfo,Indices,RBody,Body), list_concat([ "\n\n@node ", Body, ", next, previous, up", "\n@comment node-name, next, previous, up", "\n@section ", Body, "\n" ], NewAll). rewrite_texinfo_command(subsection(RBody),Indices,NewAll) :- !, rewrite_docstring(texinfo,Indices,RBody,Body), list_concat([ "\n\n@node ", Body, ", next, previous, up", "\n@comment node-name, next, previous, up", "\n@subsection ", Body, "\n" ], NewAll). %% Other commands with special translation rewrite_texinfo_command(sp(NS),_,NewCommand) :- !, list_concat([ "\n@sp ", NS, "\n" ], NewCommand). rewrite_texinfo_command(p(""),_,"\n\n") :- !. rewrite_texinfo_command(noindent(""),_,"\n@noindent\n") :- !. rewrite_texinfo_command(begin("itemize"),_,"\n@itemize @bullet{}\n") :- !. rewrite_texinfo_command(begin("enumerate"),_,"\n@enumerate \n") :- !. rewrite_texinfo_command(begin("description"),_,"\n@table @asis\n") :- !. rewrite_texinfo_command(begin("cartouche"),_,"\n@cartouche \n") :- !. rewrite_texinfo_command(item(""),_,"\n@item ") :- !. rewrite_texinfo_command(item(S),Indices,NewCommand) :- !, rewrite_docstring(texinfo,Indices,S,NS), list_concat([ "\n@item ", NS, "\n" ], NewCommand). rewrite_texinfo_command('}',_,"@}") :- !. rewrite_texinfo_command('{',_,"@{") :- !. rewrite_texinfo_command('@',_,"@@") :- !. rewrite_texinfo_command(end("itemize"),_,"\n@end itemize \n") :- !. rewrite_texinfo_command(end("enumerate"),_,"\n@end enumerate \n") :- !. rewrite_texinfo_command(end("description"),_,"\n@end table \n") :- !. rewrite_texinfo_command(end("cartouche"),_,"\n@end cartouche \n") :- !. rewrite_texinfo_command(begin("verbatim"),_,"\n@smallexample ") :- !. %% Was: (but this tended to insert extra blank line at the end of an example) %% rewrite_texinfo_command(end("verbatim"),_,"\n@end smallexample \n") :- !. rewrite_texinfo_command(end("verbatim"),_,"@end smallexample \n") :- !. rewrite_texinfo_command(today(""),_,"@today ") :- !. % rewrite_texinfo_command(hfill(""),_,"\n@iftex\n@hfill \n@end iftex\n") :- !. rewrite_texinfo_command(hfill(""),_,"@hfill ") :- !. rewrite_texinfo_command(iso(""),_,"@key{ @bullet{} ISO @bullet{} }") :- !. %% Special body: escape @s! rewrite_texinfo_command(includeverbatim(Body),_,NBody) :- !, texinfo_escape_ats_etc(Body,NBody). rewrite_texinfo_command('`'([X]),_,[0'@,0'`,X]) :- !. %% Special case for i rewrite_texinfo_command(''''("i"),_,"@\'{@dotless{i}}") :- !. rewrite_texinfo_command(''''([X]),_,[0'@,0'\',X]) :- !. rewrite_texinfo_command('^'([X]),_,[0'@,0'^,X]) :- !. rewrite_texinfo_command('..'([X]),_,[0'@,0'",X]) :- !. rewrite_texinfo_command('~'([X]),_,[0'@,0'~,X]) :- !. rewrite_texinfo_command('='([X]),_,[0'@,0'=,X]) :- !. rewrite_texinfo_command(uref(URL),_,NBody) :- !, list_concat([ "@uref{", URL, "}" ], NBody). rewrite_texinfo_command(uref(Text,URL),Indices,NBody) :- !, rewrite_docstring(texinfo,Indices,Text,RText), list_concat([ "@uref{", URL, ",", RText, "}" ],NBody). rewrite_texinfo_command(email(Address),_,NBody) :- !, list_concat([ "@email{", Address, "}" ],NBody). rewrite_texinfo_command(email(Text,Address),Indices,NBody) :- !, rewrite_docstring(texinfo,Indices,Text,RText), list_concat( [ "@email{", Address, ",", RText, "}" ],NBody). rewrite_texinfo_command(image(IFile),_,NBody) :- !, list_concat( [ "@image{", IFile, "}" ], NBody). rewrite_texinfo_command(image(IFile,Width,Height),_,NBody) :- !, list_concat( [ "@image{", IFile, ",", Width, "pt,", Height, "pt}" ], NBody). %% Commands with a more or less direct translation to a texinfo command rewrite_texinfo_command(Command,Indices,NewAll) :- rewrite_command_body_texinfo(Command,NewCommand,RBody), rewrite_docstring(texinfo,Indices,RBody,NewBody), !, list_concat( [ "@", NewCommand, "{", NewBody, "}" ], NewAll). rewrite_texinfo_command(Command,_Indices,Command) :- error_message("could not rewrite command ~w into texinfo format",[Command]), fail. rewrite_command_body_texinfo(footnote(Body),"footnote",Body) :- !. rewrite_command_body_texinfo(bf(Body),"strong",Body) :- !. rewrite_command_body_texinfo(em(Body),"emph",Body) :- !. rewrite_command_body_texinfo(tt(Body),"code",Body) :- !. rewrite_command_body_texinfo(key(Body),"key",Body) :- !. %% A variable in a program rewrite_command_body_texinfo(var(Body),"code",Body) :- !. rewrite_command_body_texinfo(ref(Body),"ref",Body) :- !. %% Accents, etc. rewrite_command_body_texinfo('.'([X]),"dotaccent",[X]) :- !. rewrite_command_body_texinfo('u'([X]),"u",[X]) :- !. rewrite_command_body_texinfo('v'([X]),"v",[X]) :- !. rewrite_command_body_texinfo('H'([X]),"H",[X]) :- !. rewrite_command_body_texinfo('t'([X,Y]),"tieaccent",[X,Y]) :- !. rewrite_command_body_texinfo('c'([X]),",",[X]) :- !. rewrite_command_body_texinfo('d'([X]),"udotaccent",[X]) :- !. rewrite_command_body_texinfo('b'([X]),"ubaraccent",[X]) :- !. rewrite_command_body_texinfo('oe'(""),"oe","") :- !. rewrite_command_body_texinfo('OE'(""),"OE","") :- !. rewrite_command_body_texinfo('ae'(""),"ae","") :- !. rewrite_command_body_texinfo('AE'(""),"AE","") :- !. rewrite_command_body_texinfo('aa'(""),"aa","") :- !. rewrite_command_body_texinfo('AA'(""),"AA","") :- !. rewrite_command_body_texinfo('o'(""), "o" ,"") :- !. rewrite_command_body_texinfo('O'(""), "O" ,"") :- !. rewrite_command_body_texinfo('l'(""), "l" ,"") :- !. rewrite_command_body_texinfo('L'(""), "L" ,"") :- !. rewrite_command_body_texinfo('ss'(""),"ss","") :- !. rewrite_command_body_texinfo('?'(""), "questiondown" ,"") :- !. rewrite_command_body_texinfo('!'(""), "exclamdown" ,"") :- !. rewrite_command_body_texinfo('i'(""), "dotless" ,"i") :- !. rewrite_command_body_texinfo('j'(""), "dotless" ,"j") :- !. rewrite_command_body_texinfo(copyright(""), "copyright" ,"") :- !. rewrite_command_body_texinfo(bullet(""), "bullet" ,"") :- !. rewrite_command_body_texinfo(result(""), "result" ,"") :- !. rewrite_command_body_texinfo(Command,CommandNameS,Body) :- Command =.. [CommandName,Body], atom_codes(CommandName,CommandNameS), xsbdoc_warning(['unrecognized command in string (passed on): ', CommandName,Body]). %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %% Concept definition index entry: handled below, with em(...) %% rewrite_command(html,index(Body),_,Body) :- %% !. %% Concept definition index entry (NOT including the body in-line) rewrite_html_command(cindex(_Body),_,"") :- !. %% Reference to concept (NOT emphasized, goes only to global) rewrite_html_command(concept(Body),_,Body) :- !. %% Predicate/Application/Property/Type/Operator/Library/File/etc. references rewrite_html_command(Command,Indices,NewAll) :- Command =.. [Type,RBody], codetype(Type), !, rewrite_docstring(html,Indices,RBody,Body), list_concat([ "", Body, "" ], NewAll). rewrite_html_command(subsection(RBody),Indices,NewAll) :- !, rewrite_docstring(html,Indices,RBody,Body), list_concat([ "

", Body, "

\n" ],NewAll). rewrite_html_command(section(RBody),Indices,NewAll) :- !, rewrite_docstring(html,Indices,RBody,Body), list_concat([ "

", Body, "

\n" ],NewAll). %% Other commands with special translation rewrite_html_command(sp(NS),_,NewCommand) :- !, number_codes(N,NS), N1 is N+1, html_blank_lines(N1,NewCommand). rewrite_html_command(p(""),_,"

") :- !. rewrite_html_command(noindent(""),_,"") :- !. rewrite_html_command(begin("itemize"),_,"