Skip to content

Commit f11cfc5

Browse files
committed
allow pass string as character name.
1 parent b8d65d3 commit f11cfc5

File tree

3 files changed

+19
-14
lines changed

3 files changed

+19
-14
lines changed

YukimiScript.CodeGen/PyMO.fs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -345,9 +345,9 @@ let private genCommand
345345
| "__text_begin" ->
346346
match call.Arguments.[0] with
347347
| Symbol "null" as n -> Ok { context with CurrentComplexCommand = Some (sayCommand, [n])}
348-
| Symbol x ->
348+
| String x ->
349349
match Map.tryFind x context.Characters with
350-
| None -> Error ("未能找到角色定义 " + x + "", call.DebugInformation)
350+
| None -> Ok { context with CurrentComplexCommand = Some (sayCommand, [Constant.String x])}
351351
| Some x -> Ok { context with CurrentComplexCommand = Some (sayCommand, [Constant.String x])}
352352
| _ -> failwith ""
353353
| "__text_type" -> Error ("错误的__text_type用法。", call.DebugInformation)

YukimiScript.Parser/Dom.fs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,12 @@ module Dom =
198198
| Ok (ExternDefination x) -> x
199199
| _ -> failwith "Bug here!"
200200

201-
[ parse "- extern __text_begin character=null", [ "character", Types.symbol ]
201+
[ parse "- extern __text_begin character=null", [
202+
"character", ParameterType ("string | null", set [ String'; ExplicitSymbol' "null" ]) ]
202203
parse "- extern __text_type text", [ "text", Types.string ]
203204
parse "- extern __text_pushMark mark", [ "mark", Types.symbol ]
204205
parse "- extern __text_popMark mark", [ "mark", Types.symbol ]
205-
parse "- extern __text_end hasMore", [ "hasMore", Types.symbol] ]
206+
parse "- extern __text_end hasMore", [ "hasMore", Types.bool ] ]
206207

207208

208209
let linkToExternCommands (x: Dom) : Result<Dom, exn> =

YukimiScript.Parser/Text.fs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ let private commandCall =
1717
}
1818

1919

20-
let private bareText =
21-
let charPred x =
20+
let private bareText, characterNameText =
21+
let charPred isCharacterNameText x =
2222
Seq.exists
2323
((=) x)
2424
[ '\n'
@@ -28,14 +28,19 @@ let private bareText =
2828
'>'
2929
'#'
3030
'\\'
31-
'\r' ]
31+
'\r'
32+
if isCharacterNameText then ':' ]
3233
|> not
3334

34-
let textChar = predicate charPred anyChar
35+
36+
let p isCharacterNameText =
37+
let textChar = predicate (charPred isCharacterNameText) anyChar
38+
39+
oneOrMore textChar
40+
3541

36-
oneOrMore textChar
37-
|> map (toString >> TextSlice.Text)
38-
|> name "text"
42+
p false |> map (toString >> TextSlice.Text) |> name "text",
43+
p true |> map toString
3944

4045

4146
let rec private markBlock () =
@@ -70,7 +75,7 @@ let text =
7075
let! character =
7176
parser {
7277
do! whitespace0
73-
let! character = symbol
78+
let! character = characterNameText
7479
do! literal ":"
7580
return character
7681
}
@@ -123,7 +128,7 @@ let toCommands (text: TextBlock) : CommandCall list =
123128
UnnamedArgs = []
124129
NamedArgs =
125130
[ if text.Character.IsSome then
126-
"character", Constant <| Symbol text.Character.Value ] }
131+
"character", Constant <| String text.Character.Value ] }
127132

128133
let rec textSliceToCommand x =
129134
x
@@ -147,7 +152,6 @@ let toCommands (text: TextBlock) : CommandCall list =
147152

148153
yield! textSliceToCommand text.Text
149154

150-
151155
{ Callee = "__text_end"
152156
UnnamedArgs = []
153157
NamedArgs = [ "hasMore", Constant <| Symbol (text.HasMore.ToString().ToLower()) ] } ]

0 commit comments

Comments
 (0)