src/Pure/System/bash.ML
author wenzelm
Sat, 20 Feb 2021 23:01:35 +0100
changeset 73264 440546ea20e6
parent 67200 src/Pure/System/bash_syntax.ML@d49727160f0a
child 74147 d030b988d470
permissions -rw-r--r--
clarified modules;

(*  Title:      Pure/System/bash.ML
    Author:     Makarius

Syntax for GNU bash.
*)

signature BASH =
sig
  val string: string -> string
  val strings: string list -> string
end;

structure Bash: BASH =
struct

fun string "" = "\"\""
  | string str =
      str |> translate_string (fn ch =>
        let val c = ord ch in
          (case ch of
            "\t" => "$'\\t'"
          | "\n" => "$'\\n'"
          | "\f" => "$'\\f'"
          | "\r" => "$'\\r'"
          | _ =>
              if Symbol.is_ascii_letter ch orelse Symbol.is_ascii_digit ch orelse
                exists_string (fn c => c = ch) "+,-./:_" then ch
              else if c < 16 then "$'\\x0" ^ Int.fmt StringCvt.HEX c ^ "'"
              else if c < 32 orelse c >= 127 then "$'\\x" ^ Int.fmt StringCvt.HEX c ^ "'"
              else "\\" ^ ch)
        end);

val strings = space_implode " " o map string;

end;