/// <summary> /// Creates a parser with a grammar that matches one or more consecutive characters until any of the specified /// stop characters are parsed and joins them into a <see cref="string"/>, excluding the stop character. /// </summary> /// <param name="stops">The characters at which to stop consuming characters.</param> /// <returns>A parser with a grammar that consumes consecutive characters until any stop character is parsed /// or the sequence ends.</returns> protected IParser<char, string> AnyCharacterUntil(params char[] stops) { Contract.Requires(stops != null); Contract.Requires(stops.Length > 0); Contract.Ensures(Contract.Result<IParser<char, string>>() != null); return AnyCharacter.Not(Character(c => stops.Contains(c))).OneOrMore().Join(); }
/// <summary> /// Creates a parser with a grammar that matches one or more consecutive characters until any of the specified /// stop words are parsed and joins them into a <see cref="string"/>, excluding the stop word. /// </summary> /// <param name="stopWords">The strings at which to stop consuming characters.</param> /// <returns>A parser with a grammar that consumes consecutive characters until any stop word is parsed /// or the sequence ends.</returns> protected IParser<char, string> AnyCharacterUntil(params string[] stopWords) { Contract.Requires(stopWords != null); Contract.Requires(stopWords.Length > 0); Contract.Ensures(Contract.Result<IParser<char, string>>() != null); var stops = new List<IParser<char, string>>(); foreach (var word in stopWords) { Contract.Assume(!string.IsNullOrEmpty(word)); stops.Add(Word(word)); } return AnyCharacter.Not(stops.Any()).OneOrMore().Join(); }