Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MPR#5212: ocamlbuild does not warn for bad input #219

Closed
damiendoligez opened this issue Mar 3, 2017 · 2 comments
Closed

MPR#5212: ocamlbuild does not warn for bad input #219

damiendoligez opened this issue Mar 3, 2017 · 2 comments
Labels

Comments

@damiendoligez
Copy link
Member

PR transferred from https://caml.inria.fr/mantis/view.php?id=5212

I saw a parser example in the Genlex module. It took me HOURS to compile a similar example in ocamlbuild! This tool is fantastic for meany reasons, but is a bit weak for useability. Hopefully that can be improved, with better messaging :

(1) ocamlbuild -tags camlp4 example.byte does not work, but it does not tell that the camlp4 tag is not recognised or not usefull

(2) ocamlbuild -tags pp example.byte explains that pp waits for an argument, which is good, but :

(3) ocamlbuild -tags pp(camlp4o) example.byte gives the error bash: syntax error near unexpected token '(' which is not clear that it comes from ocamlbuild. a line such as ocamlbuild tag : bash : syntax error near unexpected token '(' would be better

(4) echo "example.ml:pp(camlp4o)" > _tags ; ocamlbuild example.byte gives the error Failure: lexing: empty token. where it is not clear that it comes from the _tags file, ant that it is due to ocamlbuild. One could think it comes from camlp4. A better localisation of the error would be appreciated. Example : File _tags, line 1, character 0-10 : bad syntax

(5) echo "<example.ml>:pp(camlp4o)" > _tags ; ocamlbuild example.byte eventually works. But why the -tags pp(camlp4o) option refuses it? It is not clear at all what to put on the tags option and what to put in the _tags file. At least, every line such as true : pp(camlp4o) should be equivalent to -tags pp(camlp4o) ?

Thanks,
William


file example.ml :

open Genlex
let _ = 
  let str = Stream.of_string "2 * (1 + 2)" in
  let lexer = Genlex.make_lexer [] in
  let rec parse_expr = parser
      [< 'Int n >] -> n
    | [< 'Kwd "("; n = parse_expr; 'Kwd ")" >] -> n
    | [< n1 = parse_expr; n2 = parse_remainder n1 >] -> n2
  and parse_remainder n1 = parser
      [< 'Kwd "+"; n2 = parse_expr >] -> n1+n2
  in
  Printf.printf "hello\n%!";
  parse_expr (lexer str)

See also the long discussion in the Mantis PR.

@gasche
Copy link
Member

gasche commented Mar 3, 2017

(1) is now solved:

$ ocamlbuild -tags camlp4 example.byte
Configuration "true: quiet, camlp4", line 1, characters 13-19:
Warning: the tag "camlp4" is not used in any flag or dependency declaration, so it will have no effect; it may be a typo. Otherwise you can use `mark_tag_used` in your myocamlbuild.ml to disable this warning.
+ /home/gasche/.opam/4.04.0/bin/ocamldep.opt -modules example.ml > example.ml.depends
File "example.ml", line 1, characters 8-10:
Error: Syntax error
Command exited with code 2.
Compilation unsuccessful after building 1 target (0 cached) in 00:00:00.

@gasche
Copy link
Member

gasche commented Mar 3, 2017

(4) is also now solved:

$ echo "example.ml:pp(camlp4o)" > _tags; ocamlbuild example.byte
File "_tags", line 1, characters 0-11:
Lexing error: Invalid globbing pattern "example.ml".
Compilation unsuccessful after building 0 targets (0 cached) in 00:00:00.

I'm actually proud of the usability improvements we made since this ticket was opened. The rest is a bash parsing issue that is not in our control: -tags pp(camlp4o) should be -tags "pp(camlp4)". The only thing we can do is to have the manual show example of these quotes, and it actually does (look for -tag "). Closing. Best issue of the day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants