protected override int InnerParse(ParseArgs args) { var scanner = args.Scanner; int count = 0; var pos = scanner.Position; int length = 0; while (count < Maximum) { int curPos = scanner.Position; int stopMatch; if (skipMatches) { args.Push(); stopMatch = Inner.Parse(args); args.PopFailed(); } else { stopMatch = Inner.Parse(args); } if (stopMatch >= 0) { if (Capture) length += stopMatch; else if (!Skip) scanner.Position = curPos; break; } var ofs = scanner.Advance(1); if (ofs >= 0) { length++; count++; } else { scanner.Position = curPos; break; } } if (count < Minimum) { scanner.Position = pos; return -1; } return length; }
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; }
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; } }
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 (separator != null && count > 0) { sepMatch = separator.Parse(args); if (sepMatch < 0) break; } var childMatch = Inner.Parse(args); if (childMatch > 0) { length += childMatch + sepMatch; count++; } else { 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; }
protected override int InnerParse(ParseArgs args) { if (args.IsRoot) { var scanner = args.Scanner; var pos = scanner.Position; args.Push(); var match = Inner.Parse(args); MatchCollection matches = null; if (match >= 0 && !AllowPartialMatch && !scanner.IsEof) { args.PopFailed(); scanner.Position = pos; match = -1; } else { matches = args.Pop(); } IEnumerable<Parser> errors = null; if (args.Errors != null) { var errorList = new List<Parser>(args.Errors.Count); for (int i = 0; i < args.Errors.Count; i++) { var error = args.Errors[i]; if (!errorList.Contains(error)) errorList.Add(error); } errors = errorList; } args.Root = new GrammarMatch(this, scanner, pos, match, matches, args.ErrorIndex, args.ChildErrorIndex, errors); return match; } return base.InnerParse(args); }