/// <summary> /// Tries to parse any of specified words. /// </summary> public bool ParseWord(LexicalState state, bool ignoreCase, params string[] words) { if (state.IsEndOfData) { return(false); } foreach (string word in words) { if (state.Position + word.Length > state.Length) { continue; } string captured = state.Get(state.Position, word.Length); bool matches = ignoreCase ? String.Compare(captured, word, StringComparison.OrdinalIgnoreCase) == 0 : captured == word; if (matches) { state.AddIncrement(Key, word.Length); return(true); } } return(false); }
/// <summary> /// Tries to parse a single character using specified function. /// </summary> public bool ParseCharacter(LexicalState state, Func <char, bool> check) { if (state.IsEndOfData) { return(false); } if (!check(state.Get(state.Position))) { return(false); } state.AddIncrement(Key, 1); return(true); }
/// <summary> /// Tries to parse a single character using specified function. /// </summary> public bool ParseCharacter(LexicalState state, Func<char, bool> check) { if (state.IsEndOfData) return false; if (!check(state.Get(state.Position))) return false; state.AddIncrement(Key, 1); return true; }
/// <summary> /// Tries to parse any of specified words. /// </summary> public bool ParseWord(LexicalState state, bool ignoreCase, params string[] words) { if (state.IsEndOfData) return false; foreach (string word in words) { if (state.Position + word.Length > state.Length) continue; string captured = state.Get(state.Position, word.Length); bool matches = ignoreCase ? String.Compare(captured, word, StringComparison.OrdinalIgnoreCase) == 0 : captured == word; if (matches) { state.AddIncrement(Key, word.Length); return true; } } return false; }