/// <summary> /// Returns the mapper type for an item, or null if it is not a mapper type /// </summary> /// <param name="item">The item to investigate</param> /// <returns>The mapper type or null</returns> public static Type MapperType(BNFItem item) { return (item.GetType().IsConstructedGenericType&& item.GetType().GetGenericTypeDefinition() == typeof(Mapper <>) ? item.GetType().GetGenericArguments().First() : null); }
/// <summary> /// Constructs a new match /// </summary> /// <param name="token">The token that matched</param> /// <param name="item">The item that matched</param> /// <param name="subMatches">Submatches</param> public Match(BNFItem token, ParseToken item, Match[] subMatches, bool matched) { Token = token; Item = item; SubMatches = subMatches; Matched = matched; }
/// <summary> /// Constructs a new mapper item /// </summary> /// <param name="token">The token being matched</param> /// <param name="matcher">The matcher function</param> public static Mapper <T> Mapper <T>(BNFItem token, Func <Match, T> matcher) { return(new BNF.Mapper <T>(token, matcher)); }
/// <summary> /// The token in the sequence /// </summary> /// <param name="sequence">The token to repeat</param> public static Sequence Sequence(BNFItem sequence) { return(new BNF.Sequence(sequence)); }
/// <summary> /// Constructs a new optional item /// </summary> /// <param name="item">The item to parse</param> public static Optional Optional(BNFItem token) { return(new BNF.Optional(token)); }
/// <summary> /// Constructs a new mapper item /// </summary> /// <param name="token">The token being matched</param> /// <param name="matcher">The matcher function</param> public Mapper(BNFItem token, Func <Match, T> matcher) { Matcher = matcher; Token = token; }