Exemplo n.º 1
0
        public static void SetRequiredParen(CleanupAstNodeStates states)
        {
            for (var i = 2; i < states.Count; i++)
            {
                var closeToken = states[i];
                if (closeToken.Token != TokenKind.CloseSquared)
                    continue;
                var openToken = states[i];
                if (openToken.Token != TokenKind.OpenSquared)
                    continue;
                closeToken.Token = TokenKind.Comma;
                closeToken.Content = ",";
            }
            for (var i = states.Count - 1; i > 0; i--)
            {
                var openToken = states[i];
                if (openToken.Token != TokenKind.OpenSquared)
                    continue;

                var idToken = states[i - 1];
                if (idToken.Token != TokenKind.Identifier)
                    continue;
                var closeTokenId = states.GetNextMachingTokenKind(TokenKind.CloseSquared, TokenKind.OpenSquared, i);

                var toAdd = new List<ParseNode>();
                for (var addRange = i; addRange <= closeTokenId; addRange++)
                {
                    toAdd.Add(states[addRange].Clone());
                }
                states.InsertRange(i - 1, toAdd);
                i += toAdd.Count;

                closeTokenId = states.GetNextMachingTokenKind(TokenKind.CloseSquared, TokenKind.OpenSquared, i);
                states.RemoveRange(i, closeTokenId);
            }
        }
Exemplo n.º 2
0
        static void AddExplicitCastIntToString(CleanupAstNodeStates blockStates, int startRange, bool isFunction)
        {
            int insertPos;
            if (!isFunction)
                insertPos = startRange + 1;
            else
                insertPos = blockStates.GetNextMachingTokenKind(TokenKind.CloseParen, TokenKind.OpenParen, startRange) + 1;
            var addTokens = new List<ParseNode>
                {
                    TokenKind.Dot.BuildTokenFromId(),
                    TokenKind.Identifier.BuildTokenFromId("ConvStr"),
                    TokenKind.OpenParen.BuildTokenFromId(),
                    TokenKind.CloseParen.BuildTokenFromId(),
                };

            blockStates.InsertRange(insertPos, addTokens);
        }
Exemplo n.º 3
0
 static bool ComputeInsertCastPosition(CleanupAstNodeStates states, int assign, out int tokenToInsert)
 {
     tokenToInsert = assign + 2;
     if (states[tokenToInsert].Token == TokenKind.OpenParen)
     {
         var matchingCloseParen = states.GetNextMachingTokenKind(TokenKind.CloseParen, TokenKind.OpenParen,
                                                                 tokenToInsert);
         tokenToInsert = matchingCloseParen + 1;
     }
     if (states[tokenToInsert].Token != TokenKind.SemiColon)
         return true;
     return false;
 }