예제 #1
0
        public string[] ExportOptions( )
        {
            DotNetCoreRegexOptions options = OptionsControl.GetSelectedOptions( );
            var json = JsonSerializer.Serialize(options);

            return(new[] { $"json:{json}" });
        }
예제 #2
0
        internal void SetSelectedOptions(DotNetCoreRegexOptions options)
        {
            try
            {
                ++ChangeCounter;

                Options     = options.Clone( );
                DataContext = Options;
            }
            finally
            {
                --ChangeCounter;
            }
        }
예제 #3
0
        public void ImportOptions(string[] options)
        {
            var json = options.FirstOrDefault(o => o.StartsWith("json:"))?.Substring("json:".Length);

            DotNetCoreRegexOptions options_obj;

            if (string.IsNullOrWhiteSpace(json))
            {
                options_obj = new DotNetCoreRegexOptions( );
            }
            else
            {
                options_obj = JsonSerializer.Deserialize <DotNetCoreRegexOptions>(json);
            }

            OptionsControl.SetSelectedOptions(options_obj);
        }
예제 #4
0
        static Regex CreateHighlightingRegex(DotNetCoreRegexOptions options)
        {
            var pb = new PatternBuilder( );

            pb.Add(@"\(\?\#.*?(\)|$)");               // comment
            if (options.IgnorePatternWhitespace)
            {
                pb.Add(@"\#[^\n]*");                                               // line comment
            }
            pb.Add(@"\\[pP]\{.*?(\}|$)");                                          // (skip)
            pb.Add(@"(?'left_par'\()");                                            // '('
            pb.Add(@"(?'right_par'\))");                                           // ')'
            pb.Add(@"(?'left_brace'\{) \d+(,(\d+)?)? ((?'right_brace'\})|$)");     // '{...}'
            pb.Add(@"(?'left_bracket'\[) \]? (\\.|.)*? ((?'right_bracket'\])|$)"); // '[...]'
            pb.Add(@"\\.");                                                        // (skip)

            return(pb.ToRegex( ));
        }
예제 #5
0
        static Regex GetCachedHighlightingRegex(DotNetCoreRegexOptions options)
        {
            string key = options.IgnorePatternWhitespace.ToString( );

            lock ( CachedHighlightingRegexes )
            {
                if (CachedHighlightingRegexes.TryGetValue(key, out Regex regex))
                {
                    return(regex);
                }

                regex = CreateHighlightingRegex(options);

                CachedHighlightingRegexes.Add(key, regex);

                return(regex);
            }
        }
예제 #6
0
        static Regex CreateCachedColouringRegex(DotNetCoreRegexOptions options)
        {
            // (some patterns includes incomplete constructs)

            var pb = new PatternBuilder( );

            pb.BeginGroup("comment");
            pb.Add(@"\(\?\#.*?(\)|$)");
            if (options.IgnorePatternWhitespace)
            {
                pb.Add(@"\#[^\n]*");
            }
            pb.EndGroup( );

            var escapes_pb = new PatternBuilder( );

            escapes_pb.BeginGroup("escape");
            escapes_pb.Add(@"\\[0-7]{2,3}");
            escapes_pb.Add(@"\\x[0-9A-Fa-f]{1,2}");
            escapes_pb.Add(@"\\c[A-Za-z]");
            escapes_pb.Add(@"\\u[0-9A-Fa-f]{1,4}");
            escapes_pb.Add(@"\\(p|P)\{.*?(\}|$)");
            escapes_pb.Add(@"\\k<([A-Za-z]+>)?");
            escapes_pb.Add(@"\\.");
            escapes_pb.EndGroup( );

            pb.AddGroup(null, $@"\[\]?({escapes_pb.ToPattern( )} |.)*?(\]|$)");

            pb.Add(@"\(\?(?'name'<(?![=!]).*?(>|$))");               // (balancing groups covered too)
            pb.Add(@"\(\?(?'name''.*?('|$))");
            pb.Add(@"(?'name'\\k<.*?(>|$))");
            pb.Add(@"(?'name'\\k'.*?('|$))");

            pb.Add(escapes_pb.ToPattern( ));

            var regex = pb.ToRegex( );

            return(regex);
        }
예제 #7
0
		public DotNetCoreMatcher( string pattern, DotNetCoreRegexOptions options )
		{
			Pattern = pattern;
			Options = options;
		}
예제 #8
0
        public IMatcher ParsePattern(string pattern)
        {
            DotNetCoreRegexOptions options = OptionsControl.GetSelectedOptions( );

            return(new DotNetCoreMatcher(pattern, options));
        }