状態遷移表をLTSAに変換する(改訂版)

状態遷移表をLTSAスクリプトに変換するツールの改訂版。
StateTableモジュールを使用して状態遷移表を読み込む。

#light
open StateTable
open System.Text.RegularExpressions
module main =
  let (states,variables,actions,values,transitions) =
    let dir = System.IO.Directory.GetCurrentDirectory()
    (dir + @"\sample.xlsx","Sheet1")
      |> ToStateTable
      
  type TransExpPart = string
  type TransExp = string
  type Script = string
 
  let ToTransExpPart (action,trans):TransExpPart =
    let exp = sprintf"%s->%s" action trans
    match Regex.IsMatch("[a-z_].+",trans) with
    |true -> exp
    |_ -> "_" + exp

  let ToTransExp ((states:string[]),(actions:string[]),(transitions:string[][])):TransExp=
    [|for i in 0..states.Length-1 do
        let subpro = states.[i] + "=\n"
        let trans = 
          [|for j in 0..actions.Length-1 do
              match transitions.[i].[j] with
              |"×" -> yield ""
              |_ -> yield ((actions.[j],transitions.[i].[j])|>ToTransExpPart)|]
            |> Array.filter (fun x->x.Length>0) |> String.concat "\n  |"
        yield subpro + "  (" + trans + ")"          
    |] |> String.concat ",\n"
  
  let ToScript (transExp):Script =
    transExp |> sprintf "Process=S0,\n%s."
  
  let script = 
    (states,actions,transitions) 
        |> ToTransExp
        |> ToScript
    
  System.IO.File.WriteAllText("ltsa.txt",script)