summaryrefslogtreecommitdiff
path: root/stdlib/scanf.mli
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/scanf.mli')
-rw-r--r--stdlib/scanf.mli78
1 files changed, 49 insertions, 29 deletions
diff --git a/stdlib/scanf.mli b/stdlib/scanf.mli
index c147f7a04b..bb68d40fc6 100644
--- a/stdlib/scanf.mli
+++ b/stdlib/scanf.mli
@@ -45,7 +45,8 @@
material with module {!Printf} or {!Format}),
- [f] is a function that has as many arguments as the number of values to
- read in the input. *)
+ read in the input.
+*)
(** {7 A simple example} *)
@@ -62,7 +63,8 @@
then [bscanf Scanning.stdin "%d" f] reads an integer [n] from the
standard input and returns [f n] (that is [n + 1]). Thus, if we
evaluate [bscanf stdin "%d" f], and then enter [41] at the
- keyboard, we get [42] as the final result. *)
+ keyboard, we get [42] as the final result.
+*)
(** {7 Formatted input as a functional feature} *)
@@ -75,8 +77,9 @@
useful additions to easily define complex tokens; as expected within a
functional programming language, the formatted input functions also
support polymorphism, in particular arbitrary interaction with
- polymorphic user-defined scanners. Furthermore, the OCaml formatted input
- facility is fully type-checked at compile time. *)
+ polymorphic user-defined scanners. Furthermore, the OCaml formatted input
+ facility is fully type-checked at compile time.
+*)
(** {6 Formatted input channel} *)
@@ -101,7 +104,8 @@ type scanbuf = in_channel;;
Note: a scanning action may often require to examine one character in
advance; when this ``lookahead'' character does not belong to the token
read, it is stored back in the scanning buffer and becomes the next
- character yet to be read. *)
+ character yet to be read.
+*)
val stdin : in_channel;;
(** The standard input notion for the [Scanf] module.
@@ -154,7 +158,8 @@ val from_string : string -> in_channel;;
(** [Scanning.from_string s] returns a formatted input channel which reads
from the given string.
Reading starts from the first character in the string.
- The end-of-input condition is set when the end of the string is reached. *)
+ The end-of-input condition is set when the end of the string is reached.
+*)
val from_function : (unit -> char) -> in_channel;;
(** [Scanning.from_function f] returns a formatted input channel with the
@@ -163,20 +168,24 @@ val from_function : (unit -> char) -> in_channel;;
When scanning needs one more character, the given function is called.
When the function has no more character to provide, it {e must} signal an
- end-of-input condition by raising the exception [End_of_file]. *)
+ end-of-input condition by raising the exception [End_of_file].
+*)
val from_channel : Pervasives.in_channel -> in_channel;;
(** [Scanning.from_channel ic] returns a formatted input channel which reads
from the regular input channel [ic] argument, starting at the current
- reading position. *)
+ reading position.
+*)
val end_of_input : in_channel -> bool;;
(** [Scanning.end_of_input ic] tests the end-of-input condition of the given
- formatted input channel. *)
+ formatted input channel.
+*)
val beginning_of_input : in_channel -> bool;;
(** [Scanning.beginning_of_input ic] tests the beginning of input condition of
- the given formatted input channel. *)
+ the given formatted input channel.
+*)
val name_of_input : in_channel -> string;;
(** [Scanning.name_of_input ic] returns the name of the character source
@@ -186,7 +195,8 @@ val name_of_input : in_channel -> string;;
val stdib : in_channel;;
(** A deprecated alias for [Scanning.stdin], the scanning buffer reading from
- [Pervasives.stdin]. *)
+ [Pervasives.stdin].
+*)
end;;
@@ -216,8 +226,9 @@ type ('a, 'b, 'c, 'd) scanner =
*)
exception Scan_failure of string;;
-(** The exception that formatted input functions raise when the input cannot be
- read according to the given format. *)
+(** The exception that formatted input functions raise when the input cannot
+ be read according to the given format.
+*)
(** {6 The general formatted input function} *)
@@ -231,18 +242,21 @@ val bscanf : Scanning.in_channel -> ('a, 'b, 'c, 'd) scanner;;
[Scanf.sscanf "x= 1" "%s = %i" f] returns [2].
Arguments [r1] to [rN] are user-defined input functions that read the
- argument corresponding to a [%r] conversion. *)
+ argument corresponding to the [%r] conversions specified in the format
+ string.
+*)
(** {6 Format string description} *)
-(** The format is a character string which contains three types of
+(** The format string is a character string which contains three types of
objects:
- plain characters, which are simply matched with the characters of the
input (with a special case for space and line feed, see {!Scanf.space}),
- conversion specifications, each of which causes reading and conversion of
one argument for the function [f] (see {!Scanf.conversion}),
- scanning indications to specify boundaries of tokens
- (see scanning {!Scanf.indication}). *)
+ (see scanning {!Scanf.indication}).
+*)
(** {7:space The space character in format strings} *)
@@ -261,7 +275,8 @@ val bscanf : Scanning.in_channel -> ('a, 'b, 'c, 'd) scanner;;
also matches no amount of whitespace at all; hence, the call [bscanf ib
"Price = %d $" (fun p -> p)] succeeds and returns [1] when reading an
input with various whitespace in it, such as [Price = 1 $],
- [Price = 1 $], or even [Price=1$]. *)
+ [Price = 1 $], or even [Price=1$].
+*)
(** {7:conversion Conversion specifications in format strings} *)
@@ -385,7 +400,8 @@ val bscanf : Scanning.in_channel -> ('a, 'b, 'c, 'd) scanner;;
analysis and parsing. If it appears not expressive enough for your
needs, several alternative exists: regular expressions (module
[Str]), stream parsers, [ocamllex]-generated lexers,
- [ocamlyacc]-generated parsers. *)
+ [ocamlyacc]-generated parsers.
+*)
(** {7:indication Scanning indications in format strings} *)
@@ -401,10 +417,10 @@ val bscanf : Scanning.in_channel -> ('a, 'b, 'c, 'd) scanner;;
Note:
- - As usual in format strings, [%] characters must be escaped using [%%]
- and [%\@] is equivalent to [\@]; this rule still holds within range
- specifications and scanning indications.
- For instance, ["%s@%%"] reads a string up to the next [%] character.
+ - As usual in format strings, [%] and [\@] characters must be escaped
+ using [%%] and [%\@]; this rule still holds within range specifications
+ and scanning indications.
+ For instance, ["%s@%%"] reads a string up to the next [%] character.
- The scanning indications introduce slight differences in the syntax of
[Scanf] format strings, compared to those used for the [Printf]
module. However, the scanning indications are similar to those used in
@@ -412,7 +428,8 @@ val bscanf : Scanning.in_channel -> ('a, 'b, 'c, 'd) scanner;;
by [!Scanf.bscanf], it is wise to use printing functions from the
[Format] module (or, if you need to use functions from [Printf], banish
or carefully double check the format strings that contain ['\@']
- characters). *)
+ characters).
+*)
(** {7 Exceptions during scanning} *)
@@ -433,7 +450,7 @@ val bscanf : Scanning.in_channel -> ('a, 'b, 'c, 'd) scanner;;
- as a consequence, scanning a [%s] conversion never raises exception
[End_of_file]: if the end of input is reached the conversion succeeds and
simply returns the characters read so far, or [""] if none were ever read.
- *)
+*)
(** {6 Specialised formatted input functions} *)
@@ -448,14 +465,16 @@ val fscanf : Pervasives.in_channel -> ('a, 'b, 'c, 'd) scanner;;
position, and so on).
As a consequence, never mix direct low level reading and high level
- scanning from the same regular input channel. *)
+ scanning from the same regular input channel.
+*)
val sscanf : string -> ('a, 'b, 'c, 'd) scanner;;
(** Same as {!Scanf.bscanf}, but reads from the given string. *)
val scanf : ('a, 'b, 'c, 'd) scanner;;
(** Same as {!Scanf.bscanf}, but reads from the predefined formatted input
- channel {!Scanf.Scanning.stdin} that is connected to [Pervasives.stdin]. *)
+ channel {!Scanf.Scanning.stdin} that is connected to [Pervasives.stdin].
+*)
val kscanf :
Scanning.in_channel -> (Scanning.in_channel -> exn -> 'd) ->
@@ -464,7 +483,8 @@ val kscanf :
[ef] that is called in case of error: if the scanning process or
some conversion fails, the scanning function aborts and calls the
error handling function [ef] with the formatted input channel and the
- exception that aborted the scanning process as arguments. *)
+ exception that aborted the scanning process as arguments.
+*)
(** {6 Reading format strings from input} *)
@@ -496,10 +516,10 @@ val format_from_string :
@since 3.10.0
*)
-val unescaped : string -> string
+val unescaped : string -> string;;
(** Return a copy of the argument with escape sequences, following the
lexical conventions of OCaml, replaced by their corresponding
- special characters. If there is no escape sequence in the
+ special characters. If there is no escape sequence in the
argument, still return a copy, contrary to String.escaped.
@since 4.00.0
*)