Exemplo n.º 1
0
 /// <summary>
 /// Invokes all mappers of the given type and returns the result
 /// and the BNF match for each item
 /// </summary>
 /// <param name="source">The list of tokens to examine</param>
 /// <param name="instance">The instance to match, or <c>null</c> to match any</param>
 /// <typeparam name="T">The mapper type to match</typeparam>
 /// <returns>A sequence of the invoked mappers and the match tokens</returns>
 private IEnumerable <Tuple <T, Match> > GetMappers <T>(IEnumerable <Match> source, BNF.Mapper <T> instance = null)
 {
     return(source
            .Where(n => n.Matched)
            .Where(n => n.Token is BNF.Mapper <T>)
            .Where(n => instance == null || n.Token == instance)
            .Select(n =>
                    new Tuple <T, Match>(
                        ((BNF.Mapper <T>)n.Token).Matcher(n),
                        n
                        )
                    ));
 }
Exemplo n.º 2
0
 /// <summary>
 /// Invokes all mappers of the given type and returns the result
 /// and the BNF match for each item, but does not recurse into submatches
 /// </summary>
 /// <param name="instance">The instance to match</param>
 /// <typeparam name="T">The mapper type to match</typeparam>
 /// <returns>A sequence of the invoked mappers and the match tokens</returns>
 public IEnumerable <Tuple <T, Match> > GetFirstLevelMappers <T>(BNF.Mapper <T> instance = null)
 {
     return(GetMappers(this.SubMatches, instance));
 }
Exemplo n.º 3
0
 /// <summary>
 /// Invokes all mappers of the given type and returns the result
 /// and the BNF match for each item
 /// </summary>
 /// <param name="instance">The instance to match, or <c>null</c> to match any</param>
 /// <typeparam name="T">The mapper type to match</typeparam>
 /// <returns>A sequence of the invoked mappers and the match tokens</returns>
 public IEnumerable <Tuple <T, Match> > GetMappers <T>(BNF.Mapper <T> instance = null)
 {
     return(GetMappers(Flat, instance));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Invokes all mappers of the given type and returns the result, but does not recurse into submatches
 /// </summary>
 /// <param name="instance">The instance to match, or <c>null</c> to match any</param>
 /// <typeparam name="T">The mapper type to match</typeparam>
 /// <returns>A sequence of the invoked mappers</returns>
 public IEnumerable <T> InvokeFirstLevelMappers <T>(BNF.Mapper <T> instance = null)
 {
     return(GetFirstLevelMappers(instance).Select(x => x.Item1));
 }
Exemplo n.º 5
0
 /// <summary>
 /// Gets the first mapper that has the given instance
 /// </summary>
 /// <param name="instance">The instance to find</param>
 /// <typeparam name="T">The mapped type</typeparam>
 /// <returns>The item returned by the mapper</returns>
 public T FirstOrDefaultMapper <T>(BNF.Mapper <T> instance)
 {
     return(InvokeMappers(instance).FirstOrDefault());
 }
Exemplo n.º 6
0
 /// <summary>
 /// Gets the last mapper that has the given instance
 /// </summary>
 /// <param name="instance">The instance to find</param>
 /// <typeparam name="T">The mapped type</typeparam>
 /// <returns>The item returned by the mapper</returns>
 public T LastMapper <T>(BNF.Mapper <T> instance)
 {
     return(InvokeMappers(instance).Last());
 }