public static Token Parse(string s, CultureInfo cultureInfo) { if (string.IsNullOrEmpty(s)) { return(new NullToken()); } int length = s.Length; int startingPos = 0; return(ParseUnion(ref startingPos, false).Optimize()); Token ParseUnion(ref int pos, bool mustClose) { UnionToken unionToken = new UnionToken(); ConcatenationToken concatenationToken = null; int startpos = pos; bool closed = false; while (pos < length) { Token token = null; if (TryMatchCharacter(ref pos, Token.GroupBegin)) { // parse group token = ParseUnion(ref pos, true); } else if (mustClose && TryMatchCharacter(ref pos, Token.GroupEnd)) { closed = true; break; } else if (TryMatchCharacter(ref pos, Token.GroupSeparator)) { unionToken.Tokens.Add(concatenationToken as Token ?? new NullToken()); concatenationToken = null; continue; } else if (TryMatchCharacter(ref pos, Token.RangeBegin)) { // parse range token = ParseRange(ref pos); } else if (TryParseCharacterClass(ref pos, out string characters)) { token = new CharsetToken(characters); } int savedpos = pos; if (TryParseQuantifier(ref pos, out int minlen, out int maxlen)) { if (token == null) { throw new ArgumentException(string.Format( CultureInfo.InvariantCulture, Properties.Resources.E_InvalidRegex_TokenNotQuantifiable, s, savedpos)); } token.MinCount = minlen; token.MaxCount = maxlen; }
public IParseFunction Visit(UnionToken target) => VisitUnion(target.Union, isMemoized, model);
protected override IParseResult TryGetTokenWithoutNullCheck(IStringStream inputStream, out IToken token) { inputStream.Pop(); token = new UnionToken(_initialStreamPosition); return(new SuccessParseResult()); }