protected override IEnumerable<ParseStep> GetFailParseSteps(IRegexEngine engine, State initialState, State currentState, bool skipAdvance) { yield return ParseStep.Fail(this, initialState, currentState); if (!skipAdvance) { engine.State = engine.State.Advance(); yield return ParseStep.AdvanceIndex(this, engine.State); } }
protected override IEnumerable<ParseStep> GetSuccessParseStep(IRegexEngine engine, State initialState) { var matchedText = engine.Input.Substring(initialState.Index, engine.State.Index - initialState.Index); IList<IList<ParenCapture>> captureSet = new List<IList<ParenCapture>>(); foreach (CapturingParens capturingParen in Children.FindBy(node => node is CapturingParens)) { var captures = engine.GetCaptures(capturingParen.Number); captureSet.Add(new ReadOnlyCollection<ParenCapture>(captures.ToList())); engine.PopCapture(capturingParen.Number); } yield return ParseStep.Match(this, initialState, matchedText, new ReadOnlyCollection<IList<ParenCapture>>(captureSet)); if (initialState.Index == engine.State.Index) { // If we had a successful match, and the engine didn't move, we need to move it ourselves now. engine.State = engine.State.Advance(); yield return ParseStep.AdvanceIndex(this, engine.State); } yield return ParseStep.BeginParse(this, engine.State); }
internal static ParseStep StateSaved(RegexNode node, State currentState, string message) { return new ParseStep { Type = ParseStepType.StateSaved, Node = node, CurrentState = currentState }.WithMessage(step => message); }
internal static ParseStep Pass(RegexNode node, string matchedText, State initialState, State currentState) { return new ParseStep { Type = ParseStepType.Pass, Node = node, MatchedText = matchedText, InitialState = initialState, CurrentState = currentState }.WithMessage(step => node.GetPassMessage(step.MatchedText, step.InitialState)); }
internal static ParseStep Match(Regex regex, State initialState, string matchedText, IList<IList<ParenCapture>> captures) { return new ParseStep { Type = ParseStepType.Match, Node = regex, MatchedText = matchedText, InitialState = initialState, Captures = captures }.WithMessage(step => regex.GetPassMessage(step.MatchedText, step.InitialState)); }
internal static ParseStep Fail(RegexNode node, State initialState, State currentState, string additionalMessage = null) { return new ParseStep { Type = ParseStepType.Fail, Node = node, InitialState = initialState, CurrentState = currentState }.WithMessage(step => (additionalMessage != null ? additionalMessage + ": " : "") + node.GetFailMessage(step.InitialState)); }
internal static ParseStep EndOfString(RegexNode node, State currentState) { return new ParseStep { Type = ParseStepType.EndOfString, Node = node, CurrentState = currentState }.WithMessage(step => "End of string"); }
internal static ParseStep Capture(RegexNode node, string capturedText, int captureNumber, State initialState, State currentState) { return new ParseStep { Type = ParseStepType.Capture, Node = node, MatchedText = capturedText, CaptureNumber = captureNumber, InitialState = initialState, CurrentState = currentState }.WithMessage(step => string.Format( "Captured '{0}' (capture number: {1}) starting at index {2}", step.MatchedText, step.CaptureNumber, step.InitialState.Index)); }
protected abstract IEnumerable<ParseStep> GetSuccessParseStep(IRegexEngine engine, State initialState);
internal static ParseStep AdvanceIndex(RegexNode node, State state) { return new ParseStep { Type = ParseStepType.AdvanceIndex, Node = node, CurrentState = state, }.WithMessage(step => string.Format("Advanced index to {0}", step.CurrentState.Index)); }
public static ParseStep StartLookaround(RegexNode node, State currentState) { return new ParseStep { Type = ParseStepType.LookaroundStart, Node = node, CurrentState = currentState }.WithMessage(step => "Look-around started"); }
public static ParseStep ResetIndex(RegexNode node, State initialState, State currentState) { return new ParseStep { Type = ParseStepType.ResetIndex, Node = node, InitialState = initialState, CurrentState = currentState }.WithMessage(step => string.Format("Resetting index to {0}", step.InitialState.Index)); }
public static ParseStep BeginParse(RegexNode node, State initialState) { return new ParseStep { Type = ParseStepType.BeginParse, Node = node, InitialState = initialState }.WithMessage(step => "Parse started"); }
public RegexEngineInternal(string input) { _input = input; State = new State(input, 0); }
public SavedState(IEnumerator<ParseStep> enumerator, LinkedListNode<RegexNode> item, State currentState) { _item = item; _state = currentState; _enumerator = enumerator; }
internal static ParseStep Backtrack(RegexNode node, State initialState, State backtrackState) { return new ParseStep { Type = ParseStepType.Backtrack, Node = node, InitialState = initialState, CurrentState = backtrackState }.WithMessage(step => string.Format("Backtracking to {0}", step.CurrentState.Index)); }
protected abstract IEnumerable<ParseStep> GetFailParseSteps(IRegexEngine engine, State initialState, State currentState, bool skipAdvance);