Ejemplo n.º 1
0
        public TokenCollection(Token[] tokenArray)
        {
            this.tokenArray = new Token[tokenArray.Length];

            for (int i = 0; i < tokenArray.Length; i++)
            {
                this.tokenArray[i] = tokenArray[i];
            }
        }
Ejemplo n.º 2
0
 public TokenEnum(Token[] list)
 {
     tokenArray = list;
 }
Ejemplo n.º 3
0
 private IEnumerable<IEnumerable<Token>> BlockOf(IEnumerable<IEnumerable<Token>> TokenEnumeration, Token identifier)
 {
     List<IEnumerable<Token>> block = new List<IEnumerable<Token>>();
     int begin = -1;
     int end = -1;
     bool beginFound = false;
     bool endFound = false;
     int openingsBefore = 0;
     int openingsAfter = 0;
     bool inLine = true; // If I am on the same line, I will not count contraopenings :) take care !
     for (int i = 0; i > -1 && i < TokenEnumeration.Count(); i++)
     {
         for (int j = 0; j >= -1 && i > -1 && j < TokenEnumeration.ElementAt(i).Count() && i < TokenEnumeration.Count(); j++)
         {
             if (TokenEnumeration.ElementAt(i).ElementAt(j).name == identifier.name)
             {
                 while (!beginFound && i > -1)
                 {
                     IEnumerable<Token> ttt = TokenEnumeration.ElementAt(i);
                     if (!inLine)
                     {
                         openingsBefore -= TokenEnumeration.ElementAt(i).Where(t => t.name.Equals("}")).Count();
                     }
                     openingsBefore += TokenEnumeration.ElementAt(i).Where(t => t.name.Equals("{")).Count();
                     if (openingsBefore > 0)
                     {
                         beginFound = true;
                         begin = i;
                     }
                     else
                     {
                         inLine = false;
                         i--;
                     }
                 }
                 if (i == -1)
                 {
                     beginFound = true;
                     i = 0;
                     begin = i;
                 }
             }
             if (beginFound)
             {
                 openingsBefore = 0; // reset counter
                 inLine = true;
                 while (!endFound)
                 {
                     if (!inLine)
                     {
                         openingsBefore -= TokenEnumeration.ElementAt(i).Where(t => t.name.Equals("{")).Count();
                     }
                     openingsBefore += TokenEnumeration.ElementAt(i).Where(t => t.name.Equals("}")).Count();
                     if (openingsBefore > 0)
                     {
                         block.Add(TokenEnumeration.ElementAt(i));
                         endFound = true;
                         end = i;
                     }
                     else
                     {
                         inLine = false;
                         block.Add(TokenEnumeration.ElementAt(i));
                         i++;
                     }
                 }
             }
             if (beginFound && endFound)
             { break; }
             //if (i == -1) i = TokenEnumeration.Count()+20;
         }
         if (beginFound && endFound)
         { break; }
     }
     return block;
 }