caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: blue storm <bluestorm.dylc@gmail.com>
To: Serge Leblanc <serge.leblanc@orange.fr>
Cc: caml-list@yquem.inria.fr
Subject: Re: [Caml-list] DELETE_RULE arguments?
Date: Wed, 22 Jul 2009 12:03:01 +0200	[thread overview]
Message-ID: <527cf6bc0907220303l4b5ea63ch442c92d186f45cc1@mail.gmail.com> (raw)
In-Reply-To: <1248006890.4590.166.camel@serge2>

On Sun, Jul 19, 2009 at 2:34 PM, Serge Leblanc<serge.leblanc@orange.fr> wrote:
> Otherwise, is there a way to know if the active syntax, is the revised or
> not?

The way used in Camlp4Parsers/Camlp4ListComprehension.ml is to try to
delete a rule and see if it fails :

  value is_revised =
    try do {
      DELETE_RULE Gram expr: "["; sem_expr_for_list; "::"; expr; "]" END;
      True
    } with [ Not_found -> False ];

It works fine in this case as the grammar rule have to be deleted
anyway, but if you don't want to affect the grammar you could test
parsing for failure. Something like :

  value is_revised =
    try do { Gram.parse_string Syntax.expr Loc.ghost "fun [ x -> x]"; True }
    with [ _ -> False];

Of course, those tests could fail given a syntax that is neither the
classic nor the revised syntax. Eg. if you write an extension adding
the fun [ .. ] syntax to the standard syntax and it would return true.
A safer way to test the used syntaxes is the Register.loaded_modules values :

# #camlp4o;;
# Camlp4.Register.loaded_modules;;
- : string list ref =
{contents =
  ["Camlp4OCamlParserParser"; "Camlp4OCamlRevisedParserParser";
   "Camlp4OCamlParser"; "Camlp4OCamlRevisedParser"]}

# #camlp4r;;
# Camlp4.Register.loaded_modules;
- : ref (list string) =
{val=["Camlp4OCamlRevisedParserParser"; "Camlp4OCamlRevisedParser"]}


      parent reply	other threads:[~2009-07-22 10:03 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-07-19 12:34 Serge Leblanc
2009-07-21 22:35 ` [Caml-list] " Serge Leblanc
2009-07-22  7:26   ` blue storm
2009-07-22 12:54     ` Serge Leblanc
2009-07-22 10:03 ` blue storm [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=527cf6bc0907220303l4b5ea63ch442c92d186f45cc1@mail.gmail.com \
    --to=bluestorm.dylc@gmail.com \
    --cc=caml-list@yquem.inria.fr \
    --cc=serge.leblanc@orange.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).