Exemplo n.º 1
0
        static Regex CreateHighlightingRegex( )
        {
            var pb = new PatternBuilder( );

            pb.Add(@"\\.");
            pb.AddGroup("left_par", @"(?'left_par'\()");               // '('
            pb.AddGroup("right_par", @"(?'right_par'\))");             // ')'

            return(pb.ToRegex( ));
        }
Exemplo n.º 2
0
        Regex CreateColouringRegex(WebView2RegexOptions options)
        {
            var pb_escape = new PatternBuilder( );

            pb_escape.BeginGroup("escape");
            pb_escape.Add(@"\\c[A-Za-z]");               // \cx control char
            pb_escape.Add(@"\\x[0-9a-fA-F]{1,2}");       // hexadecimal char
            pb_escape.Add(@"\\u[0-9a-fA-F]{1,4}");       // hexadecimal char

            if (options.u)
            {
                // language=regex
                pb_escape.Add(@"\\u\{[0-9a-fA-F]+(\}|$)");              // hexadecimal char
                // language=regex
                pb_escape.Add(@"\\(p|P)\{.*?(\}|$)");                   // unicode property
            }


            pb_escape.Add(@"\\.");               // \.
            pb_escape.EndGroup( );

            var pb = new PatternBuilder( );

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

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

            pb.Add(pb_escape.ToPattern( ));

            return(pb.ToRegex( ));
        }
Exemplo n.º 3
0
        static Regex CreateColouringRegex(GrammarEnum grammar)
        {
            var pb_escape = new PatternBuilder( );

            pb_escape.BeginGroup("escape");

            if (grammar == GrammarEnum.ECMAScript)
            {
                pb_escape.Add(@"\\c[A-Za-z]");
            }
            if (grammar == GrammarEnum.ECMAScript)
            {
                pb_escape.Add(@"\\x[0-9A-Fa-f]{1,2}");                                                   // (two digits required)
            }
            if (grammar == GrammarEnum.awk)
            {
                pb_escape.Add(@"\\[0-7]{1,3}");                                            // octal code
            }
            if (grammar == GrammarEnum.ECMAScript)
            {
                pb_escape.Add(@"\\u[0-9A-Fa-f]{1,4}");                                                   // (four digits required)
            }
            if (grammar == GrammarEnum.basic ||
                grammar == GrammarEnum.grep)
            {
                pb_escape.Add(@"(?!\\\( | \\\) | \\\{ | \\\})\\.");
            }
            else
            {
                pb_escape.Add(@"\\.");
            }

            pb_escape.EndGroup( );

            //

            var pb_class = new PatternBuilder( ).AddGroup("class", @"\[(?'c'[:=.]) .*? (\k<c>\] | $)");

            //

            var pb = new PatternBuilder( );

            pb.Add(pb_escape.ToPattern( ));

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

            // (group names and comments are not supported by C++ Regex)

            return(pb.ToRegex( ));
        }
Exemplo n.º 4
0
        Regex CreateColouringRegex( )
        {
            bool is_literal = OptionsControl.IsOptionSelected("literal");

            if (is_literal)
            {
                return(PatternBuilder.AlwaysFailsRegex);
            }

            var pb_escape = new PatternBuilder( );

            pb_escape.BeginGroup("escape");

            pb_escape.Add(@"\\[pP][A-Za-z]");             // Unicode character class (one-letter name)
            pb_escape.Add(@"\\[pP]\{.*?(\}|$)");          // Unicode character class
            pb_escape.Add(@"\\0[0-7]{1,2}");              // octal, two digits after 0
            pb_escape.Add(@"\\[0-7]{1,3}");               // octal, three digits
            pb_escape.Add(@"\\x[0-9a-fA-F]{1,2}");        // hexa, two digits
            pb_escape.Add(@"\\x\{[0-9a-fA-F]*(\}|$)");    // hexa, error if empty
            pb_escape.Add(@"\\Q.*?(\\E|$)");              // quoted sequence, \Q...\E
            pb_escape.Add(@"\\.");

            pb_escape.EndGroup( );

            //

            var pb_class = new PatternBuilder( ).AddGroup("class", @"\[(?'c'[:]) .*? (\k<c>\] | $)");               // only [: :], no [= =], no [. .]

            //

            var pb = new PatternBuilder( );

            pb.Add(pb_escape.ToPattern( ));

            //

            pb.AddGroup(null, $@"\[ \]? ({pb_class.ToPattern( )} | {pb_escape.ToPattern( )} | . )*? (\]|$)");               // TODO: check 'escape' part

            //

            pb.Add(@"\(\?P(?'name'<.*?>)");

            return(pb.ToRegex( ));
        }
Exemplo n.º 5
0
        static Regex CreateCachedColouringRegex(RegexOptions options)
        {
            // (some patterns includes incomplete constructs)

            var pb = new PatternBuilder( );

            pb.BeginGroup("comment");
            pb.Add(@"\(\?\#.*?(\)|$)");
            if (options.HasFlag(RegexOptions.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);
        }
Exemplo n.º 6
0
        static Regex CreateHighlightingRegex(GrammarEnum grammar, bool modX)
        {
            bool is_perl =
                grammar == GrammarEnum.perl ||
                grammar == GrammarEnum.ECMAScript ||
                grammar == GrammarEnum.normal ||
                grammar == GrammarEnum.JavaScript ||
                grammar == GrammarEnum.JScript;

            bool is_POSIX_extended =
                grammar == GrammarEnum.extended ||
                grammar == GrammarEnum.egrep ||
                grammar == GrammarEnum.awk;

            bool is_POSIX_basic =
                grammar == GrammarEnum.basic ||
                grammar == GrammarEnum.sed ||
                grammar == GrammarEnum.grep ||
                grammar == GrammarEnum.emacs;

            bool is_emacs =
                grammar == GrammarEnum.emacs;


            var pb = new PatternBuilder( );

            if (is_perl)
            {
                pb.Add(@"(\(\?\#.*?(\)|$))");                         // comment
            }
            if (is_perl && modX)
            {
                pb.Add(@"(\#[^\n]*)");                                 // line comment
            }
            if (is_perl || is_POSIX_extended)
            {
                pb.Add(@"\\Q.*?(\\E|$)");                   // skip \Q...\E
                pb.Add(@"\\[xNpPgk]\{.*?(\}|$)");           // (skip)
            }

            if (is_perl || is_POSIX_extended)
            {
                pb.AddGroup("left_par", @"\(");                                                   // '('
                pb.AddGroup("right_par", @"\)");                                                  // ')'
                pb.Add(@"(?'left_brace'\{) \s* \d+ \s* (, \s* \d*)? \s* ((?'right_brace'\})|$)"); // '{...}' (spaces are allowed)
            }

            if (is_POSIX_basic)
            {
                pb.AddGroup("left_par", @"\\\(");                        // '\('
                pb.AddGroup("right_par", @"\\\)");                       // '\)'
                pb.Add(@"(?'left_brace'\\{).*?((?'right_brace'\\})|$)"); // '\{...\}'
            }

            if (is_perl || is_POSIX_extended || is_POSIX_basic)
            {
                pb.Add(@"((?'left_bracket'\[) \]? ((\[:.*? (:\]|$)) | \\. | .)*? ((?'right_bracket'\])|$) )"); // [...]
                pb.Add(@"\\.");                                                                                // '\...'
            }

            return(pb.ToRegex( ));
        }
Exemplo n.º 7
0
        static Regex CreateColouringRegex(GrammarEnum grammar, bool modX)
        {
            bool is_perl =
                grammar == GrammarEnum.perl ||
                grammar == GrammarEnum.ECMAScript ||
                grammar == GrammarEnum.normal ||
                grammar == GrammarEnum.JavaScript ||
                grammar == GrammarEnum.JScript;

            bool is_POSIX_extended =
                grammar == GrammarEnum.extended ||
                grammar == GrammarEnum.egrep ||
                grammar == GrammarEnum.awk;

            bool is_POSIX_basic =
                grammar == GrammarEnum.basic ||
                grammar == GrammarEnum.sed ||
                grammar == GrammarEnum.grep ||
                grammar == GrammarEnum.emacs;

            bool is_emacs =
                grammar == GrammarEnum.emacs;


            var pb_escape = new PatternBuilder( );

            pb_escape.BeginGroup("escape");

            if (is_perl || is_POSIX_extended || is_POSIX_basic)
            {
                pb_escape.Add(@"\\[1-9]");                                                                // back reference
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\c[A-Za-z]");                                              // ASCII escape
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\x[0-9A-Fa-f]{1,2}");                                              // hex, two digits
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\x\{[0-9A-Fa-f]+(\}|$)");                                              // hex, four digits
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\0[0-7]{1,3}");                                              // octal, three digits
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\N\{.*?(\}|$)");                                              // symbolic name
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\[pP]\{.*?(\}|$)");                                              // property
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\[pP].");                                              // property, short name
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\Q.*?(\\E|$)");
            }
            ;                                                                                   // quoted sequence
            if (is_emacs)
            {
                pb_escape.Add(@"\\[sS].");                          // syntax group
            }
            if (is_perl || is_POSIX_extended)
            {
                pb_escape.Add(@"\\.");                                              // various
            }
            if (is_POSIX_basic)
            {
                pb_escape.Add(@"(?!\\\( | \\\) | \\\{ | \\\})\\.");                                // various
            }
            pb_escape.EndGroup( );

            var pb_class = new PatternBuilder( );

            pb_class.BeginGroup("class");

            if (is_perl || is_POSIX_extended || is_POSIX_basic)
            {
                pb_class.Add(@"\[(?'c'[:=.]) .*? (\k<c>\] | $)");
            }

            pb_class.EndGroup( );


            var pb = new PatternBuilder( );

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

            if (is_perl)
            {
                pb.Add(@"\(\?(?'name'<(?![=!]).*?(>|$)) | \(\?(?'name''.*?('|$))");
            }
            if (is_perl)
            {
                pb.Add(@"(?'name'\\g-?[1-9]) | (?'name'\\g\{.*?(\}|$))");                         // back reference
            }
            if (is_perl)
            {
                pb.Add(@"(?'name'\\[gk]<.*?(>|$)) | (?'name'\\[gk]'.*?('|$))");                         // back reference
            }
            if (is_perl || is_POSIX_extended || is_POSIX_basic)
            {
                pb.AddGroup(null, $@"\[ \]? ({pb_class.ToPattern( )} | {pb_escape.ToPattern( )} | . )*? (\]|$)");
            }

            pb.Add(pb_escape.ToPattern( ));

            return(pb.ToRegex( ));
        }