@@ -12,19 +12,23 @@ let help () =
1212 " Compile YukimiScript to Lua:"
1313 " ykmc <INPUT_FILE> [--target-<TARGET> <OUTPUT_FILE>] [OPTIONS...]"
1414 " Create diagram:"
15- " ykmc dgml < INPUT_DIR> <OUTPUT_DGML_FILE > [OPTIONS...]"
15+ " ykmc diagram <DIAGRAM_TYPE> < INPUT_DIR> <OUTPUT_FILE > [OPTIONS...]"
1616 " Create charset file:"
1717 " ykmc charset <INPUT_DIR> <OUTPUT_CHARSET_FILE> [OPTIONS...]"
1818 " "
1919 " Options:"
2020 " --lib <LIB_DIR> Include external libraries."
2121 " "
22+ " Diagram Types:"
23+ " dgml Visual Studio Directed Graph Markup Language."
24+ " mermaid Flowchart in Mermaid."
25+ " "
2226 " Targets:"
2327 " lua Lua 5.1 for Lua Runtime 5.1 or LuaJIT (UTF-8)"
2428 " "
2529 " Example:"
2630 " ykmc ./Example/main.ykm --target-lua ./main.lua --lib ./Example/lib/"
27- " ykmc dgml ./Example/scenario ./Example.dgml --lib ./Example/lib"
31+ " ykmc diagram dgml ./Example/scenario ./Example.dgml --lib ./Example/lib"
2832 " ykmc charset ./Example/ ./ExampleCharset.txt --lib ./Example/lib"
2933 " " ]
3034 |> List.iter Console.WriteLine
@@ -42,8 +46,13 @@ type TargetOption =
4246 | Lua of outputFile : string
4347
4448
49+ type DiagramType =
50+ | Dgml
51+ | Mermaid
52+
53+
4554type CmdArg =
46- | Dgml of inputDir : string * outputDgml : string * Options
55+ | Diagram of DiagramType * inputDir : string * output : string * Options
4756 | Charset of inputDir : string * outputCharsetFile : string * Options
4857 | Compile of inputFile : string * TargetOption list * Options
4958
@@ -67,12 +76,21 @@ let rec parseTargetsAndOptions =
6776 |> Result.map ( fun options -> [], options)
6877
6978
79+ let parseDiagramType =
80+ function
81+ | " dgml" -> Ok Dgml
82+ | " mermaid" -> Ok Mermaid
83+ | _ -> Error ()
84+
85+
7086let parseArgs =
7187 function
72- | " dgml" :: inputDir :: outputDgml :: options ->
73- parseOptions defaultOptions options
74- |> Result.map ( fun options ->
75- Dgml ( inputDir, outputDgml, options))
88+ | " diagram" :: diagramType :: inputDir :: output :: options ->
89+ parseDiagramType diagramType
90+ |> Result.bind ( fun diagramType ->
91+ parseOptions defaultOptions options
92+ |> Result.map ( fun options ->
93+ Diagram ( diagramType, inputDir, output, options)))
7694
7795 | " charset" :: inputDir :: charsetFile :: options ->
7896 parseOptions defaultOptions options
@@ -104,7 +122,12 @@ let doAction errStringing =
104122 let lua = YukimiScript.CodeGen.Lua.generateLua <| Intermediate.ofDom dom
105123 File.WriteAllText( output, lua, Text.Encoding.UTF8))
106124
107- | Dgml ( inputDir, outDgml, options) ->
125+ | Diagram ( diagramType, inputDir, out, options) ->
126+ let diagramExporter =
127+ match diagramType with
128+ | Dgml -> Diagram.exportDgml
129+ | _ -> failwith " "
130+
108131 let lib = loadLibs errStringing options.Lib
109132 getYkmFiles inputDir
110133 |> Array.map ( fun path ->
@@ -113,8 +136,8 @@ let doAction errStringing =
113136 |> List.ofArray
114137 |> Diagram.analyze
115138 |> unwrapDomException errStringing
116- |> Diagram.exportDgml
117- |> fun dgml -> File.WriteAllText( outDgml , dgml , Text.Encoding.UTF8)
139+ |> diagramExporter
140+ |> fun diagram -> File.WriteAllText( out , diagram , Text.Encoding.UTF8)
118141
119142 | Charset ( inputDir, outCharset, options) ->
120143 let lib = loadLibs errStringing options.Lib
0 commit comments