2009-08-23 02:24:48 +00:00
|
|
|
/**
|
|
|
|
* Scintilla source code edit control
|
|
|
|
* @file LexMySQL.cxx
|
|
|
|
* Lexer for MySQL
|
|
|
|
*
|
2013-08-28 00:44:27 +00:00
|
|
|
* Improved by Mike Lischke <mike.lischke@oracle.com>
|
2009-08-23 02:24:48 +00:00
|
|
|
* Adopted from LexSQL.cxx by Anders Karlsson <anders@mysql.com>
|
|
|
|
* Original work by Neil Hodgson <neilh@scintilla.org>
|
|
|
|
* Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>
|
|
|
|
* The License.txt file describes the conditions under which this software may be distributed.
|
|
|
|
*/
|
2009-04-26 18:59:23 +00:00
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdarg.h>
|
2010-08-21 23:59:56 +00:00
|
|
|
#include <assert.h>
|
|
|
|
#include <ctype.h>
|
2009-04-26 18:59:23 +00:00
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
#include "ILexer.h"
|
|
|
|
#include "Scintilla.h"
|
|
|
|
#include "SciLexer.h"
|
2009-04-26 18:59:23 +00:00
|
|
|
|
2010-08-21 23:59:56 +00:00
|
|
|
#include "WordList.h"
|
|
|
|
#include "LexAccessor.h"
|
2009-04-26 18:59:23 +00:00
|
|
|
#include "Accessor.h"
|
|
|
|
#include "StyleContext.h"
|
2010-08-21 23:59:56 +00:00
|
|
|
#include "CharacterSet.h"
|
|
|
|
#include "LexerModule.h"
|
2009-04-26 18:59:23 +00:00
|
|
|
|
|
|
|
using namespace Scintilla;
|
|
|
|
|
|
|
|
static inline bool IsAWordChar(int ch) {
|
|
|
|
return (ch < 0x80) && (isalnum(ch) || ch == '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsAWordStart(int ch) {
|
|
|
|
return (ch < 0x80) && (isalpha(ch) || ch == '_');
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool IsANumberChar(int ch) {
|
|
|
|
// Not exactly following number definition (several dots are seen as OK, etc.)
|
|
|
|
// but probably enough in most cases.
|
|
|
|
return (ch < 0x80) &&
|
|
|
|
(isdigit(ch) || toupper(ch) == 'E' ||
|
|
|
|
ch == '.' || ch == '-' || ch == '+');
|
|
|
|
}
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the current content context represent a keyword and set the context state if so.
|
|
|
|
*/
|
2013-08-28 00:44:27 +00:00
|
|
|
static void CheckForKeyword(StyleContext& sc, WordList* keywordlists[], int activeState)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position length = sc.LengthCurrent() + 1; // +1 for the next char
|
2009-08-23 02:24:48 +00:00
|
|
|
char* s = new char[length];
|
|
|
|
sc.GetCurrentLowered(s, length);
|
|
|
|
if (keywordlists[0]->InList(s))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_MAJORKEYWORD | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (keywordlists[1]->InList(s))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_KEYWORD | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (keywordlists[2]->InList(s))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_DATABASEOBJECT | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (keywordlists[3]->InList(s))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_FUNCTION | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (keywordlists[5]->InList(s))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_PROCEDUREKEYWORD | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (keywordlists[6]->InList(s))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_USER1 | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (keywordlists[7]->InList(s))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_USER2 | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (keywordlists[8]->InList(s))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_USER3 | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
delete [] s;
|
|
|
|
}
|
2009-04-26 18:59:23 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
2009-04-26 18:59:23 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
#define HIDDENCOMMAND_STATE 0x40 // Offset for states within a hidden command.
|
|
|
|
#define MASKACTIVE(style) (style & ~HIDDENCOMMAND_STATE)
|
|
|
|
|
|
|
|
static void SetDefaultState(StyleContext& sc, int activeState)
|
|
|
|
{
|
|
|
|
if (activeState == 0)
|
|
|
|
sc.SetState(SCE_MYSQL_DEFAULT);
|
|
|
|
else
|
|
|
|
sc.SetState(SCE_MYSQL_HIDDENCOMMAND);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ForwardDefaultState(StyleContext& sc, int activeState)
|
|
|
|
{
|
|
|
|
if (activeState == 0)
|
|
|
|
sc.ForwardSetState(SCE_MYSQL_DEFAULT);
|
|
|
|
else
|
|
|
|
sc.ForwardSetState(SCE_MYSQL_HIDDENCOMMAND);
|
|
|
|
}
|
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
static void ColouriseMySQLDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *keywordlists[],
|
2009-08-23 02:24:48 +00:00
|
|
|
Accessor &styler)
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
StyleContext sc(startPos, length, initStyle, styler, 127);
|
|
|
|
int activeState = (initStyle == SCE_MYSQL_HIDDENCOMMAND) ? HIDDENCOMMAND_STATE : initStyle & HIDDENCOMMAND_STATE;
|
2009-04-26 18:59:23 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
for (; sc.More(); sc.Forward())
|
|
|
|
{
|
2009-04-26 18:59:23 +00:00
|
|
|
// Determine if the current state should terminate.
|
2013-08-28 00:44:27 +00:00
|
|
|
switch (MASKACTIVE(sc.state))
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
|
|
|
case SCE_MYSQL_OPERATOR:
|
2013-08-28 00:44:27 +00:00
|
|
|
SetDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case SCE_MYSQL_NUMBER:
|
|
|
|
// We stop the number definition on non-numerical non-dot non-eE non-sign char.
|
|
|
|
if (!IsANumberChar(sc.ch))
|
2013-08-28 00:44:27 +00:00
|
|
|
SetDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case SCE_MYSQL_IDENTIFIER:
|
|
|
|
// Switch from identifier to keyword state and open a new state for the new char.
|
|
|
|
if (!IsAWordChar(sc.ch))
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
CheckForKeyword(sc, keywordlists, activeState);
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
// Additional check for function keywords needed.
|
|
|
|
// A function name must be followed by an opening parenthesis.
|
2013-08-28 00:44:27 +00:00
|
|
|
if (MASKACTIVE(sc.state) == SCE_MYSQL_FUNCTION && sc.ch != '(')
|
|
|
|
{
|
|
|
|
if (activeState > 0)
|
|
|
|
sc.ChangeState(SCE_MYSQL_HIDDENCOMMAND);
|
|
|
|
else
|
|
|
|
sc.ChangeState(SCE_MYSQL_DEFAULT);
|
|
|
|
}
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
SetDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_MYSQL_VARIABLE:
|
|
|
|
if (!IsAWordChar(sc.ch))
|
2013-08-28 00:44:27 +00:00
|
|
|
SetDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case SCE_MYSQL_SYSTEMVARIABLE:
|
|
|
|
if (!IsAWordChar(sc.ch))
|
|
|
|
{
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position length = sc.LengthCurrent() + 1;
|
2009-08-23 02:24:48 +00:00
|
|
|
char* s = new char[length];
|
|
|
|
sc.GetCurrentLowered(s, length);
|
|
|
|
|
|
|
|
// Check for known system variables here.
|
|
|
|
if (keywordlists[4]->InList(&s[2]))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_KNOWNSYSTEMVARIABLE | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
delete [] s;
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
SetDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_MYSQL_QUOTEDIDENTIFIER:
|
|
|
|
if (sc.ch == '`')
|
|
|
|
{
|
|
|
|
if (sc.chNext == '`')
|
|
|
|
sc.Forward(); // Ignore it
|
|
|
|
else
|
2013-08-28 00:44:27 +00:00
|
|
|
ForwardDefaultState(sc, activeState);
|
2009-04-26 18:59:23 +00:00
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case SCE_MYSQL_COMMENT:
|
|
|
|
if (sc.Match('*', '/'))
|
|
|
|
{
|
|
|
|
sc.Forward();
|
2013-08-28 00:44:27 +00:00
|
|
|
ForwardDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_MYSQL_COMMENTLINE:
|
|
|
|
if (sc.atLineStart)
|
2013-08-28 00:44:27 +00:00
|
|
|
SetDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case SCE_MYSQL_SQSTRING:
|
|
|
|
if (sc.ch == '\\')
|
|
|
|
sc.Forward(); // Escape sequence
|
|
|
|
else
|
|
|
|
if (sc.ch == '\'')
|
|
|
|
{
|
|
|
|
// End of single quoted string reached?
|
|
|
|
if (sc.chNext == '\'')
|
|
|
|
sc.Forward();
|
|
|
|
else
|
2013-08-28 00:44:27 +00:00
|
|
|
ForwardDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_MYSQL_DQSTRING:
|
|
|
|
if (sc.ch == '\\')
|
|
|
|
sc.Forward(); // Escape sequence
|
|
|
|
else
|
|
|
|
if (sc.ch == '\"')
|
|
|
|
{
|
|
|
|
// End of single quoted string reached?
|
|
|
|
if (sc.chNext == '\"')
|
|
|
|
sc.Forward();
|
|
|
|
else
|
2013-08-28 00:44:27 +00:00
|
|
|
ForwardDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
2013-08-28 00:44:27 +00:00
|
|
|
case SCE_MYSQL_PLACEHOLDER:
|
|
|
|
if (sc.Match('}', '>'))
|
|
|
|
{
|
|
|
|
sc.Forward();
|
|
|
|
ForwardDefaultState(sc, activeState);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (sc.state == SCE_MYSQL_HIDDENCOMMAND && sc.Match('*', '/'))
|
|
|
|
{
|
|
|
|
activeState = 0;
|
|
|
|
sc.Forward();
|
|
|
|
ForwardDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
2009-04-26 18:59:23 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
// Determine if a new state should be entered.
|
2013-08-28 00:44:27 +00:00
|
|
|
if (sc.state == SCE_MYSQL_DEFAULT || sc.state == SCE_MYSQL_HIDDENCOMMAND)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
|
|
|
switch (sc.ch)
|
|
|
|
{
|
|
|
|
case '@':
|
|
|
|
if (sc.chNext == '@')
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_SYSTEMVARIABLE | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
sc.Forward(2); // Skip past @@.
|
|
|
|
}
|
|
|
|
else
|
|
|
|
if (IsAWordStart(sc.ch))
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_VARIABLE | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
sc.Forward(); // Skip past @.
|
|
|
|
}
|
|
|
|
else
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_OPERATOR | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case '`':
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_QUOTEDIDENTIFIER | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case '#':
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_COMMENTLINE | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case '\'':
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_SQSTRING | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case '\"':
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_DQSTRING | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext)))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_NUMBER | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (IsAWordStart(sc.ch))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_IDENTIFIER | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (sc.Match('/', '*'))
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_COMMENT | activeState);
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2019-05-04 18:14:48 +00:00
|
|
|
// Skip first char of comment introducer and check for hidden command.
|
|
|
|
// The second char is skipped by the outer loop.
|
|
|
|
sc.Forward();
|
|
|
|
if (sc.GetRelativeCharacter(1) == '!')
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
2019-05-04 18:14:48 +00:00
|
|
|
// Version comment found. Skip * now.
|
|
|
|
sc.Forward();
|
2013-08-28 00:44:27 +00:00
|
|
|
activeState = HIDDENCOMMAND_STATE;
|
2009-08-23 02:24:48 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_HIDDENCOMMAND);
|
|
|
|
}
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
else if (sc.Match('<', '{'))
|
|
|
|
{
|
|
|
|
sc.SetState(SCE_MYSQL_PLACEHOLDER | activeState);
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
if (sc.Match("--"))
|
|
|
|
{
|
|
|
|
// Special MySQL single line comment.
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_COMMENTLINE | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
sc.Forward(2);
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
// Check the third character too. It must be a space or EOL.
|
|
|
|
if (sc.ch != ' ' && sc.ch != '\n' && sc.ch != '\r')
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.ChangeState(SCE_MYSQL_OPERATOR | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
if (isoperator(static_cast<char>(sc.ch)))
|
2013-08-28 00:44:27 +00:00
|
|
|
sc.SetState(SCE_MYSQL_OPERATOR | activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
// Do a final check for keywords if we currently have an identifier, to highlight them
|
|
|
|
// also at the end of a line.
|
|
|
|
if (sc.state == SCE_MYSQL_IDENTIFIER)
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
CheckForKeyword(sc, keywordlists, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
|
|
|
|
// Additional check for function keywords needed.
|
|
|
|
// A function name must be followed by an opening parenthesis.
|
|
|
|
if (sc.state == SCE_MYSQL_FUNCTION && sc.ch != '(')
|
2013-08-28 00:44:27 +00:00
|
|
|
SetDefaultState(sc, activeState);
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
sc.Complete();
|
2009-04-26 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Helper function to determine if we have a foldable comment currently.
|
|
|
|
*/
|
|
|
|
static bool IsStreamCommentStyle(int style)
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
return MASKACTIVE(style) == SCE_MYSQL_COMMENT;
|
2009-04-26 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Code copied from StyleContext and modified to work here. Should go into Accessor as a
|
|
|
|
* companion to Match()...
|
|
|
|
*/
|
2019-05-04 18:14:48 +00:00
|
|
|
static bool MatchIgnoreCase(Accessor &styler, Sci_Position currentPos, const char *s)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
2019-05-04 18:14:48 +00:00
|
|
|
for (Sci_Position n = 0; *s; n++)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
|
|
|
if (*s != tolower(styler.SafeGetCharAt(currentPos + n)))
|
|
|
|
return false;
|
|
|
|
s++;
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2009-04-26 18:59:23 +00:00
|
|
|
// Store both the current line's fold level and the next lines in the
|
|
|
|
// level store to make it easy to pick up with each increment.
|
2019-05-04 18:14:48 +00:00
|
|
|
static void FoldMySQLDoc(Sci_PositionU startPos, Sci_Position length, int initStyle, WordList *[], Accessor &styler)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
2009-04-26 18:59:23 +00:00
|
|
|
bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
|
|
|
|
bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
|
|
|
|
bool foldOnlyBegin = styler.GetPropertyInt("fold.sql.only.begin", 0) != 0;
|
|
|
|
|
|
|
|
int visibleChars = 0;
|
2019-05-04 18:14:48 +00:00
|
|
|
Sci_Position lineCurrent = styler.GetLine(startPos);
|
2009-04-26 18:59:23 +00:00
|
|
|
int levelCurrent = SC_FOLDLEVELBASE;
|
2009-08-23 02:24:48 +00:00
|
|
|
if (lineCurrent > 0)
|
2009-04-26 18:59:23 +00:00
|
|
|
levelCurrent = styler.LevelAt(lineCurrent - 1) >> 16;
|
|
|
|
int levelNext = levelCurrent;
|
2009-08-23 02:24:48 +00:00
|
|
|
|
2009-04-26 18:59:23 +00:00
|
|
|
int styleNext = styler.StyleAt(startPos);
|
|
|
|
int style = initStyle;
|
2013-08-28 00:44:27 +00:00
|
|
|
int activeState = (style == SCE_MYSQL_HIDDENCOMMAND) ? HIDDENCOMMAND_STATE : style & HIDDENCOMMAND_STATE;
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2010-09-05 22:56:27 +00:00
|
|
|
bool endPending = false;
|
|
|
|
bool whenPending = false;
|
|
|
|
bool elseIfPending = false;
|
2009-08-23 02:24:48 +00:00
|
|
|
|
|
|
|
char nextChar = styler.SafeGetCharAt(startPos);
|
2019-05-04 18:14:48 +00:00
|
|
|
for (Sci_PositionU i = startPos; length > 0; i++, length--)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
2009-04-26 18:59:23 +00:00
|
|
|
int stylePrev = style;
|
2013-08-28 00:44:27 +00:00
|
|
|
int lastActiveState = activeState;
|
2009-04-26 18:59:23 +00:00
|
|
|
style = styleNext;
|
|
|
|
styleNext = styler.StyleAt(i + 1);
|
2013-08-28 00:44:27 +00:00
|
|
|
activeState = (style == SCE_MYSQL_HIDDENCOMMAND) ? HIDDENCOMMAND_STATE : style & HIDDENCOMMAND_STATE;
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
char currentChar = nextChar;
|
|
|
|
nextChar = styler.SafeGetCharAt(i + 1);
|
|
|
|
bool atEOL = (currentChar == '\r' && nextChar != '\n') || (currentChar == '\n');
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2013-08-28 00:44:27 +00:00
|
|
|
switch (MASKACTIVE(style))
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
|
|
|
case SCE_MYSQL_COMMENT:
|
|
|
|
if (foldComment)
|
|
|
|
{
|
2013-08-28 00:44:27 +00:00
|
|
|
// Multiline comment style /* .. */ just started or is still in progress.
|
|
|
|
if (IsStreamCommentStyle(style) && !IsStreamCommentStyle(stylePrev))
|
|
|
|
levelNext++;
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_MYSQL_COMMENTLINE:
|
|
|
|
if (foldComment)
|
2019-05-04 18:14:48 +00:00
|
|
|
{
|
2009-08-23 02:24:48 +00:00
|
|
|
// Not really a standard, but we add support for single line comments
|
|
|
|
// with special curly braces syntax as foldable comments too.
|
|
|
|
// MySQL needs -- comments to be followed by space or control char
|
2010-07-12 22:19:51 +00:00
|
|
|
if (styler.Match(i, "--"))
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
|
|
|
char chNext2 = styler.SafeGetCharAt(i + 2);
|
|
|
|
char chNext3 = styler.SafeGetCharAt(i + 3);
|
|
|
|
if (chNext2 == '{' || chNext3 == '{')
|
|
|
|
levelNext++;
|
|
|
|
else
|
|
|
|
if (chNext2 == '}' || chNext3 == '}')
|
|
|
|
levelNext--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case SCE_MYSQL_HIDDENCOMMAND:
|
2013-08-28 00:44:27 +00:00
|
|
|
/*
|
2010-09-05 22:56:27 +00:00
|
|
|
if (endPending)
|
|
|
|
{
|
|
|
|
// A conditional command is not a white space so it should end the current block
|
|
|
|
// before opening a new one.
|
|
|
|
endPending = false;
|
|
|
|
levelNext--;
|
|
|
|
if (levelNext < SC_FOLDLEVELBASE)
|
|
|
|
levelNext = SC_FOLDLEVELBASE;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
}*/
|
|
|
|
if (activeState != lastActiveState)
|
2009-08-23 02:24:48 +00:00
|
|
|
levelNext++;
|
|
|
|
break;
|
|
|
|
case SCE_MYSQL_OPERATOR:
|
2010-09-05 22:56:27 +00:00
|
|
|
if (endPending)
|
|
|
|
{
|
|
|
|
endPending = false;
|
|
|
|
levelNext--;
|
|
|
|
if (levelNext < SC_FOLDLEVELBASE)
|
|
|
|
levelNext = SC_FOLDLEVELBASE;
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
if (currentChar == '(')
|
|
|
|
levelNext++;
|
|
|
|
else
|
|
|
|
if (currentChar == ')')
|
2010-09-05 22:56:27 +00:00
|
|
|
{
|
2009-08-23 02:24:48 +00:00
|
|
|
levelNext--;
|
2010-09-05 22:56:27 +00:00
|
|
|
if (levelNext < SC_FOLDLEVELBASE)
|
|
|
|
levelNext = SC_FOLDLEVELBASE;
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
break;
|
|
|
|
case SCE_MYSQL_MAJORKEYWORD:
|
|
|
|
case SCE_MYSQL_KEYWORD:
|
|
|
|
case SCE_MYSQL_FUNCTION:
|
|
|
|
case SCE_MYSQL_PROCEDUREKEYWORD:
|
|
|
|
// Reserved and other keywords.
|
|
|
|
if (style != stylePrev)
|
|
|
|
{
|
2010-09-05 22:56:27 +00:00
|
|
|
// END decreases the folding level, regardless which keyword follows.
|
|
|
|
bool endFound = MatchIgnoreCase(styler, i, "end");
|
|
|
|
if (endPending)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
|
|
|
levelNext--;
|
|
|
|
if (levelNext < SC_FOLDLEVELBASE)
|
|
|
|
levelNext = SC_FOLDLEVELBASE;
|
|
|
|
}
|
|
|
|
else
|
2010-09-05 22:56:27 +00:00
|
|
|
if (!endFound)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
2010-09-05 22:56:27 +00:00
|
|
|
if (MatchIgnoreCase(styler, i, "begin"))
|
|
|
|
levelNext++;
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
2010-09-05 22:56:27 +00:00
|
|
|
{
|
|
|
|
if (!foldOnlyBegin)
|
|
|
|
{
|
|
|
|
bool whileFound = MatchIgnoreCase(styler, i, "while");
|
|
|
|
bool loopFound = MatchIgnoreCase(styler, i, "loop");
|
|
|
|
bool repeatFound = MatchIgnoreCase(styler, i, "repeat");
|
|
|
|
bool caseFound = MatchIgnoreCase(styler, i, "case");
|
|
|
|
|
|
|
|
if (whileFound || loopFound || repeatFound || caseFound)
|
|
|
|
levelNext++;
|
2009-08-23 02:24:48 +00:00
|
|
|
else
|
|
|
|
{
|
2010-09-05 22:56:27 +00:00
|
|
|
// IF alone does not increase the fold level as it is also used in non-block'ed
|
|
|
|
// code like DROP PROCEDURE blah IF EXISTS.
|
|
|
|
// Instead THEN opens the new level (if not part of an ELSEIF or WHEN (case) branch).
|
|
|
|
if (MatchIgnoreCase(styler, i, "then"))
|
|
|
|
{
|
|
|
|
if (!elseIfPending && !whenPending)
|
|
|
|
levelNext++;
|
|
|
|
else
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
2010-09-05 22:56:27 +00:00
|
|
|
elseIfPending = false;
|
|
|
|
whenPending = false;
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
2010-09-05 22:56:27 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Neither of if/then/while/loop/repeat/case, so check for
|
|
|
|
// sub parts of IF and CASE.
|
|
|
|
if (MatchIgnoreCase(styler, i, "elseif"))
|
|
|
|
elseIfPending = true;
|
|
|
|
if (MatchIgnoreCase(styler, i, "when"))
|
|
|
|
whenPending = true;
|
|
|
|
}
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
2010-09-05 22:56:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2010-09-05 22:56:27 +00:00
|
|
|
// Keep the current end state for the next round.
|
|
|
|
endPending = endFound;
|
|
|
|
}
|
|
|
|
break;
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2010-09-05 22:56:27 +00:00
|
|
|
default:
|
2013-08-28 00:44:27 +00:00
|
|
|
if (!isspacechar(currentChar) && endPending)
|
2010-09-05 22:56:27 +00:00
|
|
|
{
|
|
|
|
// END followed by a non-whitespace character (not covered by other cases like identifiers)
|
|
|
|
// also should end a folding block. Typical case: END followed by self defined delimiter.
|
|
|
|
levelNext--;
|
|
|
|
if (levelNext < SC_FOLDLEVELBASE)
|
|
|
|
levelNext = SC_FOLDLEVELBASE;
|
2009-08-23 02:24:48 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-08-28 00:44:27 +00:00
|
|
|
|
|
|
|
// Go up one level if we just ended a multi line comment.
|
|
|
|
if (IsStreamCommentStyle(stylePrev) && !IsStreamCommentStyle(style))
|
|
|
|
{
|
|
|
|
levelNext--;
|
|
|
|
if (levelNext < SC_FOLDLEVELBASE)
|
|
|
|
levelNext = SC_FOLDLEVELBASE;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (activeState == 0 && lastActiveState != 0)
|
|
|
|
{
|
|
|
|
// Decrease fold level when we left a hidden command.
|
|
|
|
levelNext--;
|
|
|
|
if (levelNext < SC_FOLDLEVELBASE)
|
|
|
|
levelNext = SC_FOLDLEVELBASE;
|
|
|
|
}
|
|
|
|
|
2010-09-05 22:56:27 +00:00
|
|
|
if (atEOL)
|
2009-08-23 02:24:48 +00:00
|
|
|
{
|
2010-09-05 22:56:27 +00:00
|
|
|
// Apply the new folding level to this line.
|
|
|
|
// Leave pending states as they are otherwise a line break will de-sync
|
|
|
|
// code folding and valid syntax.
|
|
|
|
int levelUse = levelCurrent;
|
|
|
|
int lev = levelUse | levelNext << 16;
|
|
|
|
if (visibleChars == 0 && foldCompact)
|
|
|
|
lev |= SC_FOLDLEVELWHITEFLAG;
|
|
|
|
if (levelUse < levelNext)
|
|
|
|
lev |= SC_FOLDLEVELHEADERFLAG;
|
|
|
|
if (lev != styler.LevelAt(lineCurrent))
|
|
|
|
styler.SetLevel(lineCurrent, lev);
|
2019-05-04 18:14:48 +00:00
|
|
|
|
2010-09-05 22:56:27 +00:00
|
|
|
lineCurrent++;
|
|
|
|
levelCurrent = levelNext;
|
|
|
|
visibleChars = 0;
|
|
|
|
}
|
2010-08-21 23:59:56 +00:00
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
if (!isspacechar(currentChar))
|
2010-09-05 22:56:27 +00:00
|
|
|
visibleChars++;
|
|
|
|
}
|
2009-04-26 18:59:23 +00:00
|
|
|
}
|
|
|
|
|
2009-08-23 02:24:48 +00:00
|
|
|
//--------------------------------------------------------------------------------------------------
|
|
|
|
|
2009-04-26 18:59:23 +00:00
|
|
|
static const char * const mysqlWordListDesc[] = {
|
|
|
|
"Major Keywords",
|
|
|
|
"Keywords",
|
|
|
|
"Database Objects",
|
|
|
|
"Functions",
|
|
|
|
"System Variables",
|
|
|
|
"Procedure keywords",
|
|
|
|
"User Keywords 1",
|
|
|
|
"User Keywords 2",
|
2009-08-23 02:24:48 +00:00
|
|
|
"User Keywords 3",
|
|
|
|
0
|
2009-04-26 18:59:23 +00:00
|
|
|
};
|
|
|
|
|
2015-06-07 21:19:26 +00:00
|
|
|
LexerModule lmMySQL(SCLEX_MYSQL, ColouriseMySQLDoc, "mysql", FoldMySQLDoc, mysqlWordListDesc);
|