Wording.ml

(* Copyright INRIA and Microsoft Corporation, 2008-2013. *)
(* DDMF is distributed under CeCILL-B license. *)

INCLUDE "preamble.ml"

(* This module is useful for singular/plural case distinctions. *)
(* It outputs "" if var is 1 or a list/sequence of size 1, *)
(* and "s" otherwise. *)

let ending_of_int i =
  if i < 0 then
    invalid_arg ("ending_of_int received " ^ (string_of_int i))
  else if i = 1 then "" else "s"

(* sequential is a Maple list or set. *)
let ending_of_seq s =
  if <:bool< not type($(s), 'sequential') >> then
    invalid_arg ("ending_of_seq received" ^ (Maple.serialization_of_t s))
  else ending_of_int <:int< nops($(s)) >>

(* Takes an OCaml list of sec_entities and produces a paragraph that *)
(* contains their enumeration in text flow, for example, *)
(* [p1; p2; p3] is transformed to "p1, p2, and p3". *)
let enumeration_of_ents l =
  match List.length l with
  | 0 -> <:par<>>
  | 1 -> List.hd l
  | 2 -> List.hd l @:@ <:par< and >> @:@ List.nth l 1
  | _ ->
      List.fold_right
        (@:@)
        (List.map (fun a -> a @:@ <:par<, >>) (List.rev (List.tl (List.rev l))))
        (<:par<and >> @:@ List.hd (List.rev l))

(* The same as enumeration_of_ents, but taking an 'a maple list as input. *)
let enumeration_of_maples l =
  enumeration_of_ents (List.map (fun a -> <:par<<:isymb<$(a)>>>>) l)

(* The same as enumeration_of_ents, but taking a maple list as input *)
let enumeration_of_maplelist l =
  enumeration_of_maples (CommonTools.symb_list_of_symb l)

let ordinal n =
  match n with
  | 1 -> <:par<first>>
  | 2 -> <:par<second>>
  | 3 -> <:par<third>>
  | _ -> match n mod 100 with
    | 11 -> <:par<$(int: n)th>>
    | 12 -> <:par<$(int: n)th>>
    | 13 -> <:par<$(int: n)th>>
    | _ -> match n mod 10 with
      | 1 -> <:par<$(int: n)st>>
      | 2 -> <:par<$(int: n)nd>>
      | 3 -> <:par<$(int: n)rd>>
      | _ -> <:par<$(int: n)th>>

Generated by GNU Enscript 1.6.5.90.