Exemple #1
0
 /// <summary>
 /// Returns a parser success of <paramref name="value"/>.
 /// </summary>
 /// <typeparam name="T">The return type of the parser.</typeparam>
 /// <typeparam name="TToken">The type of the tokens.</typeparam>
 /// <param name="value">The value to succeed with.</param>
 /// <returns>The parser created.</returns>
 public static Parser <T, TToken> Value <T, TToken>(T value) =>
 input => ParserResult.Success(value, input);
Exemple #2
0
 /// <summary>
 /// Returns a parser error with message <paramref name="errorMessage"/>.
 /// </summary>
 /// <typeparam name="T">The return type of the parser.</typeparam>
 /// <typeparam name="TToken">The type of the tokens.</typeparam>
 /// <param name="errorMessage">The error message to return.</param>
 /// <returns>The parser created.</returns>
 public static Parser <T, TToken> Error <T, TToken>(string errorMessage) =>
 input => ParserResult.Error <T, TToken>(errorMessage, input);
Exemple #3
0
 /// <summary>
 /// Parses a singular lexeme from the input and advances the input by one.
 /// Returns an error with <paramref name="errorMessage"/> if the input is empty.
 /// </summary>
 /// <typeparam name="TToken">The type of the tokens.</typeparam>
 /// <param name="errorMessage">The error message to return.</param>
 /// <returns>The parser created.</returns>
 public static Parser <Lexeme <TToken>, TToken> One <TToken>(string errorMessage) =>
 input =>
 input.Length == 0
         ? ParserResult.Error <Lexeme <TToken>, TToken>(errorMessage, input)
         : ParserResult.Success(input[0], input.Advance(1));