public bool TryMatch(string src, int startIndex, out Token tok) { var match = regex.Match(src, startIndex); if (match.Success) { var span = new Span(startIndex, startIndex + match.Length); if (kind.HasValue()) { tok = new Token(span, kind, match.Value); } else { tok = new Token(span, kind); } return(true); } else { tok = null; return(false); } }