caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] how to get location of a polymorphic variant via compiler libs
@ 2017-10-19 10:55 Matej Košík
  2017-10-19 11:01 ` Thomas Refis
  0 siblings, 1 reply; 2+ messages in thread
From: Matej Košík @ 2017-10-19 10:55 UTC (permalink / raw)
  To: caml-list


[-- Attachment #1.1.1: Type: text/plain, Size: 541 bytes --]

Hi,

I am using compiler-libs for getting locations of lexical items I am interested in.
(modules, values, types, non-polymorphic variants, record labels).

If I have a code like this:

  type t = [`Foo | `Bar]

does the parse-tree hold the location of "`Foo" (or "`Bar") somewhere?

(I am not interested in the location of the whole type definition --- just the location of a specific polymorphic variant/constructor.)

The attachment display the available parse-tree I can see
(and not able to find bits I am interested in)

[-- Attachment #1.1.2: parsetree.txt --]
[-- Type: text/plain, Size: 1537 bytes --]

val structure : Parsetree.structure =
  [{pstr_desc =
     Pstr_type (Asttypes.Recursive,
      [{ptype_name =
         {Asttypes.txt = "t";
          loc =
           {loc_start =
             {Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0; pos_cnum = 5};
            loc_end =
             {Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0; pos_cnum = 6};
            loc_ghost = false}};
        ptype_params = []; ptype_cstrs = []; ptype_kind = Ptype_abstract;
        ptype_private = Asttypes.Public;
        ptype_manifest =
         Some
          {ptyp_desc =
            Ptyp_variant
             ([Rtag ("Foo", [], true, []); Rtag ("Bar", [], true, [])],
             Asttypes.Closed, None);
           ptyp_loc =
            {loc_start =
              {Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0;
               pos_cnum = 9};
             loc_end =
              {Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0;
               pos_cnum = 22};
             loc_ghost = false};
           ptyp_attributes = []};
        ptype_attributes = [];
        ptype_loc =
         {loc_start =
           {Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0; pos_cnum = 0};
          loc_end =
           {Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0; pos_cnum = 22};
          loc_ghost = false}}]);
    pstr_loc =
     {loc_start =
       {Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0; pos_cnum = 0};
      loc_end =
       {Lexing.pos_fname = ""; pos_lnum = 1; pos_bol = 0; pos_cnum = 22};
      loc_ghost = false}}]

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [Caml-list] how to get location of a polymorphic variant via compiler libs
  2017-10-19 10:55 [Caml-list] how to get location of a polymorphic variant via compiler libs Matej Košík
@ 2017-10-19 11:01 ` Thomas Refis
  0 siblings, 0 replies; 2+ messages in thread
From: Thomas Refis @ 2017-10-19 11:01 UTC (permalink / raw)
  To: Matej Košík; +Cc: caml users

[-- Attachment #1: Type: text/plain, Size: 714 bytes --]

https://github.com/ocaml/ocaml/blob/trunk/parsing/parsetree.mli#L144

2017-10-19 11:55 GMT+01:00 Matej Košík <mail@matej-kosik.net>:

> Hi,
>
> I am using compiler-libs for getting locations of lexical items I am
> interested in.
> (modules, values, types, non-polymorphic variants, record labels).
>
> If I have a code like this:
>
>   type t = [`Foo | `Bar]
>
> does the parse-tree hold the location of "`Foo" (or "`Bar") somewhere?
>
> (I am not interested in the location of the whole type definition --- just
> the location of a specific polymorphic variant/constructor.)
>
> The attachment display the available parse-tree I can see
> (and not able to find bits I am interested in)
>

[-- Attachment #2: Type: text/html, Size: 1140 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-10-19 11:01 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-10-19 10:55 [Caml-list] how to get location of a polymorphic variant via compiler libs Matej Košík
2017-10-19 11:01 ` Thomas Refis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).