Ejemplo n.º 1
0
        public string[] ExportOptions( )
        {
            IcuRegexOptions options = OptionsControl.GetSelectedOptions( );
            var             json    = JsonSerializer.Serialize(options);

            return(new[] { $"json:{json}" });
        }
Ejemplo n.º 2
0
        Regex CreateHighlightingRegex(IcuRegexOptions options)
        {
            var pb = new PatternBuilder( );

            pb.Add(@"\(\?\#.*?(\)|$)");               // comment

            if (options.UREGEX_COMMENTS)
            {
                pb.Add(@"\#.*?(\n|$)");                            // line-comment
            }
            pb.Add(@"\\Q.*?(\\E|$)");                              // quoted part

            pb.Add(@"(?'left_par'\()");                            // '('
            pb.Add(@"(?'right_par'\))");                           // ')'
            pb.Add(@"\\[NpPx]\{.*?(\}|$)");                        // (skip)
            pb.Add(@"(?'left_brace'\{).*?((?'right_brace'\})|$)"); // '{...}'

            string posix_bracket = @"(\[:.*?(:\]|$))";             // [:...:]

            pb.Add($@"
						(?'left_bracket'\[)
						\]?
						(?> {posix_bracket} | (?'left_bracket'\[)(?<c>) | (\\. | [^\[\]])+ | (?'right_bracket'\])(?<-c>))*
						(?(c)(?!))
						(?'right_bracket'\])?
						|
						(?'right_bracket'\])
						"                        );

            pb.Add(@"\\.");               // '\...'

            return(pb.ToRegex( ));
        }
Ejemplo n.º 3
0
        Regex GetCachedHighlightingRegex( )
        {
            IcuRegexOptions options = OptionsControl.GetSelectedOptions( );

            if (options.UREGEX_LITERAL)
            {
                return(PatternBuilder.AlwaysFailsRegex);
            }

            object key = options.UREGEX_COMMENTS;

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

                regex = CreateHighlightingRegex(options);

                CachedHighlightingRegexes.Add(key, regex);

                return(regex);
            }
        }
Ejemplo n.º 4
0
        public IcuMatcher(string pattern, IcuRegexOptions options)
        {
            Options = options;

            if (!string.IsNullOrWhiteSpace(options.Limit) && !int.TryParse(options.Limit, out var limit))
            {
                throw new ApplicationException("Invalid limit. Please enter an integer number.");
            }

            Pattern = pattern;
        }
Ejemplo n.º 5
0
        internal void SetSelectedOptions(IcuRegexOptions options)
        {
            try
            {
                ++ChangeCounter;

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

            IcuRegexOptions options_obj;

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

            OptionsControl.SetSelectedOptions(options_obj);
        }
Ejemplo n.º 7
0
        Regex CreateColouringRegex(IcuRegexOptions options)
        {
            var pb_escape = new PatternBuilder( );

            pb_escape.BeginGroup("escape");
            pb_escape.Add(@"\\c[A-Za-z]");             // \cx control char
            pb_escape.Add(@"\\[NpP]\{.*?(\} | $)");    // named character, property
            pb_escape.Add(@"\\[uUx][0-9a-fA-F]+");     // hexadecimal char
            pb_escape.Add(@"\\x\{[0-9a-fA-F]+(\}|$)"); // hexadecimal char
            pb_escape.Add(@"\\0[0-7]+");               // octal
            pb_escape.Add(@"\\Q.*?(\\E|$)");           // quoted part
            pb_escape.Add(@"\\.");                     // \.
            pb_escape.EndGroup( );

            var pb = new PatternBuilder( );

            pb.BeginGroup("comment");
            pb.Add(@"\(\?\#.*?(\)|$)");               // comment
            if (options.UREGEX_COMMENTS)
            {
                pb.Add(@"\#.*?(\n|$)");                                         // line-comment
            }
            pb.EndGroup( );

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

            string posix_bracket = @"(?'escape'\[:.*?(:\]|$))";             // [:...:], use escape colour

            pb.Add($@"
						\[
						\]?
						(?> {posix_bracket} | \[(?<c>) | ({pb_escape.ToPattern( )} | [^\[\]])+ | \](?<-c>))*
						(?(c)(?!))
						\]
						"                        );

            pb.Add(pb_escape.ToPattern( ));

            return(pb.ToRegex( ));
        }
Ejemplo n.º 8
0
        public IMatcher ParsePattern(string pattern)
        {
            IcuRegexOptions options = OptionsControl.GetSelectedOptions( );

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