protected override bool OnParse(ParseResult result, bool errorPass) { if (_inner.Count == 0) { return(false); } if (result.GetIsInfiniteRecursion()) { return(result.Error(ParseError.InvalidGrammar, "Grammar contains left recursion")); } var results = ResultPool.CreateList(); ParseResult bestResult = null; foreach (var parser in _inner) { var inner = result.Peek(parser, errorPass); results.Add(inner); if (inner.IsBetterThan(bestResult)) { bestResult = inner; } } Debug.Assert(bestResult != null, "bestResult != null"); if (bestResult.Success) { result.Apply(bestResult, errorPass); ResultPool.ReleaseList(results); return(true); } var max = results.Max(x => x.MaxErrorIndex); foreach (var parseResult in results) { if (parseResult.MaxErrorIndex == max) { result.Error(parseResult, errorPass); } } ResultPool.ReleaseList(results); return(false); }
public ResultHelper(ResultPool resultPool) { _resultPool = resultPool; _resultOwner = new ResultMemoryOwner(resultPool); }
public ResultMemoryOwner(ResultPool resultPool) { _resultPool = resultPool; }