Commit Graph

137 Commits (9124ab82d14b0fe4c8092af0f666b19d42139af0)

Author SHA1 Message Date
Jérémie Dimino 9124ab82d1
Deprecate Pervasives (#1605)
- inline Pervasives in Stdlib and re-add Pervasives as a deprecated
module that aliases all elements of Stdlib except the stdlib modules.

- remove special case for Stdlib.Pervasives in printtyp.ml
2018-08-27 12:42:14 +01:00
Nicolás Ojeda Bär 09b4aee5a4
Merge pull request #1940 from dbuenzli/option-support
Improve stdlib support for option values
2018-08-08 13:48:50 +02:00
Gabriel Scherer ed97c44bd2
Merge pull request #1948 from keleshev/refactor-format
Refactor Format module to use Queue and Stack
2018-08-08 12:58:45 +02:00
Daniel Bünzli f9c97d16c0 Add Format.pp_print_option. 2018-08-08 11:45:35 +02:00
Vladimir Keleshev cac5702555 Format: make `pp_skip_token` gracefully handle empty queue
Function `pp_skip_token` had a comment saying that the queue is never empty
when it is called.  However, I came up with a unit test that falsifies that
invariant, see `pp_skip_token.ml`. This prompted to change `pp_skip_token` to
gracefully handle the case when the queue is empty. Before, the invariant was
wrong, but the code still worked correctly because the exception would have
been caught in `advance_left` which used to use `Queue.Empty` exception for
control flow.
2018-08-08 11:12:20 +02:00
Daniel Bünzli 51802eddc7 Add Format.pp_print_result. 2018-08-08 10:34:07 +02:00
Vladimir Keleshev c11c7d7cae Format: remove make_queue_element
Since it doesn't bring anything to the table. Use record constructor instead.
2018-08-07 21:29:43 +02:00
Vladimir Keleshev 1193d6591c Format: convert pp_format_elem into a record type
For better readability.
2018-08-07 21:29:38 +02:00
Vladimir Keleshev 903341bcf9 Format: convert pp_scan_elem into a record type
For better readability.
2018-08-07 21:29:23 +02:00
Vladimir Keleshev ff79fcc329 Format: rename pp_queue_elem.elem_size to size
The original name is tautological, plus the new name works better with
record field punning.
2018-08-07 21:23:46 +02:00
Vladimir Keleshev f8c72d5b8e Format: replace inline list stacks with Stdlib.Stack
This reduces the volume of code in Format and adds clarity by using a
familiar Stack interface. However, this introduces a dependency from
Format to Stack.
2018-08-07 21:22:23 +02:00
Vladimir Keleshev cd958be9b6 Format: replace bespoke queue for Stdlib.Queue
This reduces the volume of code in Format and adds clarity by using a
familiar Queue interface. However, this introduces a dependency from
Format to Queue.

Note, `state.pp_queue` was unnecessarily mutable.
2018-08-07 21:16:59 +02:00
Vladimir Keleshev c1036e199d Format: introduce Size module
Use proper abstract module instead of "%identity" trick.
Add Size.unknown and Size.is_unknown to aid readability
instead of relying on a comment saying that negative
sizes mean unkown sizes.
2018-08-07 21:16:59 +02:00
Drup 82f5376044 Relax the type of make_iprintf and improve Format.ifprintf. 2018-08-02 23:17:47 +02:00
Drup 68490ebbbb Add dprintf, the delayed printf function. 2018-08-02 23:09:20 +02:00
Drup 12238e40ae Remove the state argument in CamlinternalFormat.make_printf.
This state argument was passed around, but never used, except
by the continuation.
2018-08-02 23:09:20 +02:00
Pierre Weis a000769c8d Fix MPR#7235 (#1870) 2018-07-02 10:30:57 +02:00
Frédéric Bour 7b6d2282d2 Use raise_notrace rather than raise in format.ml (#1731)
Calls to raise in Format can accidentally appear in backtraces,
especially when formatting an error message after catching an exception.

By using raise_notrace, the backtrace is no longer clobbered.
2018-04-20 12:54:20 +01:00
Fourchaux 72cfdd56e9 Typos and basic grammar error fixing (#1280) 2017-08-10 11:59:23 +01:00
pierreweis 4e695f6e04 [format] Documentation review and rephrasing.
- Some addition for formatted pretty-printing.
- Some simplification and precision; in particular, explicitely naming the
  standard pretty-printer when we are talking about the standard pretty-printer
2017-04-03 15:44:52 +02:00
pierreweis 78b048da50 [format] Function to clear tag stack similar to clearing box stack
In this function, we repeatedly close the open tags.
This function is now called when resetting the pretty-printing engine.

This is a fix: before this commit, tags were never closed when flushing
the pretty-printing engine. Actually, tags were *only* removed from the
the tag stack.

Detail: opened -> open.
2017-04-03 15:42:27 +02:00
Richard Bonichon bc7084cae3 [format] Remove pp_flush_formatter function
This function is broken.

Before you use this function, you might be in either one of these cases:
1. There are no pending open boxes/tags. In this case, flushing the stack has no
   effect.
2. You still have some open boxes and/or tags. Thus the function call flushes
   them. Now, if you still had some pretty-printing to do afterwards, it makes
   no sense to have called this function.
   Say for the sake of the argument that only 1 box was left open before the
   call:
   - Either the rest (e.g. continuation) of your pretty-printing routine assumed
     that the box was *closed*: now it is broken.
   - Or it *knew* the box was open. The question is now why does it not close it
     itself (or pass this obligation to yet another part of the pretty-printing
     routine) ?

In either case, this function should *not* be used and thus it should not be
exposed to the user. Let us state here that it breaks the invariants upon which
the Format module has been based.
2017-04-03 15:42:27 +02:00
Richard Bonichon 37b9f4ccdb [format] Add symbolic pretty-printing 2017-04-03 15:39:57 +02:00
Richard Bonichon 98095f9973 [format] Introduce indentation as a separate output feature
Before this commit, indentation was identical to outputting blanks.
This is generally true but not always: in some applications you may want to use
'\t' as indentation but not for blanks, ...

The `formatter_out_functions` record is extended with an extra settable field
`out_indent`.

This allows the user to control this aspect of pretty-printing.

The teststuite has been update to reflect this modification.
2017-04-03 15:39:57 +02:00
Richard Bonichon 12642c60cc [format] Documentation fixes and enhancements
- Typos
- English
- Extended documentation for semantic tags
2017-04-03 15:38:18 +02:00
Pierre Chambart cb78373081 Use inline record in Format 2016-06-09 17:14:33 +02:00
Damien Doligez 520fb2df50 Merge tag 4.03.0 into trunk. 2016-04-28 16:13:21 +02:00
Spiros Eliopoulos 11cbedf115 expose function to flush formatter's internal queue
Previous to this commit the Format API did not allow the user to flush a
formatter's internal queue without also flushing the formatter's output
stream. This was a problem for custom formatters that may have been used
in conjunction with kfprintf or ikfprintf. When the continuation was
called, the formatter's queue of operations may not have been flushed.
The only way that the user could force a queue flush was to call
pp_print_flush, forcing the user to introduce a blocking call before it
was necessary, regardless of other buffer state within the system.

Exposing the internal queue flushing operation solves this problem.

Names may be changed to protect aesthetic sensibilities.
2016-04-04 08:51:48 -04:00
Damien Doligez 5401ce8473 Update headers for the new license.
Remains to be done: remove all headers in testsuite/tests.
2016-02-18 16:59:16 +01:00
pierreweis 699b223217 Careful code review/rewriting. Moving obsolete stuff to the proper devoted section. Documentation. 2015-12-24 13:54:16 +01:00
Mark Shinwell 347fec44fb Add Format.kasprintf and fix Misc.fatal_errorf to use it 2015-12-23 10:47:31 +00:00
Gabriel Scherer b2e81d7800 Merge pull request #267 from yallop/faster-ifprintf
A more efficient implementation of ifprintf
2015-10-31 16:54:40 +01:00
alainfrisch a127e661b2 Code cleanup: replace let-binding of type unit with sequence. 2015-10-27 11:28:36 +01:00
Jeremy Yallop 19301282d5 Use make_iprintf to build Format.ikfprintf and Format.ifprintf. 2015-10-27 00:02:45 +00:00
Pierre Weis e02d472aa4 Renaming: flush_buf_formatter into flush_buffer_formatter.
flush_str_formatter rewritten using flush_buffer_formatter.

Consistent naming of pretty-printer formatter as ppf not strange x or o
parameters.

Function ksprintf purposedly defines a new continuation embedding the old
one.

Function asprintf rewritten in a more natural way; spurious pp_flush_queue
deleted in the conitnuation, since it is already done via following
flush_buffer_formatter call.

Indent.


git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@16429 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-09-21 17:08:11 +00:00
Gabriel Scherer 926cc79f1c PR#6824: fix buffer sharing on partial application of Format.asprintf
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@16043 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2015-04-26 20:00:57 +00:00
Damien Doligez cbfe627f92 merge changes from branch 4.02 from branching (rev 14852) to 4.02.0+rc1 (rev 15121)
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@15125 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-08-22 13:45:02 +00:00
Gabriel Scherer 49d3f7b9f8 PR#6418: support "@[<hov %d>" in the new format implementation (Benoît Vaugon)
The bootstrap procedure, as for commit trunk@14973 (see there for
detailed build instructions), requires to first commit a temporary
patch:

> diff -Naur old/typing/typecore.ml new/typing/typecore.ml
> --- old/typing/typecore.ml        2014-06-11 18:16:24.851647309 +0200
> +++ new/typing/typecore.ml        2014-06-11 18:15:50.075646418 +0200
> @@ -2758,16 +2758,9 @@
>        let mk_int n = mk_cst (Const_int n)
>        and mk_string str = mk_cst (Const_string (str, None))
>        and mk_char chr = mk_cst (Const_char chr) in
> -      let mk_block_type bty = match bty with
> -        | Pp_hbox   -> mk_constr "Pp_hbox"   []
> -        | Pp_vbox   -> mk_constr "Pp_vbox"   []
> -        | Pp_hvbox  -> mk_constr "Pp_hvbox"  []
> -        | Pp_hovbox -> mk_constr "Pp_hovbox" []
> -        | Pp_box    -> mk_constr "Pp_box"    []
> -        | Pp_fits   -> mk_constr "Pp_fits"   [] in
>        let rec mk_formatting_lit fmting = match fmting with
> -        | Open_box (org, bty, idt) ->
> -          mk_constr "Open_box" [ mk_string org; mk_block_type bty; mk_int idt ]
> +        | Open_box _ ->
> +          assert false
>          | Close_box ->
>            mk_constr "Close_box" []
>          | Close_tag ->
> @@ -2950,6 +2943,19 @@
>            mk_constr "Alpha" [ mk_fmt rest ]
>          | Theta rest ->
>            mk_constr "Theta" [ mk_fmt rest ]
> +        | Formatting_lit (Open_box (org, _bty, _idt), rest) ->
> +          mk_constr "Formatting_gen" [
> +            mk_constr "Open_box" [
> +              mk_constr "Format" [
> +                mk_constr "String_literal" [
> +                  mk_string "<>";
> +                  mk_constr "End_of_format" [];
> +                ];
> +                mk_string "@[<>";
> +              ]
> +            ];
> +            mk_fmt rest;
> +          ]
>          | Formatting_lit (fmting, rest) ->
>            mk_constr "Formatting_lit" [ mk_formatting_lit fmting; mk_fmt rest ]
>          | Formatting_gen (fmting, rest) ->

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14984 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-06-14 21:08:50 +00:00
Gabriel Scherer 7cb9d0d84e PR#6418: fix format regression on "@{<..%d..%s..>" (Benoît Vaugon)
To be able to compile this patch, you should temporarily apply the
following patch to bootstrap the format type change:

> diff -Naur old/typing/typecore.ml new/typing/typecore.ml
> --- old/typing/typecore.ml	2014-06-06 03:37:03.240926150 +0200
> +++ new/typing/typecore.ml	2014-06-06 03:37:24.696926699 +0200
> @@ -2956,7 +2956,7 @@
>          | Theta rest ->
>            mk_constr "Theta" [ mk_fmt rest ]
>          | Formatting (fmting, rest) ->
> -          mk_constr "Formatting" [ mk_formatting fmting; mk_fmt rest ]
> +          mk_constr "Formatting_lit" [ mk_formatting fmting; mk_fmt rest ]
>          | Reader rest ->
>            mk_constr "Reader" [ mk_fmt rest ]
>          | Scan_char_set (width_opt, char_set, rest) ->

Bootstrap process:

  make core
  apply the patch above
  make core
  make promote-cross
  make partialclean
  revert the patch above, apply the commit
  make partialclean
  make core
  make coreboot

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14973 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-06-09 13:53:47 +00:00
Gabriel Scherer 3ffa399b37 Use a nominal datatype for CamlinternalFormat.format6
This should make the type-checking of formats simpler and more robust:
instead of trying to find a pair as previously, we can now use the
path of the format6 type directly.

A nice side-effect of the change is that the internal definition of
formats (as a pair) is not printed in error messages anymore.
Because format6 is in fact defined in the CamlinternalFormatBasics
submodule of Pervasives, and has an alias at the toplevel of
Pervasives, error messages still expand the definition:

> Error: This expression has type
>          ('a, 'b, 'c, 'd, 'd, 'a) format6 =
>            ('a, 'b, 'c, 'd, 'd, 'a) CamlinternalFormatBasics.format6
>        but an expression was expected of type ...

Passing the option `-short-paths` does avoid this expansion and
returns exactly the same error message as 4.01:

> Error: This expression has type ('a, 'b, 'c, 'd, 'd, 'a) format6
>        but an expression was expected of type ...

(To get this error message without -short-paths, one would need to
define format6 directly in Pervasives; but this type is mutually
recursive with several GADT types that we don't want to add in the
Pervasives namespace unqualified. This is why I'll keep the alias
for now.)

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14868 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-05-14 15:07:13 +00:00
Gabriel Scherer 0e1584665e fix a regression in Format formatting printing routines
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14842 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-05-12 15:38:37 +00:00
Gabriel Scherer 72669307e8 second part of Benoît Vaugon's format+gadts patch
To finish the bootstrap cycle, run:

  make library-cross
  make promote
  make partialclean
  make core

  make library-cross
  make promote-cross
  make partialclean
  make ocamlc ocamllex ocamltools

  make library-cross
  make promote
  make partialclean
  make core
  make compare

git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14810 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-05-12 15:37:37 +00:00
Damien Doligez 5b8df637d2 merge branch "safe-string"
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14705 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2014-04-29 11:56:17 +00:00
Gabriel Scherer 8ba031a7db Format: pp_print_list and pp_print_text, contributed by Daniel Bünzli
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@14123 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-09-13 15:55:41 +00:00
Pierre Weis 626c696aee Wrong quoting chase.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13717 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-05-29 18:03:55 +00:00
Damien Doligez db9ea0df59 PR#6024: Format syntax for printing @ is incompatible with 3.12.1
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13713 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-05-29 15:56:25 +00:00
Pierre Weis faf9cb478d Revert sprintf type. Add a new function to support %a conversions in sprintf functionality.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13609 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-04-25 09:14:09 +00:00
Pierre Weis a79b51b675 Complete rewriting of Format.mk_printf. Convergence between Printf and Format codes.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13606 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-04-24 14:56:25 +00:00
Pierre Weis 1d1d751326 PR#5973 (old @ escape was still implemented in Format) + bootstrap.
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13601 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2013-04-23 21:44:30 +00:00
Damien Doligez def31744f9 remove all $Id keywords
git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@13013 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
2012-10-15 17:50:56 +00:00