[Ocaml-pxp-users] Setting line number

Gerd Stolpmann info at gerd-stolpmann.de
Tue Dec 16 08:22:42 PST 2014


Well, I see generally two possibilities:

 - The nodes of the document trees are created by cloning so-called
   exemplar nodes. At this point you can override the position method.

   You are using default_spec which is:

   let default_spec =
     make_spec_from_mapping
      ~super_root_exemplar:      (new super_root_impl default_extension)
      ~comment_exemplar:         (new comment_impl default_extension)
      ~default_pinstr_exemplar:  (new pinstr_impl default_extension)
      ~data_exemplar:            (new data_impl default_extension)
      ~default_element_exemplar: (new element_impl default_extension)
      ~element_mapping:          (Hashtbl.create 1)
      ()

   You could change here default_element_exemplar, and create your own
   exemplar object. The mechanism is now that the parser will call
   exemplar#create_element when the actual node for the tree is created.
   create_element gets the position as argument, and at this point you
   can modify the position, something like:

   let back_exemplar = new element_impl default_extension

   let default_element_exemplar =
     object
       inherit element_impl default_extension
       method create_element ... ?position ... =
         let position' = ... in
         back_exemplar # create_element ... ?position:position' ...
     end

   Of course, this is totally untested, but could work. I don't think
   this influences the positions in error messages, though.

 - The other idea is more adventurous: modify the positions returned by
   entity objects. Entity objects are defined in Pxp_entity, and there
   are line and column methods. You can define the top-level entity
   object if you use a source Entity(f,r) because the function f 
   is called to get the entity object.

   The function from_string returns an ExtID source, unfortunately.
   I think you can use it nevertheless, something like

   let ExtID(ext_id, r) = from_string ... in

   let f dtd =
      let entity =
        object
          inherit external_entity r dtd ...
             (* see Pxp_types.open_source *)
          
          method line = super#line + offset
       end in
     Entity(f,r)

   let source = Entity(f,r)

   Again, completely untested. 

Gerd

Am Dienstag, den 16.12.2014, 14:03 +0000 schrieb Dario Teixeira:
> Hi,
> 
> When using Pxp_tree_parser.parse_content_entity to parse from a string,
> is there a way to set the first line number to a value other than the
> default (probably 1)?
> 
> Yes, I realise I can just add the line number offset to the value given
> 
> by node#position, but for this particular application [1] it would much
> easier if I could just tell PXP that line numbering starts at N.
> 
> Thanks in advance for any help!
> Best regards,
> Dario Teixeira
> 
> 
> [1] https://github.com/darioteixeira/lambdoc/blob/master/src/lib/lambdoc_read_lambxml_impl/parser.ml
> _______________________________________________
> Ocaml-pxp-users mailing list
> Ocaml-pxp-users at orcaware.com
> http://www.orcaware.com/mailman/listinfo/ocaml-pxp-users

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd at gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 473 bytes
Desc: This is a digitally signed message part
URL: <http://www.orcaware.com/pipermail/ocaml-pxp-users/attachments/20141216/c18d97bc/attachment.sig>


More information about the Ocaml-pxp-users mailing list