@@ -2,12 +2,13 @@ namespace YukimiScript.Parser
22
33open YukimiScript.Parser .Parser
44open YukimiScript.Parser .Elements
5+ open YukimiScript.Parser .TypeChecker
56
67
78type Dom =
89 { HangingEmptyLine: DebugInformation list
9- Externs: ( ExternDefination * DebugInformation ) list
10- Macros: ( MacroDefination * Block * DebugInformation ) list
10+ Externs: ( ExternDefination * BlockParamTypes * DebugInformation) list
11+ Macros: ( MacroDefination * BlockParamTypes * Block * DebugInformation ) list
1112 Scenes: ( SceneDefination * Block * DebugInformation ) list }
1213
1314
@@ -46,6 +47,9 @@ module Dom =
4647 exception ExternRepeatException of name : string * debugInfo : DebugInformation seq
4748
4849
50+ exception ExternCannotHasContentException of name : string * DebugInformation
51+
52+
4953 let private saveCurrentBlock state =
5054 match state.CurrentBlock with
5155 | None -> state
@@ -56,17 +60,32 @@ module Dom =
5660 Macros =
5761 match label with
5862 | MacroDefination x ->
59- ( x, List.rev block, debugInfo)
60- :: state.Result.Macros
61- | SceneDefination _ -> state.Result.Macros
62- | _ -> raise UnknownException
63+ let block = List.rev block
64+ match parametersTypeFromBlock x.Param block with
65+ | Ok t -> ( x, t, block, debugInfo) :: state.Result.Macros
66+ | Error e -> raise e
67+ | _ -> state.Result.Macros
6368 Scenes =
6469 match label with
65- | MacroDefination _ -> state.Result.Scenes
6670 | SceneDefination x ->
6771 ( x, List.rev block, debugInfo)
6872 :: state.Result.Scenes
69- | _ -> raise UnknownException } }
73+ | _ -> state.Result.Scenes
74+ Externs =
75+ match label with
76+ | ExternDefination ( ExternCommand ( n, p)) ->
77+ if
78+ List.forall ( fst >> function
79+ | CommandCall c when c.Callee = " __type" -> true
80+ | _ -> false ) block
81+ then
82+ match parametersTypeFromBlock p block with
83+ | Ok t ->
84+ ( ExternCommand ( n, p), t, debugInfo)
85+ :: state.Result.Externs
86+ | Error e -> raise e
87+ else raise <| ExternCannotHasContentException ( n, debugInfo)
88+ | _ -> state.Result.Externs} }
7089
7190
7291 let private analyzeFold state ( line , debugInfo ) =
@@ -98,16 +117,7 @@ module Dom =
98117 | Line.Text x -> pushOperation <| Text x
99118 | SceneDefination scene -> Ok <| setLabel state ( SceneDefination scene)
100119 | MacroDefination macro -> Ok <| setLabel state ( MacroDefination macro)
101- | ExternDefination ( ExternCommand ( name, param)) ->
102- let nextState = saveCurrentBlock state
103-
104- { nextState with
105- Result =
106- { nextState.Result with
107- Externs =
108- ( ExternCommand( name, param), debugInfo)
109- :: nextState.Result.Externs } }
110- |> Ok
120+ | ExternDefination extern' -> Ok <| setLabel state ( ExternDefination extern')
111121
112122
113123 exception CannotDefineSceneInLibException of string
@@ -138,28 +148,23 @@ module Dom =
138148
139149
140150 let expandTextCommands ( x : Dom ) : Dom =
141- let mapBlock ( defination , block , debugInfo ) =
142- let block =
143- block
144- |> List.collect
145- ( function
146- | Text x, debugInfo ->
147- [ if debugInfo.Comment.IsSome then
148- EmptyLine, debugInfo
149-
150- yield ! Text.expandTextBlock x debugInfo ]
151- | x -> [ x ])
151+ let mapBlock =
152+ List.collect ( function
153+ | Text x, debugInfo ->
154+ [ if debugInfo.Comment.IsSome then
155+ EmptyLine, debugInfo
152156
153- defination, block, debugInfo
157+ yield ! Text.expandTextBlock x debugInfo ]
158+ | x -> [ x ])
154159
155160 { x with
156- Scenes = List.map mapBlock x.Scenes
157- Macros = List.map mapBlock x.Macros }
161+ Scenes = List.map ( fun ( def , block , d ) -> def , mapBlock block , d ) x.Scenes
162+ Macros = List.map ( fun ( def , t , b , d ) -> def , t , mapBlock b , d ) x.Macros }
158163
159164
160165 let expandUserMacros ( x : Dom ) =
161166 let macros =
162- List.map ( fun ( a , b , _ ) -> a, b) x.Macros
167+ List.map ( fun ( a , _ , b , _ ) -> a, b) x.Macros
163168
164169 x.Scenes
165170 |> List.map
@@ -199,7 +204,7 @@ module Dom =
199204
200205
201206 let linkToExternCommands ( x : Dom ) : Result < Dom , exn > =
202- let externs = systemCommands @ List.map fst x.Externs
207+ let externs = systemCommands @ List.map ( fun ( x , _ , _ ) -> x ) x.Externs
203208
204209 let linkSingleCommand ( op , debugInfo ) =
205210 match op with
0 commit comments