/// <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); }
private void Parse_CASE(ref ParseItem i_Item) { i_Item.Indent = eIndent.SingleLF; while (i_Item != null && i_Item.Next != null) { Application.DoEvents(); if (mb_Abort) return; i_Item = i_Item.Next; switch (i_Item.Type) { // remove linebreaks which the user has put into the SQL code. // Linebreaks set in ParseParenthesis() are permanent and will not be deleted here! case eType.LineBreak: i_Item.Remove(false); break; case eType.ParOpen: i_Item = i_Item.Next; ParseCommands(ref i_Item); break; case eType.ParClose: // finish parsing on ")" i_Item = i_Item.Prev; return; case eType.Comand: case eType.Keyword: switch (i_Item.Cmd) { case eCmd.When: ParseItem.SetLinebreakBefore(i_Item, 1); break; // ELSE and END are commands in the IF command. // Here they are keywords as part of the SELECT command case eCmd.Else: i_Item.Type = eType.Keyword; ParseItem.SetLinebreakBefore(i_Item, 1); break; case eCmd.End: i_Item.Type = eType.Keyword; i_Item.Outdent = eIndent.DoubleLF; return; } break; } } }