mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 03:05:28 -05:00
feat: New format and parser for cpp
This commit is contained in:
parent
056889ce23
commit
1a38c0bba2
36 changed files with 127 additions and 88 deletions
|
|
@ -45,7 +45,7 @@ let to_string_diagnostic (self : t) : string =
|
||||||
Format.asprintf "@[<h>%a@]" pp_diagnostic self
|
Format.asprintf "@[<h>%a@]" pp_diagnostic self
|
||||||
|
|
||||||
(* we use funtions from Bytes *)
|
(* we use funtions from Bytes *)
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
exception Indefinite
|
exception Indefinite
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -28,7 +28,7 @@ val pp_diagnostic : t CCFormat.printer
|
||||||
val to_string_diagnostic : t -> string
|
val to_string_diagnostic : t -> string
|
||||||
|
|
||||||
(* we use funtions from Bytes *)
|
(* we use funtions from Bytes *)
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
val encode : ?buf:Buffer.t -> t -> string
|
val encode : ?buf:Buffer.t -> t -> string
|
||||||
val decode : string -> (t, string) result
|
val decode : string -> (t, string) result
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
let verbose = try Sys.getenv "VERBOSE" = "1" with _ -> false
|
let verbose = try Sys.getenv "VERBOSE" = "1" with _ -> false
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
module J = Yojson.Safe
|
module J = Yojson.Safe
|
||||||
module Fmt = CCFormat
|
module Fmt = CCFormat
|
||||||
|
|
|
||||||
|
|
@ -13,11 +13,11 @@ type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
open CCShims_
|
open CCShims_
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include Array
|
include Array
|
||||||
|
|
||||||
[@@@elifge 4.6]
|
[@@@elif ge 4.6]
|
||||||
|
|
||||||
include Array
|
include Array
|
||||||
|
|
||||||
|
|
@ -542,7 +542,7 @@ module Infix = struct
|
||||||
let ( -- ) = ( -- )
|
let ( -- ) = ( -- )
|
||||||
let ( --^ ) = ( --^ )
|
let ( --^ ) = ( --^ )
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
type 'a t = 'a array
|
type 'a t = 'a array
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
(** {2 Arrays} *)
|
(** {2 Arrays} *)
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include module type of Array
|
include module type of Array
|
||||||
(** @inline
|
(** @inline
|
||||||
{{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html} Documentation for the standard Array module}*)
|
{{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html} Documentation for the standard Array module}*)
|
||||||
|
|
||||||
[@@@elifge 4.6]
|
[@@@elif ge 4.6]
|
||||||
|
|
||||||
include module type of Array
|
include module type of Array
|
||||||
(** @inline
|
(** @inline
|
||||||
|
|
@ -333,7 +333,7 @@ module Infix : sig
|
||||||
(** [x --^ y] creates an array containing integers in the range [x .. y]. Right bound excluded.
|
(** [x --^ y] creates an array containing integers in the range [x .. y]. Right bound excluded.
|
||||||
@since 0.17 *)
|
@since 0.17 *)
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include CCShims_syntax.LET with type 'a t := 'a array
|
include CCShims_syntax.LET with type 'a t := 'a array
|
||||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||||
|
|
|
||||||
|
|
@ -14,13 +14,13 @@ type 'a printer = Format.formatter -> 'a -> unit
|
||||||
|
|
||||||
(** {2 Arrays} *)
|
(** {2 Arrays} *)
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include module type of ArrayLabels with module Floatarray = Array.Floatarray
|
include module type of ArrayLabels with module Floatarray = Array.Floatarray
|
||||||
(** @inline
|
(** @inline
|
||||||
{{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html} Documentation for the standard Array module}*)
|
{{: https://caml.inria.fr/pub/docs/manual-ocaml/libref/Array.html} Documentation for the standard Array module}*)
|
||||||
|
|
||||||
[@@@elifge 4.6]
|
[@@@elif ge 4.6]
|
||||||
|
|
||||||
include module type of ArrayLabels with module Floatarray = Array.Floatarray
|
include module type of ArrayLabels with module Floatarray = Array.Floatarray
|
||||||
(** @inline
|
(** @inline
|
||||||
|
|
@ -347,7 +347,7 @@ module Infix : sig
|
||||||
(** [x --^ y] creates an array containing integers in the range [x .. y]. Right bound excluded.
|
(** [x --^ y] creates an array containing integers in the range [x .. y]. Right bound excluded.
|
||||||
@since 0.17 *)
|
@since 0.17 *)
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include CCShims_syntax.LET with type 'a t := 'a array
|
include CCShims_syntax.LET with type 'a t := 'a array
|
||||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[@@@ifge 4.12]
|
[@@@if ge 4.12]
|
||||||
|
|
||||||
include Atomic
|
include Atomic
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -301,7 +301,7 @@ let mark_close_style st : string =
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
type stag += Style of ANSI_codes.style list
|
type stag += Style of ANSI_codes.style list
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -334,7 +334,7 @@ module ANSI_codes : sig
|
||||||
is a very shiny style. *)
|
is a very shiny style. *)
|
||||||
end
|
end
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
val styling : ANSI_codes.style list -> 'a printer -> 'a printer
|
val styling : ANSI_codes.style list -> 'a printer -> 'a printer
|
||||||
(** [styling st p] is the same printer as [p], except it locally sets
|
(** [styling st p] is the same printer as [p], except it locally sets
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ let opaque_identity x = x
|
||||||
include Sys
|
include Sys
|
||||||
include CCShims_.Stdlib
|
include CCShims_.Stdlib
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include Fun
|
include Fun
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(** Basic operations on Functions *)
|
(** Basic operations on Functions *)
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include module type of Fun
|
include module type of Fun
|
||||||
(** @inline *)
|
(** @inline *)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,12 @@
|
||||||
(* This file is free software, part of containers. See file "license" for more details. *)
|
(* This file is free software, part of containers. See file "license" for more details. *)
|
||||||
|
|
||||||
[@@@ifge 4.07]
|
[@@@if ge 4.07]
|
||||||
[@@@else_]
|
[@@@else_]
|
||||||
|
|
||||||
module Stdlib = Pervasives
|
module Stdlib = Pervasives
|
||||||
|
|
||||||
[@@@endif]
|
[@@@endif]
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
include Int
|
include Int
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
(** Basic Int functions *)
|
(** Basic Int functions *)
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
include module type of Int
|
include module type of Int
|
||||||
(** @inline
|
(** @inline
|
||||||
|
|
|
||||||
|
|
@ -48,7 +48,7 @@ let rec assq_opt x = function
|
||||||
|
|
||||||
(* end of backport *)
|
(* end of backport *)
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include List
|
include List
|
||||||
|
|
||||||
|
|
@ -1470,7 +1470,7 @@ module Infix = struct
|
||||||
let ( -- ) = ( -- )
|
let ( -- ) = ( -- )
|
||||||
let ( --^ ) = ( --^ )
|
let ( --^ ) = ( --^ )
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
let ( let+ ) = ( >|= )
|
let ( let+ ) = ( >|= )
|
||||||
let ( let* ) = ( >>= )
|
let ( let* ) = ( >>= )
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ type 'a gen = unit -> 'a option
|
||||||
type 'a printer = Format.formatter -> 'a -> unit
|
type 'a printer = Format.formatter -> 'a -> unit
|
||||||
type 'a random_gen = Random.State.t -> 'a
|
type 'a random_gen = Random.State.t -> 'a
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
include module type of List with type 'a t := 'a list
|
include module type of List with type 'a t := 'a list
|
||||||
(** @inline
|
(** @inline
|
||||||
|
|
@ -983,7 +983,7 @@ module Infix : sig
|
||||||
(** [i --^ j] is the infix alias for [range']. Second bound [j] excluded.
|
(** [i --^ j] is the infix alias for [range']. Second bound [j] excluded.
|
||||||
@since 0.17 *)
|
@since 0.17 *)
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
include CCShims_syntax.LET with type 'a t := 'a t
|
include CCShims_syntax.LET with type 'a t := 'a t
|
||||||
(** @inline *)
|
(** @inline *)
|
||||||
|
|
|
||||||
|
|
@ -177,7 +177,7 @@ module Infix = struct
|
||||||
let ( <$> ) = map
|
let ( <$> ) = map
|
||||||
let ( <+> ) = ( <+> )
|
let ( <+> ) = ( <+> )
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
let ( let+ ) = ( >|= )
|
let ( let+ ) = ( >|= )
|
||||||
let ( let* ) = ( >>= )
|
let ( let* ) = ( >>= )
|
||||||
|
|
|
||||||
|
|
@ -171,7 +171,7 @@ module Infix : sig
|
||||||
val ( <+> ) : 'a t -> 'a t -> 'a t
|
val ( <+> ) : 'a t -> 'a t -> 'a t
|
||||||
(** [o1 <+> o2] is [o1] if [o1] is [Some _], [o2] if [o1] is [None]. *)
|
(** [o1 <+> o2] is [o1] if [o1] is [Some _], [o2] if [o1] is [None]. *)
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
include CCShims_syntax.LET with type 'a t := 'a t
|
include CCShims_syntax.LET with type 'a t := 'a t
|
||||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||||
|
|
|
||||||
|
|
@ -251,7 +251,7 @@ module Infix = struct
|
||||||
let ( ||| ) = both
|
let ( ||| ) = both
|
||||||
let[@inline] ( <?> ) p msg = set_error_message msg p
|
let[@inline] ( <?> ) p msg = set_error_message msg p
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
let ( let+ ) = ( >|= )
|
let ( let+ ) = ( >|= )
|
||||||
let ( let* ) = ( >>= )
|
let ( let* ) = ( >>= )
|
||||||
|
|
|
||||||
|
|
@ -667,7 +667,7 @@ module Infix : sig
|
||||||
[a ||| b] parses [a], then [b], then returns the pair of their results.
|
[a ||| b] parses [a], then [b], then returns the pair of their results.
|
||||||
@since 3.6 *)
|
@since 3.6 *)
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
include CCShims_syntax.LET with type 'a t := 'a t
|
include CCShims_syntax.LET with type 'a t := 'a t
|
||||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||||
|
|
|
||||||
|
|
@ -178,7 +178,7 @@ let fix ?(sub1 = []) ?(sub2 = []) ?(subn = []) ~base fuel st =
|
||||||
let pure x _st = x
|
let pure x _st = x
|
||||||
let ( <*> ) f g st = f st (g st)
|
let ( <*> ) f g st = f st (g st)
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
let ( let+ ) = ( >|= )
|
let ( let+ ) = ( >|= )
|
||||||
let ( let* ) = ( >>= )
|
let ( let* ) = ( >>= )
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ val fix :
|
||||||
val pure : 'a -> 'a t
|
val pure : 'a -> 'a t
|
||||||
val ( <*> ) : ('a -> 'b) t -> 'a t -> 'b t
|
val ( <*> ) : ('a -> 'b) t -> 'a t -> 'b t
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
include CCShims_syntax.LET with type 'a t := 'a t
|
include CCShims_syntax.LET with type 'a t := 'a t
|
||||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||||
|
|
|
||||||
|
|
@ -269,7 +269,7 @@ module Infix = struct
|
||||||
let ( >>= ) e f = flat_map f e
|
let ( >>= ) e f = flat_map f e
|
||||||
let ( <*> ) = ( <*> )
|
let ( <*> ) = ( <*> )
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
let ( let+ ) = ( >|= )
|
let ( let+ ) = ( >|= )
|
||||||
let ( let* ) = ( >>= )
|
let ( let* ) = ( >>= )
|
||||||
|
|
|
||||||
|
|
@ -191,7 +191,7 @@ module Infix : sig
|
||||||
[Ok (a b)]. Otherwise, it fails, and the error of [a] is chosen
|
[Ok (a b)]. Otherwise, it fails, and the error of [a] is chosen
|
||||||
over the error of [b] if both fail. *)
|
over the error of [b] if both fail. *)
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
val ( let+ ) : ('a, 'e) t -> ('a -> 'b) -> ('b, 'e) t
|
val ( let+ ) : ('a, 'e) t -> ('a -> 'b) -> ('b, 'e) t
|
||||||
(** @since 2.8 *)
|
(** @since 2.8 *)
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[@@@ifge 4.07]
|
[@@@if ge 4.07]
|
||||||
|
|
||||||
module Stdlib = Stdlib
|
module Stdlib = Stdlib
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||||
@since 2.8
|
@since 2.8
|
||||||
|
|
|
||||||
|
|
@ -388,7 +388,7 @@ module Split = struct
|
||||||
let right ~by s = try Some (right_exn ~by s) with Not_found -> None
|
let right ~by s = try Some (right_exn ~by s) with Not_found -> None
|
||||||
end
|
end
|
||||||
|
|
||||||
[@@@ifge 4.04]
|
[@@@if ge 4.04]
|
||||||
[@@@else_]
|
[@@@else_]
|
||||||
|
|
||||||
let split_on_char c s : _ list =
|
let split_on_char c s : _ list =
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
include Unit
|
include Unit
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -666,7 +666,7 @@ let pp ?(pp_start = fun _ () -> ()) ?(pp_stop = fun _ () -> ())
|
||||||
v;
|
v;
|
||||||
pp_stop fmt ()
|
pp_stop fmt ()
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
let ( let+ ) = ( >|= )
|
let ( let+ ) = ( >|= )
|
||||||
let ( let* ) = ( >>= )
|
let ( let* ) = ( >>= )
|
||||||
|
|
|
||||||
|
|
@ -397,7 +397,7 @@ val pp :
|
||||||
By defaults [pp_start] and [pp_stop] does nothing and [pp_sep] defaults to
|
By defaults [pp_start] and [pp_stop] does nothing and [pp_sep] defaults to
|
||||||
(fun out -> Format.fprintf out ",@ "). *)
|
(fun out -> Format.fprintf out ",@ "). *)
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
val ( let+ ) : ('a, 'e) t -> ('a -> 'b) -> ('b, 'e) t
|
val ( let+ ) : ('a, 'e) t -> ('a -> 'b) -> ('b, 'e) t
|
||||||
(** @since 2.8 *)
|
(** @since 2.8 *)
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,8 @@
|
||||||
module C = Configurator.V1
|
module C = Configurator.V1
|
||||||
|
|
||||||
type conf = { os_type: string; major: int; minor: int }
|
type conf = { os_type: string; major: int; minor: int }
|
||||||
|
type comp = Le | Ge
|
||||||
type op = Le | Ge
|
type condition = Version of comp * int * int | Os_type of string
|
||||||
|
|
||||||
type condition =
|
|
||||||
| Version of op * int * int
|
|
||||||
| Os_type of string
|
|
||||||
|
|
||||||
type line =
|
type line =
|
||||||
| If of condition
|
| If of condition
|
||||||
|
|
@ -14,6 +10,7 @@ type line =
|
||||||
| Else
|
| Else
|
||||||
| Endif
|
| Endif
|
||||||
| Raw of string
|
| Raw of string
|
||||||
|
| Eol
|
||||||
| Eof
|
| Eof
|
||||||
|
|
||||||
let prefix ~pre s =
|
let prefix ~pre s =
|
||||||
|
|
@ -32,13 +29,34 @@ let prefix ~pre s =
|
||||||
check 0
|
check 0
|
||||||
)
|
)
|
||||||
|
|
||||||
|
let get_tag_from_opt s pos =
|
||||||
|
let rec get_start pos =
|
||||||
|
let p = String.index_from s pos '[' in
|
||||||
|
if p > String.length s - 5 then
|
||||||
|
raise_notrace Not_found
|
||||||
|
else if s.[p + 1] = '@' && s.[p + 2] = '@' && s.[p + 3] = '@' then
|
||||||
|
p
|
||||||
|
else
|
||||||
|
get_start (p + 1)
|
||||||
|
in
|
||||||
|
try
|
||||||
|
let start = get_start pos in
|
||||||
|
Some (get_start pos, String.index_from s (start + 4) ']')
|
||||||
|
with Not_found -> None
|
||||||
|
|
||||||
|
let split_trim s c =
|
||||||
|
try
|
||||||
|
let p = String.index s c in
|
||||||
|
( String.trim (String.sub s 0 p),
|
||||||
|
String.trim (String.sub s (p + 1) (String.length s - p - 1)) )
|
||||||
|
with Not_found -> s, ""
|
||||||
|
|
||||||
let eval ~conf = function
|
let eval ~conf = function
|
||||||
| Os_type ty -> conf.os_type = ty
|
| Os_type ty -> conf.os_type = ty
|
||||||
| Version (op, i, j) ->
|
| Version (op, i, j) ->
|
||||||
match op with
|
(match op with
|
||||||
| Le -> (conf.major, conf.minor) <= (i, j)
|
| Le -> (conf.major, conf.minor) <= (i, j)
|
||||||
| Ge -> (conf.major, conf.minor) >= (i, j)
|
| Ge -> (conf.major, conf.minor) >= (i, j))
|
||||||
|
|
||||||
|
|
||||||
let preproc_lines ~file ~conf (ic : in_channel) : unit =
|
let preproc_lines ~file ~conf (ic : in_channel) : unit =
|
||||||
let pos = ref 0 in
|
let pos = ref 0 in
|
||||||
|
|
@ -47,40 +65,54 @@ let preproc_lines ~file ~conf (ic : in_channel) : unit =
|
||||||
in
|
in
|
||||||
let pp_pos () = Printf.printf "#%d %S\n" !pos file in
|
let pp_pos () = Printf.printf "#%d %S\n" !pos file in
|
||||||
|
|
||||||
let parse_line () : line =
|
let parse_condition condition =
|
||||||
match input_line ic with
|
flush_all ();
|
||||||
| exception End_of_file -> Eof
|
match split_trim condition ' ' with
|
||||||
| line ->
|
| "le", value -> Scanf.sscanf value "%d.%d" (fun x y -> Version (Le, x, y))
|
||||||
let line' = String.trim line in
|
| "ge", value -> Scanf.sscanf value "%d.%d" (fun x y -> Version (Ge, x, y))
|
||||||
incr pos;
|
| "os", value -> Os_type (String.lowercase_ascii value)
|
||||||
if line' <> "" && line'.[0] = '[' then
|
| _ -> failwith (Printf.sprintf "Syntax error condition: %s" condition)
|
||||||
if prefix line' ~pre:"[@@@ifle" then
|
in
|
||||||
Scanf.sscanf line' "[@@@ifle %d.%d]" (fun x y -> If (Version (Le, x, y)))
|
|
||||||
else if prefix line' ~pre:"[@@@ifge" then
|
let rec parse_from line pos =
|
||||||
Scanf.sscanf line' "[@@@ifge %d.%d]" (fun x y -> If (Version (Ge, x, y)))
|
match get_tag_from_opt line pos with
|
||||||
else if prefix line' ~pre:"[@@@elifle" then
|
| None -> [ Raw (String.sub line pos (String.length line - pos)); Eol ]
|
||||||
Scanf.sscanf line' "[@@@elifle %d.%d]" (fun x y -> Elseif (Version (Le, x, y)))
|
| Some (s, e) ->
|
||||||
else if prefix line' ~pre:"[@@@elifge" then
|
let tag = String.sub line (s + 4) (e - s - 4) |> String.trim in
|
||||||
Scanf.sscanf line' "[@@@elifge %d.%d]" (fun x y -> Elseif (Version (Ge, x, y)))
|
flush_all ();
|
||||||
else if prefix line' ~pre:"[@@@ifos" then
|
let op, rest = split_trim tag ' ' in
|
||||||
Scanf.sscanf line' "[@@@ifos %s@]" (fun os_type ->
|
let next_token =
|
||||||
If (Os_type (String.lowercase_ascii os_type)))
|
match op with
|
||||||
else if prefix line' ~pre:"[@@@elifos" then
|
| "if" -> If (parse_condition rest)
|
||||||
Scanf.sscanf line' "[@@@elifos %s@]" (fun os_type ->
|
| "elif" -> Elseif (parse_condition rest)
|
||||||
Elseif (Os_type (String.lowercase_ascii os_type)))
|
| "else_" -> Else
|
||||||
else if line' = "[@@@else_]" then
|
| "endif" -> Endif
|
||||||
Else
|
| _ -> Raw (String.sub line s (e - s + 1))
|
||||||
else if line' = "[@@@endif]" then
|
in
|
||||||
Endif
|
if s = 0 && s = String.length line then
|
||||||
else
|
[ next_token ]
|
||||||
Raw line
|
|
||||||
else
|
else
|
||||||
Raw line
|
next_token :: parse_from line (e + 1)
|
||||||
|
in
|
||||||
|
|
||||||
|
let parse_line () : line list =
|
||||||
|
match input_line ic with
|
||||||
|
| exception End_of_file -> [ Eof ]
|
||||||
|
| line -> parse_from line 0
|
||||||
|
in
|
||||||
|
|
||||||
|
let get_next =
|
||||||
|
let q = Queue.create () in
|
||||||
|
fun () ->
|
||||||
|
try Queue.pop q
|
||||||
|
with Queue.Empty ->
|
||||||
|
List.iter (fun x -> Queue.push x q) (parse_line ());
|
||||||
|
Queue.pop q
|
||||||
in
|
in
|
||||||
|
|
||||||
(* entry point *)
|
(* entry point *)
|
||||||
let rec top () =
|
let rec top () =
|
||||||
match parse_line () with
|
match get_next () with
|
||||||
| Eof -> ()
|
| Eof -> ()
|
||||||
| If condition ->
|
| If condition ->
|
||||||
if eval ~conf condition then (
|
if eval ~conf condition then (
|
||||||
|
|
@ -89,28 +121,35 @@ let preproc_lines ~file ~conf (ic : in_channel) : unit =
|
||||||
) else
|
) else
|
||||||
skip_block ~elseok:true ()
|
skip_block ~elseok:true ()
|
||||||
| Raw s ->
|
| Raw s ->
|
||||||
print_endline s;
|
print_string s;
|
||||||
|
top ()
|
||||||
|
| Eol ->
|
||||||
|
print_newline ();
|
||||||
top ()
|
top ()
|
||||||
| Elseif _ | Else | Endif -> fail "unexpected elseif|else|endif"
|
| Elseif _ | Else | Endif -> fail "unexpected elseif|else|endif"
|
||||||
(* current block is the valid one *)
|
(* current block is the valid one *)
|
||||||
and cat_block () =
|
and cat_block () =
|
||||||
match parse_line () with
|
match get_next () with
|
||||||
| Eof -> fail "unexpected EOF"
|
| Eof -> fail "unexpected EOF"
|
||||||
| If _ -> fail "nested if not supported"
|
| If _ -> fail "nested if not supported"
|
||||||
| Raw s ->
|
| Raw s ->
|
||||||
print_endline s;
|
print_string s;
|
||||||
|
cat_block ()
|
||||||
|
| Eol ->
|
||||||
|
print_newline ();
|
||||||
cat_block ()
|
cat_block ()
|
||||||
| Endif ->
|
| Endif ->
|
||||||
|
flush_all ();
|
||||||
pp_pos ();
|
pp_pos ();
|
||||||
top ()
|
top ()
|
||||||
| Elseif _ | Else -> skip_block ~elseok:false ()
|
| Elseif _ | Else -> skip_block ~elseok:false ()
|
||||||
(* skip current block.
|
(* skip current block.
|
||||||
@param elseok if true, we should evaluate "elseif" *)
|
@param elseok if true, we should evaluate "elseif" *)
|
||||||
and skip_block ~elseok () =
|
and skip_block ~elseok () =
|
||||||
match parse_line () with
|
match get_next () with
|
||||||
| Eof -> fail "unexpected EOF"
|
| Eof -> fail "unexpected EOF"
|
||||||
| If _ -> fail "nested if not supported"
|
| If _ -> fail "nested if not supported"
|
||||||
| Raw _ -> skip_block ~elseok ()
|
| Raw _ | Eol -> skip_block ~elseok ()
|
||||||
| Endif ->
|
| Endif ->
|
||||||
pp_pos ();
|
pp_pos ();
|
||||||
top ()
|
top ()
|
||||||
|
|
@ -138,7 +177,7 @@ let () =
|
||||||
let os_type = String.lowercase_ascii (C.ocaml_config_var_exn c "os_type") in
|
let os_type = String.lowercase_ascii (C.ocaml_config_var_exn c "os_type") in
|
||||||
|
|
||||||
let ic = open_in file in
|
let ic = open_in file in
|
||||||
preproc_lines ~file ~conf:{os_type; major; minor} ic;
|
preproc_lines ~file ~conf:{ os_type; major; minor } ic;
|
||||||
|
|
||||||
Printf.printf "(* file preprocessed in %.3fs *)\n" (Unix.gettimeofday () -. t0);
|
Printf.printf "(* file preprocessed in %.3fs *)\n" (Unix.gettimeofday () -. t0);
|
||||||
()
|
()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
(* This file is free software, part of containers. See file "license" for more details. *)
|
(* This file is free software, part of containers. See file "license" for more details. *)
|
||||||
|
|
||||||
[@@@ifge 4.07]
|
[@@@if ge 4.07]
|
||||||
[@@@else_]
|
[@@@else_]
|
||||||
|
|
||||||
module Stdlib = Pervasives
|
module Stdlib = Pervasives
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ module Test = struct
|
||||||
in
|
in
|
||||||
Printf.sprintf "(test :file '%s'%s :n %d)" self.__FILE__ what self.n
|
Printf.sprintf "(test :file '%s'%s :n %d)" self.__FILE__ what self.n
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
let get_state (r : _ QCheck.TestResult.t) : _ QCheck.TestResult.state =
|
let get_state (r : _ QCheck.TestResult.t) : _ QCheck.TestResult.state =
|
||||||
QCheck.TestResult.get_state r
|
QCheck.TestResult.get_state r
|
||||||
|
|
|
||||||
|
|
@ -519,7 +519,7 @@ module Make (P : PARAM) = struct
|
||||||
let ( >|= ) a f = map f a
|
let ( >|= ) a f = map f a
|
||||||
let ( <*> ) = app
|
let ( <*> ) = app
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
let ( let+ ) = ( >|= )
|
let ( let+ ) = ( >|= )
|
||||||
let ( let* ) = ( >>= )
|
let ( let* ) = ( >>= )
|
||||||
|
|
|
||||||
|
|
@ -147,7 +147,7 @@ module Make (P : PARAM) : sig
|
||||||
val ( >|= ) : 'a t -> ('a -> 'b) -> 'b t
|
val ( >|= ) : 'a t -> ('a -> 'b) -> 'b t
|
||||||
val ( <*> ) : ('a -> 'b) t -> 'a t -> 'b t
|
val ( <*> ) : ('a -> 'b) t -> 'a t -> 'b t
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
include CCShims_syntax.LET with type 'a t := 'a t
|
include CCShims_syntax.LET with type 'a t := 'a t
|
||||||
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
(** Let operators on OCaml >= 4.08.0, nothing otherwise
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
include (val Containers_testlib.make ~__FILE__ ())
|
include (val Containers_testlib.make ~__FILE__ ())
|
||||||
module Cbor = Containers_cbor
|
module Cbor = Containers_cbor
|
||||||
|
|
||||||
[@@@ifge 4.08]
|
[@@@if ge 4.08]
|
||||||
|
|
||||||
let gen_c : Cbor.t Q.Gen.t =
|
let gen_c : Cbor.t Q.Gen.t =
|
||||||
let open Q.Gen in
|
let open Q.Gen in
|
||||||
|
|
|
||||||
|
|
@ -45,7 +45,7 @@ t @@ fun () ->
|
||||||
assert_equal ~printer:CCFun.id "coucou\n" (Buffer.contents buf2);
|
assert_equal ~printer:CCFun.id "coucou\n" (Buffer.contents buf2);
|
||||||
true;;
|
true;;
|
||||||
|
|
||||||
[@@@ifge 4.8]
|
[@@@if ge 4.8]
|
||||||
|
|
||||||
t @@ fun () ->
|
t @@ fun () ->
|
||||||
set_color_default true;
|
set_color_default true;
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue