/// <summary> /// The actual matching method of the token kind against the input text. /// </summary> protected override sealed MatchResult Match(IInputText text) { var peek = text.Peek(_symbol.Length); if (peek == _symbol) { return(MatchResult.Succeed(peek)); } return(MatchResult.Fail); }
protected static Token GetToken(IInputText text, IEnumerable <MatchableTokenKind> tokenKinds) { foreach (var kind in tokenKinds) { if (kind.TryMatch(text, out Token token)) { return(token); } } return(null); }
protected virtual Token GetToken(IInputText text) { foreach (var kind in TokenKinds) { if (kind.TryMatch(text, out Token token)) { return(token); } } return(null); }
public TwoOperandsCalculator(IOutputText outputText, IInputText inputText) { this.OutputText = outputText; this.InputText = inputText; this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.PreOperatorNumber, 0, MemoryFieldNames.Categories.Standard)); this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.PostOperatorNumber, 0, MemoryFieldNames.Categories.Standard)); this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.YearsNumber, 0, MemoryFieldNames.Categories.Special)); this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.EffectiveInterestNumber, 0, MemoryFieldNames.Categories.Special)); this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.StartNumber, 0, MemoryFieldNames.Categories.Special)); this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.RateNumber, 0, MemoryFieldNames.Categories.Special)); this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.EndNumber, 0, MemoryFieldNames.Categories.Special)); this.MemoryFields.Add(new SimpleMemoryField <int>(MemoryFieldNames.RatesPerAnnumNumber, 12, MemoryFieldNames.Categories.Special)); this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.NominalInterestRateNumber, 0, MemoryFieldNames.Categories.Special)); this.MemoryFields.Add(new SimpleMemoryField <double>(MemoryFieldNames.RepaymentRateNumber, 0, MemoryFieldNames.Categories.Special)); this.MemoryFields.Add(new SimpleMemoryField <bool>(MemoryFieldNames.IsAdvance, false, MemoryFieldNames.Categories.Special)); }
/// <summary> /// Tries to match the token kind against the input text. /// </summary> /// <param name="text">The input text. Not null.</param> /// <param name="token">The token of this kind if matching succeeds. Null otherwise.</param> /// <returns></returns> public bool TryMatch(IInputText text, out Token token) { var match = Match(text); if (match.Success) { var matchValue = match.Value; if (string.IsNullOrEmpty(matchValue)) { throw new InvalidOperationException("A successful match should always yield a non-empty lexeme."); } token = new Token(this, text.Position, matchValue); return(true); } token = null; return(false); }
public TokenizationException(IInputText inputText, string message) : base(message) { InputText = inputText; }
/// <summary> /// Creates a lexeme for the token. /// </summary> /// <param name="text">The input text. Not null.</param> /// <remarks>The text position should not be amended.</remarks> protected abstract string CreateLexeme(IInputText text);
/// <summary> /// Creates a token of this kind at the current position of input text. /// </summary> /// <param name="text">The input text. Not null.</param> public Token CreateTokenAtCurrentPosition(IInputText text) { return(new Token(this, text.Position, CreateLexeme(text))); }
/// <summary> /// The actual matching against the input text. /// </summary> /// <returns>The matching result. Not null. A successful match should always yield a non-empty lexeme.</returns> protected abstract MatchResult Match(IInputText text);
/// <summary> /// Returns null. /// </summary> /// <param name="text">The input text. Not used.</param> protected sealed override string CreateLexeme(IInputText text) => null;
/// <summary> /// Creates a lexeme for the token by peeking 50 characters starting at the current position. /// </summary> /// <param name="text">The input text. Not null.</param> /// <remarks>The text position is not be amended.</remarks> protected sealed override string CreateLexeme(IInputText text) => text.Peek(50);
/// <summary> /// The actual matching method of the token kind against the input text. /// </summary> protected override sealed MatchResult Match(IInputText text) => text.Match(_regex);
protected Token CreateUnknownToken(IInputText text) => _unknown.CreateTokenAtCurrentPosition(text);