Пример #1
0
        public static TGroup ContinueWithMany <TGroup, T>(this ITokenMatcherItemGroup <TGroup> group, string captureName, Action <TokenMatcherGroup> configuration, Func <TokenMatcherState, T> captureConversion, int minimum = 1, int maximum = int.MaxValue)
        {
            var g = new TokenMatcherGroup(captureName, captureConversion);

            configuration(g);

            return(group.AddItem(new TokenMatcherQuantitizer(g, minimum, maximum)));
        }
Пример #2
0
        public static TGroup ContinueWithOptionalGroup <TGroup, T>(this ITokenMatcherItemGroup <TGroup> group, string captureName, Action <TokenMatcherGroup> configuration, Func <TokenMatcherState, T> captureConversion)
        {
            var g = new TokenMatcherGroup(captureName, captureConversion);

            configuration(g);

            return(group.AddItem(new TokenMatcherOptional(g)));
        }
Пример #3
0
        public static TGroup ContinueWithGroup <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName, Action <TokenMatcherGroup> configuration)
        {
            var g = new TokenMatcherGroup(captureName, null);

            configuration(g);

            return(group.AddItem(g));
        }
Пример #4
0
        public static TGroup ContinueWithMany <TGroup, T>(
            this ITokenMatcherItemGroup <TGroup> group,
            string captureName,
            Action <TokenMatcherGroup> configuration,
            TokenMatcherItemBase separator,
            Func <TokenMatcherState, T> captureConversion,
            int minimum = 1,
            int maximum = int.MaxValue)
            where T : class
        {
            var firstKey = captureName + "." + nameof(TokenMatcherHelper) + "." + nameof(ContinueWithMany) + ".firstCapture";

            var fg = new TokenMatcherGroup(firstKey, captureConversion);

            configuration(fg);

            var ig = new TokenMatcherGroup(captureName, captureConversion);

            ig.AddItem(separator);
            configuration(ig);

            var igq = new TokenMatcherQuantitizer(ig, Math.Max(0, minimum - 1), maximum < int.MaxValue ? maximum - 1 : int.MaxValue);

            var g = new TokenMatcherGroup(captureName, (Func <TokenMatcherState, List <T> >)(s =>
            {
                var f = s.Captures.TryGetValue(firstKey, out var fv) ? fv as T : null;
                var l = s.Captures.TryGetValue(captureName, out var lv) ? lv as IEnumerable : null;

                if (f == null)
                {
                    return(l.Cast <T>().ToList());
                }

                if (l != null)
                {
                    var nl = new List <T>()
                    {
                        f
                    };
                    nl.AddRange(l.Cast <T>());
                    return(nl);
                }
                else
                {
                    return(new List <T>(1)
                    {
                        f
                    });
                }
            }));

            g.AddItem(fg).AddItem(igq);

            return(group.AddItem(g));
        }
Пример #5
0
 public static TGroup ContinueWithMany <TGroup, T>(
     this ITokenMatcherItemGroup <TGroup> group,
     string captureName,
     Action <TokenMatcherGroup> configuration,
     string separator,
     Func <TokenMatcherState, T> captureConversion,
     int minimum = 1,
     int maximum = int.MaxValue)
     where T : class
 => group.ContinueWithMany(
     captureName,
     configuration,
     new TokenMatcherItem(null, null, TokenType.Operator, new Regex("^" + Regex.Escape(separator) + "$")),
     captureConversion,
     minimum,
     maximum);
Пример #6
0
 public static TGroup ContinueWithOperator <TGroup, T>(this ITokenMatcherItemGroup <TGroup> group, string captureName, Func <Token, T> captureConversion, params string[] operators)
 => group.ContinueWith(captureName, captureConversion, TokenType.Operator, operators.ToRegex());
Пример #7
0
 public static TGroup ContinueWithOperator <TGroup>(this ITokenMatcherItemGroup <TGroup> group, params string[] operators)
 => group.ContinueWith(null, TokenType.Operator, operators.ToRegex());
Пример #8
0
 public static TGroup ContinueWithOperator <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName, string[] operators)
 => group.ContinueWith(captureName, TokenType.Operator, operators.ToRegex());
Пример #9
0
 public static TGroup ContinueWithKeyword <TGroup, T>(this ITokenMatcherItemGroup <TGroup> group, string captureName, Func <Token, T> captureConversion, params string[] keywords)
 => group.ContinueWith(captureName, captureConversion, TokenType.Keyword, keywords.ToRegex());
Пример #10
0
 public static TGroup ContinueWithOperator <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string @operator)
 => group.ContinueWith(null, TokenType.Operator, @operator.ToRegex());
Пример #11
0
 public static TGroup ContinueWithOptional <TGroup, T>(this ITokenMatcherItemGroup <TGroup> group, string captureName, Func <Token, T> captureConversion, TokenType typeMask, Regex textPattern)
 => group.AddItem(new TokenMatcherOptional(new TokenMatcherItem(captureName, captureConversion, typeMask, textPattern)));
Пример #12
0
 public static TGroup ContinueWithOptionalOperator <TGroup, T>(this ITokenMatcherItemGroup <TGroup> group, string captureName, Func <Token, T> captureConversion, string @operator)
 => group.ContinueWithOptional(captureName, captureConversion, TokenType.Operator, @operator.ToRegex());
Пример #13
0
 public static TGroup ContinueWithExpression <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName)
 => group.AddItem(new TokenMatcherExpressionItem(captureName));
Пример #14
0
 public static TGroup ContinueWithIdentifier <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName)
 => group.ContinueWith(captureName, TokenType.Identifier, null);
Пример #15
0
 public static TGroup ContinueWith <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName, TokenType typeMask, Regex textPattern)
 => group.AddItem(new TokenMatcherItem(captureName, null, typeMask, textPattern));
Пример #16
0
 public static TGroup ContinueWithMany <TGroup>(this ITokenMatcherItemGroup <TGroup> group, Action <TokenMatcherGroup> configuration, int minimum = 1, int maximum = int.MaxValue)
 => group.ContinueWithMany(null, configuration, minimum, maximum);
Пример #17
0
 public static TGroup ContinueWithOptionalGroup <TGroup>(this ITokenMatcherItemGroup <TGroup> group, Action <TokenMatcherGroup> configuration)
 => group.ContinueWithOptionalGroup(null, configuration);
Пример #18
0
 public static TGroup ContinueWithValue <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName)
 => group.ContinueWith(captureName, t => t.GetValue(), TokenType.Value, null);
Пример #19
0
 public static TGroup ContinueWithKeyword <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string keyword)
 => group.ContinueWith(null, TokenType.Keyword, keyword.ToRegex());
Пример #20
0
 public static TGroup ContinueWithOptional <TGroup>(this ITokenMatcherItemGroup <TGroup> group, TokenType typeMask, Regex textPattern)
 => group.ContinueWithOptional(null, typeMask, textPattern);
Пример #21
0
 public static TGroup ContinueWithKeyword <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName, string[] keywords)
 => group.ContinueWith(captureName, TokenType.Keyword, keywords.ToRegex());
Пример #22
0
 public static TGroup ContinueWithOptionalKeyword <TGroup>(this ITokenMatcherItemGroup <TGroup> group, params string[] keywords)
 => group.ContinueWithOptional(null, TokenType.Keyword, keywords.ToRegex());
Пример #23
0
 public static TGroup ContinueWithOptionalKeyword <TGroup, T>(this ITokenMatcherItemGroup <TGroup> group, string captureName, Func <Token, T> captureConversion, string keyword)
 => group.ContinueWithOptional(captureName, captureConversion, TokenType.Keyword, keyword.ToRegex());