protected int RunLexerUntil(int stopAt)
 {
     if (_lexer.InputPosition < stopAt)
     {
         int startAt = _lexer.InputPosition;
         _tokens.ClearSpace(startAt, stopAt - startAt);
         _nestedTokens.ClearSpace(startAt, stopAt - startAt);
         for (Maybe <Token> t_; _lexer.InputPosition < stopAt && (t_ = _lexer.NextToken()).HasValue;)
         {
             Token t = t_.Value;
             if (t.EndIndex > stopAt)
             {
                 _tokens.ClearSpace(t.StartIndex, t.Length);
                 _nestedTokens.ClearSpace(t.StartIndex, t.Length);
             }
             if (t.Children != null)
             {
                 foreach (var ct in t.Children)
                 {
                     _nestedTokens[ct.StartIndex] = new EditorToken(ct.TypeInt, ct.Length, ct.Value);
                 }
             }
             if (!IsWhitespace(t.TypeInt))
             {
                 var et = new EditorToken(t.TypeInt, t.Length, t.Value);
                 _tokens[t.StartIndex] = StoreLexerError(et);
             }
         }
         if (_lexerError != null && _tokens.Count != 0)
         {
             _tokens.Last = StoreLexerError(_tokens.Last);
         }
     }
     return(_lexer.InputPosition);
 }
Exemple #2
0
        public void TestClearSpace()
        {
            for (int iter = 0; iter < 10; iter++)
            {
                int i1 = MathEx.Square(_r.Next(50)) + 1;                      // e.g. 100
                int i0 = _r.Next(i1);                                         // e.g. 50
                int i2 = i1 + MathEx.Square(_r.Next(50)) + 1;                 // e.g. 100
                int i3 = i2 + _r.Next(2500);                                  // e.g. 1000

                SparseAList <int> list = new SparseAList <int>();
                list.ClearSpace(0, i1);
                Assert.AreEqual(i1, list.Count);
                Assert.AreEqual(0, list.GetRealItemCount());
                Assert.AreEqual(0, list[i1 - 1]);
                if (_testExceptions)
                {
                    Assert.Throws <ArgumentOutOfRangeException>(() => { var _ = list[i1]; });
                    Assert.Throws <ArgumentOutOfRangeException>(() => { list.ClearSpace(0, -1); });
                    Assert.Throws <ArgumentOutOfRangeException>(() => { list.ClearSpace(-1, 10); });
                }
                list.ClearSpace(i0, i2 - i0);
                Assert.AreEqual(i2, list.Count);
                Assert.AreEqual(0, list.GetRealItemCount());
                for (int i = i0; i < i2; i++)
                {
                    list[i] = i;
                }
                list.ClearSpace(i1, i3 - i1);
                Assert.AreEqual(i3, list.Count);
                Assert.AreEqual(i1 - i0, list.GetRealItemCount());
                list.ClearSpace(i0 + 1, i1 - (i0 + 1));
                Assert.AreEqual(i3, list.Count);
                Assert.AreEqual(1, list.GetRealItemCount());
                list.ClearSpace(0, i0 + 1);
                Assert.AreEqual(i3, list.Count);
                Assert.AreEqual(0, list.GetRealItemCount());
            }
        }