Exemplo n.º 1
0
        protected override int InnerParse(ParseArgs args)
        {
            var count = Items.Count;

            if (HasNamedChildren)
            {
                args.Push();
                for (int i = 0; i < count; i++)
                {
                    var parser = Items[i];
                    if (parser != null)
                    {
                        var match = parser.Parse(args);
                        if (match < 0)
                        {
                            args.ClearMatches();
                        }
                        else
                        {
                            args.PopSuccess();
                            return(match);
                        }
                    }
                    else
                    {
                        args.PopFailed();
                        return(0);
                    }
                }
                args.PopFailed();
            }
            else
            {
                for (int i = 0; i < count; i++)
                {
                    var parser = Items[i];
                    if (parser != null)
                    {
                        var match = parser.Parse(args);
                        if (match >= 0)
                        {
                            return(match);
                        }
                    }
                    else
                    {
                        return(0);
                    }
                }
            }
            return(-1);
        }
Exemplo n.º 2
0
        protected override int InnerParse(ParseArgs args)
        {
            if (!HasNamedChildren)
            {
                var match = Inner.Parse(args);

                return(match < 0 ? 0 : match);
            }
            else
            {
                args.Push();
                var match = Inner.Parse(args);

                if (match >= 0)
                {
                    args.PopSuccess();
                    return(match);
                }
                args.PopFailed();
                return(0);
            }
        }
Exemplo n.º 3
0
		protected override int InnerParse(ParseArgs args)
		{
			if (!HasNamedChildren)
			{
				var match = Inner.Parse(args);

				return match < 0 ? 0 : match;
			}
			else
			{
				args.Push();
				var match = Inner.Parse(args);

				if (match >= 0)
				{
					args.PopSuccess();
					return match;
				}
				args.PopFailed();
				return 0;
			}
		}
Exemplo n.º 4
0
        protected override int InnerParse(ParseArgs args)
        {
            var scanner = args.Scanner;
            int count   = 0;
            var pos     = scanner.Position;
            int length  = 0;

            // retrieve up to the maximum number
            var sepMatch = 0;

            if (Inner != null)
            {
                while (count < Maximum)
                {
                    int curPos = scanner.Position;
                    if (Until != null && count >= Minimum)
                    {
                        int stopMatch;
                        if (skipUntilMatches)
                        {
                            args.Push();
                            stopMatch = Until.Parse(args);
                            args.PopFailed();
                        }
                        else
                        {
                            stopMatch = Until.Parse(args);
                        }
                        if (stopMatch >= 0)
                        {
                            if (CaptureUntil)
                            {
                                length += stopMatch;
                            }
                            else if (!SkipUntil)
                            {
                                scanner.Position = curPos;
                            }
                            return(length);
                        }
                    }

                    if (hasChildMatch)
                    {
                        args.Push();
                    }

                    if (separator != null && count > 0)
                    {
                        sepMatch = separator.Parse(args);
                        if (sepMatch < 0)
                        {
                            if (hasChildMatch)
                            {
                                args.PopFailed();
                            }
                            break;
                        }
                    }

                    var childMatch = Inner.Parse(args);
                    if (childMatch > 0)
                    {
                        if (hasChildMatch)
                        {
                            args.PopSuccess();
                        }
                        length += childMatch + sepMatch;
                        count++;
                    }
                    else
                    {
                        if (hasChildMatch)
                        {
                            args.PopFailed();
                        }
                        if (sepMatch > 0)
                        {
                            scanner.Position = curPos;
                        }
                        break;
                    }
                }
            }
            else
            {
                while (count < Maximum)
                {
                    int curPos = scanner.Position;
                    if (Until != null && count >= Minimum)
                    {
                        int stopMatch;
                        if (skipUntilMatches)
                        {
                            args.Push();
                            stopMatch = Until.Parse(args);
                            args.PopFailed();
                        }
                        else
                        {
                            stopMatch = Until.Parse(args);
                        }
                        if (stopMatch >= 0)
                        {
                            if (CaptureUntil)
                            {
                                length += stopMatch;
                            }
                            else if (!SkipUntil)
                            {
                                scanner.Position = curPos;
                            }
                            return(length);
                        }
                    }

                    if (separator != null && count > 0)
                    {
                        sepMatch = separator.Parse(args);
                        if (sepMatch < 0)
                        {
                            break;
                        }
                    }

                    var ofs = scanner.Advance(1);
                    if (ofs >= 0)
                    {
                        length += sepMatch;
                        length++;
                        count++;
                    }
                    else
                    {
                        if (sepMatch > 0)
                        {
                            scanner.Position = curPos;
                        }
                        break;
                    }
                }
            }

            if (count < Minimum)
            {
                scanner.Position = pos;
                return(-1);
            }

            return(length);
        }