public AbstractToken NextToken()
{
// Loop through all tokens and check if they match the input string
foreach (KeyValuePair<Type, string> pair in _dictionary)
{
Match match;
if (pair.Key == typeof (Comment))
{
match = Regex.Match(_input.Substring(_counter), pair.Value, RegexOptions.Multiline);
}
else
{
// TODO: See if substring does not impose a to harsh performance drop
match = Regex.Match(_input.Substring(_counter), pair.Value);
}
if (!match.Success)
{
continue;
}
_counter += match.Value.Length;
if (!pair.Key.IsSubclassOf(typeof (AbstractToken)))
{
continue;
}
// Create new instance of the specified type with the found value as parameter
AbstractToken token = (AbstractToken)Activator.CreateInstance(pair.Key, new object[] { match.Value, _counter - match.Value.Length }, null);
return token;
}
throw new MatchException(_input[_counter].ToString(CultureInfo.InvariantCulture), _counter);
}