Пример #1
0
        private static IMachineFactory CreateMachineFactory(string pattern, RegexOptions options)
        {
            Parser            psr = new Parser();
            RegularExpression re  = psr.ParseRegularExpression(pattern, options);

            ICompiler cmp;

            //if ((options & RegexOptions.Compiled) != 0)
            //	//throw new Exception ("Not implemented.");
            //	cmp = new CILCompiler ();
            //else
            cmp = new PatternCompiler();

            re.Compile(cmp, (options & RegexOptions.RightToLeft) != 0);

            IMachineFactory machineFactory = cmp.GetMachineFactory();

            machineFactory.Mapping      = psr.GetMapping();
            machineFactory.NamesMapping = GetGroupNamesArray(machineFactory.GroupCount, machineFactory.Mapping);

            return(machineFactory);
        }
Пример #2
0
        public Regex(string pattern, RegexOptions options)
        {
            this.pattern  = pattern;
            this.roptions = options;

            this.machineFactory = cache.Lookup(pattern, options);

            if (this.machineFactory == null)
            {
                // parse and install group mapping

                Parser            psr = new Parser();
                RegularExpression re  = psr.ParseRegularExpression(pattern, options);
                this.group_count = re.GroupCount;
                this.mapping     = psr.GetMapping();

                // compile

                ICompiler cmp;
                //if ((options & RegexOptions.Compiled) != 0)
                //	//throw new Exception ("Not implemented.");
                //	cmp = new CILCompiler ();
                //else
                cmp = new PatternCompiler();

                re.Compile(cmp, RightToLeft);

                // install machine factory and add to pattern cache

                this.machineFactory         = cmp.GetMachineFactory();
                this.machineFactory.Mapping = mapping;
                cache.Add(pattern, options, this.machineFactory);
            }
            else
            {
                this.group_count = this.machineFactory.GroupCount;
                this.mapping     = this.machineFactory.Mapping;
            }
        }
Пример #3
0
        private static IMachineFactory CreateMachineFactory(string pattern, RegexOptions options)
        {
            Parser            psr = new Parser();
            RegularExpression re  = psr.ParseRegularExpression(pattern, options);

#if NET_2_1
            ICompiler cmp = new PatternCompiler();
#else
            ICompiler cmp;
            if (!old_rx)
            {
                if ((options & RegexOptions.Compiled) != 0)
                {
                    cmp = new CILCompiler();
                }
                else
                {
                    cmp = new RxCompiler();
                }
            }
            else
            {
                cmp = new PatternCompiler();
            }
#endif

            re.Compile(cmp, (options & RegexOptions.RightToLeft) != 0);

            IMachineFactory machineFactory = cmp.GetMachineFactory();
            Hashtable       mapping        = new Hashtable();
            machineFactory.Gap          = psr.GetMapping(mapping);
            machineFactory.Mapping      = mapping;
            machineFactory.NamesMapping = GetGroupNamesArray(machineFactory.GroupCount, machineFactory.Mapping);

            return(machineFactory);
        }