-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathWebGAL.fs
More file actions
57 lines (43 loc) · 1.63 KB
/
WebGAL.fs
File metadata and controls
57 lines (43 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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