caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* ocamlbuild: args to tags?
@ 2007-09-18 18:01 Jake Donham
  2007-09-24 12:29 ` [Caml-list] " Nicolas Pouillard
  0 siblings, 1 reply; 5+ messages in thread
From: Jake Donham @ 2007-09-18 18:01 UTC (permalink / raw)
  To: caml-list

Hi,

Is there a way to pass arguments to a preprocessor via the _tags file? 
(In particular, I have added a -classes option to Deriving to give 
default classes to all the types in a file.). Following the recent 
discussion, I have this in myocamlbuild.ml:

   dispatch begin function
     | After_rules ->
         flag ["ocaml"; "pp"; "deriving"] (A"deriving");
         flag ["ocaml"; "pp"; "Show"] (S[A"-classes"; A"Show"]);

So now if I put

   <foo.ml> : deriving,Show

in _tags I get -pp 'deriving -classes Show' in the command line. What I 
would like, however, is to be able to write

   <foo.ml> : deriving(Show,Typeable)

or

   <foo.ml> : deriving,classes(Show,Typeable)

i.e. to be able to pass some arbitrary args rather than hard-coding Show 
as a tag. Is there any way to do this? I don't understand how Ocamlbuild 
decides whether flags should be associated with the main command or with 
the preprocessor command; if I write classes(Foo) in _tags I get 
-classes Foo in the main command, no matter what I have tried in 
myocamlbuild.ml.

Thanks,

Jake


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

* Re: [Caml-list] ocamlbuild: args to tags?
  2007-09-18 18:01 ocamlbuild: args to tags? Jake Donham
@ 2007-09-24 12:29 ` Nicolas Pouillard
  2007-09-24 14:03   ` skaller
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Pouillard @ 2007-09-24 12:29 UTC (permalink / raw)
  To: jake.donham; +Cc: caml-list

Excerpts from jake.donham's message of Tue Sep 18 20:01:56 +0200 2007:
> Hi,
> 
> Is there a way to pass arguments to a preprocessor via the _tags file? 

Yes,  but  that's  not  what  you  want.  Moreover  this feature is not really
encouraged.

> (In particular, I have added a -classes option to Deriving to give 
> default classes to all the types in a file.). Following the recent 
> discussion, I have this in myocamlbuild.ml:
> 
>    dispatch begin function
>      | After_rules ->
>          flag ["ocaml"; "pp"; "deriving"] (A"deriving");
>          flag ["ocaml"; "pp"; "Show"] (S[A"-classes"; A"Show"]);
> 
> So now if I put
> 
>    <foo.ml> : deriving,Show
> 
> in _tags I get -pp 'deriving -classes Show' in the command line. What I 
> would like, however, is to be able to write
> 
>    <foo.ml> : deriving(Show,Typeable)
> 
> or
> 
>    <foo.ml> : deriving,classes(Show,Typeable)

Yes but you cannot do that for now. One feasible feature would be:

  <foo.ml>: deriving, classes{Show,Typeable}

Which will expands to:

  <foo.ml>: deriving, classesShow, classesTypeable

And then in your plugin you can do:

  List.iter begin fun class_name ->
    flag ["ocaml"; "pp"; "classes"^class_name] (S[A"-classes"; A class_name])
  end ["Show"; "Typeable"]

> i.e. to be able to pass some arbitrary args rather than hard-coding Show 
> as a tag. Is there any way to do this?

No I don't really want to complicate tags...

> I don't understand how Ocamlbuild 
> decides whether flags should be associated with the main command or with 
> the preprocessor command; if I write classes(Foo) in _tags I get 
> -classes Foo in the main command, no matter what I have tried in 
> myocamlbuild.ml.

Yes  thats the not encouraged feature by using the syntax `flag(arg)' you pass
the arguments `-flag arg' to *any* command that reference the matched file. It's
merely because you cannot control when the flag is applied that this form is not encouraged.

However the classic way of using tag have a fine grained control:

  flag ["ocaml"; "pp"; "Show"] (S[A"-classes"; A"Show"]);

Here  only  commands  tagged  "ocaml",  "pp"  and  "Show"  will  add the flags
"-classes  Show".  Both commands and files contribute to this set of tags, and
that's  the  conjunction  that  trigger the flags (but I think that you've got
this one, and that's the flag(arg) behavior that leads to confusion).

Regards,

HTH
-- 
Nicolas Pouillard aka Ertai


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

* Re: [Caml-list] ocamlbuild: args to tags?
  2007-09-24 12:29 ` [Caml-list] " Nicolas Pouillard
@ 2007-09-24 14:03   ` skaller
  2007-09-24 15:23     ` Nicolas Pouillard
  0 siblings, 1 reply; 5+ messages in thread
From: skaller @ 2007-09-24 14:03 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: jake.donham, caml-list

On Mon, 2007-09-24 at 14:29 +0200, Nicolas Pouillard wrote:
> Excerpts from jake.donham's message of Tue Sep 18 20:01:56 +0200 2007:
> > Hi,
> > 
> > Is there a way to pass arguments to a preprocessor via the _tags file? 
> 
> Yes,  but  that's  not  what  you  want.  Moreover  this feature is not really
> encouraged.

Just my 2c .. I think all this stuff is wrong. I think it should be
done like this:

(* My Ocaml File .. *)
(*#Syntax Mycamlp4syn *) (* for compatibility *)
#syntax Mycamlp4syn;     (* better *)

In other words, if you're using a language mycamplp4syn, you should
say so IN the file using it .. not on the command line.

Ocamlbuild then 

* finds the dependencies
* builds them
* applies them to the files using them

I think it is wrong software engineering the current way.
If you use a module you have to either open it or at least use
its name:

	List.map

Just because camlp4 modules are *meta* should not excuse them
from this requirement.

Command line should be used for performance tuning and debugging,
and for mapping abstract resources (like modules and syntaxen)
onto the file system .. but not for specifying semantic requirements.


-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


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

* Re: [Caml-list] ocamlbuild: args to tags?
  2007-09-24 14:03   ` skaller
@ 2007-09-24 15:23     ` Nicolas Pouillard
  2007-09-24 17:38       ` skaller
  0 siblings, 1 reply; 5+ messages in thread
From: Nicolas Pouillard @ 2007-09-24 15:23 UTC (permalink / raw)
  To: skaller; +Cc: nicolas.pouillard, jake.donham, caml-list

Excerpts from skaller's message of Mon Sep 24 16:03:37 +0200 2007:
> On Mon, 2007-09-24 at 14:29 +0200, Nicolas Pouillard wrote:
> > Excerpts from jake.donham's message of Tue Sep 18 20:01:56 +0200 2007:
> > > Hi,
> > > 
> > > Is there a way to pass arguments to a preprocessor via the _tags file? 
> > 
> > Yes,  but  that's  not  what  you  want.  Moreover  this feature is not really
> > encouraged.
> 
> Just my 2c .. I think all this stuff is wrong. I think it should be
> done like this:

Being  able  to specify things like syntax extensions in the same place can be
very  precious  and not incompatible with an "in the file itself" way of doing
so.

> (* My Ocaml File .. *)
> (*#Syntax Mycamlp4syn *) (* for compatibility *)
> #syntax Mycamlp4syn;     (* better *)

This  sounds  like  a  good  idea.  That's  not a new one and it was our first
choice  when  designing  ocamlbuild. However after some reflections we decided
that  one  can  first do _tags method and then provide a way to read tags from
the file itself.

The  main  problem  with  the  solution with embedded tags is that one must at
least  define  a  how to read these annotations. This is not that easy since a
.ml  file  can  be  a  pre-processed file with a totally different syntax. One
moreover  don't  want  to  only  focus  on  OCaml  files  but also C files for
instance.

I hope this makes our first decision clear...

Regards,
-- 
Nicolas Pouillard aka Ertai


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

* Re: [Caml-list] ocamlbuild: args to tags?
  2007-09-24 15:23     ` Nicolas Pouillard
@ 2007-09-24 17:38       ` skaller
  0 siblings, 0 replies; 5+ messages in thread
From: skaller @ 2007-09-24 17:38 UTC (permalink / raw)
  To: Nicolas Pouillard; +Cc: caml-list, jake.donham

On Mon, 2007-09-24 at 17:23 +0200, Nicolas Pouillard wrote:

> > (* My Ocaml File .. *)
> > (*#Syntax Mycamlp4syn *) (* for compatibility *)
> > #syntax Mycamlp4syn;     (* better *)
> 
> This  sounds  like  a  good  idea.  That's  not a new one and it was our first
> choice  when  designing  ocamlbuild. However after some reflections we decided
> that  one  can  first do _tags method and then provide a way to read tags from
> the file itself.

There's slight difference in view as expressed here. 
I wouldn't suggested arbitrary "tags" or hints be first class syntax
(although one might put them in comments).

I'm not against tags annotations.. I'm suggesting the specification
of the syntax extension doesn't belong on the command line, 
or in a tags file, it belongs in the file.

> The  main  problem  with  the  solution with embedded tags is that one must at
> least  define  a  how to read these annotations. This is not that easy since a
> .ml  file  can  be  a  pre-processed file with a totally different syntax. 

No, this should not be allowed: that's my point. Every Ocaml file uses
THE syntax for either *.mli or *.ml, end of story. If it uses some
other language, it should have a different extension.

However the syntax can be extensible, but the extensions must be 
at least loaded, if not defined, IN the file.

Felix does this. It uses Dypgen GLR parser and OCS Scheme
to implement it. You have to say:

	open syntax felix;

or you can't parse anything except syntax extensions :)
The whole of the language proper (except nonterminals
mapped to terminals such as literals) is specified
by a dynamically specified grammar. In Felix,
you can extend the grammar 'anywhere', the extensions are
properly scoped.

So actually, there's no problem designing a syntax which allows
loading another syntax, that is, a bootstrap syntax. For Ocaml,
you could easily add a directive

	open syntax Mysyntax

or

	#syntax Mysyntax

to the standard grammar, and make camlp4 parse it and use it
to load syntax extensions. Running camlp4 so this happens should
be the mandatory, no -pp command stuff: camlp4 IS the Ocaml parser.

Then, when you run, say, ocamldoc, it knows which extensions to load,
as does the human reader.

It's just the same as

	let (@) f g x = f (g x)

The "syntax extension" of the user defined operator @ for composition
is defined IN the program.

-- 
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net


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

end of thread, other threads:[~2007-09-24 17:39 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-09-18 18:01 ocamlbuild: args to tags? Jake Donham
2007-09-24 12:29 ` [Caml-list] " Nicolas Pouillard
2007-09-24 14:03   ` skaller
2007-09-24 15:23     ` Nicolas Pouillard
2007-09-24 17:38       ` skaller

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