|
1 | 1 | module YukimiScript.CodeGen.Lua |
2 | 2 |
|
3 | 3 | open YukimiScript.Parser |
4 | | -open YukimiScript.Parser.Dom |
5 | 4 | open YukimiScript.Parser.Elements |
6 | 5 |
|
7 | 6 |
|
8 | | -let generateLua (x: Dom) : string = |
| 7 | +let generateLua (Intermediate scenes) : string = |
9 | 8 | let luaCall (x: string) = |
10 | 9 | let i = x.LastIndexOf '.' |
11 | 10 | x.[..i-1] + ":" + x.[i+1..] |
12 | 11 |
|
13 | 12 | let sb = System.Text.StringBuilder () |
14 | | - sb.Append("return function(api) return {") |> ignore |
| 13 | + sb.AppendLine("return function(api) return {") |> ignore |
15 | 14 |
|
16 | | - x.Scenes |
17 | | - |> List.iter (fun (defination, block, debugInfo) -> |
| 15 | + scenes |
| 16 | + |> List.iter (fun (IntermediateScene (defination, commands)) -> |
18 | 17 | sb .Append(" [\"") |
19 | 18 | .Append(Constants.string2literal defination.Name) |
20 | 19 | .Append("\"] = {") |> ignore |
21 | 20 |
|
22 | | - if debugInfo.Comment.IsSome then |
23 | | - sb .Append(" -- ") |
24 | | - .Append(debugInfo.Comment.Value) |> ignore |
25 | | - |
26 | 21 | sb.AppendLine() |> ignore |
27 | 22 |
|
28 | | - block |
29 | | - |> List.iter (fun (op, debugInfo) -> |
30 | | - match op with |
31 | | - | EmptyLine -> () |
32 | | - | CommandCall c -> |
33 | | - sb .Append(" function() ") |
34 | | - .Append(luaCall <| "api." + c.Callee) |
35 | | - .Append("(") |> ignore |
36 | | - |
37 | | - let args = |
38 | | - c.UnnamedArgs |
39 | | - |> List.map (function |
40 | | - | Symbol "true" -> "true" |
41 | | - | Symbol "false" -> "false" |
42 | | - | Symbol "null" | Symbol "nil" -> "nil" |
43 | | - | Symbol x -> luaCall <| "api." + x |
44 | | - | Integer x -> string x |
45 | | - | Number x -> string x |
46 | | - | String x -> "\"" + Constants.string2literal x + "\"") |
47 | | - |
48 | | - if not <| List.isEmpty args then |
49 | | - args |
50 | | - |> List.reduce (fun a b -> a + ", " + b) |
51 | | - |> sb.Append |
52 | | - |> ignore |
53 | | - |
54 | | - sb.Append(") end,") |> ignore |
55 | | - |
56 | | - | _ -> failwith "This construction is not supported." |
57 | | - |
58 | | - if debugInfo.Comment.IsSome then |
59 | | - sb.Append(" -- ").Append(debugInfo.Comment.Value) |> ignore |
| 23 | + commands |
| 24 | + |> List.iter (fun c -> |
| 25 | + sb .Append(" function() ") |
| 26 | + .Append(luaCall <| "api." + c.Callee) |
| 27 | + .Append("(") |> ignore |
| 28 | + |
| 29 | + let args = |
| 30 | + c.UnnamedArgs |
| 31 | + |> List.map (function |
| 32 | + | Symbol "true" -> "true" |
| 33 | + | Symbol "false" -> "false" |
| 34 | + | Symbol "null" | Symbol "nil" -> "nil" |
| 35 | + | Symbol x -> "api." + x |
| 36 | + | Integer x -> string x |
| 37 | + | Number x -> string x |
| 38 | + | String x -> "\"" + Constants.string2literal x + "\"") |
| 39 | + |
| 40 | + if not <| List.isEmpty args then |
| 41 | + args |
| 42 | + |> List.reduce (fun a b -> a + ", " + b) |
| 43 | + |> sb.Append |
| 44 | + |> ignore |
| 45 | + |
| 46 | + sb.Append(") end,") |> ignore |
60 | 47 |
|
61 | 48 | sb.AppendLine() |> ignore |
62 | 49 | ) |
|
0 commit comments