caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Parse error with camlp4 while sources compile
@ 2014-08-13 15:30 Andrea Giugliano
  2014-08-13 16:28 ` Gabriel Scherer
  0 siblings, 1 reply; 5+ messages in thread
From: Andrea Giugliano @ 2014-08-13 15:30 UTC (permalink / raw)
  To: caml-list

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

Dear list,

I am trying to test my ocaml application using a test coverage tool 
called bisect (http://bisect.x9c.fr/index.html).
This tool uses camlp4 to instrument the source code, i.e. adding the 
check points to say that the source code has been explored by the tests.
When I try to instrument my application, I get the following error from 
camlp4:

Parse error: [module_type] expected after ":" (in [module_declaration])
Error while running external preprocessor

Is it possible that camlp4 does not support the functor feature of OCaml?
Has anyone had this error before?

I googled for the error string and similar errors, but I could not find 
anything promising.
I also searched the archives of this mailing list and the wg-camlp4 
mailing list, but nothing similar was present.
The following source files raise the same error (they successfully 
compile though!):

(* test.mli -------------- *)

module type a = sig
     type t
end

module A (AO : a) : sig
     val f : AO.t -> bool
end

(* test.ml --------------- *)

module type a = sig
     type t
end

module A (AO : a) = struct
     let f ( x : AO.t) = true
end

let _ = print_endline "test"
(* ------------------------- *)

I attached them and the Makefile that I am using to create the executable.
If you want to reproduce the error, you need to have installed Ocaml 
4.01, ocamlfind and the last version of bisect
(the most comfortable installation is through OPAM:
     opam install ocamlfind
     opam install bisect).
Thanks for your attention,

Andrea Giugliano

[-- Attachment #2: Makefile --]
[-- Type: text/plain, Size: 415 bytes --]

OCAMLFIND=ocamlfind
CAMLOPT=$(shell command -v ocamlopt.opt || command -v ocamlopt || echo missing_ocamlopt)
WARNINGS=-w -26-8-23
COMPFLAGS=$(WARNINGS) 
BISECTDIR=$(shell $(OCAMLFIND) -query bisect)

test.native:
	$(CAMLOPT) -I $(BISECTDIR) -pp 'camlp4o str.cma $(BISECTDIR)/bisect_pp.cmo' $(COMPFLAGS) -I $(BISECTDIR) bisect.cmxa -o my test.mli test.ml

justNative:
	$(CAMLOPT) $(COMPFLAGS) -o my test.mli test.ml

[-- Attachment #3: test.ml --]
[-- Type: text/x-ocaml, Size: 123 bytes --]

module type a = sig
    type t
end

module A (AO : a) = struct
    let f ( x : AO.t) = true
end

let _ = print_endline "!"

[-- Attachment #4: test.mli --]
[-- Type: text/x-ocaml, Size: 89 bytes --]

module type a = sig
    type t
end

module A (AO : a) : sig
    val f : AO.t -> bool
end

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

* Re: [Caml-list] Parse error with camlp4 while sources compile
  2014-08-13 15:30 [Caml-list] Parse error with camlp4 while sources compile Andrea Giugliano
@ 2014-08-13 16:28 ` Gabriel Scherer
  2014-08-13 18:36   ` Drup
  2014-08-13 22:43   ` Andrea Giugliano
  0 siblings, 2 replies; 5+ messages in thread
From: Gabriel Scherer @ 2014-08-13 16:28 UTC (permalink / raw)
  To: Andrea Giugliano; +Cc: caml users

Camlp4 uses a different parser technology than the OCaml compiler, so
it warns about syntax errors in a different way. It happens sometimes
to be wrong, but it is most of the time right, and gives relatively
good error message. (In case there is a discrepancy between what the
compiler accepts and Camlp4 accept, I recommend that you write code
accepted by both.)

module A (AO : a) : sig
> Parse error: [module_type] expected after ":" (in [module_declaration])

Module type names, as module names, must start with an uppercase
letter. Rename the signature into A or ASig, and you will be fine (for
this particular error).

On Wed, Aug 13, 2014 at 5:30 PM, Andrea Giugliano <ag400@leicester.ac.uk> wrote:
> Dear list,
>
> I am trying to test my ocaml application using a test coverage tool called
> bisect (http://bisect.x9c.fr/index.html).
> This tool uses camlp4 to instrument the source code, i.e. adding the check
> points to say that the source code has been explored by the tests.
> When I try to instrument my application, I get the following error from
> camlp4:
>
> Parse error: [module_type] expected after ":" (in [module_declaration])
> Error while running external preprocessor
>
> Is it possible that camlp4 does not support the functor feature of OCaml?
> Has anyone had this error before?
>
> I googled for the error string and similar errors, but I could not find
> anything promising.
> I also searched the archives of this mailing list and the wg-camlp4 mailing
> list, but nothing similar was present.
> The following source files raise the same error (they successfully compile
> though!):
>
> (* test.mli -------------- *)
>
> module type a = sig
>     type t
> end
>
> module A (AO : a) : sig
>     val f : AO.t -> bool
> end
>
> (* test.ml --------------- *)
>
> module type a = sig
>     type t
> end
>
> module A (AO : a) = struct
>     let f ( x : AO.t) = true
> end
>
> let _ = print_endline "test"
> (* ------------------------- *)
>
> I attached them and the Makefile that I am using to create the executable.
> If you want to reproduce the error, you need to have installed Ocaml 4.01,
> ocamlfind and the last version of bisect
> (the most comfortable installation is through OPAM:
>     opam install ocamlfind
>     opam install bisect).
> Thanks for your attention,
>
> Andrea Giugliano
>
> --
> 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

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

* Re: [Caml-list] Parse error with camlp4 while sources compile
  2014-08-13 16:28 ` Gabriel Scherer
@ 2014-08-13 18:36   ` Drup
  2014-08-13 18:47     ` Gabriel Scherer
  2014-08-13 22:43   ` Andrea Giugliano
  1 sibling, 1 reply; 5+ messages in thread
From: Drup @ 2014-08-13 18:36 UTC (permalink / raw)
  To: Gabriel Scherer, Andrea Giugliano; +Cc: caml users

Le 13/08/2014 18:28, Gabriel Scherer a écrit :
> Module type names, as module names, must start with an uppercase
> letter. Rename the signature into A or ASig, and you will be fine (for
> this particular error).
In this case, camlp4 is wrong (and in my experience, it's often wrong 
..). Module type names can start with a lower case letter.

# module type a = sig end ;;
module type a = sig  end

It's considered bad style, and is little know, since camlp4 get it 
wrong, but it works.


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

* Re: [Caml-list] Parse error with camlp4 while sources compile
  2014-08-13 18:36   ` Drup
@ 2014-08-13 18:47     ` Gabriel Scherer
  0 siblings, 0 replies; 5+ messages in thread
From: Gabriel Scherer @ 2014-08-13 18:47 UTC (permalink / raw)
  To: Drup; +Cc: Andrea Giugliano, caml users

Indeed, the manual says that modtype-name may be any identifier, not
just a capitalized one:
  http://caml.inria.fr/pub/docs/manual-ocaml/names.html#modtype-name

I've never seen any source code using this, though.

On Wed, Aug 13, 2014 at 8:36 PM, Drup <drupyog+caml@zoho.com> wrote:
> Le 13/08/2014 18:28, Gabriel Scherer a écrit :
>
>> Module type names, as module names, must start with an uppercase
>> letter. Rename the signature into A or ASig, and you will be fine (for
>> this particular error).
>
> In this case, camlp4 is wrong (and in my experience, it's often wrong ..).
> Module type names can start with a lower case letter.
>
> # module type a = sig end ;;
> module type a = sig  end
>
> It's considered bad style, and is little know, since camlp4 get it wrong,
> but it works.
>

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

* Re: [Caml-list] Parse error with camlp4 while sources compile
  2014-08-13 16:28 ` Gabriel Scherer
  2014-08-13 18:36   ` Drup
@ 2014-08-13 22:43   ` Andrea Giugliano
  1 sibling, 0 replies; 5+ messages in thread
From: Andrea Giugliano @ 2014-08-13 22:43 UTC (permalink / raw)
  To: Gabriel Scherer; +Cc: caml users

Hello,

thanks a lot for your help!
This solved my problem, and I learned also that it is bad style to write 
module names.
Thanks again,

Andrea

On 13/08/14 17:28, Gabriel Scherer wrote:
> Camlp4 uses a different parser technology than the OCaml compiler, so
> it warns about syntax errors in a different way. It happens sometimes
> to be wrong, but it is most of the time right, and gives relatively
> good error message. (In case there is a discrepancy between what the
> compiler accepts and Camlp4 accept, I recommend that you write code
> accepted by both.)
>
> module A (AO : a) : sig
>> Parse error: [module_type] expected after ":" (in [module_declaration])
> Module type names, as module names, must start with an uppercase
> letter. Rename the signature into A or ASig, and you will be fine (for
> this particular error).
>
> On Wed, Aug 13, 2014 at 5:30 PM, Andrea Giugliano <ag400@leicester.ac.uk> wrote:
>> Dear list,
>>
>> I am trying to test my ocaml application using a test coverage tool called
>> bisect (http://bisect.x9c.fr/index.html).
>> This tool uses camlp4 to instrument the source code, i.e. adding the check
>> points to say that the source code has been explored by the tests.
>> When I try to instrument my application, I get the following error from
>> camlp4:
>>
>> Parse error: [module_type] expected after ":" (in [module_declaration])
>> Error while running external preprocessor
>>
>> Is it possible that camlp4 does not support the functor feature of OCaml?
>> Has anyone had this error before?
>>
>> I googled for the error string and similar errors, but I could not find
>> anything promising.
>> I also searched the archives of this mailing list and the wg-camlp4 mailing
>> list, but nothing similar was present.
>> The following source files raise the same error (they successfully compile
>> though!):
>>
>> (* test.mli -------------- *)
>>
>> module type a = sig
>>      type t
>> end
>>
>> module A (AO : a) : sig
>>      val f : AO.t -> bool
>> end
>>
>> (* test.ml --------------- *)
>>
>> module type a = sig
>>      type t
>> end
>>
>> module A (AO : a) = struct
>>      let f ( x : AO.t) = true
>> end
>>
>> let _ = print_endline "test"
>> (* ------------------------- *)
>>
>> I attached them and the Makefile that I am using to create the executable.
>> If you want to reproduce the error, you need to have installed Ocaml 4.01,
>> ocamlfind and the last version of bisect
>> (the most comfortable installation is through OPAM:
>>      opam install ocamlfind
>>      opam install bisect).
>> Thanks for your attention,
>>
>> Andrea Giugliano
>>
>> --
>> 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


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

end of thread, other threads:[~2014-08-13 22:43 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-13 15:30 [Caml-list] Parse error with camlp4 while sources compile Andrea Giugliano
2014-08-13 16:28 ` Gabriel Scherer
2014-08-13 18:36   ` Drup
2014-08-13 18:47     ` Gabriel Scherer
2014-08-13 22:43   ` Andrea Giugliano

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