Skip to content

Support camlp5 by using Toploop.parse_toplevel_phrase instead of Parse.toplevel_phrase - #486

Merged
Octachron merged 1 commit into
ocaml-community:masterfrom
aqjune:camlp5
Jun 26, 2025
Merged

Support camlp5 by using Toploop.parse_toplevel_phrase instead of Parse.toplevel_phrase#486
Octachron merged 1 commit into
ocaml-community:masterfrom
aqjune:camlp5

Conversation

@aqjune

@aqjune aqjune commented Apr 23, 2024

Copy link
Copy Markdown
Contributor

This resolves issue #485 (and the equivalent issue discussed in this thread) by fixing the definition of parse_toplevel_phrase_default of UTop to use !Toploop.parse_toplevel_phrase instead of Parse.toplevel_phrase.

Note that !Toploop.parse_toplevel_phrase is equal to Parse.toplevel_phrase when utop was just initiated: https://github.com/ocaml/ocaml/blob/trunk/toplevel/topcommon.ml#L29

However, a user may add its preprocessor to Toploop.parse_toplevel_phrase later using camlp5, making !Toploop.parse_toplevel_phrase and Parse.toplevel_phrase unequal.

This patch simply replaces Parse.toplevel_phrase with !Toploop.parse_toplevel_phrase so that the preprocessor can do its work.

Comment thread src/lib/uTop.ml
Error ([], "Unknown parsing error (please report it to the utop project): " ^ Printexc.to_string exn)

let parse_toplevel_phrase_default = parse_default Parse.toplevel_phrase
let parse_toplevel_phrase_default = fun str -> parse_default !Toploop.parse_toplevel_phrase str

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a bit of unusual way to write

let parse_toplevel_phrase_default str = ...

Otherwise the change is correct. However, we probably also want parse_use_file to use Toploop.parse_use_file.

Don't hesitate to tell me if you don't wish to come back to this PR. Also without answer, I am planning to merge the current state, and fix those minor quibbles subsequently.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for reviewing this patch! Yes, please feel free fix as you wish or even merge it. :)

@Octachron Octachron left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I propose to merge (tomorrow) and I will send minor fixes as PR later.

@Octachron
Octachron merged commit 8f18dd7 into ocaml-community:master Jun 26, 2025
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Octachron added a commit to Octachron/opam-repository that referenced this pull request Jul 25, 2025
CHANGES:

* Add support for OCaml 5.4 (ocaml-community/utop#500, @Octachron, @anmonteiro)
* restore backtrace (ocaml-community/utop#503, fixes ocaml-community/utop#501, @ysalmon)
* support camlp$n preprocessor (ocaml-community/utop#486, fixes ocaml-community/utop#485, @aqjune)
* utop configuration and state files (utoprc, utop-history) are now always in the relevant
  utop subdirectory (ocaml-community/utop#484, fixes ocaml-community/utop#478, ocaml-community/utop#481 and ocaml-community/utop#499, @tuohy).
* fix emacs completion for qualified paths (Module.M.some_name) (ocaml-community/utop#497, fix ocaml-community/utop#455, @juergenhoetzel, @bbatsov)
* implicit bindings for emacs mode (ocaml-community/utop#465, fix ocaml-community/utop#412, @bencef)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants