예제 #1
0
        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);
            }
        }
예제 #2
0
        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);
        }
예제 #3
0
 internal static ParseStep StateSaved(RegexNode node, State currentState, string message)
 {
     return new ParseStep
     {
         Type = ParseStepType.StateSaved,
         Node = node,
         CurrentState = currentState
     }.WithMessage(step => message);
 }
예제 #4
0
 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));
 }
예제 #5
0
 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));
 }
예제 #6
0
 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));
 }
예제 #7
0
 internal static ParseStep EndOfString(RegexNode node, State currentState)
 {
     return new ParseStep
     {
         Type = ParseStepType.EndOfString,
         Node = node,
         CurrentState = currentState
     }.WithMessage(step => "End of string");
 }
예제 #8
0
 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));
 }
예제 #9
0
 protected abstract IEnumerable<ParseStep> GetSuccessParseStep(IRegexEngine engine, State initialState);
예제 #10
0
 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));
 }
예제 #11
0
 public static ParseStep StartLookaround(RegexNode node, State currentState)
 {
     return new ParseStep
     {
         Type = ParseStepType.LookaroundStart,
         Node = node,
         CurrentState = currentState
     }.WithMessage(step => "Look-around started");
 }
예제 #12
0
 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));
 }
예제 #13
0
 public static ParseStep BeginParse(RegexNode node, State initialState)
 {
     return new ParseStep
     {
         Type = ParseStepType.BeginParse,
         Node = node,
         InitialState = initialState
     }.WithMessage(step => "Parse started");
 }
예제 #14
0
 public RegexEngineInternal(string input)
 {
     _input = input;
     State = new State(input, 0);
 }
예제 #15
0
 public SavedState(IEnumerator<ParseStep> enumerator, LinkedListNode<RegexNode> item, State currentState)
 {
     _item = item;
     _state = currentState;
     _enumerator = enumerator;
 }
예제 #16
0
 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));
 }
예제 #17
0
 protected abstract IEnumerable<ParseStep> GetFailParseSteps(IRegexEngine engine, State initialState, State currentState, bool skipAdvance);