Commit f1e9419a authored by gerd's avatar gerd

removal of E_pinstr_member


git-svn-id: https://godirepo.camlcity.org/svn/lib-pxp/trunk@739 dbe99aee-44db-0310-b2b3-d33182c8eb97
parent 4542d28a
......@@ -58,6 +58,7 @@ for PXP; if you are looking for the stable distribution, please go
<p>Addition: Pxp_event.close_entities</p>
<p>Removed: Pxp_core_types_type, Pxp_type_anchor. Pxp_core_types
has now three submodules A, S, I taking over the roles</p>
<p>Removed: E_pinstr_member. Instead, E_pinstr events are emitted</p>
</li>
<li><p><em>1.2.0test*:</em> New ~minimization option for the
[write] and [display] methods (user wish).</p>
......
......@@ -63,7 +63,8 @@ possible to enable more node types by setting appropriate
special node type for comments.
- Processing instructions (denoted by [<? ... ?>] parentheses) are
not ignored, but normally no nodes are created for them. The
instructions are only gathered up, so one can check for their
instructions are only gathered up, and attached to the surrounding
node, so one can check for their
presence but not for their exact location. By setting the
config option [enable_pinstr_nodes], however, processing instructions
are added to the tree as normal nodes. There is also a special node
......@@ -127,7 +128,7 @@ are outside the regular document tree.
Normally, the processing instructions are also not included
into the document tree. They are considered as an extra property of the
element containing them, and can be retrieved by the
element to which they are attached, and can be retrieved by the
{!Pxp_document.node.pinstr}
method of the element node. If this way of handling processing instructions
is not exact enough, the parser can optionally create processing instruction
......@@ -305,7 +306,7 @@ is generated at the top of the tree. This node has type [T_super_root].}
parser add comment nodes when it parses comments. These nodes have
type [T_comment].}
{- The option [enable_pinstr_nodes] changes the
way processing instructions are added to the document. Instead of appending
way processing instructions are added to the document. Instead of attaching
such instructions to their containing elements as additional properties, this
mode forces the parser to create real nodes of type [T_pinstr] for them.}
{- The option [drop_ignorable_whitespace] (enabled by default) can
......@@ -576,19 +577,21 @@ PI is called the target, and it is stored separated from the rest of the PI:
<?target rest?>
]}
The exact location where a PI occurs is not represented (by default). The
parser puts the PI into the object that represents the embracing construct (an
element, a DTD, or the whole document); that means you can find out which PIs
occur in a certain element, in the DTD, or in the whole document, but you
cannot lookup the exact position within the construct.
The exact location where a PI occurs is not represented (by
default). The parser attaches the PI to the object that represents the
embracing construct (an element, a DTD, or the whole document); that
means you can find out which PIs occur in a certain element, in the
DTD, or in the whole document, but you cannot lookup the exact
position within the construct.
{b Parser option:}
If you require the exact location of PIs, it is possible to
create extra nodes for them. This mode is controlled by the option
create regular nodes for them instead of attaching them to the surrounding
node as property. This mode is controlled by the option
[enable_pinstr_nodes]. The additional nodes have the node type
[T_pinstr target], and are created
from special exemplars contained in the [spec] (see
{!Pxp_document.spec}).
{!Pxp_document.spec}).
{3 The representation of comments}
......
......@@ -4206,6 +4206,16 @@ let solidify ?dtd cfg spec next_ev : 'ext solid_xml =
failwith ("Pxp_document.solidify: Unexpected " ^ txt ^ " event")
in
let create_delayed_super_root entity_id (srpos, children, pilist) =
let n = create_super_root_node
~entity_id ?position:srpos spec !eff_dtd in
List.iter
(fun pi -> n # add_pinstr pi)
(List.rev pilist);
n # set_nodes (List.rev children);
n
in
while not !eof do
let ev = next_ev() in
match ev with
......@@ -4236,10 +4246,8 @@ let solidify ?dtd cfg spec next_ev : 'ext solid_xml =
match !super_root_details with
| None ->
r
| Some pos ->
create_super_root_node
~entity_id:r#entity_id
?position:pos spec !eff_dtd in
| Some srparams ->
create_delayed_super_root r#entity_id srparams in
return := Some r';
r_doc # init_root r' lit_root;
| _ ->
......@@ -4251,10 +4259,12 @@ let solidify ?dtd cfg spec next_ev : 'ext solid_xml =
if !doc_state = Null then doc_state := NA;
super_state := Start_seen;
if cfg.enable_super_root_node then (
super_root_details := Some !pos;
(*
let n = create_super_root_node ?position:!pos spec !eff_dtd in
Stack.push n stack;
(* The creation of the super root node is delayed until we
know the entity ID of the top element
*)
super_root_details := Some(!pos, [], []);
(* first list: the children in reverse order
second list: the PI's to attach in reverse order
*)
)
......@@ -4330,41 +4340,48 @@ let solidify ?dtd cfg spec next_ev : 'ext solid_xml =
(* A PI may occur everywhere between start_doc and end_doc. *)
if !doc_state = End_seen then unexpected "E_pinstr";
if !doc_state = Null then doc_state := NA;
if !super_state <> Start_seen && !root_state <> Start_seen then
unexpected "E_pinstr";
let pi = new proc_instruction target value !eff_dtd#encoding in
if !depth = 0 && (!super_state <> Start_seen ||
not cfg.enable_super_root_node) then (
(* Cannot process E_pinstr here. Should be E_pinstr_member. *)
()
if !depth = 0 then (
if cfg.enable_super_root_node then (
match !super_root_details with
| None ->
unexpected "E_pinstr"
| Some (srpos, children, pilist) ->
(* Add PI to super root node
(attached, or as regular child)
*)
if cfg.enable_pinstr_nodes then (
let n = create_pinstr_node
~entity_id:eid ?position:!pos spec !eff_dtd pi in
super_root_details := Some(srpos, n::children, pilist)
)
else (
super_root_details := Some(srpos, children, pi::pilist)
)
)
else (
(* Add processing instruction to document, if any *)
if not cfg.enable_super_root_node then (
match !return_doc with
Some doc -> doc # add_pinstr pi
| None -> () (* PI is lost *)
);
)
)
else
else (
(* Add PI to parent element (attached, or as regular child) *)
if cfg.enable_pinstr_nodes then (
let n = create_pinstr_node
~entity_id:eid ?position:!pos spec !eff_dtd pi in
(Stack.top stack) # append_node n
)
else (
(* Cannot process E_pinstr here. Should be E_pinstr_member. *)
()
);
pos := None
| Some (E_pinstr_member(target,value,_)) ->
if !doc_state = End_seen then unexpected "E_pinstr";
if !doc_state = Null then doc_state := NA;
let pi = new proc_instruction target value !eff_dtd#encoding in
if !depth = 0 && (!super_state <> Start_seen ||
not cfg.enable_super_root_node) then (
(* Add processing instruction to document, if any *)
match !return_doc with
Some doc -> doc # add_pinstr pi
| None -> () (* PI is lost *)
)
else
if not cfg.enable_pinstr_nodes then (
else
(Stack.top stack) # add_pinstr pi
);
);
pos := None
| Some (E_comment data) ->
(* A comment may occur everywhere between start_doc and end_doc.
* Only below the super root or the simple root node it is
......@@ -4372,15 +4389,25 @@ let solidify ?dtd cfg spec next_ev : 'ext solid_xml =
*)
if !doc_state = End_seen then unexpected "E_comment";
if !doc_state = Null then doc_state := NA;
if (cfg.enable_super_root_node && !super_state = Start_seen) ||
(!root_state = Start_seen) then (
try
if cfg.enable_comment_nodes then begin
let n = create_comment_node ?position:!pos spec !eff_dtd data in
(Stack.top stack) # append_node n
end
with
Stack.Empty -> ()
if !super_state <> Start_seen && !root_state <> Start_seen then
unexpected "E_comment";
if cfg.enable_comment_nodes then (
if !depth = 0 then (
if cfg.enable_super_root_node then (
match !super_root_details with
| None ->
unexpected "E_comment"
| Some (srpos, children, pilist) ->
(* Add comment to super root node, if enabled *)
let n = create_comment_node
?position:!pos spec !eff_dtd data in
super_root_details := Some(srpos, n::children, pilist);
)
)
else (
let n = create_comment_node ?position:!pos spec !eff_dtd data in
(Stack.top stack) # append_node n
)
);
pos := None
......@@ -4406,10 +4433,8 @@ let solidify ?dtd cfg spec next_ev : 'ext solid_xml =
match !super_root_details with
| None ->
n
| Some pos ->
create_super_root_node
~entity_id:n#entity_id
?position:pos spec !eff_dtd in
| Some srparams ->
create_delayed_super_root n#entity_id srparams in
`Node n'
| _ -> assert false
)
......@@ -4472,7 +4497,7 @@ let liquefy_node ?(omit_end = false) ?(omit_positions = false)
(fun target ->
List.map
(fun pi ->
E_pinstr_member(target,pi#value,eid)
E_pinstr(target,pi#value,eid)
)
(n # pinstr target)
)
......@@ -4571,7 +4596,7 @@ let liquefy_doc ?(omit_end = false) ?(omit_positions = false)
(fun target ->
List.map
(fun pi ->
E_pinstr_member(target,pi#value,eid)
E_pinstr(target,pi#value,eid)
)
(doc # pinstr target)
)
......
......@@ -554,7 +554,7 @@ class type [ 'ext ] node =
method pinstr : string -> proc_instruction list
(** [pinstr n] returns all processing instructions that are
* directly contained in this object and that have a target
* attached to this object and that have a target
* specification of [n].
*
* {b Domain.} All node types. However, it is only reasonable to
......@@ -571,14 +571,15 @@ class type [ 'ext ] node =
* is added to this node, and can be queried by calling this method.
*
* If the mentioned config option is not active (which is the default),
* the [proc_instruction] object is simply added to the containing
* element, and the exact position of the instruction is not reflected
* in the tree.
* the [proc_instruction] object is attached to the containing
* element, but does not become a regular child of the element.
* Especially, the exact position of the instruction among the
* children is not reflected in the tree.
*)
method pinstr_names : string list
(** Returns the targets of all processing instructions that are
* directly contained in this object. The target is the first word
* attached to this object. The target is the first word
* in the processing instruction. Use the [pinstr] method to get
* the full data of a processing instruction.
*
......@@ -849,7 +850,7 @@ class type [ 'ext ] node =
method add_pinstr : proc_instruction -> unit
(** [add_pinstr pi]:
* Adds the processing instruction [pi] to the set of
* processing instructions contained in this node. If this is an
* processing instructions attached to this node. If this is an
* element node, you can add any number of processing instructions.
* If it is a processing instruction node, you can put at most
* one processing instruction into this node.
......
......@@ -173,7 +173,7 @@ object (self)
ep_early_events <- ep_early_events @ ev_list
end
else begin
let ev = E_pinstr_member(target,value,ent_id) in
let ev = E_pinstr(target,value,ent_id) in
if init_done then
event_handler ev
else
......
......@@ -578,9 +578,6 @@ let wr_dsp do_display default_prefix dtd_style minimization out enc rep_enc get_
| Some (E_pinstr (target, value, ent_id)) ->
wms "<? "; wms target; wms " "; wms value; wms "?>";
wr_dsp_event None
| Some (E_pinstr_member (target, value, ent_id)) ->
wms "<? "; wms target; wms " "; wms value; wms "?>";
wr_dsp_event None
| Some (E_comment data) ->
wms "<!--"; wms data; wms "-->";
wr_dsp_event None
......@@ -633,8 +630,6 @@ let string_of_event e =
sprintf "E_char_data(\"%s\")" (String.escaped data)
| E_pinstr(target,data,entid) ->
sprintf "E_pinstr(%s,%s,<%d>)" target data (Oo.id entid)
| E_pinstr_member(target,data,entid) ->
sprintf "E_pinstr_member(%s,%s,<%d>)" target data (Oo.id entid)
| E_comment data ->
sprintf "E_comment(\"%s\")" (String.escaped data)
| E_position(ent,line,col) ->
......
......@@ -229,7 +229,6 @@ type event =
| E_end_tag of (string * Pxp_lexer_types.entity_id)
| E_char_data of string
| E_pinstr of (string * string * Pxp_lexer_types.entity_id)
| E_pinstr_member of (string * string * Pxp_lexer_types.entity_id)
| E_comment of string
| E_start_super
| E_end_super
......
......@@ -73,12 +73,13 @@ type config =
* If [enable_pinstr_nodes] the node for element [s] will contain
* two additional subnodes of type [T_pinstr], one as left sibling
* of "foo", and one as right sibling.
* Aany code processing such a tree must be prepared that
* processing instructions occur as normal tree members.
* Any code processing such a tree must be prepared that
* processing instructions occur as normal tree members, and are no
* longer attached to the surrounding nodes.
*
* The event-based parser reacts on the [enable_pinstr_nodes] mode
* by emitting [E_pinstr] events at the locations where the PI's
* occur in the text.
* by emitting [E_pinstr] events exactly at the locations where the
* PI's occur in the text.
*)
enable_comment_nodes : bool;
......@@ -652,11 +653,7 @@ type event =
| E_char_data of string
(** Character data *)
| E_pinstr of (string * string * Pxp_lexer_types.entity_id)
(** A processing instruction [<?target value?>] as node *)
| E_pinstr_member of (string * string * Pxp_lexer_types.entity_id)
(** A processing instruction [<?target value?>] that is to be
attached to the surrounding element or super root node
*)
(** A processing instruction [<?target value?>] *)
| E_comment of string
(** A comment node. The string does not include the delimiters *)
| E_start_super
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment