protected LexCapture Execute(string name, string pattern, bool advance = true, bool autoAnchor = true) { if (Captures.Count > MaxStack) { throw new InvalidOperationException(); } if (autoAnchor) { pattern = "\\G" + pattern; } var regex = Patterns.GetOrAdd(pattern, p => new Regex(p, RegexOptions.Compiled)); var regMatch = regex.Match(Input, Position); var matchResult = new LexCapture(Position) { Match = regMatch, StackPosition = MatchStack.Count, StackId = CurrentStackId(), Type = new LexToken(name, pattern, advance) }; if (matchResult.Match?.Success == true) { AddCaptureToCaptureHistory(matchResult); } return(matchResult); }
private void AddCaptureToCaptureHistory(LexCapture matchResult) { Captures.Add(matchResult); if (Captures.Count > MaxStack) { throw new InvalidOperationException(); } }