Exemple #1
0
        static StackObject *get_Value_0(ILIntepreter __intp, StackObject *__esp, IList <object> __mStack, CLRMethod __method, bool isNewObj)
        {
            ILRuntime.Runtime.Enviorment.AppDomain __domain = __intp.AppDomain;
            StackObject *ptr_of_this_method;
            StackObject *__ret = ILIntepreter.Minus(__esp, 1);

            ptr_of_this_method = ILIntepreter.Minus(__esp, 1);
            System.Text.RegularExpressions.Capture instance_of_this_method = (System.Text.RegularExpressions.Capture) typeof(System.Text.RegularExpressions.Capture).CheckCLRTypes(StackObject.ToObject(ptr_of_this_method, __domain, __mStack));
            __intp.Free(ptr_of_this_method);

            var result_of_this_method = instance_of_this_method.Value;

            return(ILIntepreter.PushObject(__ret, __mStack, result_of_this_method));
        }
Exemple #2
0
        public static string ReplaceLeadingZeros(System.Text.RegularExpressions.Match m)
        {
            string retVal = m.Value;

            System.Text.RegularExpressions.Capture capt = m.Groups["ID"];


            if (capt == null)
            {
                return(retVal);
            }

            int ind = capt.Index - m.Index;

            System.Text.StringBuilder sb = new System.Text.StringBuilder(retVal);
            sb.Remove(ind, capt.Length);
            sb.Insert(ind, capt.Value.TrimStart('0'));
            retVal    = sb.ToString();
            sb.Length = 0;
            sb        = null;

            return(retVal);
        }
Exemple #3
0
        public static string ReplaceGroup(System.Text.RegularExpressions.Regex regex, string input, string groupName, ReplaceCallback_t pfnReplace)
        {
            return(regex.Replace(input, new System.Text.RegularExpressions.MatchEvaluator(
                                     delegate(System.Text.RegularExpressions.Match m)
            {
                string retVal = m.Value;
                System.Text.RegularExpressions.Capture capt = m.Groups[groupName];

                if (capt == null)
                {
                    return retVal;
                }

                int ind = capt.Index - m.Index;
                System.Text.StringBuilder sb = new System.Text.StringBuilder(retVal);
                sb.Remove(ind, capt.Length);
                sb.Insert(ind, pfnReplace(capt.Value));
                retVal = sb.ToString();
                sb.Length = 0;
                sb = null;
                return retVal;
            })
                                 ));
        }
Exemple #4
0
        public ParseResult parse(string input_filename)
        {
            ParseResult result = new ParseResult();

            if (input_filename == null)
            {
                throw new NullReferenceException();
            }

            if (input_filename.Length == 0)
            {
                result.Remainder = input_filename;
                result.Stamp     = null;
                return(result);
            }

            Stamp  stamp_struct = new Stamp();
            string redigit      = "([0-9]|[xX])";
            string redash       = @"\-";
            string releft       = @"(([\[|\(])*)";
            string reright      = @"(([\]|\)])*)";

            string reyyyymmdd = (releft) + (redigit + "{4}") + redash + (redigit + "{1,2}") + redash + (redigit + "{1,2}") + (reright);
            string remmddyyyy = (releft) + (redigit + "{1,2}") + redash + (redigit + "{1,2}") + redash + (redigit + "{4}") + (reright);

            System.Text.RegularExpressions.Regex   regex_pattern;
            System.Text.RegularExpressions.Match   regex_match;
            System.Text.RegularExpressions.Capture regex_capture = null;

            regex_pattern = new System.Text.RegularExpressions.Regex(reyyyymmdd);
            regex_match   = regex_pattern.Match(input_filename);

            if (regex_match.Success)
            {
                regex_capture = regex_match.Captures[0];
                string[] tokens = this.tokenize(regex_capture.ToString());
                stamp_struct.Year  = tokens[0];
                stamp_struct.Month = tokens[1];
                stamp_struct.Day   = tokens[2];
                stamp_struct.calc();
                result.Stamp = stamp_struct;
            }
            else
            {
                regex_pattern = new System.Text.RegularExpressions.Regex(remmddyyyy);
                regex_match   = regex_pattern.Match(input_filename);
                if (regex_match.Success)
                {
                    regex_capture = regex_match.Captures[0];
                    string[] tokens = this.tokenize(regex_capture.ToString());
                    stamp_struct.Year  = tokens[2];
                    stamp_struct.Month = tokens[0];
                    stamp_struct.Day   = tokens[1];
                    stamp_struct.calc();
                    result.Stamp = stamp_struct;
                }
                else
                {
                    result.Remainder = input_filename;
                    result.Stamp     = null;
                    return(result);
                }
            }

            if (regex_match == null)
            {
                throw new Exception();
            }

            string before = "";
            string after  = "";

            if (regex_capture.Length > 0)
            {
                if (regex_capture.Index < 1)
                {
                    before = "";
                    after  = input_filename.Substring(regex_capture.Index + regex_capture.Length);
                }
                else
                {
                    before = input_filename.Substring(0, regex_capture.Index);
                    after  = input_filename.Substring(regex_capture.Index + regex_capture.Length);
                }
            }

            result.Remainder = before + after;

            return(result);
        }
Exemple #5
0
 public RegexCapture(System.Text.RegularExpressions.Capture capture)
 {
     this._Value  = capture.Value;
     this._Index  = capture.Index;
     this._Length = capture.Length;
 }
Exemple #6
0
        private async Task <ExecValue> executeNativeRegexFunctionAsync(ExecutionContext ctx, FunctionDefinition func,
                                                                       ObjectData thisValue)
        {
            if (func == ctx.Env.RegexContainsFunction)
            {
                ObjectData arg     = ctx.FunctionArguments.Single();
                ObjectData arg_val = arg.DereferencedOnce();
                string     arg_str = arg_val.NativeString;

                ObjectData pattern_obj = thisValue.GetField(ctx.Env.RegexPatternField);
                ObjectData pattern_val = pattern_obj.DereferencedOnce();
                string     pattern     = pattern_val.NativeString;

                bool val = new System.Text.RegularExpressions.Regex(pattern).IsMatch(arg_str);

                ExecValue result = ExecValue.CreateReturn(await ObjectData.CreateInstanceAsync(ctx,
                                                                                               func.ResultTypeName.Evaluation.Components, val).ConfigureAwait(false));
                return(result);
            }
            else if (func == ctx.Env.RegexMatchFunction)
            {
                ObjectData arg     = ctx.FunctionArguments.Single();
                ObjectData arg_val = arg.DereferencedOnce();
                string     arg_str = arg_val.NativeString;

                ObjectData pattern_obj = thisValue.GetField(ctx.Env.RegexPatternField);
                ObjectData pattern_val = pattern_obj.DereferencedOnce();
                string     pattern     = pattern_val.NativeString;

                System.Text.RegularExpressions.Regex           regex   = new System.Text.RegularExpressions.Regex(pattern);
                System.Text.RegularExpressions.MatchCollection matches = regex.Matches(arg_str);

                var elements = new List <ObjectData>();
                for (int match_idx = 0; match_idx < matches.Count; ++match_idx)
                {
                    System.Text.RegularExpressions.Match match = matches[match_idx];
                    ObjectData match_start_val = await createNat64Async(ctx, (UInt64)match.Index).ConfigureAwait(false);

                    ObjectData match_end_val = await createNat64Async(ctx, (UInt64)(match.Index + match.Length)).ConfigureAwait(false);

                    ObjectData array_captures_ptr;

                    {
                        if (!ctx.Env.DereferencedOnce(ctx.Env.MatchCapturesProperty.TypeName.Evaluation.Components,
                                                      out IEntityInstance array_captures_type, out bool dummy))
                        {
                            throw new Exception($"Internal error {ExceptionCode.SourceInfo()}");
                        }

                        ExecValue ret = await createObject(ctx, true, array_captures_type, ctx.Env.ArrayDefaultConstructor, null)
                                        .ConfigureAwait(false);

                        if (ret.IsThrow)
                        {
                            return(ret);
                        }

                        array_captures_ptr = ret.ExprValue;
                        ctx.Heap.TryInc(ctx, array_captures_ptr, RefCountIncReason.StoringLocalPointer, "");

                        // skipping implicit "everything" group
                        for (int grp_idx = 1; grp_idx < match.Groups.Count; ++grp_idx)
                        {
                            System.Text.RegularExpressions.Group group = match.Groups[grp_idx];
                            string group_name = regex.GroupNameFromNumber(grp_idx);
                            if (group_name == $"{grp_idx}") // hack for anonymous captures
                            {
                                group_name = null;
                            }

                            for (int cap_idx = 0; cap_idx < group.Captures.Count; ++cap_idx)
                            {
                                System.Text.RegularExpressions.Capture cap = group.Captures[cap_idx];

                                ObjectData cap_start_val = await createNat64Async(ctx, (UInt64)cap.Index).ConfigureAwait(false);

                                ObjectData cap_end_val = await createNat64Async(ctx, (UInt64)(cap.Index + cap.Length)).ConfigureAwait(false);

                                ObjectData cap_opt_name_val;
                                {
                                    Option <ObjectData> opt_group_name_obj;
                                    if (group_name != null)
                                    {
                                        ObjectData str_ptr = await createStringAsync(ctx, group_name).ConfigureAwait(false);

                                        opt_group_name_obj = new Option <ObjectData>(str_ptr);
                                    }
                                    else
                                    {
                                        opt_group_name_obj = new Option <ObjectData>();
                                    }

                                    IEntityInstance opt_cap_type = ctx.Env.CaptureConstructor.Parameters.Last().TypeName.Evaluation.Components;
                                    ExecValue       opt_exec     = await createOption(ctx, opt_cap_type, opt_group_name_obj).ConfigureAwait(false);

                                    if (opt_exec.IsThrow)
                                    {
                                        return(opt_exec);
                                    }
                                    cap_opt_name_val = opt_exec.ExprValue;
                                }
                                ExecValue capture_obj_exec = await createObject(ctx, false, ctx.Env.CaptureType.InstanceOf,
                                                                                ctx.Env.CaptureConstructor, null, cap_start_val, cap_end_val, cap_opt_name_val).ConfigureAwait(false);

                                if (capture_obj_exec.IsThrow)
                                {
                                    return(capture_obj_exec);
                                }
                                ObjectData capture_ref = await capture_obj_exec.ExprValue.ReferenceAsync(ctx).ConfigureAwait(false);

                                ExecValue append_exec = await callNonVariadicFunctionDirectly(ctx, ctx.Env.ArrayAppendFunction, null,
                                                                                              array_captures_ptr, capture_ref).ConfigureAwait(false);

                                if (append_exec.IsThrow)
                                {
                                    return(append_exec);
                                }
                            }
                        }
                    }
                    ObjectData match_val;
                    {
                        ExecValue ret = await createObject(ctx, false, ctx.Env.MatchType.InstanceOf,
                                                           ctx.Env.MatchConstructor, null, match_start_val, match_end_val, array_captures_ptr).ConfigureAwait(false);

                        ctx.Heap.TryRelease(ctx, array_captures_ptr, null, false, RefCountDecReason.DroppingLocalPointer, "");

                        if (ret.IsThrow)
                        {
                            return(ret);
                        }

                        match_val = ret.ExprValue;
                    }

                    elements.Add(match_val);
                }

                ObjectData heap_chunk = await createChunkOnHeap(ctx, ctx.Env.MatchType.InstanceOf, elements).ConfigureAwait(false);

                ExecValue result = ExecValue.CreateReturn(heap_chunk);
                return(result);
            }
            else
            {
                throw new NotImplementedException($"{ExceptionCode.SourceInfo()}");
            }
        }