/// <summary> /// Compiles the pattern. /// </summary> public static IEnumerable <iToken> Compile(string pPattern) { List <iToken> tokens = new List <iToken>(); StringReader reader = new StringReader(pPattern); int c; while ((c = reader.Read()) != -1) { string s = ((char)c).ToString(CultureInfo.InvariantCulture); switch (s) { case "#": tokens.Add(new TokenDigit()); break; case "@": tokens.Add(new TokenAlpha()); break; case "*": tokens.Add(new TokenWild()); break; case "|": tokens.Add(new TokenOr()); break; case "(": tokens.Add(new TokenGroup(ReadGroup(reader))); break; case "[": tokens.Add(new TokenSet(ReadSet(reader))); break; case "?": iToken prev = tokens.LastOrDefault(); if (prev == null) { continue; } tokens.Remove(prev); tokens.Add(new TokenOptional(prev)); break; default: if (TokenWild.All.Contains(s) || s == ".") { tokens.Add(new TokenStatic(s)); } break; } } return(tokens); }
/// <summary> /// Constructor /// </summary> public TokenOptional(iToken pToken) { _token = pToken; }