Beispiel #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)));
        }
Beispiel #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)));
        }
Beispiel #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));
        }
Beispiel #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));
        }
Beispiel #5
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)));
Beispiel #6
0
 public static TGroup ContinueWithExpression <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName)
 => group.AddItem(new TokenMatcherExpressionItem(captureName));
Beispiel #7
0
 public static TGroup ContinueWith <TGroup>(this ITokenMatcherItemGroup <TGroup> group, string captureName, TokenType typeMask, Regex textPattern)
 => group.AddItem(new TokenMatcherItem(captureName, null, typeMask, textPattern));