internal MappingParsingRule( ParsingRule <T> content, Func <T, TResult> func) { Content = content; Func = func; }
/// <summary> /// Creates a grammar rule that matches a <see cref="Lexical.Token"/> of the specified <see cref="Lexeme"/>, and converts the matched <see cref="Lexical.Token"/> to the parsing result using the specified converter. /// </summary> /// <typeparam name="TResult">The type of the parsing result.</typeparam> /// <param name="lexeme">The specified <see cref="Lexeme"/> of the <see cref="Lexical.Token"/> to match.</param> /// <param name="func">The converter from the matched <see cref="Lexical.Token"/> to the parsing result.</param> /// <returns>The grammar rule created that matches a <see cref="Lexical.Token"/> of <paramref name="lexeme"/>.</returns> /// <exception cref="ArgumentNullException">The parameter is <see langword="null"/>.</exception> public static ParsingRule <TResult> GetParsingRule <TResult>( this Lexeme lexeme, Func <Token, TResult> func) { if (lexeme == null || func == null) { throw new ArgumentNullException(); } return(ParsingRule <TResult> .Token(lexeme, func)); }
internal RepeatingParsingRule( ParsingRule <T> content, Func <IEnumerable <T>, TResult> func, int min, int max) { Content = content; Func = func; Min = min; Max = max; }
/// <summary> /// Creates the union of the current parsing rule and another. /// </summary> /// <param name="rule">The other parsing rule.</param> /// <returns>The union of the current parsing rule and the other.</returns> /// <exception cref="ArgumentNullException">The parameter is <see langword="null"/>.</exception> public ParsingRule <TResult> Or(ParsingRule <TResult> rule) { if (rule == null) { throw new ArgumentNullException(); } else { return(new AlternateParsingRule <TResult>(this, rule)); } }
/// <summary> /// Creates the concatenation of the current parsing rule and another. /// </summary> /// <typeparam name="T2">The type of the result of the other parsing rule.</typeparam> /// <typeparam name="TR">The type of the final parsing result.</typeparam> /// <param name="rule">The other parsing rule.</param> /// <param name="func">The converter that combines the results from the two parsing rules to the final parsing result.</param> /// <returns>The concatenation of the current parsing rule and the other.</returns> /// <exception cref="ArgumentNullException">The parameter is <see langword="null"/>.</exception> public ParsingRule <TR> Concat <T2, TR>(ParsingRule <T2> rule, Func <TResult, T2, TR> func) { if (rule == null || func == null) { throw new ArgumentNullException(); } else { return(new ConcatenateParsingRule <TResult, T2, TR>(this, rule, func)); } }
/// <summary> /// Creates the union of two grammar rules. /// </summary> /// <param name="left">The first grammar rule.</param> /// <param name="right">The second grammar rule.</param> /// <returns>The union of the two grammar rules.</returns> /// <exception cref="ArgumentNullException">The parameter is <see langword="null"/>.</exception> public static ParsingRule <TResult> Or <TResult>(ParsingRule <TResult> left, ParsingRule <TResult> right) { if (left == null || right == null) { throw new ArgumentNullException(); } else { return(new AlternateParsingRule <TResult>(left, right)); } }
internal AlternateParsingRule(ParsingRule <TResult> first, ParsingRule <TResult> second) { First = first; Second = second; }
internal ConcatenateParsingRule(ParsingRule <T1> first, ParsingRule <T2> second, Func <T1, T2, TResult> func) { First = first; Second = second; Func = func; }