Skip to content

Commit

Permalink
Pprintast now depends on Printast
Browse files Browse the repository at this point in the history
  • Loading branch information
goldfirere committed Jun 14, 2023
1 parent ff05909 commit bdac10c
Show file tree
Hide file tree
Showing 17 changed files with 104 additions and 84 deletions.
33 changes: 18 additions & 15 deletions ocaml/.depend
Original file line number Diff line number Diff line change
Expand Up @@ -431,6 +431,7 @@ parsing/docstrings.cmi : \
parsing/parsetree.cmi \
parsing/location.cmi
parsing/jane_syntax.cmo : \
parsing/printast.cmi \
parsing/parsetree.cmi \
parsing/longident.cmi \
parsing/location.cmi \
Expand All @@ -440,6 +441,7 @@ parsing/jane_syntax.cmo : \
parsing/ast_helper.cmi \
parsing/jane_syntax.cmi
parsing/jane_syntax.cmx : \
parsing/printast.cmx \
parsing/parsetree.cmi \
parsing/longident.cmx \
parsing/location.cmx \
Expand All @@ -456,14 +458,12 @@ parsing/jane_syntax.cmi : \
parsing/asttypes.cmi
parsing/jane_syntax_parsing.cmo : \
parsing/parsetree.cmi \
utils/misc.cmi \
parsing/location.cmi \
utils/language_extension.cmi \
parsing/ast_helper.cmi \
parsing/jane_syntax_parsing.cmi
parsing/jane_syntax_parsing.cmx : \
parsing/parsetree.cmi \
utils/misc.cmx \
parsing/location.cmx \
utils/language_extension.cmx \
parsing/ast_helper.cmx \
Expand Down Expand Up @@ -514,15 +514,13 @@ parsing/longident.cmx : \
parsing/longident.cmi :
parsing/parse.cmo : \
parsing/syntaxerr.cmi \
parsing/pprintast.cmi \
parsing/parser.cmi \
parsing/location.cmi \
parsing/lexer.cmi \
parsing/docstrings.cmi \
parsing/parse.cmi
parsing/parse.cmx : \
parsing/syntaxerr.cmx \
parsing/pprintast.cmx \
parsing/parser.cmx \
parsing/location.cmx \
parsing/lexer.cmx \
Expand Down Expand Up @@ -570,6 +568,7 @@ parsing/parsetree.cmi : \
parsing/location.cmi \
parsing/asttypes.cmi
parsing/pprintast.cmo : \
parsing/printast.cmi \
parsing/parsetree.cmi \
parsing/longident.cmi \
parsing/location.cmi \
Expand All @@ -578,6 +577,7 @@ parsing/pprintast.cmo : \
parsing/ast_helper.cmi \
parsing/pprintast.cmi
parsing/pprintast.cmx : \
parsing/printast.cmx \
parsing/parsetree.cmi \
parsing/longident.cmx \
parsing/location.cmx \
Expand All @@ -589,27 +589,28 @@ parsing/pprintast.cmi : \
parsing/parsetree.cmi \
parsing/longident.cmi
parsing/printast.cmo : \
parsing/pprintast.cmi \
parsing/parsetree.cmi \
parsing/longident.cmi \
parsing/location.cmi \
utils/clflags.cmi \
parsing/asttypes.cmi \
parsing/printast.cmi
parsing/printast.cmx : \
parsing/pprintast.cmx \
parsing/parsetree.cmi \
parsing/longident.cmx \
parsing/location.cmx \
utils/clflags.cmx \
parsing/asttypes.cmi \
parsing/printast.cmi
parsing/printast.cmi : \
parsing/parsetree.cmi
parsing/parsetree.cmi \
parsing/asttypes.cmi
parsing/syntaxerr.cmo : \
parsing/printast.cmi \
parsing/location.cmi \
parsing/syntaxerr.cmi
parsing/syntaxerr.cmx : \
parsing/printast.cmx \
parsing/location.cmx \
parsing/syntaxerr.cmi
parsing/syntaxerr.cmi : \
Expand Down Expand Up @@ -1011,6 +1012,7 @@ typing/layouts.cmo : \
typing/path.cmi \
utils/misc.cmi \
parsing/location.cmi \
utils/language_extension.cmi \
typing/ident.cmi \
parsing/builtin_attributes.cmi \
parsing/asttypes.cmi \
Expand All @@ -1019,6 +1021,7 @@ typing/layouts.cmx : \
typing/path.cmx \
utils/misc.cmx \
parsing/location.cmx \
utils/language_extension.cmx \
typing/ident.cmx \
parsing/builtin_attributes.cmx \
parsing/asttypes.cmi \
Expand Down Expand Up @@ -1060,14 +1063,14 @@ typing/mtype.cmi : \
typing/ident.cmi \
typing/env.cmi
typing/oprint.cmo : \
parsing/pprintast.cmi \
parsing/printast.cmi \
typing/outcometree.cmi \
typing/layouts.cmi \
utils/language_extension.cmi \
parsing/asttypes.cmi \
typing/oprint.cmi
typing/oprint.cmx : \
parsing/pprintast.cmx \
parsing/printast.cmx \
typing/outcometree.cmi \
typing/layouts.cmx \
utils/language_extension.cmx \
Expand Down Expand Up @@ -1326,7 +1329,6 @@ typing/printtyped.cmo : \
typing/types.cmi \
typing/typedtree.cmi \
parsing/printast.cmi \
parsing/pprintast.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
parsing/longident.cmi \
Expand All @@ -1340,7 +1342,6 @@ typing/printtyped.cmx : \
typing/types.cmx \
typing/typedtree.cmx \
parsing/printast.cmx \
parsing/pprintast.cmx \
typing/path.cmx \
parsing/parsetree.cmi \
parsing/longident.cmx \
Expand Down Expand Up @@ -1652,16 +1653,17 @@ typing/typedecl.cmo : \
typing/typedecl_separability.cmi \
typing/subst.cmi \
typing/printtyp.cmi \
parsing/printast.cmi \
typing/primitive.cmi \
typing/predef.cmi \
parsing/pprintast.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
typing/oprint.cmi \
utils/misc.cmi \
parsing/longident.cmi \
parsing/location.cmi \
typing/layouts.cmi \
parsing/jane_syntax.cmi \
typing/includecore.cmi \
typing/ident.cmi \
typing/errortrace.cmi \
Expand All @@ -1685,16 +1687,17 @@ typing/typedecl.cmx : \
typing/typedecl_separability.cmx \
typing/subst.cmx \
typing/printtyp.cmx \
parsing/printast.cmx \
typing/primitive.cmx \
typing/predef.cmx \
parsing/pprintast.cmx \
typing/path.cmx \
parsing/parsetree.cmi \
typing/oprint.cmx \
utils/misc.cmx \
parsing/longident.cmx \
parsing/location.cmx \
typing/layouts.cmx \
parsing/jane_syntax.cmx \
typing/includecore.cmx \
typing/ident.cmx \
typing/errortrace.cmx \
Expand Down Expand Up @@ -2024,8 +2027,8 @@ typing/typetexp.cmo : \
typing/types.cmi \
typing/typedtree.cmi \
typing/printtyp.cmi \
parsing/printast.cmi \
typing/predef.cmi \
parsing/pprintast.cmi \
typing/path.cmi \
parsing/parsetree.cmi \
typing/oprint.cmi \
Expand All @@ -2048,8 +2051,8 @@ typing/typetexp.cmx : \
typing/types.cmx \
typing/typedtree.cmx \
typing/printtyp.cmx \
parsing/printast.cmx \
typing/predef.cmx \
parsing/pprintast.cmx \
typing/path.cmx \
parsing/parsetree.cmi \
typing/oprint.cmx \
Expand Down
2 changes: 1 addition & 1 deletion ocaml/compilerlibs/Makefile.compilerlibs
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ PARSING = \
parsing/location.cmo \
parsing/longident.cmo \
parsing/docstrings.cmo \
parsing/printast.cmo \
parsing/syntaxerr.cmo \
parsing/ast_helper.cmo \
parsing/jane_syntax_parsing.cmo parsing/jane_syntax.cmo \
Expand All @@ -69,7 +70,6 @@ PARSING = \
parsing/parser.cmo \
parsing/lexer.cmo \
parsing/parse.cmo \
parsing/printast.cmo \
parsing/ast_mapper.cmo \
parsing/attr_helper.cmo \
parsing/ast_invariants.cmo \
Expand Down
11 changes: 5 additions & 6 deletions ocaml/dune
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,10 @@
lazy_backtrack diffing diffing_with_keys language_extension

;; PARSING
location longident docstrings syntaxerr ast_helper camlinternalMenhirLib
ast_iterator parser lexer parse printast pprintast ast_mapper attr_helper
builtin_attributes ast_invariants depend jane_syntax_parsing jane_syntax
; manual update: mli only files
asttypes parsetree
location longident docstrings printast syntaxerr ast_helper
camlinternalMenhirLib ast_iterator parser lexer parse pprintast ast_mapper
attr_helper builtin_attributes ast_invariants depend jane_syntax_parsing
jane_syntax ; manual update: mli only files asttypes parsetree

;; TYPING
ident path primitive shape layouts types btype oprint subst predef datarepr
Expand Down Expand Up @@ -245,13 +244,13 @@
(location.mli as compiler-libs/location.mli)
(longident.mli as compiler-libs/longident.mli)
(docstrings.mli as compiler-libs/docstrings.mli)
(printast.mli as compiler-libs/printast.mli)
(syntaxerr.mli as compiler-libs/syntaxerr.mli)
(ast_helper.mli as compiler-libs/ast_helper.mli)
(camlinternalMenhirLib.mli as compiler-libs/camlinternalMenhirLib.mli)
(parser.mli as compiler-libs/parser.mli)
(lexer.mli as compiler-libs/lexer.mli)
(parse.mli as compiler-libs/parse.mli)
(printast.mli as compiler-libs/printast.mli)
(pprintast.mli as compiler-libs/pprintast.mli)
(ast_mapper.mli as compiler-libs/ast_mapper.mli)
(ast_iterator.mli as compiler-libs/ast_iterator.mli)
Expand Down
1 change: 1 addition & 0 deletions ocaml/otherlibs/dynlink/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ COMPILERLIBS_SOURCES=\
parsing/location.ml \
parsing/longident.ml \
parsing/docstrings.ml \
parsing/printast.ml \
parsing/syntaxerr.ml \
parsing/ast_helper.ml \
parsing/jane_syntax_parsing.ml \
Expand Down
5 changes: 5 additions & 0 deletions ocaml/otherlibs/dynlink/dune
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
location
longident
docstrings
printast
syntaxerr
jane_syntax_parsing
jane_syntax
Expand Down Expand Up @@ -126,6 +127,7 @@
(copy_files ../../parsing/location.ml)
(copy_files ../../parsing/longident.ml)
(copy_files ../../parsing/docstrings.ml)
(copy_files ../../parsing/printast.ml)
(copy_files ../../parsing/syntaxerr.ml)
(copy_files ../../parsing/jane_syntax_parsing.ml)
(copy_files ../../parsing/jane_syntax.ml)
Expand Down Expand Up @@ -183,6 +185,7 @@
(copy_files ../../parsing/location.mli)
(copy_files ../../parsing/longident.mli)
(copy_files ../../parsing/docstrings.mli)
(copy_files ../../parsing/printast.mli)
(copy_files ../../parsing/syntaxerr.mli)
(copy_files ../../parsing/jane_syntax_parsing.mli)
(copy_files ../../parsing/jane_syntax.mli)
Expand Down Expand Up @@ -278,6 +281,7 @@
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Symbol.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Path.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Docstrings.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Printast.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Syntaxerr.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Lazy_backtrack.cmo
.dynlink_compilerlibs.objs/byte/dynlink_compilerlibs__Ast_helper.cmo
Expand Down Expand Up @@ -351,6 +355,7 @@
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Path.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Lazy_backtrack.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Docstrings.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Printast.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Syntaxerr.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Ast_helper.cmx
.dynlink_compilerlibs.objs/native/dynlink_compilerlibs__Jane_syntax_parsing.cmx
Expand Down
43 changes: 0 additions & 43 deletions ocaml/parsing/parse.ml
Original file line number Diff line number Diff line change
Expand Up @@ -104,46 +104,3 @@ let constr_ident= wrap Parser.parse_constr_longident
let extended_module_path = wrap Parser.parse_mod_ext_longident
let simple_module_path = wrap Parser.parse_mod_longident
let type_ident = wrap Parser.parse_mty_longident

(* Error reporting for Syntaxerr *)
(* The code has been moved here so that one can reuse Pprintast.tyvar *)

let prepare_error err =
let open Syntaxerr in
match err with
| Unclosed(opening_loc, opening, closing_loc, closing) ->
Location.errorf
~loc:closing_loc
~sub:[
Location.msg ~loc:opening_loc
"This '%s' might be unmatched" opening
]
"Syntax error: '%s' expected" closing

| Expecting (loc, nonterm) ->
Location.errorf ~loc "Syntax error: %s expected." nonterm
| Not_expecting (loc, nonterm) ->
Location.errorf ~loc "Syntax error: %s not expected." nonterm
| Applicative_path loc ->
Location.errorf ~loc
"Syntax error: applicative paths of the form F(X).t \
are not supported when the option -no-app-func is set."
| Variable_in_scope (loc, var) ->
Location.errorf ~loc
"In this scoped type, variable %a \
is reserved for the local type %s."
Pprintast.tyvar var var
| Other loc ->
Location.errorf ~loc "Syntax error"
| Ill_formed_ast (loc, s) ->
Location.errorf ~loc
"broken invariant in parsetree: %s" s
| Invalid_package_type (loc, s) ->
Location.errorf ~loc "invalid package type: %s" s

let () =
Location.register_error_of_exn
(function
| Syntaxerr.Error err -> Some (prepare_error err)
| _ -> None
)
9 changes: 2 additions & 7 deletions ocaml/parsing/pprintast.ml
Original file line number Diff line number Diff line change
Expand Up @@ -287,13 +287,7 @@ let iter_loc f ctxt {txt; loc = _} = f ctxt txt

let constant_string f s = pp f "%S" s

let tyvar ppf s =
if String.length s >= 2 && s.[1] = '\'' then
(* without the space, this would be parsed as
a character literal *)
Format.fprintf ppf "' %s" s
else
Format.fprintf ppf "'%s" s
let tyvar = Printast.tyvar

let tyvar_loc f str = tyvar f str.txt
let string_quot f x = pp f "`%s" x
Expand Down Expand Up @@ -1954,3 +1948,4 @@ let structure_item = structure_item reset_ctxt
let signature_item = signature_item reset_ctxt
let binding = binding reset_ctxt
let payload = payload reset_ctxt

4 changes: 1 addition & 3 deletions ocaml/parsing/pprintast.mli
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,4 @@ val signature_item: Format.formatter -> Parsetree.signature_item -> unit
val binding: Format.formatter -> Parsetree.value_binding -> unit
val payload: Format.formatter -> Parsetree.payload -> unit

val tyvar: Format.formatter -> string -> unit
(** Print a type variable name, taking care of the special treatment
required for the single quote character in second position. *)

This comment has been minimized.

Copy link
@antalsz

antalsz Jun 29, 2023

Contributor

Stray newline

This comment has been minimized.

Copy link
@goldfirere

goldfirere Jun 30, 2023

Author Collaborator

Got fixed later, evidently, because it's gone now. Thanks.

This comment has been minimized.

Copy link
@antalsz

antalsz Jun 30, 2023

Contributor

My apologies, I accidentally reviewed some of the earlier commits instead of the later ones, and this must have slipped through 😅

Loading

0 comments on commit bdac10c

Please sign in to comment.