caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] camlp4: LIST1 construct on record patterns
@ 2002-01-13  5:38 Jeff Henrikson
  2002-01-13 13:48 ` Daniel de Rauglaudre
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Henrikson @ 2002-01-13  5:38 UTC (permalink / raw)
  To: caml-list

In camlp4, I don't seem to be able to break apart a record pattern in any way.  I must not understand how to use LIST1 properly:



let try_extend _ =
  let cons = "Bogus" in
  let test_label_eq = Grammar.Entry.find expr "test_label_eq" in
  let lbl_expr_list = Grammar.Entry.find expr "lbl_expr_list" in
  EXTEND
    expr: LEVEL "simple"
    [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" ->
          <:expr<{$list:memb$}>> ] ]
    ;
  END;;

try_extend "junk";;

...
      [ [ $cons$; "{"; memb = LIST1 reenter SEP ";" ; "}" ->
            <:expr<{$list:memb$}>> ] ]
                          ^^^^
      ;
    END;;
This expression has type Obj.t list but is here used with type
  (MLast.patt * MLast.expr) list


Isn't an Obj.t a completely opaque meaningless entity?

Substituting test_label_eq for lbl_expr_list makes no difference.  I got those identifiers by running:

Grammar.Entry.print expr;;

which doesn't tell me the meaning of test_label_eq, and

Grammar.Entry.print (Grammar.Entry.find expr "test_label_eq");;

doesn't tell me anything either.  Do I just have to go read the source code to know their meaning?  I would have except I guess it
doesn't come default now that camlp4 is part of ocaml.


Jeff Henrikson




-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] camlp4: LIST1 construct on record patterns
  2002-01-13  5:38 [Caml-list] camlp4: LIST1 construct on record patterns Jeff Henrikson
@ 2002-01-13 13:48 ` Daniel de Rauglaudre
  2002-01-14  2:17   ` Jeff Henrikson
  0 siblings, 1 reply; 5+ messages in thread
From: Daniel de Rauglaudre @ 2002-01-13 13:48 UTC (permalink / raw)
  To: caml-list

Hi,

On Sun, Jan 13, 2002 at 12:38:49AM -0500, Jeff Henrikson wrote:

>       [ [ $cons$; "{"; memb = LIST1 reenter SEP ";" ; "}" ->
>             <:expr<{$list:memb$}>> ] ]
>                           ^^^^
> This expression has type Obj.t list but is here used with type
>   (MLast.patt * MLast.expr) list

The problem is that Grammar.Entry.find cannot answer the right entry
type, since it can be any type. It is like "input_value". This is a
problem indeed to search for hidden entries. You have to know its real
type and magicify it (sorry):

  let lbl_expr_list =
    (Obj.magic (Grammar.Entry.find expr "lbl_expr_list") :
       (MLast.patt * MLast.expr) list Grammar.Entry.e)
  in
  ...

Something like that, I have not checked...

Yes, it is a little bit dirty, but I cannot export all the small
entries of the grammar.

> which doesn't tell me the meaning of test_label_eq

The entry "test_label_eq" is a hack to allow to separate the rules:
    { lbl_expr_list }
    { expr with lbl_expr_list }

The system of grammar of Camlp4 is not strong enough to separate
"lbl_expr_list" and "expr" which can start with the same tokens (it is
LL(infinity), because the first label can be A.B.C.D...lab). In
revised syntax, to avoid that problem, the "expr" must be
parenthesised.

There is some other hacks like that in the normal syntax.

The entry "test_label_eq" is written with a parser; it is created with
Grammar.Entry.of_parser and is not extensible and not visible by
Grammar.Entry.print. See the sources: camlp4/etc/pa_o.ml.

Sorry, Luke, you entered the dark side of Camlp4... :-)

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* RE: [Caml-list] camlp4: LIST1 construct on record patterns
  2002-01-13 13:48 ` Daniel de Rauglaudre
@ 2002-01-14  2:17   ` Jeff Henrikson
  2002-01-14  2:49     ` Jeff Henrikson
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Henrikson @ 2002-01-14  2:17 UTC (permalink / raw)
  To: Daniel de Rauglaudre; +Cc: caml-list

I actually tried magicing it into what I wanted it to be before, but was unable to guess it's real type.  Apparently I still can't:


open Printf;;

let try_extend _ =
  let cons = "Bogus" in
  let lbl_expr_list =
    (Obj.magic (Grammar.Entry.find expr "lbl_expr_list") :
       (MLast.patt * MLast.expr) (* not list *) Grammar.Entry.e) in
  EXTEND
    expr: LEVEL "simple"
    [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" ->
          <:expr<{$list:memb$}>> ] ]
    ;
  END;;

try_extend 7;;

Bogus{foo="happy";bar="sad"};;


This segfaults.  Let's see if memb is even a list:


let try_extend _ =
  let cons = "Bogus" in
  let lbl_expr_list =
    (Obj.magic (Grammar.Entry.find expr "lbl_expr_list") :
       (MLast.patt * MLast.expr) (* not list *) Grammar.Entry.e) in
  EXTEND
    expr: LEVEL "simple"
    [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" ->
          (printf "Do we get here %d\n" (List.length memb); flush stdout;
          <:expr<6>>) ] ]
    ;
  END;;

try_extend 7;;

Bogus{foo="happy";bar="sad"};;


This prints "Do we get here 1", regardless of how many terms I add in Bogus{}, regardless of whether such constructors are defined
or not.

But despite all this the source code looks convincing enough:

pa_o.ml:
      | "{"; test_label_eq; lel = lbl_expr_list; "}" ->
          <:expr< { $list:lel$ } >>

> Sorry, Luke, you entered the dark side of Camlp4... :-)

Apparently the force is not strong enough within me.  ;-}


Jeff

-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* RE: [Caml-list] camlp4: LIST1 construct on record patterns
  2002-01-14  2:17   ` Jeff Henrikson
@ 2002-01-14  2:49     ` Jeff Henrikson
  2002-01-14  5:10       ` Daniel de Rauglaudre
  0 siblings, 1 reply; 5+ messages in thread
From: Jeff Henrikson @ 2002-01-14  2:49 UTC (permalink / raw)
  To: daniel.de_rauglaudre; +Cc: caml-list

Wait, sorry again, I figured out the correct type:

  let lbl_expr_list = 
    (Obj.magic (Grammar.Entry.find expr "lbl_expr_list") :
       (MLast.patt * MLast.expr) list Grammar.Entry.e) in

as you said, then "car" the first list element and it's right:

    [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" -> 
          (let memb0= List.nth memb 0 in
          <:expr<{$list:memb0$}>>) ] ]

I don't understand it though.  Is there some explanation?


Jeff



> -----Original Message-----
> From: owner-caml-list@pauillac.inria.fr
> [mailto:owner-caml-list@pauillac.inria.fr]On Behalf Of Jeff Henrikson
> Sent: Sunday, January 13, 2002 9:18 PM
> To: Daniel de Rauglaudre
> Cc: caml-list@inria.fr
> Subject: RE: [Caml-list] camlp4: LIST1 construct on record patterns
> 
> 
> I actually tried magicing it into what I wanted it to be before, but was unable to guess it's real type.  Apparently I 
> still can't:
> 
> 
> open Printf;;
> 
> let try_extend _ =
>   let cons = "Bogus" in
>   let lbl_expr_list =
>     (Obj.magic (Grammar.Entry.find expr "lbl_expr_list") :
>        (MLast.patt * MLast.expr) (* not list *) Grammar.Entry.e) in
>   EXTEND
>     expr: LEVEL "simple"
>     [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" ->
>           <:expr<{$list:memb$}>> ] ]
>     ;
>   END;;
> 
> try_extend 7;;
> 
> Bogus{foo="happy";bar="sad"};;
> 
> 
> This segfaults.  Let's see if memb is even a list:
> 
> 
> let try_extend _ =
>   let cons = "Bogus" in
>   let lbl_expr_list =
>     (Obj.magic (Grammar.Entry.find expr "lbl_expr_list") :
>        (MLast.patt * MLast.expr) (* not list *) Grammar.Entry.e) in
>   EXTEND
>     expr: LEVEL "simple"
>     [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" ->
>           (printf "Do we get here %d\n" (List.length memb); flush stdout;
>           <:expr<6>>) ] ]
>     ;
>   END;;
> 
> try_extend 7;;
> 
> Bogus{foo="happy";bar="sad"};;
> 
> 
> This prints "Do we get here 1", regardless of how many terms I add in Bogus{}, regardless of whether such constructors 
> are defined
> or not.
> 
> But despite all this the source code looks convincing enough:
> 
> pa_o.ml:
>       | "{"; test_label_eq; lel = lbl_expr_list; "}" ->
>           <:expr< { $list:lel$ } >>
> 
> > Sorry, Luke, you entered the dark side of Camlp4... :-)
> 
> Apparently the force is not strong enough within me.  ;-}
> 
> 
> Jeff
> 
> -------------------
> Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
> To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr
> 
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

* Re: [Caml-list] camlp4: LIST1 construct on record patterns
  2002-01-14  2:49     ` Jeff Henrikson
@ 2002-01-14  5:10       ` Daniel de Rauglaudre
  0 siblings, 0 replies; 5+ messages in thread
From: Daniel de Rauglaudre @ 2002-01-14  5:10 UTC (permalink / raw)
  To: caml-list

Hi,

On Sun, Jan 13, 2002 at 09:49:56PM -0500, Jeff Henrikson wrote:

>     [ [ $cons$; "{"; memb = LIST1 lbl_expr_list SEP ";" ; "}" -> 
>           (let memb0= List.nth memb 0 in
>           <:expr<{$list:memb0$}>>) ] ]
> 
> I don't understand it though.  Is there some explanation?

The entry "lbl_expr_list", as its name indicates, already parses a
list. Don't use LIST1.

-- 
Daniel de RAUGLAUDRE
daniel.de_rauglaudre@inria.fr
http://cristal.inria.fr/~ddr/
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr


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

end of thread, other threads:[~2002-01-14  5:10 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-01-13  5:38 [Caml-list] camlp4: LIST1 construct on record patterns Jeff Henrikson
2002-01-13 13:48 ` Daniel de Rauglaudre
2002-01-14  2:17   ` Jeff Henrikson
2002-01-14  2:49     ` Jeff Henrikson
2002-01-14  5:10       ` Daniel de Rauglaudre

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).