Skip to content

Commit 5e883ac

Browse files
committed
__type_symbol
1 parent a633f8c commit 5e883ac

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

YukimiScript.Parser/Macro.fs

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -174,46 +174,51 @@ let parametersTypeFromBlock (par: Parameter list) (b: Block) : Result<BlockParam
174174
"type", Types.symbol ]
175175

176176
List.choose (function
177-
| CommandCall c, d when c.Callee = "__type" -> Some (c, d)
177+
| CommandCall c, d when c.Callee = "__type" || c.Callee = "__type_symbol" -> Some (c, d)
178178
| _ -> None) b
179179
|> List.map (fun (c, d) ->
180180
matchArguments d typeMacroParams c
181181
|> Result.bind (checkApplyTypeCorrect d typeMacroParamsTypes)
182-
|> Result.map (fun x -> x, d))
182+
|> Result.map (fun x -> c.Callee, x, d))
183183
|> sequenceRL
184184
|> Result.bind (fun x ->
185185
let paramTypePairs =
186-
List.map (fun (x, d) ->
186+
List.map (fun (macroName, x, d) ->
187187
x
188188
|> readOnlyDict
189189
|> fun x ->
190190
match x.["param"], x.["type"] with
191-
| Symbol par, Symbol t -> par, t, d
191+
| Symbol par, Symbol t -> macroName, par, t, d
192192
| _ -> failwith "parametersTypeFromBlock: failed!") x
193193

194194
let dummy =
195195
paramTypePairs
196-
|> List.filter (not << fun (n, _, d) ->
196+
|> List.filter (not << fun (_, n, _, _) ->
197197
List.exists (fun p -> p.Parameter = n) par)
198-
|> List.map (fun (n, _, d) -> n, d)
198+
|> List.map (fun (_, n, _, d) -> n, d)
199199

200200
if List.length dummy = 0
201201
then
202202
par
203203
|> List.map (fun { Parameter = name; Default = _ } ->
204204
paramTypePairs
205-
|> List.filter ((=) name << fun (n, _, _) -> n)
206-
|> List.map (fun (_, t, d) -> t, d)
205+
|> List.filter ((=) name << fun (_, n, _, _) -> n)
206+
|> List.map (fun (macroName, _, t, d) -> macroName, t, d)
207207
|> function
208208
| [] -> Ok (name, Types.any)
209209
| types ->
210210
types
211-
|> List.map (fun (typeName, d) ->
212-
Types.all
213-
|> List.tryFind (fun (ParameterType (n, _)) -> n = typeName)
214-
|> function
215-
| Some x -> Ok x
216-
| None -> Error <| IsNotAType typeName)
211+
|> List.map (fun (macroName, typeName, _) ->
212+
match macroName with
213+
| "__type" ->
214+
Types.all
215+
|> List.tryFind (fun (ParameterType (n, _)) -> n = typeName)
216+
|> function
217+
| Some x -> Ok x
218+
| None -> Error <| IsNotAType typeName
219+
| "__type_symbol" ->
220+
Ok <| ParameterType ($"^{typeName}", set [ExplicitSymbol' typeName])
221+
| _ -> failwith "?")
217222
|> sequenceRL
218223
|> Result.map (fun t ->
219224
name, List.reduce sumParameterType t))

0 commit comments

Comments
 (0)