示例#1
0
        /// <summary>
        /// parses ( Variable list ) in CREATE FUNCTION, CREATE VIEW, CREATE PROCEDURE, CREATE TRIGGER 
        /// adds a newline for each comma in 
        /// CREATE PROC name (@variable, @variable)
        /// </summary>
        private void Parse_CREATE(ref ParseItem i_Item)
        {
            i_Item = i_Item.Next;
            switch (getCmd(i_Item))
            {
                case eCmd.Function:
                case eCmd.Procedure:
                case eCmd.Trigger:
                case eCmd.View:
                    break;
                default:
                    return; // CREATE command not supported (e.g. CREATE DATABASE)
            }

            i_Item = i_Item.Next;
            if (getType(i_Item) != eType.Unknown)
                return; // name of procedure, function,... is missing

            // Set linebreak after name
            ParseItem.SetLinebreakAfter(i_Item, 1);

            // indent only the outermost parenthesis (not "varchar(128)") if it contains a comma
            int s32_Parenth  = 0;
            bool  b_Indented = false;
            bool  b_RemoveLF = true;
            do
            {
                Application.DoEvents();
                if (mb_Abort)
                    return;

                i_Item = i_Item.Next;
                switch (getType(i_Item))
                {
                    case eType.ParOpen:
                        if (s32_Parenth == 0)
                        {
                            if (i_Item.Contains(eType.Comma)) // ( .. , .. , .. )
                            {
                                i_Item.Indent = eIndent.DoubleLF;
                                b_Indented = true;
                            }
                        }
                        s32_Parenth++;
                        break;

                    case eType.ParClose:
                        s32_Parenth--;
                        if (b_Indented && s32_Parenth == 0)
                        {
                            i_Item.Outdent = eIndent.DoubleLF;
                            b_Indented = false;
                        }
                        break;

                    case eType.LineBreak:
                        if (b_RemoveLF)
                            i_Item.Remove(false); // remove user linebreaks
                        break;

                    case eType.Comma: // newline for each comma in CREATE (@variable, @variable)
                        if (getType(i_Item.Next) != eType.CommentL)
                            ParseItem.SetLinebreakAfter(i_Item, 1);
                        break;

                    case eType.Keyword:
                        switch (i_Item.Cmd)
                        {
                            case eCmd.As:
                                if (s32_Parenth == 0) // ignore AS inside parenthesis
                                {
                                    ParseItem.SetLinebreakBefore(i_Item, 1);
                                    return; // stop parsing here
                                }
                                break;

                            case eCmd.On: // Trigger
                                ParseItem.SetLinebreakBefore(i_Item, 1);
                                b_RemoveLF = false; // no further linebreak parsing for triggers
                                break;

                            case eCmd.Returns: // Function
                                ParseItem.SetLinebreakBefore(i_Item, 1);
                                break;
                        }
                        break;

                    case eType.Comand:
                        switch (i_Item.Cmd)
                        {
                            // in a Trigger these words are keywords and not commands
                            case eCmd.Delete:
                            case eCmd.Insert:
                            case eCmd.Update:
                                i_Item.Type = eType.Keyword;
                                break;
                        }
                        break;
                }
            }
            while (i_Item != null);
        }