<commit_before>(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*            <NAME>, <NAME>, INRIA Rocquencourt          *)
(*                                                                     *)
(*  Copyright 2002 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the GNU Library General Public License, with    *)
(*  the special exception on linking described in file ../LICENSE.     *)
(*                                                                     *)
(***********************************************************************)

(* $Id$ *)

(** Formatted input functions. *)

(** {6 Functional input with format strings.} *)

(** The formatted input functions provided by module [Scanf] are functionals
    that apply the values they read in the input to their function argument.
    The specification of the values to read is simply given by a format string
    (the same format strings as those used to print material using module
    {!Printf} or module {!Format}).

    As an example, consider the formatted input function [scanf] that reads
    from standard input; a typical call to [scanf] is simply [scanf fmt f],
    meaning that [f] should be applied to the arguments read according to the
    format string [fmt]. For instance, if [f] is defined as [let f x = x + 1], then
    [scanf "%d" f] will read a decimal integer [i] from [stdin] and return
    [f i]; thus, if we enter [41] at the keyboard, [scanf "%d" f] evaluates to [42].

    This module provides general formatted input functions that reads from any
    kind of input, including strings, files, or anything that can return
    characters.
    Hence, a typical call to a formatted input function [scan] is
    [scan ib fmt f], meaning that [f] should be applied to the arguments
    read from input [ib], according to the format string [fmt].

    The Caml scanning facility is reminiscent of the corresponding C
    feature. It is also largely different: the formatted input functions are
    higher-order functional free from assigments; the format strings
    conventions are largely improved with useful additions to easily define
    complex tokens; the formatted input functions support arbitrary interaction
    with polymorphic user-defined scanners; in short, the formatted input
    function facility has been turned to a functional language feature: it is
    higher-order, based on functions, and fully type-checked at compile
    time. *)

(** {6 Scanning buffers} *)
module Scanning : sig

type scanbuf;;
(** The type of scanning buffers. A scanning buffer is the source from which a
    formatted input function gets characters. The scanning buffer holds the current
    state of the scan, plus a function to get the next char from the input, and
    a token buffer to store the string matched so far.

   Note: a scan 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 read. *)

val stdib : scanbuf;;
(** The scanning buffer reading from [stdin].
    [stdib] is equivalent to [Scanning.from_channel stdin].

    Note: when input is read interactively from [stdin], the carriage return
    that triggers the evaluation is incorporated in the input; thus, scanning
    specifications must properly skip this character (simply add a ['\n']
    as the last character of the format string). *)

val from_string : string -> scanbuf;;
(** [Scanning.from_string s] returns a scanning buffer which reads from the<commit_msg>Documentation.<commit_after>(***********************************************************************)
(*                                                                     *)
(*                           Objective Caml                            *)
(*                                                                     *)
(*            <NAME>, projet Cristal, INRIA Rocquencourt          *)
(*                                                                     *)
(*  Copyright 2002 Institut National de Recherche en Informatique et   *)
(*  en Automatique.  All rights reserved.  This file is distributed    *)
(*  under the terms of the GNU Library General Public License, with    *)
(*  the special exception on linking described in file ../LICENSE.     *)
(*                                                                     *)
(***********************************************************************)

(* $Id$ *)

(** Formatted input functions. *)

(** {6 Functional input with format strings.} *)

(** The formatted input functions provided by module [Scanf] are functionals
    that apply the values they read in the input to their function argument.
    The specification of the values to read is simply given by a format string
    (the same format strings as those used to print material using module
    {!Printf} or module {!Format}).

    As an example, consider the formatted input function [scanf] that reads
    from standard input; a typical call to [scanf] is simply [scanf fmt f],
    meaning that [f] should be applied to the arguments read according to the
    format string [fmt]. For instance, if [f] is defined as [let f x = x + 1], then
    [scanf "%d" f] will read a decimal integer [i] from [stdin] and return
    [f i]; thus, if we enter [41] at the keyboard, [scanf "%d" f] evaluates to [42].

    This module provides general formatted input functions that reads from any
    kind of input, including strings, files, or anything that can return
    characters.
    Hence, a typical call to a formatted input function [bscan] is
    [bscan ib fmt f], meaning that [f] should be applied to the arguments
    read from input [ib], according to the format string [fmt].

    The Caml scanning facility is reminiscent of the corresponding C feature.
    However, it is also largely different, simpler, and yet more powerful: the
    formatted input functions are higher-order functionals and the parameter
    passing mechanism is simply the regular function application not the
    variable assigment based mechanism which is typical of formatted input in
    imperative languages; the format strings also feature useful additions to
    easily define complex tokens; as expected of a functional programming
    language feature, the formatted input functions support polymorphism, in
    particular arbitrary interaction with polymorphic user-defined scanners.
    Furthermore, the Caml formatted input facility is fully type-checked at
    compile time. *)

(** {6 Scanning buffers} *)
module Scanning : sig

type scanbuf;;
(** The type of scanning buffers. A scanning buffer is the source from which a
    formatted input function gets characters. The scanning buffer holds the current
    state of the scan, plus a function to get the next char from the input, and
    a token buffer to store the string matched so far.

   Note: a scan 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 read. *)

val stdib : scanbuf;;
(** The scanning buffer reading from [stdin].
    [stdib] is equivalent to [Scanning.from_channel stdin].

    Note: when input is read interactively from [stdin], the carriage return
    that triggers the evaluation is incorporated in the input; thus, scanning
    specifications must properly skip this character (simply add a ['\n']
    as the last character of the format string). *)

val from_string : string -> scanbuf;;
(** [Scanning.from_string s] returns a scanning buffer which reads from the
{'fraction_non_alphanumeric': 0.09635254574878625, 'fraction_numerical': 0.0027387028507406944, 'mean_word_length': 2.6501590186278965, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 8, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 16, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7414322', 'n_tokens_mistral': 1841, 'n_tokens_neox': 1739, 'n_words': 1004}