⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 lexfortran.cxx

📁 非常好用的可移植的多平台C/C++源代码编辑器
💻 CXX
📖 第 1 页 / 共 2 页
字号:
	if ((strcmp(prevWord, "else") == 0 && strcmp(s, "if") == 0) || strcmp(s, "elseif") == 0)
		return -1;
	if (strcmp(s, "associate") == 0 || strcmp(s, "block") == 0
	    || strcmp(s, "blockdata") == 0 || strcmp(s, "select") == 0
	    || strcmp(s, "do") == 0 || strcmp(s, "enum") ==0
	    || strcmp(s, "function") == 0 || strcmp(s, "interface") == 0
		|| strcmp(s, "module") == 0 || strcmp(s, "program") == 0
		|| strcmp(s, "subroutine") == 0 || strcmp(s, "then") == 0
		|| (strcmp(s, "type") == 0 && chNextNonBlank != '(') ){
			if (strcmp(prevWord, "end") == 0)
				lev = 0;
			else
				lev = 1;
	} else if (strcmp(s, "end") == 0 && chNextNonBlank != '='
		|| strcmp(s, "endassociate") == 0 || strcmp(s, "endblock") == 0
		|| strcmp(s, "endblockdata") == 0 || strcmp(s, "endselect") == 0
		|| strcmp(s, "enddo") == 0 || strcmp(s, "endenum") ==0
		|| strcmp(s, "endif") == 0 || strcmp(s, "endforall") == 0
		|| strcmp(s, "endfunction") == 0 || strcmp(s, "endinterface") == 0
		|| strcmp(s, "endmodule") == 0 || strcmp(s, "endprogram") == 0
		|| strcmp(s, "endsubroutine") == 0 || strcmp(s, "endtype") == 0
		|| strcmp(s, "endwhere") == 0
		|| strcmp(s, "procedure") == 0 ) { // Take care of the module procedure statement
			lev = -1;
	} else if (strcmp(prevWord, "end") == 0 && strcmp(s, "if") == 0){ // end if
			lev = 0;
	}
	return lev;
}
// Folding the code
static void FoldFortranDoc(unsigned int startPos, int length, int initStyle,
						   Accessor &styler, bool isFixFormat) {
	//
	// bool foldComment = styler.GetPropertyInt("fold.comment") != 0;
	// Do not know how to fold the comment at the moment.
	//
	bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;
	unsigned int endPos = startPos + length;
	int visibleChars = 0;
	int lineCurrent = styler.GetLine(startPos);
	int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
	int levelCurrent = levelPrev;
	char chNext = styler[startPos];
	char chNextNonBlank;
	int styleNext = styler.StyleAt(startPos);
	int style = initStyle;
	/***************************************/
	int lastStart = 0;
	char prevWord[32] = "";
	char Label[6] = "";
	// Variables for do label folding.
	static int doLabels[100];
	static int posLabel=-1;
	/***************************************/
	for (unsigned int i = startPos; i < endPos; i++) {
		char ch = chNext;
		chNext = styler.SafeGetCharAt(i + 1);
		chNextNonBlank = chNext;
		unsigned int j=i+1;
		while(IsABlank(chNextNonBlank) && j<endPos) {
			j ++ ;
			chNextNonBlank = styler.SafeGetCharAt(j);
		}
		int stylePrev = style;
		style = styleNext;
		styleNext = styler.StyleAt(i + 1);
		bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n');
		//
		if (stylePrev == SCE_F_DEFAULT && (style == SCE_F_WORD || style == SCE_F_LABEL)) {
			// Store last word and label start point.
			lastStart = i;
		}
		/***************************************/
		if (style == SCE_F_WORD) {
			if(iswordchar(ch) && !iswordchar(chNext)) {
				char s[32];
				unsigned int k;
				for(k=0; (k<31 ) && (k<i-lastStart+1 ); k++) {
					s[k] = static_cast<char>(tolower(styler[lastStart+k]));
				}
				s[k] = '\0';
				// Handle the forall and where statement and structure.
				if (strcmp(s, "forall") == 0 || strcmp(s, "where") == 0) {
					if (strcmp(prevWord, "end") != 0) {
						j = i + 1;
						char chBrace = '(', chSeek = ')', ch1 = styler.SafeGetCharAt(j);
						// Find the position of the first (
						while (ch1 != chBrace && j<endPos) {
							j++;
							ch1 = styler.SafeGetCharAt(j);
						}
						char styBrace = styler.StyleAt(j);
						int depth = 1;
						char chAtPos;
						char styAtPos;
						while (j<endPos) {
							j++;
							chAtPos = styler.SafeGetCharAt(j);
							styAtPos = styler.StyleAt(j);
							if (styAtPos == styBrace) {
								if (chAtPos == chBrace) depth++;
								if (chAtPos == chSeek) depth--;
								if (depth == 0) break;
							}
						}
						while (j<endPos) {
							j++;
							chAtPos = styler.SafeGetCharAt(j);
							styAtPos = styler.StyleAt(j);
							if (styAtPos == SCE_F_COMMENT || IsABlank(chAtPos)) continue;
							if (isFixFormat) {
								if (!IsALineEnd(chAtPos)) {
									break;
								} else {
									if (lineCurrent < styler.GetLine(styler.Length()-1)) {
										j = styler.LineStart(lineCurrent+1);
										if (styler.StyleAt(j+5) == SCE_F_CONTINUATION) {
											j += 5;
											continue;
										} else {
											levelCurrent++;
											break;
										}
									}
								}
							} else {
								if (chAtPos == '&' && styler.StyleAt(j) == SCE_F_CONTINUATION) {
									j = GetContinuedPos(j+1, styler);
									continue;
								} else if (IsALineEnd(chAtPos)) {
									levelCurrent ++;
									break;
								} else {
									break;
								}
							}
						}
					}
				} else {
					levelCurrent += classifyFoldPointFortran(s, prevWord, chNextNonBlank);
					// Store the do Labels into array
					if (strcmp(s, "do") == 0 && IsADigit(chNextNonBlank)) {
						unsigned int k = 0;
						for (i=j; (i<j+5 && i<endPos); i++) {
							ch = styler.SafeGetCharAt(i);
							if (IsADigit(ch))
								Label[k++] = ch;
							else
								break;
						}
						Label[k] = '\0';
						posLabel ++;
						doLabels[posLabel] = atoi(Label);
					}
				}
				strcpy(prevWord, s);
			}
		} else if (style == SCE_F_LABEL) {
			if(IsADigit(ch) && !IsADigit(chNext)) {
				for(j = 0; ( j < 5 ) && ( j < i-lastStart+1 ); j++) {
					ch = styler.SafeGetCharAt(lastStart + j);
					if (IsADigit(ch) && styler.StyleAt(lastStart+j) == SCE_F_LABEL)
						Label[j] = ch;
					else
						break;
				}
				Label[j] = '\0';
				while (doLabels[posLabel] == atoi(Label) && posLabel > -1) {
					levelCurrent--;
					posLabel--;
				}
			}
		}
		if (atEOL) {
			int lev = levelPrev;
			if (visibleChars == 0 && foldCompact)
				lev |= SC_FOLDLEVELWHITEFLAG;
			if ((levelCurrent > levelPrev) && (visibleChars > 0))
				lev |= SC_FOLDLEVELHEADERFLAG;
			if (lev != styler.LevelAt(lineCurrent)) {
				styler.SetLevel(lineCurrent, lev);
			}
			lineCurrent++;
			levelPrev = levelCurrent;
			visibleChars = 0;
			strcpy(prevWord, "");
		}
		/***************************************/
		if (!isspacechar(ch)) visibleChars++;
	}
	/***************************************/
	// Fill in the real level of the next line, keeping the current flags as they will be filled in later
	int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
	styler.SetLevel(lineCurrent, levelPrev | flagsNext);
}
/***************************************/
static const char * const FortranWordLists[] = {
	"Primary keywords and identifiers",
	"Intrinsic functions",
	"Extended and user defined functions",
	0,
};
/***************************************/
static void ColouriseFortranDocFreeFormat(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
                            Accessor &styler) {
	ColouriseFortranDoc(startPos, length, initStyle, keywordlists, styler, false);
}
/***************************************/
static void ColouriseFortranDocFixFormat(unsigned int startPos, int length, int initStyle, WordList *keywordlists[],
                            Accessor &styler) {
	ColouriseFortranDoc(startPos, length, initStyle, keywordlists, styler, true);
}
/***************************************/
static void FoldFortranDocFreeFormat(unsigned int startPos, int length, int initStyle,
		WordList *[], Accessor &styler) {
	FoldFortranDoc(startPos, length, initStyle,styler, false);
}
/***************************************/
static void FoldFortranDocFixFormat(unsigned int startPos, int length, int initStyle,
		WordList *[], Accessor &styler) {
	FoldFortranDoc(startPos, length, initStyle,styler, true);
}
/***************************************/
LexerModule lmFortran(SCLEX_FORTRAN, ColouriseFortranDocFreeFormat, "fortran", FoldFortranDocFreeFormat, FortranWordLists);
LexerModule lmF77(SCLEX_F77, ColouriseFortranDocFixFormat, "f77", FoldFortranDocFixFormat, FortranWordLists);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -