@@ -2916,8 +2916,7 @@ let regex com (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Exp
29162916 | Some ( ExprType ( EntFullName " System.Text.RegularExpressions.Group" )) -> true
29172917 | _ -> false
29182918
2919- match i.CompiledName with
2920- | " .ctor" ->
2919+ let createRegex r t args =
29212920 let makeRegexConst r ( pattern : string ) flags =
29222921 let flags = RegexFlag.RegexGlobal:: flags // .NET regex are always global
29232922 RegexConstant( pattern, flags) |> makeValue r
@@ -2935,9 +2934,12 @@ let regex com (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Exp
29352934 | _ -> None
29362935 getFlags e
29372936 match args with
2938- | [ StringConst pattern] -> makeRegexConst r pattern [] |> Some
2939- | StringConst pattern::( RegexFlags flags)::_ -> makeRegexConst r pattern flags |> Some
2940- | _ -> Helper.LibCall( com, " RegExp" , " create" , t, args, i.SignatureArgTypes, ?loc= r) |> Some
2937+ | [ StringConst pattern] -> makeRegexConst r pattern []
2938+ | StringConst pattern::( RegexFlags flags)::_ -> makeRegexConst r pattern flags
2939+ | _ -> Helper.LibCall( com, " RegExp" , " create" , t, args, ?loc= r)
2940+
2941+ match i.CompiledName with
2942+ | " .ctor" -> createRegex r t args |> Some
29412943 | " get_Options" -> Helper.LibCall( com, " RegExp" , " options" , t, [ thisArg.Value], [ thisArg.Value.Type], ?loc= r) |> Some
29422944 // Capture
29432945 | " get_Index" ->
@@ -2986,6 +2988,19 @@ let regex com (ctx: Context) r t (i: CallInfo) (thisArg: Expr option) (args: Exp
29862988 | " get_Item" -> getExpr r t thisArg.Value args.Head |> Some
29872989 | " get_Count" -> propStr " length" thisArg.Value |> Some
29882990 | " GetEnumerator" -> getEnumerator com r t thisArg.Value |> Some
2991+ | " IsMatch" | " Match" | " Matches" as meth ->
2992+ match thisArg, args with
2993+ | Some thisArg, args ->
2994+ if args.Length > 2 then
2995+ $" Regex.{meth} doesn't support more than 2 arguments"
2996+ |> addError com ctx.InlinePath r
2997+ thisArg:: args |> Some
2998+ | None, input:: pattern:: args ->
2999+ let reg = createRegex None Any ( pattern:: args)
3000+ [ reg; input] |> Some
3001+ | _ -> None
3002+ |> Option.map ( fun args ->
3003+ Helper.LibCall( com, " RegExp" , Naming.lowerFirst meth, t, args, i.SignatureArgTypes, ?loc= r))
29893004 | meth ->
29903005 let meth = Naming.removeGetSetPrefix meth |> Naming.lowerFirst
29913006 Helper.LibCall( com, " RegExp" , meth, t, args, i.SignatureArgTypes, ?thisArg= thisArg, ?loc= r) |> Some
0 commit comments