protected override ParsingResult ProcessCharacterImpl(IParsingContext context, char nextChar) { ParsingResult finalResult = ParsingResult.Match; System.Diagnostics.Debug.Assert(currentCharacterIndex < tokenToMatch.Length * 2); int currentCompareCharacterIndex = currentCharacterIndex % tokenToMatch.Length; if (nextChar == tokenToMatch[currentCompareCharacterIndex]) { currentCharacterIndex++; if (this.currentCharacterIndex == tokenToMatch.Length * 2) { if (this.errorState != null) { context.CurrentState = this.errorState; context.Append(this.tokenToMatch); } else { finalResult = ParsingResult.Done; } this.currentCharacterIndex = 0; } } else { if (currentCharacterIndex == 0) { finalResult = ParsingResult.Miss; } else if (currentCompareCharacterIndex == currentCharacterIndex) { context.CurrentState = this.errorState; context.Append(this.tokenToMatch.Substring(0, this.currentCharacterIndex)); finalResult = ParsingResult.Miss; } else { context.CurrentState = this.nextState; context.Append(this.tokenToMatch.Substring(0, currentCompareCharacterIndex)); finalResult = ParsingResult.Miss; } this.currentCharacterIndex = 0; } return(finalResult); }
public ParsingResult ProcessCharacter(IParsingContext context, char nextChar) { ArgumentVerifier.CheckObjectArgument(context, "context"); foreach (IParsingState parsingState in nextStates) { ParsingResult result = parsingState.ProcessCharacter(context, nextChar); if (result != ParsingResult.Miss) { if (context.CurrentState == this) { // If the current state has not changed in the ProcessCharacter call, // we should change it now. context.CurrentState = parsingState; } return(result); } } context.Append(nextChar); return(ParsingResult.Match); }
protected virtual ParsingResult ProcessCharacterImpl(IParsingContext context, char nextChar) { ParsingResult finalResult = ParsingResult.Match; System.Diagnostics.Debug.Assert(currentCharacterIndex < tokenToMatch.Length); if (nextChar == tokenToMatch[currentCharacterIndex]) { currentCharacterIndex++; if (this.currentCharacterIndex == tokenToMatch.Length) { if (this.nextState != null) { context.CurrentState = this.nextState; } else { finalResult = ParsingResult.Done; } this.currentCharacterIndex = 0; } } else { if (currentCharacterIndex == 0) { finalResult = ParsingResult.Miss; } else { context.CurrentState = this.errorState; context.Append(this.tokenToMatch.Substring(0, this.currentCharacterIndex)); finalResult = ParsingResult.Miss; } this.currentCharacterIndex = 0; } return finalResult; }
public ParsingResult ProcessCharacter(IParsingContext context, char nextChar) { ArgumentVerifier.CheckObjectArgument(context, "context"); foreach (IParsingState parsingState in nextStates) { ParsingResult result = parsingState.ProcessCharacter(context, nextChar); if (result != ParsingResult.Miss) { if (context.CurrentState == this) { // If the current state has not changed in the ProcessCharacter call, // we should change it now. context.CurrentState = parsingState; } return result; } } context.Append(nextChar); return ParsingResult.Match; }