diff --git a/YukimiScript.CodeGen/WebGAL.fs b/YukimiScript.CodeGen/WebGAL.fs
new file mode 100644
index 0000000..a890ef4
--- /dev/null
+++ b/YukimiScript.CodeGen/WebGAL.fs
@@ -0,0 +1,57 @@
+module YukimiScript.CodeGen.WebGAL
+
+open YukimiScript.Parser
+open YukimiScript.Parser.ParserMonad
+open YukimiScript.Parser.Elements
+open System.Text
+open System
+
+
+let private generateCommand externs (sb: StringBuilder) cmd =
+ let param =
+ List.zip
+ (Map.find (cmd: IntermediateCommandCall).Callee externs
+ |> List.map (fun x -> x.Parameter))
+ cmd.Arguments
+ |> List.filter (fun (_, x) -> x <> Symbol "null")
+ sb.Append(cmd.Callee).Append(":") |> ignore
+
+ let writeArg = function
+ | String a -> sb.Append(a) |> ignore
+ | Real a -> sb.Append(a) |> ignore
+ | Integer a -> sb.Append(a) |> ignore
+ | Symbol a -> sb.Append(a) |> ignore
+
+ let writeParams =
+ List.iter (fun (p: string, a) ->
+ sb.Append(" -").Append(p).Append("=") |> ignore
+ writeArg a)
+
+ match param with
+ | [] -> ()
+ | ("content", contentArg) :: nextParams ->
+ writeArg contentArg
+ writeParams nextParams
+ | nextParams ->
+ writeParams nextParams
+
+ sb.AppendLine(";") |> ignore
+
+
+let private generateScene externs sb (scene: IntermediateScene) =
+ (sb: StringBuilder).Append("label:").Append(scene.Name).AppendLine(";") |> ignore
+ scene.Block |> List.iter (generateCommand externs sb)
+ sb.AppendLine() |> ignore
+
+
+let generateWebGAL dom (Intermediate scenes) =
+ let externs =
+ dom.Externs
+ |> Seq.map (fun (ExternCommand (a, p), _, _) -> a, p)
+ |> Map.ofSeq
+
+ let sb = StringBuilder ()
+ scenes |> Seq.iter (generateScene externs sb)
+ sb
+
+
diff --git a/YukimiScript.CodeGen/YukimiScript.CodeGen.fsproj b/YukimiScript.CodeGen/YukimiScript.CodeGen.fsproj
index feb4480..ae12bad 100644
--- a/YukimiScript.CodeGen/YukimiScript.CodeGen.fsproj
+++ b/YukimiScript.CodeGen/YukimiScript.CodeGen.fsproj
@@ -8,6 +8,7 @@
+
diff --git a/YukimiScript.CommandLineTool/Program.fs b/YukimiScript.CommandLineTool/Program.fs
index daad7e8..5df5ce7 100644
--- a/YukimiScript.CommandLineTool/Program.fs
+++ b/YukimiScript.CommandLineTool/Program.fs
@@ -36,6 +36,7 @@ let private help () =
" lua Lua 5.1 for Lua Runtime 5.1 or LuaJIT (UTF-8)"
" pymo PyMO 1.2 script, you must compile with libpymo.ykm."
" json Json."
+ " webgal WebGAL Script (WIP)."
""
"Example:"
" ykmc ./Example/main.ykm --target-pymo ./main.lua -L../lib -lpymo"
@@ -81,6 +82,7 @@ type private TargetOption =
| PyMO of outputFile: string * scriptName: string
| Bytecode of outputFile: string
| Json of outputFile: string
+ | WebGAL of outputFile: string
type private DiagramType =
@@ -129,6 +131,9 @@ let rec private parseTargetsAndOptions (inputSrc: string) =
| "--target-json" :: json :: next ->
parseTargetsAndOptions inputSrc next
|> Result.map (fun (nextTargets, options) -> Json json :: nextTargets, options)
+ | "--target-webgal" :: webgal :: next ->
+ parseTargetsAndOptions inputSrc next
+ |> Result.map (fun (nextTargets, options) -> WebGAL webgal :: nextTargets, options)
| options ->
parseOptions defaultOptions options
|> Result.map (fun options -> [], options)
@@ -172,7 +177,7 @@ let private doAction errStringing =
function
| Compile (inputFile, targets, options) ->
let libs = loadLibs options
- let intermediate = CompilePipe.compile libs inputFile |> unwrapResultExn ErrorStringing.schinese
+ let dom, intermediate = CompilePipe.compile libs inputFile |> unwrapResultExn ErrorStringing.schinese
targets
|> List.iter
@@ -193,7 +198,10 @@ let private doAction errStringing =
File.WriteAllText(output, lua, Text.Encoding.UTF8)
| Json out ->
- YukimiScript.CodeGen.Json.genJson options.Debugging intermediate out)
+ YukimiScript.CodeGen.Json.genJson options.Debugging intermediate out
+ | WebGAL outPath ->
+ let out = YukimiScript.CodeGen.WebGAL.generateWebGAL dom intermediate
+ File.WriteAllText(outPath, out.ToString()))
| Diagram (diagramType, inputDir, out, options) ->
let diagramExporter =
@@ -229,7 +237,7 @@ let private doAction errStringing =
|> Array.toList
|> Result.transposeList
|> unwrapResultExn ErrorStringing.schinese
- |> Seq.collect (fun (Intermediate s) -> s)
+ |> Seq.collect (fun (_, Intermediate s) -> s)
|> Seq.collect (fun x -> x.Block)
|> Seq.collect (fun x -> x.Arguments)
|> Seq.choose (function
diff --git a/YukimiScript.Parser/CompilePipe.fs b/YukimiScript.Parser/CompilePipe.fs
index 1463ba4..05c1c98 100644
--- a/YukimiScript.Parser/CompilePipe.fs
+++ b/YukimiScript.Parser/CompilePipe.fs
@@ -109,8 +109,8 @@ let generateIntermediate dom =
|> Result.bind (Dom.expandTextCommands >> Dom.expandUserMacros)
|> Result.bind (fun externAndSysMacro ->
Dom.expandSystemMacros externAndSysMacro
- |> Dom.linkToExternCommands
- |> Result.map Intermediate.ofDom)
+ |> Dom.linkToExternCommands)
+ |> Result.map (fun dom -> dom, Intermediate.ofDom dom)
let compile lib srcPath =