#include "StdAfx.h"
#include "crystallineparser.h"
-#include "../SyntaxColors.h"
-#include "../utils/string_util.h"
-
-#ifdef _DEBUG
-#define new DEBUG_NEW
-#endif
-
-static const TCHAR * s_apszAspKeywordList[] =
- {
- _T ("Abs"),
- _T ("AppActivate"),
- _T ("As"),
- _T ("Asc"),
- _T ("Atn"),
- _T ("Base"),
- _T ("Beep"),
- _T ("CDbl"),
- _T ("CInt"),
- _T ("CLng"),
- _T ("CSng"),
- _T ("CStr"),
- _T ("CVar"),
- _T ("Call"),
- _T ("ChDir"),
- _T ("ChDrive"),
- _T ("CheckBox"),
- _T ("Chr"),
- _T ("Close"),
- _T ("Const"),
- _T ("Cos"),
- _T ("CreateObject"),
- _T ("CreateVerifyItem"),
- _T ("CurDir"),
- _T ("Date"),
- _T ("Declare"),
- _T ("Dialog"),
- _T ("Dim"),
- _T ("Dir"),
- _T ("DlgEnable"),
- _T ("DlgText"),
- _T ("DlgVisible"),
- _T ("Do"),
- _T ("Double"),
- _T ("EOF"),
- _T ("Else"),
- _T ("Else"),
- _T ("End"),
- _T ("End"),
- _T ("Erase"),
- _T ("Error"),
- _T ("Exit"),
- _T ("Exp"),
- _T ("FileCopy"),
- _T ("FileLen"),
- _T ("Fix"),
- _T ("For"),
- _T ("For"),
- _T ("Format"),
- _T ("Function"),
- _T ("Function"),
- _T ("GetAttrName"),
- _T ("GetAttrType"),
- _T ("GetAttrValBool"),
- _T ("GetAttrValEnumInt"),
- _T ("GetAttrValEnumString"),
- _T ("GetAttrValFloat"),
- _T ("GetAttrValInt"),
- _T ("GetAttrValString"),
- _T ("GetClassId"),
- _T ("GetGeoType"),
- _T ("GetObject"),
- _T ("Global"),
- _T ("GoSub"),
- _T ("GoTo"),
- _T ("Hex"),
- _T ("Hour"),
- _T ("If"),
- _T ("If"),
- _T ("InStr"),
- _T ("Input"),
- _T ("Input#"),
- _T ("InputBox"),
- _T ("Int"),
- _T ("IsDate"),
- _T ("IsEmpty"),
- _T ("IsNull"),
- _T ("IsNumeric"),
- _T ("Kill"),
- _T ("LBound"),
- _T ("LCase"),
- _T ("LCase$"),
- _T ("LTrim"),
- _T ("Left"),
- _T ("Left$"),
- _T ("Len"),
- _T ("Let"),
- _T ("Line"),
- _T ("Log"),
- _T ("Long"),
- _T ("Loop"),
- _T ("Mid"),
- _T ("Minute"),
- _T ("MkDir"),
- _T ("Month"),
- _T ("MsgBox"),
- _T ("Name"),
- _T ("Next"),
- _T ("Next"),
- _T ("Now"),
- _T ("Oct"),
- _T ("On"),
- _T ("Open"),
- _T ("Option"),
- _T ("Print"),
- _T ("Print"),
- _T ("RTrim"),
- _T ("Rem"),
- _T ("Return"),
- _T ("Right"),
- _T ("RmDir"),
- _T ("Rnd"),
- _T ("SMDoMenu"),
- _T ("Second"),
- _T ("Seek"),
- _T ("Seek"),
- _T ("Select Case"),
- _T ("SendKeys"),
- _T ("Set"),
- _T ("SetAttrValBool"),
- _T ("SetAttrValEnumInt"),
- _T ("SetAttrValEnumString"),
- _T ("SetAttrValFloat"),
- _T ("SetAttrValInt"),
- _T ("SetAttrValString"),
- _T ("Shell"),
- _T ("Sin"),
- _T ("Space"),
- _T ("Sqr"),
- _T ("Static"),
- _T ("Step"),
- _T ("Stop"),
- _T ("Str"),
- _T ("StrComp"),
- _T ("String"),
- _T ("StringFunction"),
- _T ("Sub"),
- _T ("Tan"),
- _T ("Text"),
- _T ("TextBox"),
- _T ("Then"),
- _T ("Time"),
- _T ("TimeSerial"),
- _T ("TimeValue"),
- _T ("To"),
- _T ("Trim"),
- _T ("Type"),
- _T ("UBound"),
- _T ("UCase"),
- _T ("Val"),
- _T ("VarType"),
- _T ("VerifyCardinalities"),
- _T ("Wend"),
- _T ("Wend"),
- _T ("While"),
- _T ("While"),
- _T ("With"),
- _T ("Write"),
- _T ("Year"),
- };
-
-static bool
-IsAspKeyword (const TCHAR *pszChars, int nLength)
-{
- return ISXKEYWORDI (s_apszAspKeywordList, pszChars, nLength);
-}
unsigned
CrystalLineParser::ParseLineAsp (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
{
- if (nLength == 0)
- return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_USER1);
-
- bool bFirstChar = (dwCookie & ~(COOKIE_EXT_COMMENT|COOKIE_EXT_USER1)) == 0;
- bool bRedefineBlock = true;
- bool bDecIndex = false;
- int nIdentBegin = -1;
- int nPrevI = -1;
- int I=0;
- for (I = 0;; nPrevI = I, I = static_cast<int>(::CharNext(pszChars+I) - pszChars))
- {
- if (I == nPrevI)
- {
- // CharNext did not advance, so we're at the end of the string
- // and we already handled this character, so stop
- break;
- }
-
- if (bRedefineBlock)
- {
- int nPos = I;
- if (bDecIndex)
- nPos = nPrevI;
- if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
- {
- DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
- }
- else if (dwCookie & (COOKIE_CHAR | COOKIE_STRING))
- {
- DEFINE_BLOCK (nPos, COLORINDEX_STRING);
- }
- else if (dwCookie & COOKIE_PREPROCESSOR)
- {
- DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR);
- }
- else if (dwCookie & COOKIE_EXT_USER1)
- {
- DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
- }
- else
- {
- if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.')
- {
- DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
- }
- else
- {
- DEFINE_BLOCK (nPos, COLORINDEX_OPERATOR);
- bRedefineBlock = true;
- bDecIndex = true;
- goto out;
- }
- }
- bRedefineBlock = false;
- bDecIndex = false;
- }
-out:
-
- // Can be bigger than length if there is binary data
- // See bug #1474782 Crash when comparing SQL with with binary data
- if (I >= nLength || pszChars[I] == 0)
- break;
-
- if (dwCookie & COOKIE_COMMENT)
- {
- DEFINE_BLOCK (I, COLORINDEX_COMMENT);
- dwCookie |= COOKIE_COMMENT;
- break;
- }
-
- // String constant "...."
- if (dwCookie & COOKIE_STRING)
- {
- if (pszChars[I] == '"' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
- {
- dwCookie &= ~COOKIE_STRING;
- bRedefineBlock = true;
- }
- continue;
- }
-
- // Char constant '..'
- if (dwCookie & COOKIE_CHAR)
- {
- if (pszChars[I] == '\'' && (I == 0 || I == 1 && pszChars[nPrevI] != '\\' || I >= 2 && (pszChars[nPrevI] != '\\' || *::CharPrev(pszChars, pszChars + nPrevI) == '\\')))
- {
- dwCookie &= ~COOKIE_CHAR;
- bRedefineBlock = true;
- }
- continue;
- }
-
- // Extended comment <!--....-->
- if (dwCookie & COOKIE_EXT_COMMENT)
- {
- if (!(dwCookie & COOKIE_EXT_USER1))
- {
- if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-')
- {
- dwCookie &= ~COOKIE_EXT_COMMENT;
- bRedefineBlock = true;
- }
- }
- continue;
- }
-
- if ((dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '\'')
- {
- DEFINE_BLOCK (I, COLORINDEX_COMMENT);
- dwCookie |= COOKIE_COMMENT;
- break;
- }
-
- // Extended comment <?....?>
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
- {
- dwCookie &= ~COOKIE_EXT_USER1;
- bRedefineBlock = true;
- continue;
- }
- }
-
- // Normal text
- if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '"')
- {
- DEFINE_BLOCK (I, COLORINDEX_STRING);
- dwCookie |= COOKIE_STRING;
- continue;
- }
-
- if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '\'')
- {
- // if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
- if (!I || !xisalnum (pszChars[nPrevI]))
- {
- DEFINE_BLOCK (I, COLORINDEX_STRING);
- dwCookie |= COOKIE_CHAR;
- continue;
- }
- }
-
- if (!(dwCookie & COOKIE_EXT_USER1))
- {
- if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength - 3 && pszChars[I] == '<' && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-')
- {
- DEFINE_BLOCK (I, COLORINDEX_COMMENT);
- I += 3;
- dwCookie |= COOKIE_EXT_COMMENT;
- dwCookie &= ~COOKIE_PREPROCESSOR;
- continue;
- }
- }
-
- if (bFirstChar)
- {
- if (!xisspace (pszChars[I]))
- bFirstChar = false;
- }
-
- // User1 start: <?
- if (I < nLength && pszChars[I] == '<' && I < nLength - 1 && (pszChars[I + 1] == '?' || pszChars[I + 1] == '%'))
- {
- DEFINE_BLOCK (I, COLORINDEX_NORMALTEXT);
- dwCookie |= COOKIE_EXT_USER1;
- nIdentBegin = -1;
- continue;
- }
-
- if (pBuf == nullptr)
- continue; // We don't need to extract keywords,
- // for faster parsing skip the rest of loop
-
- if (xisalnum (pszChars[I]) || pszChars[I] == '.')
- {
- if (nIdentBegin == -1)
- nIdentBegin = I;
- }
- else
- {
- if (nIdentBegin >= 0)
- {
- if (dwCookie & COOKIE_PREPROCESSOR)
- {
- if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
- }
- else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
- }
- else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
- }
- else
- {
- goto next;
- }
- }
- else if (dwCookie & COOKIE_EXT_USER1)
- {
- if (IsAspKeyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
- }
- else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
- }
- else
- {
- bool bFunction = false;
-
- for (int j = I; j < nLength; j++)
- {
- if (!xisspace (pszChars[j]))
- {
- if (pszChars[j] == '(')
- {
- bFunction = true;
- }
- break;
- }
- }
- if (bFunction)
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
- }
- else
- {
- goto next;
- }
- }
- }
- else if (dwCookie & COOKIE_USER1)
- {
- if (IsHtmlUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
- }
- else
- {
- goto next;
- }
- }
- bRedefineBlock = true;
- bDecIndex = true;
- nIdentBegin = -1;
-next:
- ;
- }
-
- // Preprocessor start: < or bracket
- if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-'))
- {
- DEFINE_BLOCK (I, COLORINDEX_OPERATOR);
- DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR);
- dwCookie |= COOKIE_PREPROCESSOR;
- nIdentBegin = -1;
- continue;
- }
-
- // User1 end: ?>
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
- {
- dwCookie &= ~COOKIE_EXT_USER1;
- nIdentBegin = -1;
- bRedefineBlock = true;
- bDecIndex = true;
- continue;
- }
- }
-
- // Preprocessor end: > or bracket
- if (dwCookie & COOKIE_PREPROCESSOR)
- {
- if (pszChars[I] == '>')
- {
- dwCookie &= ~COOKIE_PREPROCESSOR;
- nIdentBegin = -1;
- bRedefineBlock = true;
- bDecIndex = true;
- continue;
- }
- }
-
- // Preprocessor start: &
- if (!(dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '&')
- {
- dwCookie |= COOKIE_USER1;
- nIdentBegin = -1;
- continue;
- }
-
- // Preprocessor end: ;
- if (dwCookie & COOKIE_USER1)
- {
- if (pszChars[I] == ';')
- {
- dwCookie &= ~COOKIE_USER1;
- nIdentBegin = -1;
- continue;
- }
- }
-
- }
- }
-
- if (nIdentBegin >= 0 && (dwCookie & COOKIE_PREPROCESSOR))
- {
- if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
- }
- else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
- }
- else if (IsHtmlUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
- }
- else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
- }
- else
- {
- bool bFunction = false;
-
- for (int j = I; j < nLength; j++)
- {
- if (!xisspace (pszChars[j]))
- {
- if (pszChars[j] == '(')
- {
- bFunction = true;
- }
- break;
- }
- }
- if (bFunction)
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
- }
- }
- }
- else if (nIdentBegin >= 0 && (dwCookie & COOKIE_EXT_USER1))
- {
- if (IsAspKeyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
- }
- else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
- }
- else
- {
- bool bFunction = false;
-
- for (int j = I; j < nLength; j++)
- {
- if (!xisspace (pszChars[j]))
- {
- if (pszChars[j] == '(')
- {
- bFunction = true;
- }
- break;
- }
- }
- if (bFunction)
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
- }
- }
- }
-
- dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_PREPROCESSOR | COOKIE_EXT_USER1);
- return dwCookie;
+ return ParseLineHtmlEx(dwCookie, pszChars, nLength, pBuf, nActualItems, SRC_BASIC);
}
\r
#define COOKIE_COMMENT 0x0001\r
#define COOKIE_PREPROCESSOR 0x0002\r
+#define COOKIE_ELEMENT 0x0002\r
#define COOKIE_EXT_COMMENT 0x0004\r
#define COOKIE_STRING 0x0008\r
#define COOKIE_CHAR 0x0010\r
#define COOKIE_USER1 0x0020\r
#define COOKIE_EXT_USER1 0x0040\r
+#define COOKIE_BLOCK_STYLE 0x0080\r
+#define COOKIE_BLOCK_SCRIPT 0x0100\r
#define COOKIE_SECTION 0x0080\r
#define COOKIE_KEY 0x0100\r
#define COOKIE_EXT_COMMENT2 0x0200\r
unsigned ParseLineFortran(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLineGo(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLineHtml(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
+unsigned ParseLineHtmlEx(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems, int nEmbeddedLanguage);\r
unsigned ParseLineIni(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLineInnoSetup(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLineIS(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLinePascal(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLinePerl(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLinePhp(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
+unsigned ParseLinePhpLanguage(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLinePo(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLinePowerShell(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
unsigned ParseLinePython(unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems);\r
#endif
unsigned
-CrystalLineParser::ParseLineHtml (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
+CrystalLineParser::ParseLineHtmlEx (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems, int nEmbeddedLanguage)
{
if (nLength == 0)
- return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_USER1);
+ return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_USER1|COOKIE_ELEMENT|COOKIE_BLOCK_SCRIPT|COOKIE_BLOCK_STYLE);
- bool bFirstChar = (dwCookie & ~(COOKIE_EXT_COMMENT|COOKIE_EXT_USER1)) == 0;
bool bRedefineBlock = true;
+ if (!(dwCookie & COOKIE_ELEMENT))
+ bRedefineBlock = !(dwCookie & (COOKIE_EXT_USER1|COOKIE_BLOCK_SCRIPT|COOKIE_BLOCK_STYLE));
bool bDecIndex = false;
int nIdentBegin = -1;
int nPrevI = -1;
int nPos = I;
if (bDecIndex)
nPos = nPrevI;
- if (dwCookie & (COOKIE_COMMENT | COOKIE_EXT_COMMENT))
+ if (dwCookie & COOKIE_EXT_COMMENT)
{
DEFINE_BLOCK (nPos, COLORINDEX_COMMENT);
}
{
DEFINE_BLOCK (nPos, COLORINDEX_STRING);
}
- else if (dwCookie & COOKIE_PREPROCESSOR)
+ else if (dwCookie & COOKIE_ELEMENT)
{
DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR);
}
- else if (dwCookie & COOKIE_EXT_USER1)
- {
- DEFINE_BLOCK (nPos, COLORINDEX_FUNCNAME);
- }
else
{
if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.')
if (I >= nLength || pszChars[I] == 0)
break;
- if (dwCookie & COOKIE_COMMENT)
+ if (!(dwCookie & COOKIE_ELEMENT) && (dwCookie & (COOKIE_EXT_USER1|COOKIE_BLOCK_SCRIPT|COOKIE_BLOCK_STYLE)))
{
- DEFINE_BLOCK (I, COLORINDEX_COMMENT);
- dwCookie |= COOKIE_COMMENT;
- break;
+ if (dwCookie & COOKIE_BLOCK_SCRIPT)
+ {
+ const TCHAR *pszEnd = _tcsstr(pszChars + I, _T("</script>"));
+ int nextI = pszEnd ? (pszEnd - pszChars) : nLength;
+ dwCookie = ParseLineJava(dwCookie & ~COOKIE_BLOCK_SCRIPT, pszChars + I, nextI - I, pBuf, nActualItems);
+ if (!pszEnd)
+ dwCookie |= COOKIE_BLOCK_SCRIPT;
+ else
+ {
+ dwCookie = 0;
+ bRedefineBlock = true;
+ }
+ I = nextI - 1;
+ }
+ else if (dwCookie & COOKIE_BLOCK_STYLE)
+ {
+ const TCHAR *pszEnd = _tcsstr(pszChars + I, _T("</style>"));
+ int nextI = pszEnd ? (pszEnd - pszChars) : nLength;
+ dwCookie = ParseLineCss(dwCookie & ~COOKIE_BLOCK_STYLE, pszChars + I, nextI - I, pBuf, nActualItems);
+ if (!pszEnd)
+ dwCookie |= COOKIE_BLOCK_STYLE;
+ else
+ {
+ dwCookie = 0;
+ bRedefineBlock = true;
+ }
+ I = nextI - 1;
+ }
+ else if ((dwCookie & COOKIE_EXT_USER1))
+ {
+ const TCHAR *pszEnd = _tcsstr(pszChars + I, _T("?>"));
+ if (!pszEnd)
+ pszEnd = _tcsstr(pszChars + I, _T("%>"));
+ int nextI = pszEnd ? (pszEnd - pszChars) : nLength;
+
+ unsigned (*pParseLineFunc)(unsigned, const TCHAR *, int, TEXTBLOCK *, int &);
+ switch (nEmbeddedLanguage)
+ {
+ case SRC_BASIC: pParseLineFunc = ParseLineBasic; break;
+ case SRC_PHP: pParseLineFunc = ParseLinePhpLanguage; break;
+ default: pParseLineFunc = ParseLineJava; break;
+ }
+ dwCookie = pParseLineFunc(dwCookie & ~COOKIE_EXT_USER1, pszChars + I, nextI - I, pBuf, nActualItems);
+ if (!pszEnd)
+ dwCookie |= COOKIE_EXT_USER1;
+ else
+ {
+ dwCookie = 0;
+ bRedefineBlock = true;
+ }
+ I = nextI - 1;
+ }
+ continue;
}
// String constant "...."
continue;
}
- // Extended comment <?....?>
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
- {
- dwCookie &= ~COOKIE_EXT_USER1;
- bRedefineBlock = true;
- }
- continue;
- }
-
// Normal text
- if ((dwCookie & COOKIE_PREPROCESSOR) && pszChars[I] == '"')
+ if ((dwCookie & COOKIE_ELEMENT) && pszChars[I] == '"')
{
DEFINE_BLOCK (I, COLORINDEX_STRING);
dwCookie |= COOKIE_STRING;
continue;
}
- if ((dwCookie & COOKIE_PREPROCESSOR) && pszChars[I] == '\'')
+ if ((dwCookie & COOKIE_ELEMENT) && pszChars[I] == '\'')
{
// if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
if (!I || !xisalnum (pszChars[nPrevI]))
}
}
- if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength - 3 && pszChars[I] == '<' && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-')
+ if (I < nLength - 3 && pszChars[I] == '<' && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-')
{
DEFINE_BLOCK (I, COLORINDEX_COMMENT);
I += 3;
dwCookie |= COOKIE_EXT_COMMENT;
- dwCookie &= ~COOKIE_PREPROCESSOR;
+ dwCookie &= ~COOKIE_ELEMENT;
continue;
}
- if (bFirstChar)
+ // User1 start: <?
+ if (I < nLength && pszChars[I] == '<' && I < nLength - 1 && (pszChars[I + 1] == '?' || pszChars[I + 1] == '%'))
{
- if (!xisspace (pszChars[I]))
- bFirstChar = false;
+ DEFINE_BLOCK (I, COLORINDEX_NORMALTEXT);
+ dwCookie |= COOKIE_EXT_USER1;
+ nIdentBegin = -1;
+ continue;
}
if (pBuf == nullptr)
{
if (nIdentBegin >= 0)
{
- if (dwCookie & COOKIE_PREPROCESSOR)
+ if (dwCookie & COOKIE_ELEMENT)
{
if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
+ if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<script"), sizeof(_T("<script") - 1)) == 0)
+ dwCookie |= COOKIE_BLOCK_SCRIPT;
+ else if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<style"), sizeof(_T("<style") - 1)) == 0)
+ dwCookie |= COOKIE_BLOCK_STYLE;
}
else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
;
}
- // User1 start: <?
- if (I < nLength && pszChars[I] == '<' && I < nLength - 1 && (pszChars[I + 1] == '?' || pszChars[I + 1] == '%'))
- {
- DEFINE_BLOCK (I, COLORINDEX_FUNCNAME);
- dwCookie |= COOKIE_EXT_USER1;
- nIdentBegin = -1;
- continue;
- }
-
// Preprocessor start: < or bracket
- if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength && (pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-')/* || pszChars[I] == '{'*/))
+ if (I < nLength && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-'))
{
DEFINE_BLOCK (I, COLORINDEX_OPERATOR);
DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR);
- dwCookie |= COOKIE_PREPROCESSOR;
+ dwCookie |= COOKIE_ELEMENT;
nIdentBegin = -1;
continue;
}
- // User1 end: ?>
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
- {
- dwCookie &= ~COOKIE_EXT_USER1;
- nIdentBegin = -1;
- bRedefineBlock = true;
- bDecIndex = true;
- continue;
- }
- }
-
// Preprocessor end: > or bracket
- if (dwCookie & COOKIE_PREPROCESSOR)
+ if (dwCookie & COOKIE_ELEMENT)
{
- if (pszChars[I] == '>'/* || pszChars[I] == '}'*/)
+ if (pszChars[I] == '>')
{
- dwCookie &= ~COOKIE_PREPROCESSOR;
+ dwCookie &= ~COOKIE_ELEMENT;
nIdentBegin = -1;
bRedefineBlock = true;
bDecIndex = true;
}
}
- if (nIdentBegin >= 0 && (dwCookie & COOKIE_PREPROCESSOR))
+ if (nIdentBegin >= 0 && (dwCookie & COOKIE_ELEMENT))
{
if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
+ if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<script"), sizeof(_T("<script") - 1)) == 0)
+ dwCookie |= COOKIE_BLOCK_SCRIPT;
+ else if (nIdentBegin > 0 && _tcsnicmp(pszChars + nIdentBegin - 1, _T("<style"), sizeof(_T("<style") - 1)) == 0)
+ dwCookie |= COOKIE_BLOCK_STYLE;
}
else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
{
{
DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
}
- else
- {
- bool bFunction = false;
-
- for (int j = I; j < nLength; j++)
- {
- if (!xisspace (pszChars[j]))
- {
- if (pszChars[j] == '(')
- {
- bFunction = true;
- }
- break;
- }
- }
- if (bFunction)
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
- }
- }
- }
-
- // User1 start: <?
- if (I < nLength && pszChars[I] == '<' && I < nLength - 1 && (pszChars[I + 1] == '?' || pszChars[I + 1] == '%'))
- {
- DEFINE_BLOCK (I, COLORINDEX_FUNCNAME);
- dwCookie |= COOKIE_EXT_USER1;
- nIdentBegin = -1;
- goto end;
}
- // Preprocessor start: < or {
- if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength && (pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-')/* || pszChars[I] == '{'*/))
- {
- DEFINE_BLOCK (I, COLORINDEX_OPERATOR);
- DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR);
- dwCookie |= COOKIE_PREPROCESSOR;
- nIdentBegin = -1;
- goto end;
- }
-
- // User1 end: ?>
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
- {
- dwCookie &= ~COOKIE_EXT_USER1;
- nIdentBegin = -1;
- }
- }
-
- // Preprocessor end: > or }
- if (dwCookie & COOKIE_PREPROCESSOR)
- {
- if (pszChars[I] == '>'/* || pszChars[I] == '}'*/)
- {
- dwCookie &= ~COOKIE_PREPROCESSOR;
- nIdentBegin = -1;
- }
- }
-
-end:
- dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_PREPROCESSOR | COOKIE_EXT_USER1);
+ dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_ELEMENT | COOKIE_EXT_USER1 | COOKIE_BLOCK_SCRIPT | COOKIE_BLOCK_STYLE);
return dwCookie;
}
+
+unsigned
+CrystalLineParser::ParseLineHtml (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
+{
+ return ParseLineHtmlEx(dwCookie, pszChars, nLength, pBuf, nActualItems, SRC_JAVA);
+}
}
unsigned
-CrystalLineParser::ParseLinePhp (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
+CrystalLineParser::ParseLinePhp(unsigned dwCookie, const TCHAR* pszChars, int nLength, TEXTBLOCK* pBuf, int& nActualItems)
+{
+ return ParseLineHtmlEx(dwCookie, pszChars, nLength, pBuf, nActualItems, SRC_PHP);
+}
+
+unsigned
+CrystalLineParser::ParseLinePhpLanguage (unsigned dwCookie, const TCHAR *pszChars, int nLength, TEXTBLOCK * pBuf, int &nActualItems)
{
if (nLength == 0)
- return dwCookie & (COOKIE_EXT_COMMENT|COOKIE_EXT_USER1);
+ return dwCookie & (COOKIE_EXT_COMMENT);
- bool bFirstChar = (dwCookie & ~(COOKIE_EXT_COMMENT|COOKIE_EXT_USER1)) == 0;
const TCHAR *pszCommentBegin = nullptr;
const TCHAR *pszCommentEnd = nullptr;
bool bRedefineBlock = true;
{
DEFINE_BLOCK (nPos, COLORINDEX_PREPROCESSOR);
}
- else if (dwCookie & COOKIE_EXT_USER1)
- {
- DEFINE_BLOCK (nPos, COLORINDEX_NORMALTEXT);
- }
else
{
if (xisalnum (pszChars[nPos]) || pszChars[nPos] == '.')
// Extended comment <!--....-->
if (dwCookie & COOKIE_EXT_COMMENT)
{
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if ((pszCommentBegin < pszChars + I) && (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
- {
- dwCookie &= ~COOKIE_EXT_COMMENT;
- bRedefineBlock = true;
- pszCommentEnd = pszChars + I + 1;
- }
- }
- else
+ if ((pszCommentBegin < pszChars + I) && (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '*'))
{
- if (I > 1 && pszChars[I] == '>' && pszChars[nPrevI] == '-' && *::CharPrev(pszChars, pszChars + nPrevI) == '-')
- {
- dwCookie &= ~COOKIE_EXT_COMMENT;
- bRedefineBlock = true;
- }
+ dwCookie &= ~COOKIE_EXT_COMMENT;
+ bRedefineBlock = true;
+ pszCommentEnd = pszChars + I + 1;
}
continue;
}
- if ((dwCookie & COOKIE_EXT_USER1) && (pszCommentEnd < pszChars + I) && (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/'))
+ if ((pszCommentEnd < pszChars + I) && (I > 0 && pszChars[I] == '/' && pszChars[nPrevI] == '/'))
{
DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
dwCookie |= COOKIE_COMMENT;
break;
}
- if ((dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '#')
+ if (pszChars[I] == '#')
{
DEFINE_BLOCK (I, COLORINDEX_COMMENT);
dwCookie |= COOKIE_COMMENT;
break;
}
- // Extended comment <?....?>
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
- {
- dwCookie &= ~COOKIE_EXT_USER1;
- bRedefineBlock = true;
- continue;
- }
- }
-
// Normal text
- if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '"')
+ if (pszChars[I] == '"')
{
DEFINE_BLOCK (I, COLORINDEX_STRING);
dwCookie |= COOKIE_STRING;
continue;
}
- if ((dwCookie & (COOKIE_PREPROCESSOR|COOKIE_EXT_USER1)) && pszChars[I] == '\'')
+ if (pszChars[I] == '\'')
{
// if (I + 1 < nLength && pszChars[I + 1] == '\'' || I + 2 < nLength && pszChars[I + 1] != '\\' && pszChars[I + 2] == '\'' || I + 3 < nLength && pszChars[I + 1] == '\\' && pszChars[I + 3] == '\'')
if (!I || !xisalnum (pszChars[nPrevI]))
}
}
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if ((pszCommentEnd < pszChars + I) && (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/'))
- {
- DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
- dwCookie |= COOKIE_EXT_COMMENT;
- pszCommentBegin = pszChars + I + 1;
- continue;
- }
- }
- else
- {
- if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength - 3 && pszChars[I] == '<' && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-')
- {
- DEFINE_BLOCK (I, COLORINDEX_COMMENT);
- I += 3;
- dwCookie |= COOKIE_EXT_COMMENT;
- dwCookie &= ~COOKIE_PREPROCESSOR;
- continue;
- }
- }
-
- if (bFirstChar)
+ if ((pszCommentEnd < pszChars + I) && (I > 0 && pszChars[I] == '*' && pszChars[nPrevI] == '/'))
{
- if (!xisspace (pszChars[I]))
- bFirstChar = false;
- }
-
- // User1 start: <?
- if (I < nLength && pszChars[I] == '<' && I < nLength - 1 && (pszChars[I + 1] == '?' || pszChars[I + 1] == '%'))
- {
- DEFINE_BLOCK (I, COLORINDEX_NORMALTEXT);
- dwCookie |= COOKIE_EXT_USER1;
- nIdentBegin = -1;
+ DEFINE_BLOCK (nPrevI, COLORINDEX_COMMENT);
+ dwCookie |= COOKIE_EXT_COMMENT;
+ pszCommentBegin = pszChars + I + 1;
continue;
}
{
if (nIdentBegin >= 0)
{
- if (dwCookie & COOKIE_PREPROCESSOR)
+ if (dwCookie & COOKIE_USER2)
{
- if (IsHtmlKeyword (pszChars + nIdentBegin, I - nIdentBegin) && (pszChars[nIdentBegin - 1] == _T ('<') || pszChars[nIdentBegin - 1] == _T ('/')))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
- }
- else if (IsHtmlUser1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
- }
- else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
- }
- else
- {
- goto next;
- }
+ DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
}
- else if (dwCookie & COOKIE_EXT_USER1)
+ if (IsPhpKeyword (pszChars + nIdentBegin, I - nIdentBegin))
{
- if (dwCookie & COOKIE_USER2)
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER1);
- }
- if (IsPhpKeyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
- }
- else if (IsPhp1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_OPERATOR);
- }
- else if (IsPhp2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
- }
- else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
- }
- else
- {
- bool bFunction = false;
+ DEFINE_BLOCK (nIdentBegin, COLORINDEX_KEYWORD);
+ }
+ else if (IsPhp1Keyword (pszChars + nIdentBegin, I - nIdentBegin))
+ {
+ DEFINE_BLOCK (nIdentBegin, COLORINDEX_OPERATOR);
+ }
+ else if (IsPhp2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
+ {
+ DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
+ }
+ else if (IsXNumber (pszChars + nIdentBegin, I - nIdentBegin))
+ {
+ DEFINE_BLOCK (nIdentBegin, COLORINDEX_NUMBER);
+ }
+ else
+ {
+ bool bFunction = false;
- for (int j = I; j < nLength; j++)
+ for (int j = I; j < nLength; j++)
+ {
+ if (!xisspace (pszChars[j]))
{
- if (!xisspace (pszChars[j]))
+ if (pszChars[j] == '(')
{
- if (pszChars[j] == '(')
- {
- bFunction = true;
- }
- break;
+ bFunction = true;
}
- }
- if (bFunction)
- {
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
- }
- else
- {
- goto next;
+ break;
}
}
- }
- else if (dwCookie & COOKIE_USER1)
- {
- if (IsHtmlUser2Keyword (pszChars + nIdentBegin, I - nIdentBegin))
+ if (bFunction)
{
- DEFINE_BLOCK (nIdentBegin, COLORINDEX_USER2);
+ DEFINE_BLOCK (nIdentBegin, COLORINDEX_FUNCNAME);
}
else
{
;
}
- // Preprocessor start: < or bracket
- if (!(dwCookie & COOKIE_EXT_USER1) && I < nLength && pszChars[I] == '<' && !(I < nLength - 3 && pszChars[I + 1] == '!' && pszChars[I + 2] == '-' && pszChars[I + 3] == '-'))
- {
- DEFINE_BLOCK (I, COLORINDEX_OPERATOR);
- DEFINE_BLOCK (I + 1, COLORINDEX_PREPROCESSOR);
- dwCookie |= COOKIE_PREPROCESSOR;
- nIdentBegin = -1;
- continue;
- }
-
- // User1 end: ?>
- if (dwCookie & COOKIE_EXT_USER1)
- {
- if (I > 0 && pszChars[I] == '>' && (pszChars[nPrevI] == '?' || pszChars[nPrevI] == '%'))
- {
- dwCookie &= ~COOKIE_EXT_USER1;
- nIdentBegin = -1;
- bRedefineBlock = true;
- bDecIndex = true;
- continue;
- }
- }
-
- // Preprocessor end: > or bracket
- if (dwCookie & COOKIE_PREPROCESSOR)
- {
- if (pszChars[I] == '>')
- {
- dwCookie &= ~COOKIE_PREPROCESSOR;
- nIdentBegin = -1;
- bRedefineBlock = true;
- bDecIndex = true;
- continue;
- }
- }
-
- // Preprocessor start: &
- if (!(dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '&')
- {
- dwCookie |= COOKIE_USER1;
- nIdentBegin = -1;
- continue;
- }
-
- // Preprocessor end: ;
- if (dwCookie & COOKIE_USER1)
- {
- if (pszChars[I] == ';')
- {
- dwCookie &= ~COOKIE_USER1;
- nIdentBegin = -1;
- continue;
- }
- }
-
// Preprocessor start: $
- if ((dwCookie & COOKIE_EXT_USER1) && pszChars[I] == '$')
+ if (pszChars[I] == '$')
{
dwCookie |= COOKIE_USER2;
nIdentBegin = -1;
}
}
- dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING | COOKIE_PREPROCESSOR | COOKIE_EXT_USER1);
+ dwCookie &= (COOKIE_EXT_COMMENT | COOKIE_STRING);
return dwCookie;
}