📄 syntax.cpp
字号:
if (strLine[I] == '<')
{
dwCookie |= COOKIE_TAG;
DEFINE_BLOCK(I, COLORINDEX_SYNTAX);
//DEFINE_BLOCK(I+1, COLORINDEX_NORMAL);
}
if (dwCookie & COOKIE_TAG)
{
//如果当前正处于字符串变量中,则应检查是否有结束字符串变量的字符串
if ( dwCookie & COOKIE_STRING )
{
int nlen;
for (int i = 0; i < g_nEndStringStrCount; i++ )
{
if(g_EndStringStr[i]==NULL)
continue;
nlen = strlen(g_EndStringStr[i]);
bMatch = TRUE;
//如果strLine的当前字符串值与结束定义字符规则中的一项相同则中止定义字符串
if (I >= nlen - 1)
{
for(int k=0; k<nlen; k++) { //向前搜索字符串检查是否与结束定义的字符串相同
if(strLine[I-nlen+1+k]!=g_EndStringStr[i][k])
{
bMatch = FALSE; //如果不匹配,中断比较
break;
}
}
if(bMatch) {
dwCookie &= ~COOKIE_STRING;
bRedefineBlock = TRUE;
goto cmpnextchar; //继续处理strLine的下一个字符
}
}
}
goto cmpnextchar; //如果没有结束定义字符串继续处理strLine的下一个字符
}
//如果当前正处于字符变量中,则应检查是否有结束字符变量的字符串
if ( dwCookie & COOKIE_CHAR )
{
int nlen;
for (i = 0; i < g_nEndCharStrCount; i++ )
{
if(g_EndCharStr[i]==NULL)
continue;
nlen = strlen(g_EndCharStr[i]);
bMatch = TRUE;
//如果strLine的当前字符值与结束定义字符规则中的一项相同则中止定义字符串
if (I >= nlen - 1)
{
for(int k=0; k<nlen; k++) { //向前搜索字符串检查是否与结束定义的字符相同
if(strLine[I-nlen+1+k]!=g_EndCharStr[i][k])
{
bMatch = FALSE; //如果不匹配,中断比较
break;
}
}
if(bMatch) {
dwCookie &= ~COOKIE_CHAR;
bRedefineBlock = TRUE;
goto cmpnextchar; //继续处理strLine的下一个字符
}
}
}
goto cmpnextchar; //如果没有结束定义字符继续处理strLine的下一个字符
}
//如果当前正处于多行注释中,则应检查是否有结束多行注释的字符串
if ( dwCookie & COOKIE_EXT_COMMENT ) {
for (i = 0; i < g_nEndCommentExStrCount; i++ )
{
if(g_EndCommentExStr[i]==NULL)
continue;
bMatch = TRUE;
int nlen = strlen(g_EndCommentExStr[i]);
if(I >= nlen - 1)
{
for(int k=0; k<nlen; k++) {
if(strLine[I-nlen+1+k]!=g_EndCommentExStr[i][k])
{
bMatch = FALSE;
break;
}
}
if(bMatch) {
dwCookie &= ~COOKIE_EXT_COMMENT;
bRedefineBlock = TRUE;
goto cmpnextchar;
}
}
}
goto cmpnextchar;
}
//处理字符串变量的开始
for (i = 0; i < g_nBeginStringStrCount; i++ ) {
if(g_BeginStringStr[i]==NULL)
continue;
int nlen = strlen(g_BeginStringStr[i]);
bMatch = TRUE;
if(I >= nlen - 1)
{
for(int k=0; k<nlen; k++)
{
if(strLine[I-nlen+1+k]!=g_BeginStringStr[i][k])
{
bMatch = FALSE;
break;
}
}
if(bMatch) {
DEFINE_BLOCK(I - nlen + 1, COLORINDEX_STRING);
dwCookie |= COOKIE_STRING;
goto cmpnextchar;
}
}
}
//处理字符型变量的开始
for (i = 0; i < g_nBeginCharStrCount; i++ )
{
if(g_BeginCharStr[i]==NULL)
continue;
int nlen = strlen(g_BeginCharStr[i]);
bMatch = TRUE;
if(I >= nlen - 1)
{
for(int k=0; k<nlen; k++)
{
if(strLine[I-nlen+1+k]!=g_BeginCharStr[i][k])
{
bMatch = FALSE;
break;
}
}
if(bMatch) {
DEFINE_BLOCK(I - nlen + 1, COLORINDEX_CHAR);
dwCookie |= COOKIE_CHAR;
goto cmpnextchar;
}
}
}
//处理多行注释的开始
for (i = 0; i < g_nBeginCommentExStrCount; i++ )
{
if(g_BeginCommentExStr[i]==NULL)
continue;
int nlen = strlen(g_BeginCommentExStr[i]);
bMatch = TRUE;
if(I >= nlen - 1)
{
for(int k=0; k<nlen; k++) {
if(strLine[I-nlen+1+k]!=g_BeginCommentExStr[i][k])
{
bMatch = FALSE;
break;
}
}
if(bMatch)
{
nActualItems--;
DEFINE_BLOCK(I - nlen + 1, COLORINDEX_COMMENT);
dwCookie |= COOKIE_EXT_COMMENT;
goto cmpnextchar;
}
}
}
bInString = FALSE;
for ( i = 0; i < g_nstrInStringCount; i++ )
{
BOOL b = ( strLine[I] == g_strInString.GetAt(i) );
bInString |= b;
if(bInString)
break;
}
if (isalnum(strLine[I]) || strLine[I] == '_' || bInString)
{
if (nIdentBegin == -1)
nIdentBegin = I;
}
else
{
if (nIdentBegin >= 0)
{
CString strtmp= strLine.Mid(nIdentBegin, I - nIdentBegin);
if (IsNumber(strtmp))
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_NUMBER);
}//*
else
{
if(strtmp.CompareNoCase(_T("script"))==0)
{
if( nIdentBegin > 0 && strLine[nIdentBegin-1] == '<')
{
dwCookie |= COOKIE_SCRIPT;
}
else if( nIdentBegin > 1 && strLine[nIdentBegin-1] == '/' && strLine[nIdentBegin-2] == '<')
{
dwCookie &= ~COOKIE_SCRIPT;
DEFINE_BLOCK(nIdentBegin-2, COLORINDEX_SYNTAX);
}
}
if( (nIdentBegin > 0) && (strLine[nIdentBegin-1] == '=') )
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_NORMAL);
}
else
{
DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX);
}
}
bRedefineBlock = TRUE;
bDecIndex = TRUE;
nIdentBegin = -1;
}
}
}
if (strLine[I] == '>')
{
bRedefineBlock = FALSE;
dwCookie &= ~COOKIE_TAG;
DEFINE_BLOCK(I, COLORINDEX_SYNTAX);
if(dwCookie & COOKIE_SCRIPT)
{
DEFINE_BLOCK(I+1, COLORINDEX_STRING);
}
else if( (I > 1) && (strLine[I-1]=='-') && (strLine[I-2]=='-') )
{
DEFINE_BLOCK(I, COLORINDEX_COMMENT);
}
else
{
DEFINE_BLOCK(I+1, COLORINDEX_NORMAL);
}
}
cmpnextchar:
i = 0;
}
Out: //当遇到单行注释时会直接跳到这儿
if (dwCookie & COOKIE_TAG) {
if (nIdentBegin >= 0)
{
CString strtmp = strLine.Mid(nIdentBegin, I - nIdentBegin);
if (IsSynWord(m_strArrayKeyWords, strtmp))
{
if( (nIdentBegin > 0) && (strLine[nIdentBegin-1]=='/') ) {
DEFINE_BLOCK(nIdentBegin-1, COLORINDEX_SYNTAX);
}
else {
DEFINE_BLOCK(nIdentBegin, COLORINDEX_SYNTAX);
}
if(strtmp.CompareNoCase(_T("script"))==0) {
if( nIdentBegin > 0 && strLine[nIdentBegin-1] == '<') {
dwCookie |= COOKIE_SCRIPT;
}
else if( nIdentBegin > 1 && strLine[nIdentBegin-1] == '/' && strLine[nIdentBegin-12] == '<') {
dwCookie &= ~COOKIE_SCRIPT;
DEFINE_BLOCK(nIdentBegin-2, COLORINDEX_NORMAL);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -