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

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

#light
open StateTable
module main =
  let (states,variables,actions,values,transitions) =
    let dir = System.IO.Directory.GetCurrentDirectory()
    (dir + @"\sample.xlsx","Sheet1")
      |> ToStateTable

  type StateExpPart = string
  type TransExpPart = string
  type StateExp = string
  type InitTransExp = string
  type TransExp = string
  type Script = string 
  
  type ToStateExpPart = State*Variable*Value -> StateExpPart
  type ToTransExpPart = State*Action*Transition -> TransExpPart
  type ToStateExp = State[]*Variable[]*Value[] -> StateExp
  type ToTransExp = State[]*Action[]*Transition[] -> TransExp
  type ToScript = StateExp*InitTransExp*TransExp -> Script
  
  let ToStateExpPart (state,variable,value):StateExpPart =
    sprintf"%s:%s:%s" state variable value
  let ToTransExpPart (state,action,trans):TransExpPart =
    let exp = sprintf"%s-->%s:%s" state trans action
    match trans with
    |"×" -> "'" + exp
    |_ -> exp
  let ToStateExp ((states:string[]), (variables:string[]), (values:string[][])):StateExp =
    [|for i in 0..states.Length-1 do
        for j in 0..variables.Length-1 do
          yield ((states.[i],variables.[j],values.[i].[j])|>ToStateExpPart)|] 
      |> String.concat "\n"
  let ToTransExp ((states:string[]),(actions:string[]),(transitions:string[][])):TransExp=
    [|for i in 0..states.Length-1 do
        for j in 0..actions.Length-1 do
          yield ((states.[i],actions.[j],transitions.[i].[j])|>ToTransExpPart)|] 
      |> String.concat "\n"
  let ToScript (stateExp, transExp):Script =
    [|"@startuml";stateExp;"[*]-->S0";transExp;"@enduml"|]
      |> String.concat "\n"
 
  let script =
    ((states,variables,values) |> ToStateExp,
     (states,actions,transitions) |> ToTransExp) 
        |> ToScript
   
  System.IO.File.WriteAllText("plantuml.txt",script)