diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/LexFortran.cxx | 50 |
1 files changed, 33 insertions, 17 deletions
diff --git a/src/LexFortran.cxx b/src/LexFortran.cxx index 60544dd48..e2109a0ab 100644 --- a/src/LexFortran.cxx +++ b/src/LexFortran.cxx @@ -1,7 +1,7 @@ // Scintilla source code edit control /** @file LexFortran.cxx ** Lexer for Fortran. - ** Writen by Chuan-jian Shen, Last changed Oct. 2002 + ** Writen by Chuan-jian Shen, Last changed Nov. 2002 **/ // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org> // The License.txt file describes the conditions under which this software may be distributed. @@ -39,7 +39,7 @@ static void ColouriseFortranDoc(unsigned int startPos, int length, int initStyle WordList &keywords2 = *keywordlists[1]; WordList &keywords3 = *keywordlists[2]; - unsigned int posLineStart = 0, currentState; + int posLineStart = 0, prevState = 0; int endPos = startPos + length; // backtrack to the beginning of the document, this may be slow for big documents. @@ -57,21 +57,24 @@ static void ColouriseFortranDoc(unsigned int startPos, int length, int initStyle for (; sc.More(); sc.Forward()) { // remember the position of the line - if (sc.atLineStart) posLineStart = sc.currentPos; + if (sc.atLineStart) { + posLineStart = sc.currentPos; + sc.SetState(SCE_F_DEFAULT); + } // Handle line continuation generically. if (sc.ch == '&') { - int chTemp = ' '; + char chTemp = ' '; int j = 1; while (IsABlank(chTemp) && j<132) { - chTemp = sc.GetRelative(j); + chTemp = static_cast<char>(sc.GetRelative(j)); j ++; } if (chTemp == '!') { sc.SetState(SCE_F_CONTINUATION); if (sc.chNext == '!') sc.ForwardSetState(SCE_F_COMMENT); } else if (chTemp == '\r' || chTemp == '\n') { - currentState = sc.state; + int currentState = sc.state; sc.SetState(SCE_F_CONTINUATION); if (currentState == SCE_F_STRING1 || currentState == SCE_F_STRING2) { sc.ForwardSetState(SCE_F_DEFAULT); @@ -111,25 +114,39 @@ static void ColouriseFortranDoc(unsigned int startPos, int length, int initStyle sc.SetState(SCE_F_DEFAULT); } } else if (sc.state == SCE_F_STRING1) { + prevState = sc.state; if (sc.ch == '\'') { if (sc.chNext == '\'') { sc.Forward(); } else { sc.ForwardSetState(SCE_F_DEFAULT); + prevState = SCE_F_DEFAULT; } } else if (sc.atLineEnd) { - sc.ChangeState(SCE_F_STRINGEOL); - sc.ForwardSetState(SCE_F_DEFAULT); + if (isFixFormat) { + sc.ForwardSetState(SCE_F_DEFAULT); + posLineStart = sc.currentPos; + } else { + sc.ChangeState(SCE_F_STRINGEOL); + sc.ForwardSetState(SCE_F_DEFAULT); + } } } else if (sc.state == SCE_F_STRING2) { + prevState = sc.state; if (sc.atLineEnd) { - sc.ChangeState(SCE_F_STRINGEOL); - sc.ForwardSetState(SCE_F_DEFAULT); + if (isFixFormat) { + sc.ForwardSetState(SCE_F_DEFAULT); + posLineStart = sc.currentPos; + } else { + sc.ChangeState(SCE_F_STRINGEOL); + sc.ForwardSetState(SCE_F_DEFAULT); + } } else if (sc.ch == '\"') { if (sc.chNext == '\"') { sc.Forward(); } else { sc.ForwardSetState(SCE_F_DEFAULT); + prevState = SCE_F_DEFAULT; } } } else if (sc.state == SCE_F_OPERATOR2) { @@ -139,7 +156,7 @@ static void ColouriseFortranDoc(unsigned int startPos, int length, int initStyle } else if (sc.state == SCE_F_CONTINUATION) { sc.SetState(SCE_F_DEFAULT); } else if (sc.state == SCE_F_LABEL) { - if (sc.currentPos >= posLineStart+5) { + if (sc.currentPos >= static_cast<unsigned int>(posLineStart+5)) { sc.SetState(SCE_F_DEFAULT); } } @@ -148,7 +165,7 @@ static void ColouriseFortranDoc(unsigned int startPos, int length, int initStyle 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 == '*')) { + if (sc.atLineStart && (tolower(sc.ch) == 'c' || sc.ch == '*') || sc.ch == '!') { sc.SetState(SCE_F_COMMENT); } else if (toLineStart > 72) { sc.SetState(SCE_F_COMMENT); @@ -156,6 +173,7 @@ static void ColouriseFortranDoc(unsigned int startPos, int length, int initStyle sc.SetState(SCE_F_LABEL); } else if (toLineStart == 5 && (!IsASpace(sc.ch) && sc.ch != '0')) { sc.SetState(SCE_F_CONTINUATION); + sc.ForwardSetState(prevState); } } else if (IsADigit(sc.ch) || (sc.ch == '.' && IsADigit(sc.chNext))) { sc.SetState(SCE_F_NUMBER); @@ -184,13 +202,12 @@ static int classifyFoldPointFortran(const char* s, const char* prevWord) { 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, "case") == 0 + || strcmp(s, "blockdata") == 0 || strcmp(s, "select") == 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) { + || strcmp(s, "then") == 0 || strcmp(s, "where") == 0) { lev = 1; } else if (strcmp(s, "end") == 0 || strcmp(s, "continue") == 0 || strcmp(s, "endassociate") == 0 || strcmp(s, "endblock") == 0 @@ -200,8 +217,7 @@ static int classifyFoldPointFortran(const char* s, const char* prevWord) { || 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 ) { + || strcmp(s, "endwhere") == 0 || strcmp(s, "procedure") == 0 ) { lev = -1; } return lev; |