BibtexLibrary.Tokenizer.Tokenizer.NextToken C# (CSharp) Метод

NextToken() публичный Метод

public NextToken ( ) : AbstractToken
Результат AbstractToken
        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);
        }

Usage Example

Пример #1
0
        public void TestTokenizer1()
        {
            Tokenizer tokenizer = new Tokenizer(new ExpressionDictionary(), "test");

            Assert.AreEqual(new Text("test"),tokenizer.NextToken());
        }
All Usage Examples Of BibtexLibrary.Tokenizer.Tokenizer::NextToken