Skip to content

Commit 4d75818

Browse files
committed
Command Line Tool Update
1 parent 89022ef commit 4d75818

File tree

18 files changed

+315
-509
lines changed

18 files changed

+315
-509
lines changed

Example.dgml

Lines changed: 0 additions & 33 deletions
This file was deleted.

Example.lua

Lines changed: 0 additions & 50 deletions
This file was deleted.

Example/lib/api.ykm

Lines changed: 0 additions & 20 deletions
This file was deleted.

Example/main.ykm

Lines changed: 0 additions & 12 deletions
This file was deleted.

Example/scenario/chapter1.ykm

Lines changed: 0 additions & 5 deletions
This file was deleted.

Example/scenario/chapter2.ykm

Lines changed: 0 additions & 20 deletions
This file was deleted.

README.md

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,26 @@
1717

1818

1919
## YukimiScript Command Line Tool
20+
2021
```
21-
Usage: ykmc <path-to-scripts> [options]
22+
Usage:
23+
Compile YukimiScript to Lua:
24+
ykmc <INPUT_FILE> [--target-<TARGET> <OUTPUT_FILE>] [OPTIONS...]
25+
Create diagram:
26+
ykmc dgml <INPUT_DIR> <OUTPUT_DGML_FILE> [OPTIONS...]
27+
Create charset file:
28+
ykmc charset <INPUT_DIR> <OUTPUT_CHARSET_FILE> [OPTIONS...]
2229
2330
Options:
24-
--lib <libDir> Add other library.
25-
--dgml <output> Create the diagram.
26-
--target-lua <output> Compile to lua source code.
27-
--charset <charset> Generate charset file in UTF-8 text.
28-
29-
Examples:
30-
Check the scripts:
31-
ykmc "./Example" --lib "./api"
32-
Create the diagram from scripts:
33-
ykmc "./Example" --lib "./api" --dgml "./diagram.dgml"
34-
Compiles to Lua source code:
35-
ykmc "./Example" --lib "./api" --target-lua "script.lua"
36-
Create charset file:
37-
ykmc "./Example" --charset "./charset.txt"
31+
--lib <LIB_DIR> Include external libraries.
32+
33+
Targets:
34+
lua Lua 5.1 for Lua Runtime 5.1 or LuaJIT
35+
36+
Example:
37+
ykmc ./Example/main.ykm --target-lua ./main.lua --lib ./Example/lib/
38+
ykmc dgml ./Example/scenario ./Example.dgml --lib ./Example/lib
39+
ykmc charset ./Example/ ./ExampleCharset.txt --lib ./Example/lib
3840
```
3941

4042

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
module YukimiScript.CommandLineTool.Compile
2+
3+
open System.IO
4+
open YukimiScript.Parser
5+
6+
7+
exception FailException
8+
9+
10+
let unwrapParseException (errStringing: ErrorStringing.ErrorStringing) fileName =
11+
function
12+
| Ok x -> x
13+
| Error ls ->
14+
ls
15+
|> List.iter (fun (lineNumber, err) ->
16+
Path.GetFileName(fileName: string) + "(" + string lineNumber + "):" + errStringing err
17+
|> stderr.WriteLine)
18+
19+
raise FailException
20+
21+
22+
let unwrapDomException (errorStringing: ErrorStringing.ErrorStringing) =
23+
function
24+
| Ok x -> x
25+
| Error err ->
26+
errorStringing err
27+
|> stderr.WriteLine
28+
raise FailException
29+
30+
31+
let private loadDom errStringing src =
32+
File.ReadAllLines src
33+
|> Parser.parseLines
34+
|> unwrapParseException errStringing src
35+
|> Dom.analyze src
36+
|> unwrapDomException errStringing
37+
38+
39+
let private findRepeat (items: (string * Elements.DebugInformation) seq) =
40+
Seq.groupBy fst items
41+
|> Seq.choose (fun (key, matches) ->
42+
if Seq.length matches <= 1 then None
43+
else Some (key, matches |> Seq.map snd))
44+
45+
46+
let checkRepeat errStringing (dom: Dom.Dom) =
47+
dom.Externs
48+
|> Seq.map (fun (Elements.ExternCommand (cmd, _), dbg) -> cmd, dbg)
49+
|> findRepeat
50+
|> Seq.tryHead
51+
|> function
52+
| None -> ()
53+
| Some x ->
54+
Dom.ExternRepeatException x
55+
|> Error
56+
|> unwrapDomException errStringing
57+
58+
dom.Scenes
59+
|> Seq.map (fun (s, _, dbg) -> s.Name, dbg)
60+
|> findRepeat
61+
|> Seq.tryHead
62+
|> function
63+
| None -> ()
64+
| Some x ->
65+
Dom.SceneRepeatException x
66+
|> Error
67+
|> unwrapDomException errStringing
68+
69+
dom.Macros
70+
|> Seq.map (fun (s, _, dbg) -> s.Name, dbg)
71+
|> findRepeat
72+
|> Seq.tryHead
73+
|> function
74+
| None -> ()
75+
| Some x ->
76+
Dom.MacroRepeatException x
77+
|> Error
78+
|> unwrapDomException errStringing
79+
80+
dom
81+
82+
83+
let getYkmFiles (dir: string) =
84+
Directory.EnumerateFiles(dir, "*.ykm", SearchOption.AllDirectories)
85+
|> Array.ofSeq
86+
87+
88+
let loadLib errStringing libPath =
89+
let doms =
90+
getYkmFiles libPath
91+
|> Array.map (fun srcPath ->
92+
srcPath, loadDom errStringing srcPath)
93+
94+
doms
95+
|> Array.iter (fun (fileName, dom) ->
96+
if Seq.isEmpty dom.Scenes |> not then
97+
unwrapDomException errStringing
98+
<| Error (Dom.CannotDefineSceneInLibException fileName))
99+
100+
doms
101+
|> Array.map snd
102+
|> Array.fold Dom.merge Dom.empty
103+
104+
105+
let loadLibs errStringing libPaths =
106+
libPaths
107+
|> List.map (loadLib errStringing)
108+
|> List.fold Dom.merge Dom.empty
109+
110+
111+
let loadSrc errStringing (lib: Dom.Dom) srcPath =
112+
Dom.merge lib (loadDom errStringing srcPath)
113+
|> Dom.expandTextCommands
114+
|> Dom.expandUserMacros lib
115+
|> unwrapDomException errStringing
116+
117+
118+
let prepareCodegen errStringing dom =
119+
Dom.expandSystemMacros dom
120+
|> Dom.linkToExternCommands
121+
|> unwrapDomException errStringing
122+

YukimiScript.CommandLineTool/ErrorProcessing.fs

Lines changed: 0 additions & 28 deletions
This file was deleted.

0 commit comments

Comments
 (0)