diff options
| -rw-r--r-- | doc/ScintillaHistory.html | 1 | ||||
| -rw-r--r-- | gtk/makefile | 4 | ||||
| -rw-r--r-- | gtk/scintilla.mak | 3 | ||||
| -rw-r--r-- | include/SciLexer.h | 17 | ||||
| -rw-r--r-- | include/Scintilla.iface | 20 | ||||
| -rw-r--r-- | src/KeyWords.cxx | 2 | ||||
| -rw-r--r-- | src/LexFortran.cxx | 274 | ||||
| -rw-r--r-- | win32/makefile | 4 | ||||
| -rw-r--r-- | win32/scintilla.mak | 3 | ||||
| -rw-r--r-- | win32/scintilla_vc6.mak | 3 | 
10 files changed, 327 insertions, 4 deletions
| diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 8a3d8f481..cb058cce4 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -108,6 +108,7 @@  	<li>Josh Wingstrom</li>  	<li>Bruce Dodson</li>  	<li>Sergey Koshcheyev</li> +	<li>Chuan-jian Shen</li>      </ul>      <p>         Images used in GTK+ version diff --git a/gtk/makefile b/gtk/makefile index 14b3819ad..cc262eb71 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -43,8 +43,8 @@ endif  #**LEXOBJS=\\\n\(\*.o \)  LEXOBJS=\  LexAda.o LexAsm.o LexAVE.o LexBaan.o LexBullant.o LexConf.o LexCPP.o \ -LexCrontab.o LexEiffel.o LexHTML.o LexLisp.o LexLua.o LexMatlab.o LexOthers.o \ -LexPascal.o LexPerl.o LexPython.o LexRuby.o LexSQL.o LexVB.o  +LexCrontab.o LexEiffel.o LexFortran.o LexHTML.o LexLisp.o LexLua.o LexMatlab.o \ +LexOthers.o LexPascal.o LexPerl.o LexPython.o LexRuby.o LexSQL.o LexVB.o   #--Autogenerated -- end of automatically generated section  # The LEXOBJS have to be treated specially as the functions in them are not called from external code diff --git a/gtk/scintilla.mak b/gtk/scintilla.mak index 96447587f..ed6ae7434 100644 --- a/gtk/scintilla.mak +++ b/gtk/scintilla.mak @@ -127,6 +127,7 @@ LEXOBJS=\  	$(DIR_O)\LexCPP.obj \  	$(DIR_O)\LexCrontab.obj \  	$(DIR_O)\LexEiffel.obj \ +	$(DIR_O)\LexFortran.obj \  	$(DIR_O)\LexHTML.obj \  	$(DIR_O)\LexLisp.obj \  	$(DIR_O)\LexLua.obj \ @@ -264,6 +265,8 @@ $(DIR_O)\LexCrontab.obj: ..\src\LexCrontab.cxx $(LEX_HEADERS)  $(DIR_O)\LexEiffel.obj: ..\src\LexEiffel.cxx $(LEX_HEADERS) +$(DIR_O)\LexFortran.obj: ..\src\LexFortran.cxx $(LEX_HEADERS) +  $(DIR_O)\LexHTML.obj: ..\src\LexHTML.cxx $(LEX_HEADERS)  $(DIR_O)\LexLisp.obj: ..\src\LexLisp.cxx $(LEX_HEADERS) diff --git a/include/SciLexer.h b/include/SciLexer.h index 083809ce3..8137db8f3 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -50,6 +50,8 @@  #define SCLEX_SCRIPTOL 33  #define SCLEX_ASM 34  #define SCLEX_CPPNOCASE 35 +#define SCLEX_FORTRAN 36 +#define SCLEX_F77 37  #define SCLEX_AUTOMATIC 1000  #define SCE_P_DEFAULT 0  #define SCE_P_COMMENTLINE 1 @@ -408,6 +410,21 @@  #define SCE_ASM_REGISTER 8  #define SCE_ASM_DIRECTIVE 9  #define SCE_ASM_DIRECTIVEOPERAND 10 +#define SCE_F_DEFAULT 0 +#define SCE_F_COMMENT 1 +#define SCE_F_NUMBER 2 +#define SCE_F_STRING1 3 +#define SCE_F_STRING2 4 +#define SCE_F_STRINGEOL 5 +#define SCE_F_OPERATOR 6 +#define SCE_F_IDENTIFIER 7 +#define SCE_F_WORD 8 +#define SCE_F_WORD2 9 +#define SCE_F_WORD3 10 +#define SCE_F_PREPROCESSOR 11 +#define SCE_F_OPERATOR2 12 +#define SCE_F_LABEL 13 +#define SCE_F_CONTINUATION 14  //--Autogenerated -- end of section automatically generated from Scintilla.iface  #endif diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 31344aa6f..fbe531780 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1462,6 +1462,8 @@ val SCLEX_MATLAB=32  val SCLEX_SCRIPTOL=33  val SCLEX_ASM=34  val SCLEX_CPPNOCASE=35 +val SCLEX_FORTRAN=36 +val SCLEX_F77=37  # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a  # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -1888,6 +1890,24 @@ val SCE_ASM_MATHINSTRUCTION=7  val SCE_ASM_REGISTER=8  val SCE_ASM_DIRECTIVE=9  val SCE_ASM_DIRECTIVEOPERAND=10 +# Lexical states for SCLEX_FORTRAN +lex Fortran=SCLEX_FORTRAN SCE_F_ +lex F77=SCLEX_F77 SCE_F_ +val SCE_F_DEFAULT=0 +val SCE_F_COMMENT=1 +val SCE_F_NUMBER=2 +val SCE_F_STRING1=3 +val SCE_F_STRING2=4 +val SCE_F_STRINGEOL=5 +val SCE_F_OPERATOR=6 +val SCE_F_IDENTIFIER=7 +val SCE_F_WORD=8 +val SCE_F_WORD2=9 +val SCE_F_WORD3=10 +val SCE_F_PREPROCESSOR=11 +val SCE_F_OPERATOR2=12 +val SCE_F_LABEL=13 +val SCE_F_CONTINUATION=14  # Events diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx index 7f77f2fad..d9682b606 100644 --- a/src/KeyWords.cxx +++ b/src/KeyWords.cxx @@ -153,6 +153,8 @@ int Scintilla_LinkLexers() {  	LINK_LEXER(lmNncrontab);  	LINK_LEXER(lmEiffel);  	LINK_LEXER(lmEiffelkw); +	LINK_LEXER(lmFortran); +	LINK_LEXER(lmF77);  	LINK_LEXER(lmHTML);  	LINK_LEXER(lmXML);  	LINK_LEXER(lmASP); diff --git a/src/LexFortran.cxx b/src/LexFortran.cxx new file mode 100644 index 000000000..85e84c58a --- /dev/null +++ b/src/LexFortran.cxx @@ -0,0 +1,274 @@ +// Scintilla source code edit control +/** @file LexFortran.cxx + ** Lexer for Fortran. + ** Writen by Chuan-jian Shen, Last changed Oct. 2002 + **/ +// Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org> +// The License.txt file describes the conditions under which this software may be distributed. + +#include <stdlib.h> +#include <string.h> +#include <ctype.h> +#include <stdio.h> +#include <stdarg.h> + +#include "Platform.h" + +#include "PropSet.h" +#include "Accessor.h" +#include "StyleContext.h" +#include "KeyWords.h" +#include "Scintilla.h" +#include "SciLexer.h" + +static inline bool IsAWordChar(const int ch) { +	return (ch < 0x80) && (isalnum(ch) || ch == '_' || ch == '%'); +} + +static inline bool IsAWordStart(const int ch) { +	return (ch < 0x80) && (isalnum(ch)); +} + +static void ColouriseFortranDoc(unsigned int startPos, int length, int initStyle, WordList *keywordlists[], +                            Accessor &styler, bool isFixFormat) { + +	WordList &keywords = *keywordlists[0]; +	WordList &keywords2 = *keywordlists[1]; +	WordList &keywords3 = *keywordlists[2]; + +	int posLineStart = 0; + +	StyleContext sc(startPos, length, initStyle, styler); + +	for (; sc.More(); sc.Forward()) { + +		if (sc.atLineStart) { +			posLineStart = sc.currentPos; +			if (sc.state == SCE_F_STRING1) { +			    // Prevent SCE_F_STRINGEOL from leaking back to previous line +			    sc.SetState(SCE_F_STRING1); +			} +			else if(sc.state == SCE_F_STRING2) { +				sc.SetState(SCE_F_STRING2); +			} +		} + +		// Handle line continuation generically. +		if (sc.ch == '&') { +			if (sc.chNext == '\n' || sc.chNext == '\r') { +				sc.Forward(); +				if (sc.ch == '\r' && sc.chNext == '\n') { +					sc.Forward(); +				} +				continue; +			} +		} + +		// Determine if the current state should terminate. +		if (sc.state == SCE_F_OPERATOR) { +			sc.SetState(SCE_F_DEFAULT); +		} else if (sc.state == SCE_F_NUMBER) { +			if (!IsAWordChar(sc.ch)) { +				sc.SetState(SCE_F_DEFAULT); +			} +		} else if (sc.state == SCE_F_IDENTIFIER) { +			if (!IsAWordChar(sc.ch) || (sc.ch == '%')) { +				char s[100]; +				sc.GetCurrentLowered(s, sizeof(s)); +				if (keywords.InList(s)) { +					sc.ChangeState(SCE_F_WORD); +				} else if (keywords2.InList(s)) { +					sc.ChangeState(SCE_F_WORD2); +				} else if (keywords3.InList(s)) { +					sc.ChangeState(SCE_F_WORD3); +				} +				sc.SetState(SCE_F_DEFAULT); +			} +		} else if (sc.state == SCE_F_COMMENT) { +			if (sc.ch == '\r' || sc.ch == '\n') { +				sc.SetState(SCE_F_DEFAULT); +			} +		} else if (sc.state == SCE_F_STRING1) { +			if (sc.ch == '&') { +				sc.Forward(); +			} else if (sc.ch == '\'') { +				sc.Forward(); +				if (sc.chNext == '\'') { +					sc.Forward(); +				} else { +					sc.SetState(SCE_F_DEFAULT); +				} +			} else if (sc.atLineEnd) { +				sc.ChangeState(SCE_F_STRINGEOL); +				sc.ForwardSetState(SCE_F_DEFAULT); +			} +		} else if (sc.state == SCE_F_STRING2) { +			if (sc.atLineEnd) { +				sc.ChangeState(SCE_F_STRINGEOL); +				sc.ForwardSetState(SCE_F_DEFAULT); +			} else if (sc.ch == '&') { +				sc.Forward(); +			} else if (sc.ch == '\"') { +				sc.Forward(); +				if (sc.chNext == '\"') { +					sc.Forward(); +				} else { +					sc.SetState(SCE_F_DEFAULT); +				} +			} +		} else if (sc.state == SCE_F_OPERATOR2) { +			if (sc.ch == '.') { +				sc.ForwardSetState(SCE_F_DEFAULT); +			} +		} else if (sc.state == SCE_F_CONTINUATION) { +			sc.SetState(SCE_F_DEFAULT); +		} else if (sc.state == SCE_F_LABEL) { +			if (sc.currentPos >= posLineStart+5) { +				sc.SetState(SCE_F_DEFAULT); +			} +		} + +		// Determine if a new state should be entered. +		if (sc.state == SCE_F_DEFAULT) { +			int toLineStart = sc.currentPos - posLineStart; +			if (isFixFormat && (toLineStart < 6 || toLineStart > 72)) { +				if (sc.atLineStart && (tolower(sc.ch) == 'c' || sc.ch == '*')) { +					sc.SetState(SCE_F_COMMENT); +				} else if (toLineStart > 72) { +					sc.SetState(SCE_F_COMMENT); +				} else if (toLineStart < 5 && !IsASpace(sc.ch)) { +					sc.SetState(SCE_F_LABEL); +				} else if (toLineStart == 5 && (sc.ch != ' ' || sc.ch != '0')) { +					sc.SetState(SCE_F_CONTINUATION); +				} +			} else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { +				sc.SetState(SCE_F_NUMBER); +			} else if (sc.ch == '.' && isalpha(sc.chNext)) { +				sc.SetState(SCE_F_OPERATOR2); +			} else if (IsAWordStart(sc.ch)) { +				sc.SetState(SCE_F_IDENTIFIER); +			} else if (sc.ch == '!') { +				sc.SetState(SCE_F_COMMENT); +			} else if (sc.ch == '\"') { +				sc.SetState(SCE_F_STRING2); +			} else if (sc.ch == '\'') { +				sc.SetState(SCE_F_STRING1); +			} else if (isoperator(static_cast<char>(sc.ch))) { +				sc.SetState(SCE_F_OPERATOR); +			} +		} +	} +	sc.Complete(); +} + +static int classifyFoldPointFortran(const char* s, const char* prevWord) { +	int lev = 0; +	if (strcmp(prevWord, "end") == 0) return lev; +	if (strcmp(s, "associate") == 0 || strcmp(s, "block") == 0 +	    || strcmp(s, "blockdata") == 0 || strcmp(s, "case") == 0 +	    || strcmp(s, "do") == 0 || strcmp(s, "enum") ==0 +	    || strcmp(s, "forall") == 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 +	    || strcmp(s, "where") == 0) { +		lev = 1; +	} else if (strcmp(s, "end") == 0 +	    || 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) { +		lev = -1; +	} +	return lev; +} +static void FoldFortranDoc(unsigned int startPos, int length, int initStyle, WordList *[], Accessor &styler) { +	//~ 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]; +	int styleNext = styler.StyleAt(startPos); +	int style = initStyle; + +	int lastStart = 0; +	char prevWord[32] = ""; + +	for (unsigned int i = startPos; i < endPos; i++) { +		char ch = chNext; +		chNext = styler.SafeGetCharAt(i + 1); +		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) +		{ +			// Store last word start point. +			lastStart = i; +		} + +		if (style == SCE_F_WORD) { +			if(iswordchar(ch) && !iswordchar(chNext)) { +				char s[32]; +				unsigned int j; +				for(j = 0; ( j < 31 ) && ( j < i-lastStart+1 ); j++) { +					s[j] = static_cast<char>(tolower(styler[lastStart + j])); +				} +				s[j] = '\0'; +				levelCurrent += classifyFoldPointFortran(s, prevWord); +				strcpy(prevWord, s); +			} +		} +		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); +} + + +LexerModule lmFortran(SCLEX_FORTRAN, ColouriseFortranDocFreeFormat, "fortran", FoldFortranDoc, FortranWordLists); +LexerModule lmF77(SCLEX_F77, ColouriseFortranDocFixFormat, "f77", FoldFortranDoc, FortranWordLists); diff --git a/win32/makefile b/win32/makefile index c9097c4f2..cc066f919 100644 --- a/win32/makefile +++ b/win32/makefile @@ -41,8 +41,8 @@ deps:  #**LEXOBJS=\\\n\(\*.o \)  LEXOBJS=\  LexAda.o LexAsm.o LexAVE.o LexBaan.o LexBullant.o LexConf.o LexCPP.o \ -LexCrontab.o LexEiffel.o LexHTML.o LexLisp.o LexLua.o LexMatlab.o LexOthers.o \ -LexPascal.o LexPerl.o LexPython.o LexRuby.o LexSQL.o LexVB.o  +LexCrontab.o LexEiffel.o LexFortran.o LexHTML.o LexLisp.o LexLua.o LexMatlab.o \ +LexOthers.o LexPascal.o LexPerl.o LexPython.o LexRuby.o LexSQL.o LexVB.o   #--Autogenerated -- end of automatically generated section  SOBJS	= ScintillaWin.o ScintillaBase.o Editor.o Document.o \ diff --git a/win32/scintilla.mak b/win32/scintilla.mak index ce7c64707..9274c51f3 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -117,6 +117,7 @@ LEXOBJS=\  	$(DIR_O)\LexCPP.obj \  	$(DIR_O)\LexCrontab.obj \  	$(DIR_O)\LexEiffel.obj \ +	$(DIR_O)\LexFortran.obj \  	$(DIR_O)\LexHTML.obj \  	$(DIR_O)\LexLisp.obj \  	$(DIR_O)\LexLua.obj \ @@ -254,6 +255,8 @@ $(DIR_O)\LexCrontab.obj: ..\src\LexCrontab.cxx $(LEX_HEADERS)  $(DIR_O)\LexEiffel.obj: ..\src\LexEiffel.cxx $(LEX_HEADERS) +$(DIR_O)\LexFortran.obj: ..\src\LexFortran.cxx $(LEX_HEADERS) +  $(DIR_O)\LexHTML.obj: ..\src\LexHTML.cxx $(LEX_HEADERS)  $(DIR_O)\LexLisp.obj: ..\src\LexLisp.cxx $(LEX_HEADERS) diff --git a/win32/scintilla_vc6.mak b/win32/scintilla_vc6.mak index 5b9a70d93..bb8e11b7a 100644 --- a/win32/scintilla_vc6.mak +++ b/win32/scintilla_vc6.mak @@ -119,6 +119,7 @@ LEXOBJS=\  	$(DIR_O)\LexCPP.obj \  	$(DIR_O)\LexCrontab.obj \  	$(DIR_O)\LexEiffel.obj \ +	$(DIR_O)\LexFortran.obj \  	$(DIR_O)\LexHTML.obj \  	$(DIR_O)\LexLisp.obj \  	$(DIR_O)\LexLua.obj \ @@ -256,6 +257,8 @@ $(DIR_O)\LexCrontab.obj: ..\src\LexCrontab.cxx $(LEX_HEADERS)  $(DIR_O)\LexEiffel.obj: ..\src\LexEiffel.cxx $(LEX_HEADERS) +$(DIR_O)\LexFortran.obj: ..\src\LexFortran.cxx $(LEX_HEADERS) +  $(DIR_O)\LexHTML.obj: ..\src\LexHTML.cxx $(LEX_HEADERS)  $(DIR_O)\LexLisp.obj: ..\src\LexLisp.cxx $(LEX_HEADERS) | 
