docs and strings
This commit is contained in:
parent
e315217f0e
commit
f6c5a2eea1
@ -1,86 +1,104 @@
|
||||
/* xml.pl : XML Module wrapper for Quintus Prolog.
|
||||
*
|
||||
* Copyright (C) 2001-2005 Binding Time Limited
|
||||
* Copyright (C) 2005-2011 John Fletcher
|
||||
*
|
||||
* Current Release: $Revision: 3.3 $
|
||||
*
|
||||
* TERMS AND CONDITIONS:
|
||||
*
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*
|
||||
*/
|
||||
:- module( xml,
|
||||
[
|
||||
xml_parse/2,
|
||||
xml_parse/3,
|
||||
xml_subterm/2,
|
||||
xml_pp/1
|
||||
] ).
|
||||
|
||||
/* xml is intended to be a rather modular module: it should be easy to
|
||||
* build a program that can output XML, but not read it, or vice versa.
|
||||
* Similarly, you may be happy to dispense with diagnosis once you are
|
||||
* sure that your code will only try to make valid calls to xml_parse/2.
|
||||
*
|
||||
* It is intended that the code should be very portable too. Clearly,
|
||||
* some small changes will be needed between platforms, but these should
|
||||
* be limited to xml_utilities. xml_utilities contains most of the shared
|
||||
* code and most of the potentially non-portable code.
|
||||
*/
|
||||
/* xml.pl : XML Module wrapper for Quintus Prolog.
|
||||
*
|
||||
* Copyright (C) 2001-2005 Binding Time Limited
|
||||
* Copyright (C) 2005-2011 John Fletcher
|
||||
*
|
||||
* Current Release: $Revision: 3.3 $
|
||||
*
|
||||
* TERMS AND CONDITIONS:
|
||||
*
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*
|
||||
*/
|
||||
:- module( xml,
|
||||
[
|
||||
xml_parse/2,
|
||||
xml_parse/3,
|
||||
xml_subterm/2,
|
||||
xml_pp/1,
|
||||
load_xml/3,
|
||||
load_xml/2
|
||||
] ).
|
||||
|
||||
:- use_module( library(lists), [append/3] ).
|
||||
/* @section xml Prolog XML module
|
||||
* xml is intended to be a rather modular module: it should be easy to
|
||||
* build a program that can output XML, but not read it, or vice versa.
|
||||
* Similarly, you may be happy to dispense with diagnosis once you are
|
||||
* sure that your code will only try to make valid calls to xml_parse/2.
|
||||
*
|
||||
* It is intended that the code should be very portable too. Clearly,
|
||||
* some small changes will be needed between platforms, but these should
|
||||
* be limited to xml_utilities. xml_utilities contains most of the shared
|
||||
* code and most of the potentially non-portable code.
|
||||
*/
|
||||
|
||||
:- use_module( library(lists), [append/3] ).
|
||||
:- use_module( library(readutil) ).
|
||||
|
||||
|
||||
:- ensure_loaded( xml/xml_driver ).
|
||||
:- ensure_loaded( xml/xml_driver ).
|
||||
|
||||
|
||||
|
||||
/* atom_codes/2, number_codes/2 and throw/1 are ISO predicates, mapped to
|
||||
* the Quintus equivalent here.
|
||||
*/
|
||||
%atom_codes( Atom, Codes ) :-
|
||||
% atom_chars( Atom, Codes ).
|
||||
|
||||
%number_codes( Number, Codes ) :-
|
||||
% number_chars( Number, Codes ).
|
||||
|
||||
/* xml_exception( +Message, +Document, +Culprit, +Path ) is a hook to
|
||||
* raise an exception to be raised in respect of a fault in the XML Term:
|
||||
* Document.
|
||||
* - Culprit is a sub-term of Document which cannot be serialized;
|
||||
* - Message is an atom naming the type of error;
|
||||
* - Path is a string encoding a list of SubTerm's ancestor elements in the
|
||||
* form <tag>{(id)}* where <tag> is the element tag and <id> is the value
|
||||
* of any attribute _named_ id.
|
||||
*/
|
||||
xml_exception( Message, Document, Culprit, Path ) :-
|
||||
raise_exception(
|
||||
application_error('XML Parse: ~s in ~q~nCulprit: ~q~nPath: ~s',
|
||||
[Message,Document,Culprit,Path] )
|
||||
).
|
||||
|
||||
/* member( ?Element, ?List ) holds when Element is a member of List.
|
||||
*/
|
||||
member( H, [H|_] ).
|
||||
member( H, [_|T] ):-
|
||||
member( H, T ).
|
||||
|
||||
/* select( ?Element, ?List0, ?List1 ) is true if List1 is equal to List0
|
||||
* with Element removed.
|
||||
*/
|
||||
select( H, [H|T], T ).
|
||||
select( Element, [H|T0], [H|T1] ):-
|
||||
select( Element, T0, T1 ).
|
||||
|
||||
/* is_list( +List ) holds when List is a list.
|
||||
*/
|
||||
%is_list( List ) :-
|
||||
% nonvar( List ),
|
||||
% is_list1( List ).
|
||||
|
||||
%is_list1( [] ).
|
||||
%is_list1( [_|_] ).
|
||||
|
||||
|
||||
/* atom_codes/2, number_codes/2 and throw/1 are ISO predicates, mapped to
|
||||
* the Quintus equivalent here.
|
||||
*/
|
||||
%atom_codes( Atom, Codes ) :-
|
||||
% atom_chars( Atom, Codes ).
|
||||
|
||||
%number_codes( Number, Codes ) :-
|
||||
% number_chars( Number, Codes ).
|
||||
|
||||
/** @pred xml_exception( +Message, +Document, +Culprit, +Path )
|
||||
* a hook to
|
||||
* raise an exception to be raised in respect of a fault in the XML Term:
|
||||
* Document.
|
||||
* - Culprit is a sub-term of Document which cannot be serialized;
|
||||
* - Message is an atom naming the type of error;
|
||||
* - Path is a string encoding a list of SubTerm's ancestor elements in the
|
||||
* form <tag>{(id)}* where <tag> is the element tag and <id> is the value
|
||||
* of any attribute _named_ id.
|
||||
*/
|
||||
xml_exception( Message, Document, Culprit, Path ) :-
|
||||
raise_exception(
|
||||
application_error('XML Parse: ~s in ~q~nCulprit: ~q~nPath: ~s',
|
||||
[Message,Document,Culprit,Path] )
|
||||
).
|
||||
|
||||
load_xml(File, XML, []) :-
|
||||
open( File, read, S),
|
||||
read_stream_to_codes(S, Doc),
|
||||
close(S),
|
||||
xml_parse(Doc, XML).
|
||||
|
||||
load_xml(File, XML) :-
|
||||
open( File, read, S),
|
||||
read_stream_to_codes(S, Doc),
|
||||
close(S),
|
||||
xml_parse(Doc, XML).
|
||||
|
||||
|
||||
/* member( ?Element, ?List ) holds when Element is a member of List.
|
||||
*/
|
||||
member( H, [H|_] ).
|
||||
member( H, [_|T] ):-
|
||||
member( H, T ).
|
||||
|
||||
/* select( ?Element, ?List0, ?List1 ) is true if List1 is equal to List0
|
||||
* with Element removed.
|
||||
*/
|
||||
select( H, [H|T], T ).
|
||||
select( Element, [H|T0], [H|T1] ):-
|
||||
select( Element, T0, T1 ).
|
||||
|
||||
/* is_list( +List ) holds when List is a list.
|
||||
*/
|
||||
%is_list( List ) :-
|
||||
% nonvar( List ),
|
||||
% is_list1( List ).
|
||||
|
||||
%is_list1( [] ).
|
||||
%is_list1( [_|_] ).
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -1,84 +1,87 @@
|
||||
/* xml_diagnosis.pl : XML exception diagnosis.
|
||||
*
|
||||
* Copyright (C) 2001-2005 Binding Time Limited
|
||||
* Copyright (C) 2005-2011 John Fletcher
|
||||
*
|
||||
* Current Release: $Revision: 3.3 $
|
||||
*
|
||||
* TERMS AND CONDITIONS:
|
||||
*
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*/
|
||||
|
||||
:- ensure_loaded( xml_generation ).
|
||||
|
||||
/* xml_fault( +Term, +Indentation, ?SubTerm, ?Path, ?Message ) identifies SubTerm
|
||||
* as a sub-term of Term which cannot be serialized after Indentation.
|
||||
* Message is an atom naming the type of error; Path is a string encoding a
|
||||
* list of SubTerm's ancestor elements in the form <tag>{(id)}* where <tag> is the
|
||||
* element tag and <id> is the value of any attribute _named_ id.
|
||||
*/
|
||||
xml_fault( Term, _Indent, Term, [], "Illegal Variable" ) :-
|
||||
var( Term ).
|
||||
xml_fault( xml(Attributes,_Content), _Indent, Term, [], Message ) :-
|
||||
member( Attribute, Attributes ),
|
||||
attribute_fault( Attribute, Term, Message ).
|
||||
xml_fault( xml(_Attributes,Content), Indent, Culprit, Path, Message ) :-
|
||||
xml_content_fault( Content, Indent, Culprit, Path, Message ).
|
||||
xml_fault( Term, _Indent, Term, [], "Illegal Term" ).
|
||||
|
||||
xml_content_fault( Term, _Indent, Term, [], "Illegal Variable" ) :-
|
||||
var( Term ).
|
||||
xml_content_fault( pcdata(Chars), _Indent, Chars, [], "Invalid Character Data" ) :-
|
||||
\+ is_chars( Chars ).
|
||||
xml_content_fault( cdata(Chars), _Indent, Chars, [], "Invalid Character Data" ) :-
|
||||
\+ is_chars( Chars ).
|
||||
xml_content_fault( [H|_T], Indent, Culprit, Path, Message ) :-
|
||||
xml_content_fault( H, Indent, Culprit, Path, Message ).
|
||||
xml_content_fault( [_H|T], Indent, Culprit, Path, Message ) :-
|
||||
xml_content_fault( T, Indent, Culprit, Path, Message ).
|
||||
xml_content_fault( namespace(_URI,_Prefix,Element), Indent, Culprit, Path, Message ) :-
|
||||
element_fault( Element, [0' |Indent], Culprit, Path, Message ).
|
||||
xml_content_fault( Element, Indent, Culprit, Path, Message ) :-
|
||||
element_fault( Element, [0' |Indent], Culprit, Path, Message ).
|
||||
xml_content_fault( Term, Indent, Term, [], "Illegal Term" ) :-
|
||||
\+ generation(Term, "", false, Indent, _Format, _Plus, _Minus ).
|
||||
|
||||
element_fault( element(Tag, _Attributes, _Contents), _Indent, Tag, [], "Tag must be an atom" ) :-
|
||||
\+ atom( Tag ).
|
||||
element_fault( element(Tag, Attributes, _Contents), _Indent, Tag, [], "Attributes must be instantiated" ) :-
|
||||
var( Attributes ).
|
||||
element_fault( element(Tag, Attributes, _Contents), _Indent, Faulty, Path, Message ) :-
|
||||
fault_path( Tag, Attributes, Path, [] ),
|
||||
member( Attribute, Attributes ),
|
||||
attribute_fault( Attribute, Faulty, Message ).
|
||||
element_fault( element(Tag, Attributes, Contents), Indent, Culprit, Path, Message ) :-
|
||||
fault_path( Tag, Attributes, Path, Path1 ),
|
||||
xml_content_fault( Contents, Indent, Culprit, Path1, Message ).
|
||||
|
||||
attribute_fault( Attribute, Attribute, "Illegal Variable" ) :-
|
||||
var( Attribute ).
|
||||
attribute_fault( Name=Value, Name=Value, "Attribute Name must be atom" ) :-
|
||||
\+ atom(Name).
|
||||
attribute_fault( Name=Value, Name=Value, "Attribute Value must be chars" ) :-
|
||||
\+ is_chars( Value ).
|
||||
attribute_fault( Attribute, Attribute, "Malformed Attribute" ) :-
|
||||
\+ Attribute = (_Name=_Value).
|
||||
|
||||
is_chars( Chars ) :-
|
||||
is_list( Chars ),
|
||||
\+ (member( Char, Chars ), \+ (integer(Char), Char >=0, Char =< 255)).
|
||||
|
||||
fault_path( Tag, Attributes ) -->
|
||||
{atom_codes( Tag, Chars )},
|
||||
chars( Chars ),
|
||||
fault_id( Attributes ),
|
||||
" ".
|
||||
|
||||
fault_id( Attributes ) -->
|
||||
{member( id=Chars, Attributes ), is_chars( Chars )},
|
||||
!,
|
||||
"(", chars(Chars), ")".
|
||||
fault_id( _Attributes ) --> "".
|
||||
/* xml_diagnosis.pl : XML exception diagnosis.
|
||||
*
|
||||
* Copyright (C) 2001-2005 Binding Time Limited
|
||||
* Copyright (C) 2005-2011 John Fletcher
|
||||
*
|
||||
* Current Release: $Revision: 3.3 $
|
||||
*
|
||||
* TERMS AND CONDITIONS:
|
||||
*
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*/
|
||||
|
||||
:- ensure_loaded( xml_generation ).
|
||||
|
||||
/* @pred xml_fault( +Term, +Indentation, ?SubTerm, ?Path, ?Message )
|
||||
*
|
||||
* identifies SubTerm
|
||||
* as a sub-term of Term which cannot be serialized after Indentation.
|
||||
* Message is an atom naming the type of error; Path is a string encoding a
|
||||
* list of SubTerm's ancestor elements in the form <tag>{(id)}* where <tag> is the
|
||||
* element tag and <id> is the value of any attribute _named_ id.
|
||||
*/
|
||||
xml_fault( Term, _Indent, Term, [], "Illegal Variable" ) :-
|
||||
var( Term ).
|
||||
xml_fault( xml(Attributes,_Content), _Indent, Term, [], Message ) :-
|
||||
member( Attribute, Attributes ),
|
||||
attribute_fault( Attribute, Term, Message ).
|
||||
xml_fault( xml(_Attributes,Content), Indent, Culprit, Path, Message ) :-
|
||||
xml_content_fault( Content, Indent, Culprit, Path, Message ).
|
||||
xml_fault( Term, _Indent, Term, [], "Illegal Term" ).
|
||||
|
||||
xml_content_fault( Term, _Indent, Term, [], "Illegal Variable" ) :-
|
||||
var( Term ).
|
||||
xml_content_fault( pcdata(Chars), _Indent, Chars, [], "Invalid Character Data" ) :-
|
||||
\+ is_chars( Chars ).
|
||||
xml_content_fault( cdata(Chars), _Indent, Chars, [], "Invalid Character Data" ) :-
|
||||
\+ is_chars( Chars ).
|
||||
xml_content_fault( [H|_T], Indent, Culprit, Path, Message ) :-
|
||||
xml_content_fault( H, Indent, Culprit, Path, Message ).
|
||||
xml_content_fault( [_H|T], Indent, Culprit, Path, Message ) :-
|
||||
xml_content_fault( T, Indent, Culprit, Path, Message ).
|
||||
xml_content_fault( namespace(_URI,_Prefix,Element), Indent, Culprit, Path, Message ) :-
|
||||
element_fault( Element, [0' |Indent], Culprit, Path, Message ).
|
||||
xml_content_fault( Element, Indent, Culprit, Path, Message ) :-
|
||||
element_fault( Element, [0' |Indent], Culprit, Path, Message ).
|
||||
xml_content_fault( Term, Indent, Term, [], "Illegal Term" ) :-
|
||||
\+ generation(Term, "", false, Indent, _Format, _Plus, _Minus ).
|
||||
|
||||
element_fault( element(Tag, _Attributes, _Contents), _Indent, Tag, [], "Tag must be an atom" ) :-
|
||||
\+ atom( Tag ).
|
||||
element_fault( element(Tag, Attributes, _Contents), _Indent, Tag, [], "Attributes must be instantiated" ) :-
|
||||
var( Attributes ).
|
||||
element_fault( element(Tag, Attributes, _Contents), _Indent, Faulty, Path, Message ) :-
|
||||
fault_path( Tag, Attributes, Path, [] ),
|
||||
member( Attribute, Attributes ),
|
||||
attribute_fault( Attribute, Faulty, Message ).
|
||||
element_fault( element(Tag, Attributes, Contents), Indent, Culprit, Path, Message ) :-
|
||||
fault_path( Tag, Attributes, Path, Path1 ),
|
||||
xml_content_fault( Contents, Indent, Culprit, Path1, Message ).
|
||||
|
||||
attribute_fault( Attribute, Attribute, "Illegal Variable" ) :-
|
||||
var( Attribute ).
|
||||
attribute_fault( Name=Value, Name=Value, "Attribute Name must be atom" ) :-
|
||||
\+ atom(Name).
|
||||
attribute_fault( Name=Value, Name=Value, "Attribute Value must be chars" ) :-
|
||||
\+ is_chars( Value ).
|
||||
attribute_fault( Attribute, Attribute, "Malformed Attribute" ) :-
|
||||
\+ Attribute = (_Name=_Value).
|
||||
|
||||
is_chars( Chars ) :-
|
||||
is_list( Chars ),
|
||||
\+ (member( Char, Chars ), \+ (integer(Char), Char >=0, Char =< 255)).
|
||||
|
||||
fault_path( Tag, Attributes ) -->
|
||||
{atom_codes( Tag, Chars )},
|
||||
chars( Chars ),
|
||||
fault_id( Attributes ),
|
||||
" ".
|
||||
|
||||
fault_id( Attributes ) -->
|
||||
{member( id=Chars, Attributes ), is_chars( Chars )},
|
||||
!,
|
||||
"(", chars(Chars), ")".
|
||||
fault_id( _Attributes ) --> "".
|
||||
|
||||
|
@ -11,11 +11,15 @@
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*/
|
||||
|
||||
/** @pred xml_parse( {+Controls}, +?Chars, ?+Document )
|
||||
*
|
||||
* xml_parse( {+Controls}, +?Chars, ?+Document ) parses Chars to/from a data
|
||||
* parses Chars to/from a data
|
||||
* structure of the form xml(<atts>, <content>). <atts> is a list of
|
||||
* <atom>=<string> attributes from the (possibly implicit) XML signature of the
|
||||
* document. <content> is a (possibly empty) list comprising occurrences of * ~~~
|
||||
* document. <content> is a (possibly empty) list comprising occurrences of
|
||||
* ~~~
|
||||
* pcdata(<string>) : Text
|
||||
* comment(<string>) : An xml comment;
|
||||
* element(<tag>,<atts>,<content>) : <tag>..</tag> encloses <content>
|
||||
@ -75,7 +79,7 @@
|
||||
* is not well-formed, diagnosis tries to identify the specific culprit term.
|
||||
*/
|
||||
|
||||
:- module( xml, [xml_parse/2,
|
||||
:- module( xml_driver, [xml_parse/2,
|
||||
xml_parse/3,
|
||||
document_to_xml/3,
|
||||
xml_subterm/2
|
||||
@ -105,7 +109,8 @@ document_to_xml( Controls, Document, Chars ) :-
|
||||
xml_exception( Message, Document, Culprit, Path )
|
||||
).
|
||||
|
||||
/** xml_subterm( +XMLTerm, ?Subterm )
|
||||
/** @pred xml_subterm( +XMLTerm, ?Subterm )
|
||||
*
|
||||
* unifies Subterm with a sub-term of Term.
|
||||
* Note that XMLTerm is a sub-term of itself.
|
||||
*/
|
||||
|
@ -1,391 +1,394 @@
|
||||
/* xml_generation.pl : Document -> XML translation
|
||||
*
|
||||
* Copyright (C) 2001-2005 Binding Time Limited
|
||||
* Copyright (C) 2005-2011 John Fletcher
|
||||
*
|
||||
* Current Release: $Revision: 3.7 $
|
||||
*
|
||||
* TERMS AND CONDITIONS:
|
||||
*
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*/
|
||||
|
||||
:- ensure_loaded( xml_utilities ).
|
||||
/* xml_generation.pl : Document -> XML translation
|
||||
*
|
||||
* Copyright (C) 2001-2005 Binding Time Limited
|
||||
* Copyright (C) 2005-2011 John Fletcher
|
||||
*
|
||||
* Current Release: $Revision: 3.7 $
|
||||
*
|
||||
* TERMS AND CONDITIONS:
|
||||
*
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*/
|
||||
|
||||
:- ensure_loaded( xml_utilities ).
|
||||
|
||||
:- use_module(library(lists)).
|
||||
|
||||
/* document_generation( +Format, +Document ) is a DCG generating Document
|
||||
* as a list of character codes. Format is true|false defining whether layouts,
|
||||
* to provide indentation, should be added between the element content of
|
||||
* the resultant "string". Note that formatting is disabled for elements that
|
||||
* are interspersed with pcdata/1 terms, such as XHTML's 'inline' elements.
|
||||
* Also, Format is over-ridden, for an individual element, by an explicit
|
||||
* 'xml:space'="preserve" attribute.
|
||||
*/
|
||||
document_generation( Format, xml(Attributes, Document) ) -->
|
||||
document_generation_body( Attributes, Format, Document ).
|
||||
|
||||
document_generation_body( [], Format, Document ) -->
|
||||
generation( Document, "", Format, [], _Format1 ).
|
||||
document_generation_body( Attributes, Format, Document ) -->
|
||||
{ Attributes = [_|_],
|
||||
xml_declaration_attributes_valid( Attributes )
|
||||
},
|
||||
"<?xml",
|
||||
generated_attributes( Attributes, Format, Format0 ),
|
||||
"?>",
|
||||
indent( true, [] ),
|
||||
generation( Document, "", Format0, [], _Format1 ).
|
||||
|
||||
generation( [], _Prefix, Format, _Indent, Format ) --> [].
|
||||
generation( [Term|Terms], Prefix, Format0, Indent, Format ) -->
|
||||
generation( Term, Prefix, Format0, Indent, Format1 ),
|
||||
generation( Terms, Prefix, Format1, Indent, Format ).
|
||||
generation( doctype(Name, External), _Prefix, Format, [], Format ) -->
|
||||
"<!DOCTYPE ",
|
||||
generated_name( Name ),
|
||||
generated_external_id( External ),
|
||||
">".
|
||||
generation( instructions(Target,Process), _Prefix, Format, Indent, Format ) -->
|
||||
indent( Format, Indent ),
|
||||
"<?", generated_name(Target), " ", chars( Process ) ,"?>".
|
||||
generation( pcdata(Chars), _Prefix, Format0, _Indent, Format1 ) -->
|
||||
pcdata_generation( Chars ),
|
||||
{character_data_format( Chars, Format0, Format1 )}.
|
||||
generation( comment( Comment ), _Prefix, Format, Indent, Format ) -->
|
||||
indent( Format, Indent ),
|
||||
"<!--", chars( Comment ), "-->".
|
||||
generation( namespace(URI, Prefix, element(Name, Atts, Content)),
|
||||
_Prefix0, Format, Indent, Format ) -->
|
||||
indent( Format, Indent ),
|
||||
"<", generated_prefixed_name( Prefix, Name ),
|
||||
generated_prefixed_attributes( Prefix, URI, Atts, Format, Format1 ),
|
||||
generated_content( Content, Format1, Indent, Prefix, Name ).
|
||||
generation( element(Name, Atts, Content), Prefix, Format, Indent, Format ) -->
|
||||
indent( Format, Indent ),
|
||||
"<", generated_prefixed_name( Prefix, Name ),
|
||||
generated_attributes( Atts, Format, Format1 ),
|
||||
generated_content( Content, Format1, Indent, Prefix, Name ).
|
||||
generation( cdata(CData), _Prefix, Format0, _Indent, Format1 ) -->
|
||||
"<![CDATA[", cdata_generation(CData), "]]>",
|
||||
{character_data_format( CData, Format0, Format1 )}.
|
||||
|
||||
generated_attributes( [], Format, Format ) --> [].
|
||||
generated_attributes( [Name=Value|Attributes], Format0, Format ) -->
|
||||
{( Name == 'xml:space',
|
||||
Value="preserve" ->
|
||||
Format1 = false
|
||||
; otherwise ->
|
||||
Format1 = Format0
|
||||
)},
|
||||
" ",
|
||||
generated_name( Name ),
|
||||
"=""",
|
||||
quoted_string( Value ),
|
||||
"""",
|
||||
generated_attributes( Attributes, Format1, Format ).
|
||||
|
||||
generated_prefixed_name( [], Name ) -->
|
||||
generated_name( Name ).
|
||||
generated_prefixed_name( Prefix, Name ) -->
|
||||
{Prefix = [_|_]},
|
||||
chars( Prefix ), ":",
|
||||
generated_name( Name ).
|
||||
|
||||
generated_content( [], _Format, _Indent, _Prefix, _Namespace ) -->
|
||||
" />". % Leave an extra space for XHTML output.
|
||||
generated_content( [H|T], Format, Indent, Prefix, Namespace ) -->
|
||||
">",
|
||||
generation( H, Prefix, Format, [0' |Indent], Format1 ),
|
||||
generation( T, Prefix, Format1, [0' |Indent], Format2 ),
|
||||
indent( Format2, Indent ),
|
||||
"</", generated_prefixed_name( Prefix, Namespace ), ">".
|
||||
|
||||
generated_prefixed_attributes( [_|_Prefix], _URI, Atts, Format0, Format ) -->
|
||||
generated_attributes( Atts, Format0, Format ).
|
||||
generated_prefixed_attributes( [], URI, Atts, Format0, Format ) -->
|
||||
{atom_codes( URI, Namespace ),
|
||||
findall( Attr, (member(Attr, Atts), \+ Attr=(xmlns=_Val)), Atts1 )
|
||||
},
|
||||
generated_attributes( [xmlns=Namespace|Atts1], Format0, Format ).
|
||||
|
||||
generated_name( Name, Plus, Minus ) :-
|
||||
atom_codes( Name, Chars ),
|
||||
append( Chars, Minus, Plus ).
|
||||
|
||||
generated_external_id( local ) --> "".
|
||||
generated_external_id( local(Literals) ) --> " [",
|
||||
generated_doctype_literals( Literals ), "
|
||||
]".
|
||||
generated_external_id( system(URL) ) -->
|
||||
" SYSTEM """,
|
||||
chars( URL ),
|
||||
"""".
|
||||
generated_external_id( system(URL,Literals) ) -->
|
||||
" SYSTEM """,
|
||||
chars( URL ),
|
||||
""" [",
|
||||
generated_doctype_literals( Literals ), "
|
||||
]".
|
||||
generated_external_id( public(URN,URL) ) -->
|
||||
" PUBLIC """,
|
||||
chars( URN ),
|
||||
""" """,
|
||||
chars( URL ),
|
||||
"""".
|
||||
generated_external_id( public(URN,URL,Literals) ) -->
|
||||
" PUBLIC """,
|
||||
chars( URN ),
|
||||
""" """,
|
||||
chars( URL ),
|
||||
""" [",
|
||||
generated_doctype_literals( Literals ), "
|
||||
]".
|
||||
|
||||
generated_doctype_literals( [] ) --> "".
|
||||
generated_doctype_literals( [dtd_literal(String)|Literals] ) --> "
|
||||
<!", cdata_generation( String ), ">",
|
||||
generated_doctype_literals( Literals ).
|
||||
|
||||
/* quoted_string( +Chars ) is a DCG representing Chars, a list of character
|
||||
* codes, as a legal XML attribute string. Any leading or trailing layout
|
||||
* characters are removed. &, " and < characters are replaced by &, "
|
||||
* and < respectively, .
|
||||
*/
|
||||
quoted_string( Raw, Plus, Minus ) :-
|
||||
quoted_string1( Raw, NoLeadingLayouts ),
|
||||
quoted_string2( NoLeadingLayouts, Layout, Layout, Plus, Minus ).
|
||||
|
||||
quoted_string1( [], [] ).
|
||||
quoted_string1( [Char|Chars], NoLeadingLayouts ) :-
|
||||
( Char > 32 ->
|
||||
NoLeadingLayouts = [Char|Chars]
|
||||
; otherwise ->
|
||||
quoted_string1( Chars, NoLeadingLayouts )
|
||||
).
|
||||
|
||||
quoted_string2( [], _LayoutPlus, _LayoutMinus, List, List ).
|
||||
quoted_string2( [Char|Chars], LayoutPlus, LayoutMinus, Plus, Minus ) :-
|
||||
( Char =< " " ->
|
||||
Plus = Plus1,
|
||||
LayoutMinus = [Char|LayoutMinus1],
|
||||
LayoutPlus = LayoutPlus1
|
||||
; Char == 34 ->
|
||||
Plus = LayoutPlus,
|
||||
escaped_quote( LayoutMinus, Plus1 ),
|
||||
LayoutPlus1 = LayoutMinus1
|
||||
; Char == 39 ->
|
||||
Plus = LayoutPlus,
|
||||
apos( LayoutMinus, Plus1 ),
|
||||
LayoutPlus1 = LayoutMinus1
|
||||
; Char =< 127 ->
|
||||
Plus = LayoutPlus,
|
||||
pcdata_7bit( Char, LayoutMinus, Plus1 ),
|
||||
LayoutPlus1 = LayoutMinus1
|
||||
; legal_xml_unicode( Char ) ->
|
||||
Plus = LayoutPlus,
|
||||
number_codes( Char, Codes ),
|
||||
pcdata_8bits_plus( Codes, LayoutMinus, Plus1 ),
|
||||
LayoutPlus1 = LayoutMinus1
|
||||
; otherwise ->
|
||||
LayoutPlus = LayoutPlus1,
|
||||
LayoutMinus = LayoutMinus1,
|
||||
Plus = Plus1
|
||||
),
|
||||
quoted_string2( Chars, LayoutPlus1, LayoutMinus1, Plus1, Minus ).
|
||||
|
||||
indent( false, _Indent ) --> [].
|
||||
indent( true, Indent ) -->
|
||||
[10],
|
||||
chars( Indent ).
|
||||
|
||||
apos --> "'".
|
||||
|
||||
escaped_quote --> """.
|
||||
|
||||
/* pcdata_generation( +Chars ) is a DCG representing Chars, a list of character
|
||||
* codes as legal XML "Parsed character data" (PCDATA) string. Any codes
|
||||
* which cannot be represented by a 7-bit character are replaced by their
|
||||
* decimal numeric character entity e.g. code 160 (non-breaking space) is
|
||||
* represented as  . Any character codes disallowed by the XML
|
||||
* specification are not encoded.
|
||||
*/
|
||||
pcdata_generation( [], Plus, Plus ).
|
||||
pcdata_generation( [Char|Chars], Plus, Minus ) :-
|
||||
( Char =< 127 ->
|
||||
pcdata_7bit( Char, Plus, Mid )
|
||||
; legal_xml_unicode( Char ) ->
|
||||
number_codes( Char, Codes ),
|
||||
pcdata_8bits_plus( Codes, Plus, Mid )
|
||||
; otherwise ->
|
||||
Plus = Mid
|
||||
),
|
||||
pcdata_generation( Chars, Mid, Minus ).
|
||||
|
||||
/* pcdata_7bit(+Char) represents the ascii character set in its
|
||||
* simplest format, using the character entities & < and >.
|
||||
*/
|
||||
pcdata_7bit( 0 ) --> "".
|
||||
pcdata_7bit( 1 ) --> "".
|
||||
pcdata_7bit( 2 ) --> "".
|
||||
pcdata_7bit( 3 ) --> "".
|
||||
pcdata_7bit( 4 ) --> "".
|
||||
pcdata_7bit( 5 ) --> "".
|
||||
pcdata_7bit( 6 ) --> "".
|
||||
pcdata_7bit( 7 ) --> "".
|
||||
pcdata_7bit( 8 ) --> "".
|
||||
pcdata_7bit( 9 ) --> [9].
|
||||
pcdata_7bit( 10 ) --> [10].
|
||||
pcdata_7bit( 11 ) --> "".
|
||||
pcdata_7bit( 12 ) --> "".
|
||||
pcdata_7bit( 13 ) --> [13].
|
||||
pcdata_7bit( 14 ) --> "".
|
||||
pcdata_7bit( 15 ) --> "".
|
||||
pcdata_7bit( 16 ) --> "".
|
||||
pcdata_7bit( 17 ) --> "".
|
||||
pcdata_7bit( 18 ) --> "".
|
||||
pcdata_7bit( 19 ) --> "".
|
||||
pcdata_7bit( 20 ) --> "".
|
||||
pcdata_7bit( 21 ) --> "".
|
||||
pcdata_7bit( 22 ) --> "".
|
||||
pcdata_7bit( 23 ) --> "".
|
||||
pcdata_7bit( 24 ) --> "".
|
||||
pcdata_7bit( 25 ) --> "".
|
||||
pcdata_7bit( 26 ) --> "".
|
||||
pcdata_7bit( 27 ) --> "".
|
||||
pcdata_7bit( 28 ) --> "".
|
||||
pcdata_7bit( 29 ) --> "".
|
||||
pcdata_7bit( 30 ) --> "".
|
||||
pcdata_7bit( 31 ) --> "".
|
||||
pcdata_7bit( 32 ) --> " ".
|
||||
pcdata_7bit( 33 ) --> "!".
|
||||
pcdata_7bit( 34 ) --> [34].
|
||||
pcdata_7bit( 35 ) --> "#".
|
||||
pcdata_7bit( 36 ) --> "$".
|
||||
pcdata_7bit( 37 ) --> "%".
|
||||
pcdata_7bit( 38 ) --> "&".
|
||||
pcdata_7bit( 39 ) --> "'".
|
||||
pcdata_7bit( 40 ) --> "(".
|
||||
pcdata_7bit( 41 ) --> ")".
|
||||
pcdata_7bit( 42 ) --> "*".
|
||||
pcdata_7bit( 43 ) --> "+".
|
||||
pcdata_7bit( 44 ) --> ",".
|
||||
pcdata_7bit( 45 ) --> "-".
|
||||
pcdata_7bit( 46 ) --> ".".
|
||||
pcdata_7bit( 47 ) --> "/".
|
||||
pcdata_7bit( 48 ) --> "0".
|
||||
pcdata_7bit( 49 ) --> "1".
|
||||
pcdata_7bit( 50 ) --> "2".
|
||||
pcdata_7bit( 51 ) --> "3".
|
||||
pcdata_7bit( 52 ) --> "4".
|
||||
pcdata_7bit( 53 ) --> "5".
|
||||
pcdata_7bit( 54 ) --> "6".
|
||||
pcdata_7bit( 55 ) --> "7".
|
||||
pcdata_7bit( 56 ) --> "8".
|
||||
pcdata_7bit( 57 ) --> "9".
|
||||
pcdata_7bit( 58 ) --> ":".
|
||||
pcdata_7bit( 59 ) --> ";".
|
||||
pcdata_7bit( 60 ) --> "<".
|
||||
pcdata_7bit( 61 ) --> "=".
|
||||
pcdata_7bit( 62 ) --> ">". % escaping necessary to prevent ']]>' sequences in pcdata.
|
||||
pcdata_7bit( 63 ) --> "?".
|
||||
pcdata_7bit( 64 ) --> "@".
|
||||
pcdata_7bit( 65 ) --> "A".
|
||||
pcdata_7bit( 66 ) --> "B".
|
||||
pcdata_7bit( 67 ) --> "C".
|
||||
pcdata_7bit( 68 ) --> "D".
|
||||
pcdata_7bit( 69 ) --> "E".
|
||||
pcdata_7bit( 70 ) --> "F".
|
||||
pcdata_7bit( 71 ) --> "G".
|
||||
pcdata_7bit( 72 ) --> "H".
|
||||
pcdata_7bit( 73 ) --> "I".
|
||||
pcdata_7bit( 74 ) --> "J".
|
||||
pcdata_7bit( 75 ) --> "K".
|
||||
pcdata_7bit( 76 ) --> "L".
|
||||
pcdata_7bit( 77 ) --> "M".
|
||||
pcdata_7bit( 78 ) --> "N".
|
||||
pcdata_7bit( 79 ) --> "O".
|
||||
pcdata_7bit( 80 ) --> "P".
|
||||
pcdata_7bit( 81 ) --> "Q".
|
||||
pcdata_7bit( 82 ) --> "R".
|
||||
pcdata_7bit( 83 ) --> "S".
|
||||
pcdata_7bit( 84 ) --> "T".
|
||||
pcdata_7bit( 85 ) --> "U".
|
||||
pcdata_7bit( 86 ) --> "V".
|
||||
pcdata_7bit( 87 ) --> "W".
|
||||
pcdata_7bit( 88 ) --> "X".
|
||||
pcdata_7bit( 89 ) --> "Y".
|
||||
pcdata_7bit( 90 ) --> "Z".
|
||||
pcdata_7bit( 91 ) --> "[".
|
||||
pcdata_7bit( 92 ) --> [92].
|
||||
pcdata_7bit( 93 ) --> "]".
|
||||
pcdata_7bit( 94 ) --> "^".
|
||||
pcdata_7bit( 95 ) --> "_".
|
||||
pcdata_7bit( 96 ) --> "`".
|
||||
pcdata_7bit( 97 ) --> "a".
|
||||
pcdata_7bit( 98 ) --> "b".
|
||||
pcdata_7bit( 99 ) --> "c".
|
||||
pcdata_7bit( 100 ) --> "d".
|
||||
pcdata_7bit( 101 ) --> "e".
|
||||
pcdata_7bit( 102 ) --> "f".
|
||||
pcdata_7bit( 103 ) --> "g".
|
||||
pcdata_7bit( 104 ) --> "h".
|
||||
pcdata_7bit( 105 ) --> "i".
|
||||
pcdata_7bit( 106 ) --> "j".
|
||||
pcdata_7bit( 107 ) --> "k".
|
||||
pcdata_7bit( 108 ) --> "l".
|
||||
pcdata_7bit( 109 ) --> "m".
|
||||
pcdata_7bit( 110 ) --> "n".
|
||||
pcdata_7bit( 111 ) --> "o".
|
||||
pcdata_7bit( 112 ) --> "p".
|
||||
pcdata_7bit( 113 ) --> "q".
|
||||
pcdata_7bit( 114 ) --> "r".
|
||||
pcdata_7bit( 115 ) --> "s".
|
||||
pcdata_7bit( 116 ) --> "t".
|
||||
pcdata_7bit( 117 ) --> "u".
|
||||
pcdata_7bit( 118 ) --> "v".
|
||||
pcdata_7bit( 119 ) --> "w".
|
||||
pcdata_7bit( 120 ) --> "x".
|
||||
pcdata_7bit( 121 ) --> "y".
|
||||
pcdata_7bit( 122 ) --> "z".
|
||||
pcdata_7bit( 123 ) --> "{".
|
||||
pcdata_7bit( 124 ) --> "|".
|
||||
pcdata_7bit( 125 ) --> "}".
|
||||
pcdata_7bit( 126 ) --> [126].
|
||||
pcdata_7bit( 127 ) --> "".
|
||||
|
||||
pcdata_8bits_plus( Codes ) -->
|
||||
"&#", chars( Codes ), ";".
|
||||
|
||||
/* character_data_format( +Chars, +Format0, ?Format1 ) holds when Format0 and
|
||||
* Format1 are the statuses of XML formatting before and after Chars -
|
||||
* which may be null.
|
||||
*/
|
||||
character_data_format( [], Format, Format ).
|
||||
character_data_format( [_Char|_Chars], _Format, false ).
|
||||
|
||||
/* cdata_generation( +Chars ) is a DCG representing Chars, a list of character
|
||||
* codes as a legal XML CDATA string. Any character codes disallowed by the XML
|
||||
* specification are not encoded.
|
||||
*/
|
||||
cdata_generation( [] ) --> "".
|
||||
cdata_generation( [Char|Chars] ) -->
|
||||
( {legal_xml_unicode( Char )}, !, [Char]
|
||||
; ""
|
||||
),
|
||||
cdata_generation( Chars ).
|
||||
|
||||
legal_xml_unicode( 9 ).
|
||||
legal_xml_unicode( 10 ).
|
||||
legal_xml_unicode( 13 ).
|
||||
legal_xml_unicode( Code ) :-
|
||||
Code >= 32,
|
||||
Code =< 55295.
|
||||
legal_xml_unicode( Code ) :-
|
||||
Code >= 57344,
|
||||
Code =< 65533.
|
||||
legal_xml_unicode( Code ) :-
|
||||
Code >= 65536,
|
||||
Code =< 1114111.
|
||||
|
||||
/* @pred document_generation( +Format, +Document )
|
||||
*
|
||||
* is a DCG generating Document
|
||||
* as a list of character codes. Format is true|false defining whether layouts,
|
||||
* to provide indentation, should be added between the element content of
|
||||
* the resultant "string". Note that formatting is disabled for elements that
|
||||
* are interspersed with pcdata/1 terms, such as XHTML's 'inline' elements.
|
||||
* Also, Format is over-ridden, for an individual element, by an explicit
|
||||
* 'xml:space'="preserve" attribute.
|
||||
*/
|
||||
document_generation( Format, xml(Attributes, Document) ) -->
|
||||
document_generation_body( Attributes, Format, Document ).
|
||||
|
||||
document_generation_body( [], Format, Document ) -->
|
||||
generation( Document, "", Format, [], _Format1 ).
|
||||
document_generation_body( Attributes, Format, Document ) -->
|
||||
{ Attributes = [_|_],
|
||||
xml_declaration_attributes_valid( Attributes )
|
||||
},
|
||||
"<?xml",
|
||||
generated_attributes( Attributes, Format, Format0 ),
|
||||
"?>",
|
||||
indent( true, [] ),
|
||||
generation( Document, "", Format0, [], _Format1 ).
|
||||
|
||||
generation( [], _Prefix, Format, _Indent, Format ) --> [].
|
||||
generation( [Term|Terms], Prefix, Format0, Indent, Format ) -->
|
||||
generation( Term, Prefix, Format0, Indent, Format1 ),
|
||||
generation( Terms, Prefix, Format1, Indent, Format ).
|
||||
generation( doctype(Name, External), _Prefix, Format, [], Format ) -->
|
||||
"<!DOCTYPE ",
|
||||
generated_name( Name ),
|
||||
generated_external_id( External ),
|
||||
">".
|
||||
generation( instructions(Target,Process), _Prefix, Format, Indent, Format ) -->
|
||||
indent( Format, Indent ),
|
||||
"<?", generated_name(Target), " ", chars( Process ) ,"?>".
|
||||
generation( pcdata(Chars), _Prefix, Format0, _Indent, Format1 ) -->
|
||||
pcdata_generation( Chars ),
|
||||
{character_data_format( Chars, Format0, Format1 )}.
|
||||
generation( comment( Comment ), _Prefix, Format, Indent, Format ) -->
|
||||
indent( Format, Indent ),
|
||||
"<!--", chars( Comment ), "-->".
|
||||
generation( namespace(URI, Prefix, element(Name, Atts, Content)),
|
||||
_Prefix0, Format, Indent, Format ) -->
|
||||
indent( Format, Indent ),
|
||||
"<", generated_prefixed_name( Prefix, Name ),
|
||||
generated_prefixed_attributes( Prefix, URI, Atts, Format, Format1 ),
|
||||
generated_content( Content, Format1, Indent, Prefix, Name ).
|
||||
generation( element(Name, Atts, Content), Prefix, Format, Indent, Format ) -->
|
||||
indent( Format, Indent ),
|
||||
"<", generated_prefixed_name( Prefix, Name ),
|
||||
generated_attributes( Atts, Format, Format1 ),
|
||||
generated_content( Content, Format1, Indent, Prefix, Name ).
|
||||
generation( cdata(CData), _Prefix, Format0, _Indent, Format1 ) -->
|
||||
"<![CDATA[", cdata_generation(CData), "]]>",
|
||||
{character_data_format( CData, Format0, Format1 )}.
|
||||
|
||||
generated_attributes( [], Format, Format ) --> [].
|
||||
generated_attributes( [Name=Value|Attributes], Format0, Format ) -->
|
||||
{( Name == 'xml:space',
|
||||
Value="preserve" ->
|
||||
Format1 = false
|
||||
; otherwise ->
|
||||
Format1 = Format0
|
||||
)},
|
||||
" ",
|
||||
generated_name( Name ),
|
||||
"=""",
|
||||
quoted_string( Value ),
|
||||
"""",
|
||||
generated_attributes( Attributes, Format1, Format ).
|
||||
|
||||
generated_prefixed_name( [], Name ) -->
|
||||
generated_name( Name ).
|
||||
generated_prefixed_name( Prefix, Name ) -->
|
||||
{Prefix = [_|_]},
|
||||
chars( Prefix ), ":",
|
||||
generated_name( Name ).
|
||||
|
||||
generated_content( [], _Format, _Indent, _Prefix, _Namespace ) -->
|
||||
" />". % Leave an extra space for XHTML output.
|
||||
generated_content( [H|T], Format, Indent, Prefix, Namespace ) -->
|
||||
">",
|
||||
generation( H, Prefix, Format, [0' |Indent], Format1 ),
|
||||
generation( T, Prefix, Format1, [0' |Indent], Format2 ),
|
||||
indent( Format2, Indent ),
|
||||
"</", generated_prefixed_name( Prefix, Namespace ), ">".
|
||||
|
||||
generated_prefixed_attributes( [_|_Prefix], _URI, Atts, Format0, Format ) -->
|
||||
generated_attributes( Atts, Format0, Format ).
|
||||
generated_prefixed_attributes( [], URI, Atts, Format0, Format ) -->
|
||||
{atom_codes( URI, Namespace ),
|
||||
findall( Attr, (member(Attr, Atts), \+ Attr=(xmlns=_Val)), Atts1 )
|
||||
},
|
||||
generated_attributes( [xmlns=Namespace|Atts1], Format0, Format ).
|
||||
|
||||
generated_name( Name, Plus, Minus ) :-
|
||||
atom_codes( Name, Chars ),
|
||||
append( Chars, Minus, Plus ).
|
||||
|
||||
generated_external_id( local ) --> "".
|
||||
generated_external_id( local(Literals) ) --> " [",
|
||||
generated_doctype_literals( Literals ), "
|
||||
]".
|
||||
generated_external_id( system(URL) ) -->
|
||||
" SYSTEM """,
|
||||
chars( URL ),
|
||||
"""".
|
||||
generated_external_id( system(URL,Literals) ) -->
|
||||
" SYSTEM """,
|
||||
chars( URL ),
|
||||
""" [",
|
||||
generated_doctype_literals( Literals ), "
|
||||
]".
|
||||
generated_external_id( public(URN,URL) ) -->
|
||||
" PUBLIC """,
|
||||
chars( URN ),
|
||||
""" """,
|
||||
chars( URL ),
|
||||
"""".
|
||||
generated_external_id( public(URN,URL,Literals) ) -->
|
||||
" PUBLIC """,
|
||||
chars( URN ),
|
||||
""" """,
|
||||
chars( URL ),
|
||||
""" [",
|
||||
generated_doctype_literals( Literals ), "
|
||||
]".
|
||||
|
||||
generated_doctype_literals( [] ) --> "".
|
||||
generated_doctype_literals( [dtd_literal(String)|Literals] ) --> "
|
||||
<!", cdata_generation( String ), ">",
|
||||
generated_doctype_literals( Literals ).
|
||||
|
||||
/* quoted_string( +Chars ) is a DCG representing Chars, a list of character
|
||||
* codes, as a legal XML attribute string. Any leading or trailing layout
|
||||
* characters are removed. &, " and < characters are replaced by &, "
|
||||
* and < respectively, .
|
||||
*/
|
||||
quoted_string( Raw, Plus, Minus ) :-
|
||||
quoted_string1( Raw, NoLeadingLayouts ),
|
||||
quoted_string2( NoLeadingLayouts, Layout, Layout, Plus, Minus ).
|
||||
|
||||
quoted_string1( [], [] ).
|
||||
quoted_string1( [Char|Chars], NoLeadingLayouts ) :-
|
||||
( Char > 32 ->
|
||||
NoLeadingLayouts = [Char|Chars]
|
||||
; otherwise ->
|
||||
quoted_string1( Chars, NoLeadingLayouts )
|
||||
).
|
||||
|
||||
quoted_string2( [], _LayoutPlus, _LayoutMinus, List, List ).
|
||||
quoted_string2( [Char|Chars], LayoutPlus, LayoutMinus, Plus, Minus ) :-
|
||||
( Char =< " " ->
|
||||
Plus = Plus1,
|
||||
LayoutMinus = [Char|LayoutMinus1],
|
||||
LayoutPlus = LayoutPlus1
|
||||
; Char == 34 ->
|
||||
Plus = LayoutPlus,
|
||||
escaped_quote( LayoutMinus, Plus1 ),
|
||||
LayoutPlus1 = LayoutMinus1
|
||||
; Char == 39 ->
|
||||
Plus = LayoutPlus,
|
||||
apos( LayoutMinus, Plus1 ),
|
||||
LayoutPlus1 = LayoutMinus1
|
||||
; Char =< 127 ->
|
||||
Plus = LayoutPlus,
|
||||
pcdata_7bit( Char, LayoutMinus, Plus1 ),
|
||||
LayoutPlus1 = LayoutMinus1
|
||||
; legal_xml_unicode( Char ) ->
|
||||
Plus = LayoutPlus,
|
||||
number_codes( Char, Codes ),
|
||||
pcdata_8bits_plus( Codes, LayoutMinus, Plus1 ),
|
||||
LayoutPlus1 = LayoutMinus1
|
||||
; otherwise ->
|
||||
LayoutPlus = LayoutPlus1,
|
||||
LayoutMinus = LayoutMinus1,
|
||||
Plus = Plus1
|
||||
),
|
||||
quoted_string2( Chars, LayoutPlus1, LayoutMinus1, Plus1, Minus ).
|
||||
|
||||
indent( false, _Indent ) --> [].
|
||||
indent( true, Indent ) -->
|
||||
[10],
|
||||
chars( Indent ).
|
||||
|
||||
apos --> "'".
|
||||
|
||||
escaped_quote --> """.
|
||||
|
||||
/* pcdata_generation( +Chars ) is a DCG representing Chars, a list of character
|
||||
* codes as legal XML "Parsed character data" (PCDATA) string. Any codes
|
||||
* which cannot be represented by a 7-bit character are replaced by their
|
||||
* decimal numeric character entity e.g. code 160 (non-breaking space) is
|
||||
* represented as  . Any character codes disallowed by the XML
|
||||
* specification are not encoded.
|
||||
*/
|
||||
pcdata_generation( [], Plus, Plus ).
|
||||
pcdata_generation( [Char|Chars], Plus, Minus ) :-
|
||||
( Char =< 127 ->
|
||||
pcdata_7bit( Char, Plus, Mid )
|
||||
; legal_xml_unicode( Char ) ->
|
||||
number_codes( Char, Codes ),
|
||||
pcdata_8bits_plus( Codes, Plus, Mid )
|
||||
; otherwise ->
|
||||
Plus = Mid
|
||||
),
|
||||
pcdata_generation( Chars, Mid, Minus ).
|
||||
|
||||
/* pcdata_7bit(+Char) represents the ascii character set in its
|
||||
* simplest format, using the character entities & < and >.
|
||||
*/
|
||||
pcdata_7bit( 0 ) --> "".
|
||||
pcdata_7bit( 1 ) --> "".
|
||||
pcdata_7bit( 2 ) --> "".
|
||||
pcdata_7bit( 3 ) --> "".
|
||||
pcdata_7bit( 4 ) --> "".
|
||||
pcdata_7bit( 5 ) --> "".
|
||||
pcdata_7bit( 6 ) --> "".
|
||||
pcdata_7bit( 7 ) --> "".
|
||||
pcdata_7bit( 8 ) --> "".
|
||||
pcdata_7bit( 9 ) --> [9].
|
||||
pcdata_7bit( 10 ) --> [10].
|
||||
pcdata_7bit( 11 ) --> "".
|
||||
pcdata_7bit( 12 ) --> "".
|
||||
pcdata_7bit( 13 ) --> [13].
|
||||
pcdata_7bit( 14 ) --> "".
|
||||
pcdata_7bit( 15 ) --> "".
|
||||
pcdata_7bit( 16 ) --> "".
|
||||
pcdata_7bit( 17 ) --> "".
|
||||
pcdata_7bit( 18 ) --> "".
|
||||
pcdata_7bit( 19 ) --> "".
|
||||
pcdata_7bit( 20 ) --> "".
|
||||
pcdata_7bit( 21 ) --> "".
|
||||
pcdata_7bit( 22 ) --> "".
|
||||
pcdata_7bit( 23 ) --> "".
|
||||
pcdata_7bit( 24 ) --> "".
|
||||
pcdata_7bit( 25 ) --> "".
|
||||
pcdata_7bit( 26 ) --> "".
|
||||
pcdata_7bit( 27 ) --> "".
|
||||
pcdata_7bit( 28 ) --> "".
|
||||
pcdata_7bit( 29 ) --> "".
|
||||
pcdata_7bit( 30 ) --> "".
|
||||
pcdata_7bit( 31 ) --> "".
|
||||
pcdata_7bit( 32 ) --> " ".
|
||||
pcdata_7bit( 33 ) --> "!".
|
||||
pcdata_7bit( 34 ) --> [34].
|
||||
pcdata_7bit( 35 ) --> "#".
|
||||
pcdata_7bit( 36 ) --> "$".
|
||||
pcdata_7bit( 37 ) --> "%".
|
||||
pcdata_7bit( 38 ) --> "&".
|
||||
pcdata_7bit( 39 ) --> "'".
|
||||
pcdata_7bit( 40 ) --> "(".
|
||||
pcdata_7bit( 41 ) --> ")".
|
||||
pcdata_7bit( 42 ) --> "*".
|
||||
pcdata_7bit( 43 ) --> "+".
|
||||
pcdata_7bit( 44 ) --> ",".
|
||||
pcdata_7bit( 45 ) --> "-".
|
||||
pcdata_7bit( 46 ) --> ".".
|
||||
pcdata_7bit( 47 ) --> "/".
|
||||
pcdata_7bit( 48 ) --> "0".
|
||||
pcdata_7bit( 49 ) --> "1".
|
||||
pcdata_7bit( 50 ) --> "2".
|
||||
pcdata_7bit( 51 ) --> "3".
|
||||
pcdata_7bit( 52 ) --> "4".
|
||||
pcdata_7bit( 53 ) --> "5".
|
||||
pcdata_7bit( 54 ) --> "6".
|
||||
pcdata_7bit( 55 ) --> "7".
|
||||
pcdata_7bit( 56 ) --> "8".
|
||||
pcdata_7bit( 57 ) --> "9".
|
||||
pcdata_7bit( 58 ) --> ":".
|
||||
pcdata_7bit( 59 ) --> ";".
|
||||
pcdata_7bit( 60 ) --> "<".
|
||||
pcdata_7bit( 61 ) --> "=".
|
||||
pcdata_7bit( 62 ) --> ">". % escaping necessary to prevent ']]>' sequences in pcdata.
|
||||
pcdata_7bit( 63 ) --> "?".
|
||||
pcdata_7bit( 64 ) --> "@".
|
||||
pcdata_7bit( 65 ) --> "A".
|
||||
pcdata_7bit( 66 ) --> "B".
|
||||
pcdata_7bit( 67 ) --> "C".
|
||||
pcdata_7bit( 68 ) --> "D".
|
||||
pcdata_7bit( 69 ) --> "E".
|
||||
pcdata_7bit( 70 ) --> "F".
|
||||
pcdata_7bit( 71 ) --> "G".
|
||||
pcdata_7bit( 72 ) --> "H".
|
||||
pcdata_7bit( 73 ) --> "I".
|
||||
pcdata_7bit( 74 ) --> "J".
|
||||
pcdata_7bit( 75 ) --> "K".
|
||||
pcdata_7bit( 76 ) --> "L".
|
||||
pcdata_7bit( 77 ) --> "M".
|
||||
pcdata_7bit( 78 ) --> "N".
|
||||
pcdata_7bit( 79 ) --> "O".
|
||||
pcdata_7bit( 80 ) --> "P".
|
||||
pcdata_7bit( 81 ) --> "Q".
|
||||
pcdata_7bit( 82 ) --> "R".
|
||||
pcdata_7bit( 83 ) --> "S".
|
||||
pcdata_7bit( 84 ) --> "T".
|
||||
pcdata_7bit( 85 ) --> "U".
|
||||
pcdata_7bit( 86 ) --> "V".
|
||||
pcdata_7bit( 87 ) --> "W".
|
||||
pcdata_7bit( 88 ) --> "X".
|
||||
pcdata_7bit( 89 ) --> "Y".
|
||||
pcdata_7bit( 90 ) --> "Z".
|
||||
pcdata_7bit( 91 ) --> "[".
|
||||
pcdata_7bit( 92 ) --> [92].
|
||||
pcdata_7bit( 93 ) --> "]".
|
||||
pcdata_7bit( 94 ) --> "^".
|
||||
pcdata_7bit( 95 ) --> "_".
|
||||
pcdata_7bit( 96 ) --> "`".
|
||||
pcdata_7bit( 97 ) --> "a".
|
||||
pcdata_7bit( 98 ) --> "b".
|
||||
pcdata_7bit( 99 ) --> "c".
|
||||
pcdata_7bit( 100 ) --> "d".
|
||||
pcdata_7bit( 101 ) --> "e".
|
||||
pcdata_7bit( 102 ) --> "f".
|
||||
pcdata_7bit( 103 ) --> "g".
|
||||
pcdata_7bit( 104 ) --> "h".
|
||||
pcdata_7bit( 105 ) --> "i".
|
||||
pcdata_7bit( 106 ) --> "j".
|
||||
pcdata_7bit( 107 ) --> "k".
|
||||
pcdata_7bit( 108 ) --> "l".
|
||||
pcdata_7bit( 109 ) --> "m".
|
||||
pcdata_7bit( 110 ) --> "n".
|
||||
pcdata_7bit( 111 ) --> "o".
|
||||
pcdata_7bit( 112 ) --> "p".
|
||||
pcdata_7bit( 113 ) --> "q".
|
||||
pcdata_7bit( 114 ) --> "r".
|
||||
pcdata_7bit( 115 ) --> "s".
|
||||
pcdata_7bit( 116 ) --> "t".
|
||||
pcdata_7bit( 117 ) --> "u".
|
||||
pcdata_7bit( 118 ) --> "v".
|
||||
pcdata_7bit( 119 ) --> "w".
|
||||
pcdata_7bit( 120 ) --> "x".
|
||||
pcdata_7bit( 121 ) --> "y".
|
||||
pcdata_7bit( 122 ) --> "z".
|
||||
pcdata_7bit( 123 ) --> "{".
|
||||
pcdata_7bit( 124 ) --> "|".
|
||||
pcdata_7bit( 125 ) --> "}".
|
||||
pcdata_7bit( 126 ) --> [126].
|
||||
pcdata_7bit( 127 ) --> "".
|
||||
|
||||
pcdata_8bits_plus( Codes ) -->
|
||||
"&#", chars( Codes ), ";".
|
||||
|
||||
/* character_data_format( +Chars, +Format0, ?Format1 ) holds when Format0 and
|
||||
* Format1 are the statuses of XML formatting before and after Chars -
|
||||
* which may be null.
|
||||
*/
|
||||
character_data_format( [], Format, Format ).
|
||||
character_data_format( [_Char|_Chars], _Format, false ).
|
||||
|
||||
/* cdata_generation( +Chars ) is a DCG representing Chars, a list of character
|
||||
* codes as a legal XML CDATA string. Any character codes disallowed by the XML
|
||||
* specification are not encoded.
|
||||
*/
|
||||
cdata_generation( [] ) --> "".
|
||||
cdata_generation( [Char|Chars] ) -->
|
||||
( {legal_xml_unicode( Char )}, !, [Char]
|
||||
; ""
|
||||
),
|
||||
cdata_generation( Chars ).
|
||||
|
||||
legal_xml_unicode( 9 ).
|
||||
legal_xml_unicode( 10 ).
|
||||
legal_xml_unicode( 13 ).
|
||||
legal_xml_unicode( Code ) :-
|
||||
Code >= 32,
|
||||
Code =< 55295.
|
||||
legal_xml_unicode( Code ) :-
|
||||
Code >= 57344,
|
||||
Code =< 65533.
|
||||
legal_xml_unicode( Code ) :-
|
||||
Code >= 65536,
|
||||
Code =< 1114111.
|
||||
|
||||
|
@ -1,198 +1,201 @@
|
||||
/* xml_pp: "pretty print" an XML Document on the current output stream.
|
||||
*
|
||||
* Copyright (C) 2001-2005 Binding Time Limited
|
||||
* Copyright (C) 2005-2011 John Fletcher
|
||||
*
|
||||
* Current Release: $Revision: 3.3 $
|
||||
*
|
||||
* TERMS AND CONDITIONS:
|
||||
*
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*/
|
||||
|
||||
:- ensure_loaded( xml_utilities ).
|
||||
|
||||
/* xml_pp( +XMLDocument ) "pretty prints" XMLDocument on the current
|
||||
* output stream.
|
||||
*/
|
||||
xml_pp( xml(Attributes, Document) ) :-
|
||||
write( 'xml( ' ), pp_attributes( Attributes, 0 ), pp_comma, nl,
|
||||
pp_list( Document, s(0) ),
|
||||
write( ' ).' ), nl.
|
||||
xml_pp( malformed(Attributes, Document) ) :-
|
||||
write( 'malformed( ' ), pp_attributes( Attributes, 0 ), pp_comma, nl,
|
||||
pp_list( Document, s(0) ),
|
||||
write( ' ).' ), nl.
|
||||
|
||||
pp_indented( [], Indent ) :-
|
||||
pp_indent( Indent), write( '[]' ).
|
||||
pp_indented( List, Indent ) :-
|
||||
List = [_|_],
|
||||
pp_indent( Indent ),
|
||||
pp_list( List, Indent ).
|
||||
pp_indented( comment(Text), Indent ) :-
|
||||
pp_indent( Indent ), write( 'comment(' ), pp_string(Text), write( ')' ).
|
||||
pp_indented( namespace(URI,Prefix,Element), Indent ) :-
|
||||
pp_indent( Indent ),
|
||||
write( 'namespace( ' ), writeq( URI ), pp_comma_sp,
|
||||
pp_string( Prefix ), pp_comma, nl,
|
||||
pp_indented( Element, s(Indent) ), nl,
|
||||
pp_indent( s(Indent) ), write( ')' ).
|
||||
pp_indented( element(Tag,Attributes,Contents), Indent ) :-
|
||||
pp_indent( Indent ), write( 'element( ' ), writeq( Tag ), pp_comma, nl,
|
||||
pp_attributes( Attributes, s(Indent) ), pp_comma, nl,
|
||||
pp_list( Contents, s(Indent) ), write( ' )' ).
|
||||
pp_indented( instructions(Target, Processing), Indent ) :-
|
||||
pp_indent( Indent ), write( 'instructions( ' ), writeq( Target ), pp_comma_sp,
|
||||
pp_string(Processing), write( ')' ).
|
||||
pp_indented( doctype(Name, DoctypeId), Indent ) :-
|
||||
pp_indent( Indent ), write( 'doctype( ' ), writeq( Name ), pp_comma_sp,
|
||||
pp_indented( DoctypeId, s(Indent) ), %'
|
||||
write( ' )' ).
|
||||
pp_indented( cdata(CData), Indent ) :-
|
||||
pp_indent( Indent ), write( 'cdata(' ), pp_string(CData), write( ')' ).
|
||||
pp_indented( pcdata(PCData), Indent ) :-
|
||||
pp_indent( Indent ), write( 'pcdata(' ), pp_string(PCData), write( ')' ).
|
||||
pp_indented( public(URN,URL), _Indent ) :-
|
||||
write( 'public(' ), pp_string(URN), pp_comma_sp,
|
||||
pp_string(URL), write( ')' ).
|
||||
pp_indented( public(URN,URL,Literals), Indent ) :-
|
||||
write( 'public(' ), pp_string(URN), pp_comma_sp,
|
||||
pp_string(URL), pp_list( Literals, s(Indent) ), write( ')' ).
|
||||
pp_indented( system(URL), _Indent ) :-
|
||||
write( 'system(' ), pp_string(URL), write( ')' ).
|
||||
pp_indented( system(URL,Literals), Indent ) :-
|
||||
write( 'system(' ), pp_string(URL), pp_comma_sp,
|
||||
pp_list( Literals, s(Indent) ), write( ')' ).
|
||||
pp_indented( local, _Indent ) :-
|
||||
write( local ).
|
||||
pp_indented( local(Literals), Indent ) :-
|
||||
write( 'local(' ), nl,
|
||||
pp_list( Literals, s(Indent) ), write( ')' ).
|
||||
pp_indented( dtd_literal(String), Indent ) :-
|
||||
pp_indent( Indent ), write( 'dtd_literal(' ), pp_string(String), write( ')' ).
|
||||
pp_indented( out_of_context(Tag), Indent ) :-
|
||||
pp_indent( Indent ), write( '/* SYNTAX ERROR */ out_of_context( ' ),
|
||||
writeq( Tag ), write( ' )' ).
|
||||
pp_indented( unparsed(String), Indent ) :-
|
||||
pp_indent( Indent ), write( '/* SYNTAX ERROR */ unparsed( ' ),
|
||||
pp_string(String), write( ' )' ).
|
||||
|
||||
pp_list( [], Indent ) :-
|
||||
pp_indent( Indent ), write( [] ).
|
||||
pp_list( [H|T], Indent ) :-
|
||||
pp_indent( Indent ), write( '[' ), nl,
|
||||
pp_indented( H, Indent ),
|
||||
pp_list1( T, Indent ),
|
||||
pp_indent( Indent ), write( ']' ).
|
||||
|
||||
pp_list1( [], _Indent ) :-
|
||||
nl.
|
||||
pp_list1( [H|T], Indent ) :-
|
||||
pp_comma, nl,
|
||||
pp_indented( H, Indent ),
|
||||
pp_list1( T, Indent ).
|
||||
|
||||
pp_attributes( [], Indent ) :-
|
||||
pp_indent( Indent ), write( [] ).
|
||||
pp_attributes( [Attribute|Attributes], Indent ) :-
|
||||
pp_indent( Indent ), write( '[' ),
|
||||
pp_attributes1( Attributes, Attribute ),
|
||||
write( ']' ).
|
||||
|
||||
pp_attributes1( [], Name=Value ) :-
|
||||
pp_name( Name ), pp_string( Value ).
|
||||
pp_attributes1( [H|T], Name=Value ) :-
|
||||
pp_name( Name ), pp_string( Value ), pp_comma_sp,
|
||||
pp_attributes1( T, H ).
|
||||
|
||||
|
||||
pp_name( Name ) :-
|
||||
( possible_operator( Name ) ->
|
||||
write( '(' ), write( Name ), write( ')=' )
|
||||
; otherwise ->
|
||||
writeq( Name ), write( '=' )
|
||||
).
|
||||
|
||||
possible_operator( (abolish) ).
|
||||
possible_operator( (attribute) ).
|
||||
possible_operator( (check_advice) ).
|
||||
possible_operator( (compile_command) ).
|
||||
possible_operator( (delay) ).
|
||||
possible_operator( (demon) ).
|
||||
possible_operator( (discontiguous) ).
|
||||
possible_operator( (div) ).
|
||||
possible_operator( (do) ).
|
||||
possible_operator( (document_export) ).
|
||||
possible_operator( (document_import) ).
|
||||
possible_operator( (dy) ).
|
||||
possible_operator( (dynamic) ).
|
||||
possible_operator( (edb) ).
|
||||
possible_operator( (eexport) ).
|
||||
possible_operator( (else) ).
|
||||
possible_operator( (except) ).
|
||||
possible_operator( (export) ).
|
||||
possible_operator( (foreign_pred) ).
|
||||
possible_operator( (from) ).
|
||||
possible_operator( (from_chars) ).
|
||||
possible_operator( (from_file) ).
|
||||
possible_operator( (from_stream) ).
|
||||
possible_operator( (global) ).
|
||||
possible_operator( (help) ).
|
||||
possible_operator( (hilog) ).
|
||||
possible_operator( (if) ).
|
||||
possible_operator( (import) ).
|
||||
possible_operator( (index) ).
|
||||
possible_operator( (initialization) ).
|
||||
possible_operator( (is) ).
|
||||
possible_operator( (listing) ).
|
||||
possible_operator( (local) ).
|
||||
possible_operator( (locked) ).
|
||||
possible_operator( (meta_predicate) ).
|
||||
possible_operator( (mod) ).
|
||||
possible_operator( (mode) ).
|
||||
possible_operator( (module_transparent) ).
|
||||
possible_operator( (multifile) ).
|
||||
possible_operator( (namic) ).
|
||||
possible_operator( (nocheck_advice) ).
|
||||
possible_operator( (nospy) ).
|
||||
possible_operator( (not) ).
|
||||
possible_operator( (of) ).
|
||||
possible_operator( (once) ).
|
||||
possible_operator( (onto_chars) ).
|
||||
possible_operator( (onto_file) ).
|
||||
possible_operator( (onto_stream) ).
|
||||
possible_operator( (parallel) ).
|
||||
possible_operator( (public) ).
|
||||
possible_operator( (r) ).
|
||||
possible_operator( (rem) ).
|
||||
possible_operator( (skipped) ).
|
||||
possible_operator( (spy) ).
|
||||
possible_operator( (table) ).
|
||||
possible_operator( (then) ).
|
||||
possible_operator( (thread_local) ).
|
||||
possible_operator( (ti) ).
|
||||
possible_operator( (ti_off) ).
|
||||
possible_operator( (traceable) ).
|
||||
possible_operator( (unskipped) ).
|
||||
possible_operator( (untraceable) ).
|
||||
possible_operator( (use_subsumptive_tabling) ).
|
||||
possible_operator( (use_variant_tabling) ).
|
||||
possible_operator( (volatile) ).
|
||||
possible_operator( (with) ).
|
||||
possible_operator( (with_input_from_chars) ).
|
||||
possible_operator( (with_output_to_chars) ).
|
||||
possible_operator( (xor) ).
|
||||
|
||||
pp_indent( 0 ).
|
||||
pp_indent( s(N) ) :-
|
||||
write( ' ' ),
|
||||
pp_indent( N ).
|
||||
|
||||
pp_comma :-
|
||||
write( ',' ).
|
||||
|
||||
pp_comma_sp :-
|
||||
write( ', ' ).
|
||||
/* xml_pp: "pretty print" an XML Document on the current output stream.
|
||||
*
|
||||
* Copyright (C) 2001-2005 Binding Time Limited
|
||||
* Copyright (C) 2005-2011 John Fletcher
|
||||
*
|
||||
* Current Release: $Revision: 3.3 $
|
||||
*
|
||||
* TERMS AND CONDITIONS:
|
||||
*
|
||||
* This program is offered free of charge, as unsupported source code. You may
|
||||
* use it, copy it, distribute it, modify it or sell it without restriction,
|
||||
* but entirely at your own risk.
|
||||
*/
|
||||
|
||||
:- ensure_loaded( xml_utilities ).
|
||||
|
||||
/** xml_pp( +XMLDocument )
|
||||
*
|
||||
* "pretty prints" XMLDocument on the current
|
||||
* output stream.
|
||||
*/
|
||||
xml_pp( xml(Attributes, Document) ) :-
|
||||
write( 'xml( ' ), pp_attributes( Attributes, 0 ), pp_comma, nl,
|
||||
pp_list( Document, s(0) ),
|
||||
write( ' ).' ), nl.
|
||||
xml_pp( malformed(Attributes, Document) ) :-
|
||||
write( 'malformed( ' ), pp_attributes( Attributes, 0 ), pp_comma, nl,
|
||||
pp_list( Document, s(0) ),
|
||||
write( ' ).' ), nl.
|
||||
|
||||
pp_indented( [], Indent ) :-
|
||||
pp_indent( Indent), write( '[]' ).
|
||||
pp_indented( List, Indent ) :-
|
||||
List = [_|_],
|
||||
pp_indent( Indent ),
|
||||
pp_list( List, Indent ).
|
||||
pp_indented( comment(Text), Indent ) :-
|
||||
pp_indent( Indent ), write( 'comment(' ), pp_string(Text), write( ')' ).
|
||||
pp_indented( namespace(URI,Prefix,Element), Indent ) :-
|
||||
pp_indent( Indent ),
|
||||
write( 'namespace( ' ), writeq( URI ), pp_comma_sp,
|
||||
pp_string( Prefix ), pp_comma, nl,
|
||||
pp_indented( Element, s(Indent) ), nl,
|
||||
pp_indent( s(Indent) ), write( ')' ).
|
||||
pp_indented( element(Tag,Attributes,Contents), Indent ) :-
|
||||
pp_indent( Indent ), write( 'element( ' ), writeq( Tag ), pp_comma, nl,
|
||||
pp_attributes( Attributes, s(Indent) ), pp_comma, nl,
|
||||
pp_list( Contents, s(Indent) ), write( ' )' ).
|
||||
pp_indented( instructions(Target, Processing), Indent ) :-
|
||||
pp_indent( Indent ), write( 'instructions( ' ), writeq( Target ), pp_comma_sp,
|
||||
pp_string(Processing), write( ')' ).
|
||||
pp_indented( doctype(Name, DoctypeId), Indent ) :-
|
||||
pp_indent( Indent ), write( 'doctype( ' ), writeq( Name ), pp_comma_sp,
|
||||
pp_indented( DoctypeId, s(Indent) ), %'
|
||||
write( ' )' ).
|
||||
pp_indented( cdata(CData), Indent ) :-
|
||||
pp_indent( Indent ), write( 'cdata(' ), pp_string(CData), write( ')' ).
|
||||
pp_indented( pcdata(PCData), Indent ) :-
|
||||
pp_indent( Indent ), write( 'pcdata(' ), pp_string(PCData), write( ')' ).
|
||||
pp_indented( public(URN,URL), _Indent ) :-
|
||||
write( 'public(' ), pp_string(URN), pp_comma_sp,
|
||||
pp_string(URL), write( ')' ).
|
||||
pp_indented( public(URN,URL,Literals), Indent ) :-
|
||||
write( 'public(' ), pp_string(URN), pp_comma_sp,
|
||||
pp_string(URL), pp_list( Literals, s(Indent) ), write( ')' ).
|
||||
pp_indented( system(URL), _Indent ) :-
|
||||
write( 'system(' ), pp_string(URL), write( ')' ).
|
||||
pp_indented( system(URL,Literals), Indent ) :-
|
||||
write( 'system(' ), pp_string(URL), pp_comma_sp,
|
||||
pp_list( Literals, s(Indent) ), write( ')' ).
|
||||
pp_indented( local, _Indent ) :-
|
||||
write( local ).
|
||||
pp_indented( local(Literals), Indent ) :-
|
||||
write( 'local(' ), nl,
|
||||
pp_list( Literals, s(Indent) ), write( ')' ).
|
||||
pp_indented( dtd_literal(String), Indent ) :-
|
||||
pp_indent( Indent ), write( 'dtd_literal(' ), pp_string(String), write( ')' ).
|
||||
pp_indented( out_of_context(Tag), Indent ) :-
|
||||
pp_indent( Indent ), write( '/* SYNTAX ERROR */ out_of_context( ' ),
|
||||
writeq( Tag ), write( ' )' ).
|
||||
pp_indented( unparsed(String), Indent ) :-
|
||||
pp_indent( Indent ), write( '/* SYNTAX ERROR */ unparsed( ' ),
|
||||
pp_string(String), write( ' )' ).
|
||||
|
||||
pp_list( [], Indent ) :-
|
||||
pp_indent( Indent ), write( [] ).
|
||||
pp_list( [H|T], Indent ) :-
|
||||
pp_indent( Indent ), write( '[' ), nl,
|
||||
pp_indented( H, Indent ),
|
||||
pp_list1( T, Indent ),
|
||||
pp_indent( Indent ), write( ']' ).
|
||||
|
||||
pp_list1( [], _Indent ) :-
|
||||
nl.
|
||||
pp_list1( [H|T], Indent ) :-
|
||||
pp_comma, nl,
|
||||
pp_indented( H, Indent ),
|
||||
pp_list1( T, Indent ).
|
||||
|
||||
pp_attributes( [], Indent ) :-
|
||||
pp_indent( Indent ), write( [] ).
|
||||
pp_attributes( [Attribute|Attributes], Indent ) :-
|
||||
pp_indent( Indent ), write( '[' ),
|
||||
pp_attributes1( Attributes, Attribute ),
|
||||
write( ']' ).
|
||||
|
||||
pp_attributes1( [], Name=Value ) :-
|
||||
pp_name( Name ), pp_string( Value ).
|
||||
pp_attributes1( [H|T], Name=Value ) :-
|
||||
pp_name( Name ), pp_string( Value ), pp_comma_sp,
|
||||
pp_attributes1( T, H ).
|
||||
|
||||
|
||||
pp_name( Name ) :-
|
||||
( possible_operator( Name ) ->
|
||||
write( '(' ), write( Name ), write( ')=' )
|
||||
; otherwise ->
|
||||
writeq( Name ), write( '=' )
|
||||
).
|
||||
|
||||
possible_operator( (abolish) ).
|
||||
possible_operator( (attribute) ).
|
||||
possible_operator( (check_advice) ).
|
||||
possible_operator( (compile_command) ).
|
||||
possible_operator( (delay) ).
|
||||
possible_operator( (demon) ).
|
||||
possible_operator( (discontiguous) ).
|
||||
possible_operator( (div) ).
|
||||
possible_operator( (do) ).
|
||||
possible_operator( (document_export) ).
|
||||
possible_operator( (document_import) ).
|
||||
possible_operator( (dy) ).
|
||||
possible_operator( (dynamic) ).
|
||||
possible_operator( (edb) ).
|
||||
possible_operator( (eexport) ).
|
||||
possible_operator( (else) ).
|
||||
possible_operator( (except) ).
|
||||
possible_operator( (export) ).
|
||||
possible_operator( (foreign_pred) ).
|
||||
possible_operator( (from) ).
|
||||
possible_operator( (from_chars) ).
|
||||
possible_operator( (from_file) ).
|
||||
possible_operator( (from_stream) ).
|
||||
possible_operator( (global) ).
|
||||
possible_operator( (help) ).
|
||||
possible_operator( (hilog) ).
|
||||
possible_operator( (if) ).
|
||||
possible_operator( (import) ).
|
||||
possible_operator( (index) ).
|
||||
possible_operator( (initialization) ).
|
||||
possible_operator( (is) ).
|
||||
possible_operator( (listing) ).
|
||||
possible_operator( (local) ).
|
||||
possible_operator( (locked) ).
|
||||
possible_operator( (meta_predicate) ).
|
||||
possible_operator( (mod) ).
|
||||
possible_operator( (mode) ).
|
||||
possible_operator( (module_transparent) ).
|
||||
possible_operator( (multifile) ).
|
||||
possible_operator( (namic) ).
|
||||
possible_operator( (nocheck_advice) ).
|
||||
possible_operator( (nospy) ).
|
||||
possible_operator( (not) ).
|
||||
possible_operator( (of) ).
|
||||
possible_operator( (once) ).
|
||||
possible_operator( (onto_chars) ).
|
||||
possible_operator( (onto_file) ).
|
||||
possible_operator( (onto_stream) ).
|
||||
possible_operator( (parallel) ).
|
||||
possible_operator( (public) ).
|
||||
possible_operator( (r) ).
|
||||
possible_operator( (rem) ).
|
||||
possible_operator( (skipped) ).
|
||||
possible_operator( (spy) ).
|
||||
possible_operator( (table) ).
|
||||
possible_operator( (then) ).
|
||||
possible_operator( (thread_local) ).
|
||||
possible_operator( (ti) ).
|
||||
possible_operator( (ti_off) ).
|
||||
possible_operator( (traceable) ).
|
||||
possible_operator( (unskipped) ).
|
||||
possible_operator( (untraceable) ).
|
||||
possible_operator( (use_subsumptive_tabling) ).
|
||||
possible_operator( (use_variant_tabling) ).
|
||||
possible_operator( (volatile) ).
|
||||
possible_operator( (with) ).
|
||||
possible_operator( (with_input_from_chars) ).
|
||||
possible_operator( (with_output_to_chars) ).
|
||||
possible_operator( (xor) ).
|
||||
|
||||
pp_indent( 0 ).
|
||||
pp_indent( s(N) ) :-
|
||||
write( ' ' ),
|
||||
pp_indent( N ).
|
||||
|
||||
pp_comma :-
|
||||
write( ',' ).
|
||||
|
||||
pp_comma_sp :-
|
||||
write( ', ' ).
|
||||
|
||||
|
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user