Source

ocaml-stringpainter / src / Basic.ml

Full commit
(*********************************************************************************************************************
 * Copyrights (C) by
 *  Pawel Wieczorek <wieczyk gmail>
 *
 * http://bitbucket.org/wieczyk/ocaml-stringpainter
 ********************************************************************************************************************)


include Engine

let sp_indent_when_multiline sp =
    if any_multiline sp
    then sp_indent sp
    else sp_nested sp

let sp_value_int  x = sp_value (string_of_int x)
let sp_value_bool x = sp_value (string_of_bool x)


let sp_list opening closing separator = function
    | [] -> sp_nested
        [ opening
        ; closing
        ]

    | [x] -> sp_nested
        [ opening
        ; x
        ; closing
        ]

    | x::xs -> sp_nested
        [ opening
        ; x
        ; sp_nested (List.map (fun y -> sp_nested [separator; y]) xs)
        ; closing
        ]

let sp_opening_square_bracket = sp_syntax "["
let sp_closing_square_bracket = sp_syntax "]"

let sp_opening_bracket  = sp_syntax "("
let sp_coma             = sp_syntax ","
let sp_semicolon        = sp_syntax ";"
let sp_closing_bracket  = sp_syntax ")"

let sp_std_list = sp_list sp_opening_bracket sp_closing_bracket sp_coma
let sp_ml_list  = sp_list sp_opening_square_bracket sp_closing_square_bracket sp_semicolon