caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] OCaml code style and syntax checking
@ 2017-07-04 14:01 Richard W.M. Jones
  2017-07-04 14:03 ` Richard W.M. Jones
  2017-07-11 12:22 ` Sébastien Hinderer
  0 siblings, 2 replies; 6+ messages in thread
From: Richard W.M. Jones @ 2017-07-04 14:01 UTC (permalink / raw)
  To: caml-list

I have a need to make automated stylistic and syntax checks to
a large amount of OCaml code.  The sort of rules would be:

 - Check that indentation is used, and used consistently.

 - Excessive use of parentheses where not needed.

 - Use ( .. ) instead of begin .. end.

 - Flag uses of various Obj.* and unsafe_* functions.

It seems to me that some of these could be tested with either camlp4
or ppx.  I think if we allowed the checker to go back to the original
code (eg to see if the parser parsed as block as '(' or 'begin'),
it might be able to check all of these things.

Anyway, before I start on it I'm wondering if anyone has ever
looked at doing this kind of thing?

Rich.


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

* Re: [Caml-list] OCaml code style and syntax checking
  2017-07-04 14:01 [Caml-list] OCaml code style and syntax checking Richard W.M. Jones
@ 2017-07-04 14:03 ` Richard W.M. Jones
  2017-07-04 14:21   ` Mark Bradley
  2017-07-11 12:22 ` Sébastien Hinderer
  1 sibling, 1 reply; 6+ messages in thread
From: Richard W.M. Jones @ 2017-07-04 14:03 UTC (permalink / raw)
  To: caml-list

On Tue, Jul 04, 2017 at 03:01:28PM +0100, Richard W.M. Jones wrote:
> I have a need to make automated stylistic and syntax checks to
> a large amount of OCaml code.  The sort of rules would be:
> 
>  - Check that indentation is used, and used consistently.
> 
>  - Excessive use of parentheses where not needed.
> 
>  - Use ( .. ) instead of begin .. end.
> 
>  - Flag uses of various Obj.* and unsafe_* functions.
> 
> It seems to me that some of these could be tested with either camlp4
> or ppx.  I think if we allowed the checker to go back to the original
> code (eg to see if the parser parsed as block as '(' or 'begin'),
> it might be able to check all of these things.
> 
> Anyway, before I start on it I'm wondering if anyone has ever
> looked at doing this kind of thing?

Now that I actually formulate the right search terms, I see
that ocp-lint exists :-/

Rich.

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

* Re: [Caml-list] OCaml code style and syntax checking
  2017-07-04 14:03 ` Richard W.M. Jones
@ 2017-07-04 14:21   ` Mark Bradley
  0 siblings, 0 replies; 6+ messages in thread
From: Mark Bradley @ 2017-07-04 14:21 UTC (permalink / raw)
  To: Richard W.M. Jones; +Cc: caml-list

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

Another idea that will get you part of the way there is to use refmt to
automatically format the OCaml files to standard layout.

This would cover 3 out of the 4 criteria because:

1. it automatically indents
2. it always reduces parentheses where it can
3. it automatically converts begin and end to parentheses.

The 4th criteria could potentially be caught using grep.

It's worth an experiment to see if you like the style of code generated by
refmt for OCaml. It certainly does a better job at formatting reason code
from my limited experiments (it doesn't seem to like vertical white space
when generating OCaml, whereas it will include it if you covert the file to
reason, testing version 1.13.5 as of writing).


On 5 July 2017 at 00:03, Richard W.M. Jones <rich@annexia.org> wrote:

> On Tue, Jul 04, 2017 at 03:01:28PM +0100, Richard W.M. Jones wrote:
> > I have a need to make automated stylistic and syntax checks to
> > a large amount of OCaml code.  The sort of rules would be:
> >
> >  - Check that indentation is used, and used consistently.
> >
> >  - Excessive use of parentheses where not needed.
> >
> >  - Use ( .. ) instead of begin .. end.
> >
> >  - Flag uses of various Obj.* and unsafe_* functions.
> >
> > It seems to me that some of these could be tested with either camlp4
> > or ppx.  I think if we allowed the checker to go back to the original
> > code (eg to see if the parser parsed as block as '(' or 'begin'),
> > it might be able to check all of these things.
> >
> > Anyway, before I start on it I'm wondering if anyone has ever
> > looked at doing this kind of thing?
>
> Now that I actually formulate the right search terms, I see
> that ocp-lint exists :-/
>
> Rich.
>
> --
> Caml-list mailing list.  Subscription management and archives:
> https://sympa.inria.fr/sympa/arc/caml-list
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>



-- 
-barkmadley
sent from an internet enabled device
http://barkmadley.com

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

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

* Re: [Caml-list] OCaml code style and syntax checking
  2017-07-04 14:01 [Caml-list] OCaml code style and syntax checking Richard W.M. Jones
  2017-07-04 14:03 ` Richard W.M. Jones
@ 2017-07-11 12:22 ` Sébastien Hinderer
  2017-07-11 13:03   ` François Bobot
  1 sibling, 1 reply; 6+ messages in thread
From: Sébastien Hinderer @ 2017-07-11 12:22 UTC (permalink / raw)
  To: caml-list

Dear Richard,

You may also be interested in Xavier Clerc's Mascot tool:
http://mascot.x9c.fr/

Sébastien.

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

* Re: [Caml-list] OCaml code style and syntax checking
  2017-07-11 12:22 ` Sébastien Hinderer
@ 2017-07-11 13:03   ` François Bobot
  2017-07-11 13:11     ` Sébastien Hinderer
  0 siblings, 1 reply; 6+ messages in thread
From: François Bobot @ 2017-07-11 13:03 UTC (permalink / raw)
  To: caml-list

Hi,

Le 11/07/2017 à 14:22, Sébastien Hinderer a écrit :
> You may also be interested in Xavier Clerc's Mascot tool:
> http://mascot.x9c.fr/

It seems to be a great tool, but it seems only available for old ocaml version
  4.00 <= ocaml-version < 4.02 : http://opam.ocaml.org/packages/mascot/

Best,

-- 
François

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

* Re: [Caml-list] OCaml code style and syntax checking
  2017-07-11 13:03   ` François Bobot
@ 2017-07-11 13:11     ` Sébastien Hinderer
  0 siblings, 0 replies; 6+ messages in thread
From: Sébastien Hinderer @ 2017-07-11 13:11 UTC (permalink / raw)
  To: caml-list

François Bobot (2017/07/11 15:03 +0200):
> Hi,
> 
> Le 11/07/2017 à 14:22, Sébastien Hinderer a écrit :
> > You may also be interested in Xavier Clerc's Mascot tool:
> > http://mascot.x9c.fr/
> 
> It seems to be a great tool, but it seems only available for old ocaml version
>  4.00 <= ocaml-version < 4.02 : http://opam.ocaml.org/packages/mascot/

Yeah, I was wondering whether it could be updated but never had the time
to investigate on this.

Sébastien.

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

end of thread, other threads:[~2017-07-11 13:11 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-04 14:01 [Caml-list] OCaml code style and syntax checking Richard W.M. Jones
2017-07-04 14:03 ` Richard W.M. Jones
2017-07-04 14:21   ` Mark Bradley
2017-07-11 12:22 ` Sébastien Hinderer
2017-07-11 13:03   ` François Bobot
2017-07-11 13:11     ` Sébastien Hinderer

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