Skip to content

Commit 7064cbb

Browse files
committed
Explicit Symbol Type
1 parent 5e883ac commit 7064cbb

File tree

5 files changed

+33
-4
lines changed

5 files changed

+33
-4
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
##
44
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
55

6+
.vscode
7+
68
# User-specific files
79
*.rsuser
810
*.suo

Examples/Type Checker Example.ykm

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
- macro checkTypeCharacterName name
2+
@__type_symbol name a
3+
@__type_symbol name b
4+
@__type_symbol name c
5+
@__type_symbol name d
6+
7+
- macro sayFromCharacter name text
8+
@checkTypeCharacterName name
9+
@__type text string
10+
11+
- scene "test"
12+
@sayFromCharacter a "Hello"
13+
@sayFromCharacter b "Hello"
14+
@sayFromCharacter c "Hello"
15+
@sayFromCharacter d "Hello"
16+

YukimiScript.Parser/Dom.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ module Dom =
7676
| ExternDefination (ExternCommand (n, p)) ->
7777
if
7878
List.forall (fst >> function
79-
| CommandCall c when c.Callee = "__type" -> true
79+
| CommandCall c when c.Callee = "__type" || c.Callee = "__type_symbol" -> true
8080
| EmptyLine -> true
8181
| _ -> false) block
8282
then

YukimiScript.Parser/ErrorStringing.fs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ let header (debug: Elements.DebugInformation) =
2020
+ string debug.LineNumber
2121
+ "):"
2222

23-
let schinese: ErrorStringing =
23+
let rec schinese: ErrorStringing =
2424
function
2525
| TypeChecker.TypeCheckFailedException (d, i, ParameterType (name, _), a) ->
2626
header d
@@ -90,4 +90,11 @@ let schinese: ErrorStringing =
9090
| CannotDefineSceneInLibException debug -> debug + ":不能在lib中定义scene。"
9191
| DiagramMacroErrorException d -> header d + "__diagram_link_to宏使用方式错误。"
9292
| CannotFindSceneException x -> "不能找到场景\"" + x + "\"的定义。"
93+
| MacroInnerException (debugInfo, x) ->
94+
header debugInfo + "在展开宏时遇到以下错误:" + System.Environment.NewLine +
95+
begin
96+
(schinese x).Split '\n'
97+
|> Array.map (fun x -> " " + x.Trim('\r'))
98+
|> Array.reduce (fun a b -> a + System.Environment.NewLine + b)
99+
end
93100
| e -> "未知错误" + e.Message

YukimiScript.Parser/Macro.fs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ let private replaceParamToArgs args macroBody =
125125
NamedArgs = List.map (fun (name, arg) -> name, replaceArg arg) macroBody.NamedArgs }
126126

127127

128+
exception MacroInnerException of DebugInformation * exn
129+
130+
128131
let rec private expandSingleOperation macros operation : Result<Block, exn> =
129132
match operation with
130133
| CommandCall command, debug ->
@@ -146,6 +149,7 @@ let rec private expandSingleOperation macros operation : Result<Block, exn> =
146149
|> sequenceRL
147150
|> Result.map List.concat
148151
| x -> Ok [ x ]
152+
|> Result.mapError (fun err -> MacroInnerException (snd operation, err))
149153

150154

151155
let expandBlock macros (block: Block) =
@@ -155,7 +159,7 @@ let expandBlock macros (block: Block) =
155159

156160

157161
let expandSystemMacros (block: Block) =
158-
let systemMacros = [ "__diagram_link_to"; "__type" ]
162+
let systemMacros = [ "__diagram_link_to"; "__type"; "__type_symbol" ]
159163

160164
block
161165
|> List.map
@@ -217,7 +221,7 @@ let parametersTypeFromBlock (par: Parameter list) (b: Block) : Result<BlockParam
217221
| Some x -> Ok x
218222
| None -> Error <| IsNotAType typeName
219223
| "__type_symbol" ->
220-
Ok <| ParameterType ($"^{typeName}", set [ExplicitSymbol' typeName])
224+
Ok <| ParameterType ($"{typeName}", set [ExplicitSymbol' typeName])
221225
| _ -> failwith "?")
222226
|> sequenceRL
223227
|> Result.map (fun t ->

0 commit comments

Comments
 (0)