diff options
Diffstat (limited to 'lexers/LexPowerPro.cxx')
| -rw-r--r-- | lexers/LexPowerPro.cxx | 132 | 
1 files changed, 68 insertions, 64 deletions
diff --git a/lexers/LexPowerPro.cxx b/lexers/LexPowerPro.cxx index 9320baf94..c21d0ab22 100644 --- a/lexers/LexPowerPro.cxx +++ b/lexers/LexPowerPro.cxx @@ -3,42 +3,46 @@  // PowerPro utility, written by Bruce Switzer, is available from http://powerpro.webeddie.com  // PowerPro lexer is written by Christopher Bean (cbean@cb-software.net)  // -// Lexer code heavily borrowed from:  +// Lexer code heavily borrowed from:  //	LexAU3.cxx by Jos van der Zande  //	LexCPP.cxx by Neil Hodgson  //	LexVB.cxx by Neil Hodgson  //  // Changes:  // 	2008-10-25 - Initial release -//	2008-10-26 - Changed how <name> is hilighted in  'function <name>' so that  +//	2008-10-26 - Changed how <name> is hilighted in  'function <name>' so that  //				 local isFunction = "" and local functions = "" don't get falsely highlighted  //	2008-12-14 - Added bounds checking for szKeyword and szDo  //			   - Replaced SetOfCharacters with CharacterSet  //			   - Made sure that CharacterSet::Contains is passed only positive values -//			   - Made sure that the return value of Accessor::SafeGetCharAt is positive before  +//			   - Made sure that the return value of Accessor::SafeGetCharAt is positive before  //				 passsing to functions that require positive values like isspacechar()  //			   - Removed unused visibleChars processing from ColourisePowerProDoc() -//			   - Fixed bug with folding logic where line continuations didn't end where  +//			   - Fixed bug with folding logic where line continuations didn't end where  //				 they were supposed to  //			   - Moved all helper functions to the top of the file  //  // Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>  // The License.txt file describes the conditions under which this software may be distributed. -#include <ctype.h> -#include <stdarg.h> -#include <stdio.h>  #include <stdlib.h>  #include <string.h> +#include <stdio.h> +#include <stdarg.h> +#include <assert.h> +#include <ctype.h> -#include "Platform.h" -#include "PropSet.h" -#include "Accessor.h" -#include "StyleContext.h" -#include "KeyWords.h" +#include "ILexer.h"  #include "Scintilla.h"  #include "SciLexer.h" + +#include "PropSetSimple.h" +#include "WordList.h" +#include "LexAccessor.h" +#include "Accessor.h" +#include "StyleContext.h"  #include "CharacterSet.h" +#include "LexerModule.h"  #ifdef SCI_NAMESPACE  using namespace Scintilla; @@ -72,13 +76,13 @@ static bool IsContinuationLine(unsigned int szLine, Accessor &styler)  }  // Routine to find first none space on the current line and return its Style -// needed for comment lines not starting on pos 1  +// needed for comment lines not starting on pos 1  static int GetStyleFirstWord(unsigned int szLine, Accessor &styler)  {  	int nsPos = styler.LineStart(szLine);  	int nePos = styler.LineStart(szLine+1) - 1;  	char ch = styler.SafeGetCharAt(nsPos); -	 +  	while (ch > 0 && isspacechar(ch) && nsPos < nePos)  	{  		nsPos++; // skip to next char @@ -91,10 +95,10 @@ static int GetStyleFirstWord(unsigned int szLine, Accessor &styler)  //returns true if there is a function to highlight  //used to highlight <name> in 'function <name>'  static bool HasFunction(Accessor &styler, unsigned int currentPos) { -	 +  	//check for presence of 'function ' -	return 	(styler.SafeGetCharAt(currentPos) == ' ' 	 -	&& tolower(styler.SafeGetCharAt(currentPos-1)) == 'n'  +	return 	(styler.SafeGetCharAt(currentPos) == ' ' +	&& tolower(styler.SafeGetCharAt(currentPos-1)) == 'n'  	&& tolower(styler.SafeGetCharAt(currentPos-2)) == 'o'  	&& tolower(styler.SafeGetCharAt(currentPos-3)) == 'i'  	&& tolower(styler.SafeGetCharAt(currentPos-4)) == 't' @@ -103,7 +107,7 @@ static bool HasFunction(Accessor &styler, unsigned int currentPos) {  	&& tolower(styler.SafeGetCharAt(currentPos-7)) == 'u'  	&& tolower(styler.SafeGetCharAt(currentPos-8)) == 'f'  	//only allow 'function ' to appear at the beginning of a line -	&& (styler.SafeGetCharAt(currentPos-9) == '\n'   		 +	&& (styler.SafeGetCharAt(currentPos-9) == '\n'  		|| styler.SafeGetCharAt(currentPos-9) == '\r'  		|| (styler.SafeGetCharAt(currentPos -9, '\0')) == '\0') //is the first line  	); @@ -116,22 +120,22 @@ static void ColourisePowerProDoc(unsigned int startPos, int length, int initStyl  	WordList &keywords2 = *keywordlists[1];  	WordList &keywords3 = *keywordlists[2];  	WordList &keywords4 = *keywordlists[3]; -	 -	//define the character sets  + +	//define the character sets  	CharacterSet setWordStart(CharacterSet::setAlpha, "_@", 0x80, true);  	CharacterSet setWord(CharacterSet::setAlphaNum, "._", 0x80, true);  	StyleContext sc(startPos, length, initStyle, styler);  	char s_save[100]; //for last line highlighting -	 +  	for (; sc.More(); sc.Forward()) { -			 +  		// **********************************************  		// save the total current word for eof processing  		char s[100];  		sc.GetCurrentLowered(s, sizeof(s)); -		  -		if ((sc.ch > 0) && setWord.Contains(sc.ch))  + +		if ((sc.ch > 0) && setWord.Contains(sc.ch))  		{  			strcpy(s_save,s);  			int tp = strlen(s_save); @@ -156,12 +160,12 @@ static void ColourisePowerProDoc(unsigned int startPos, int length, int initStyl  			case SCE_POWERPRO_OPERATOR:  				sc.SetState(SCE_POWERPRO_DEFAULT);  				break; -			 +  			case SCE_POWERPRO_NUMBER:  				if (!IsADigit(sc.ch))  					sc.SetState(SCE_POWERPRO_DEFAULT); -				 +  				break;  			case SCE_POWERPRO_IDENTIFIER: @@ -256,7 +260,7 @@ static void ColourisePowerProDoc(unsigned int startPos, int length, int initStyl  					}  				}  				break; -				 +  			case SCE_POWERPRO_FUNCTION:  				if (sc.ch == '\r' || sc.ch == '\n' || sc.ch == ' ' || sc.ch == '(') {  					sc.SetState(SCE_POWERPRO_DEFAULT); @@ -277,12 +281,12 @@ static void ColourisePowerProDoc(unsigned int startPos, int length, int initStyl  					sc.Forward();  				}  			} else if (HasFunction(styler, sc.currentPos)) {	//highlight <name> in 'function <name>' -				sc.SetState(SCE_POWERPRO_FUNCTION);  +				sc.SetState(SCE_POWERPRO_FUNCTION);  			} else if (sc.ch == '@' && sc.atLineStart) { 		//alternate function definition [label]  				sc.SetState(SCE_POWERPRO_FUNCTION);  			} else if ((sc.ch > 0) && (setWordStart.Contains(sc.ch) || (sc.ch == '?'))) {  				sc.SetState(SCE_POWERPRO_IDENTIFIER); -			} else if (sc.Match(";;+")) {  +			} else if (sc.Match(";;+")) {  				sc.SetState(SCE_POWERPRO_LINECONTINUE);  			} else if (sc.Match('/', '*')) {  				sc.SetState(SCE_POWERPRO_COMMENTBLOCK); @@ -304,7 +308,7 @@ static void ColourisePowerProDoc(unsigned int startPos, int length, int initStyl  	}  	//************************************* -	// Colourize the last word correctly  +	// Colourize the last word correctly  	//*************************************  	if (sc.state == SCE_POWERPRO_IDENTIFIER)  	{ @@ -345,7 +349,7 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  	bool foldComment = styler.GetPropertyInt("fold.comment") != 0;  	bool foldInComment = styler.GetPropertyInt("fold.comment") == 2;  	bool foldCompact = true; -	 +  	// Backtrack to previous line in case need to fix its fold status  	int lineCurrent = styler.GetLine(startPos);  	if (startPos > 0) { @@ -355,10 +359,10 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  			startPos = styler.LineStart(lineCurrent);  		}  	} -	// vars for style of previous/current/next lines  +	// vars for style of previous/current/next lines  	int style = GetStyleFirstWord(lineCurrent,styler);  	int stylePrev = 0; -	 +  	// find the first previous line without continuation character at the end  	while ((lineCurrent > 0 && IsContinuationLine(lineCurrent,styler)) ||  	       (lineCurrent > 1 && IsContinuationLine(lineCurrent-1,styler))) { @@ -371,42 +375,42 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  	// vars for getting first word to check for keywords  	bool FirstWordStart = false;  	bool FirstWordEnd = false; -		 +  	const unsigned int KEYWORD_MAX = 10;  	char szKeyword[KEYWORD_MAX]="";  	unsigned int	 szKeywordlen = 0; -	 +  	char szDo[3]="";  	int	 szDolen = 0;  	bool DoFoundLast = false; -	 +  	// var for indentlevel  	int levelCurrent = SC_FOLDLEVELBASE;  	if (lineCurrent > 0) {  		levelCurrent = styler.LevelAt(lineCurrent-1) >> 16;  	}  	int levelNext = levelCurrent; -	 +  	int	visibleChars = 0;  	int functionCount = 0; -	 +  	char chNext = styler.SafeGetCharAt(startPos);  	char chPrev = '\0';  	char chPrevPrev = '\0';  	char chPrevPrevPrev = '\0'; -	 +  	for (int i = startPos; i < endPos; i++) {  		char ch = chNext;  		chNext = styler.SafeGetCharAt(i + 1); -		 +  		if ((ch > 0) && setWord.Contains(ch)) {  			visibleChars++;  		} -		 +  		// get the syle for the current character neede to check in comment  		int stylech = styler.StyleAt(i); -		 +  		// get first word for the line for indent check max 9 characters  		if (FirstWordStart && (!(FirstWordEnd))) {  			if ((ch > 0) && !setWord.Contains(ch)) { @@ -417,8 +421,8 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  				szKeyword[szKeywordlen] = '\0';  			}  		} -		 -		// start the capture of the first word  + +		// start the capture of the first word  		if (!(FirstWordStart)) {  			if ((ch > 0) && (setWord.Contains(ch) || setWordStart.Contains(ch) || ch == ';' || ch == '/')) {  				FirstWordStart = true; @@ -433,7 +437,7 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  			if (DoFoundLast) {  				if (DoFoundLast && (ch > 0) && setWord.Contains(ch)) {  					DoFoundLast = false; -				}		 +				}  			}  			// find out if the word "do" is the last on a "if" line  			if (FirstWordEnd && strcmp(szKeyword,"if") == 0) { @@ -452,53 +456,53 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  			}  		} -		// End of Line found so process the information  +		// End of Line found so process the information  		 if ((ch == '\r' && chNext != '\n') || (ch == '\n') || (i == endPos)) { -		  +  			// **************************  			// Folding logic for Keywords  			// ************************** -			 +  			// if a keyword is found on the current line and the line doesn't end with ;;+ (continuation)  			//    and we are not inside a commentblock. -			if (szKeywordlen > 0 &&  -				(!(chPrev == '+' && chPrevPrev == ';' && chPrevPrevPrev ==';')) &&  +			if (szKeywordlen > 0 && +				(!(chPrev == '+' && chPrevPrev == ';' && chPrevPrevPrev ==';')) &&  				((!(IsStreamCommentStyle(style)) || foldInComment)) ) { -			 +  				// only fold "if" last keyword is "then"  (else its a one line if)  				if (strcmp(szKeyword,"if") == 0  && DoFoundLast) {  						levelNext++;  				} -				// create new fold for these words  +				// create new fold for these words  				if (strcmp(szKeyword,"for") == 0) {  					levelNext++;  				} -				 +  				//handle folding for functions/labels  				//Note: Functions and labels don't have an explicit end like [end function]  				//	1. functions/labels end at the start of another function  				//	2. functions/labels end at the end of the file  				if ((strcmp(szKeyword,"function") == 0) || (szKeywordlen > 0 && szKeyword[0] == '@')) {  					if (isFoldingAll) { //if we're folding the whole document (recursivly by lua script) -						 +  						if (functionCount > 0) {  							levelCurrent--;  						} else {  							levelNext++;  						} -						functionCount++;	 -						 +						functionCount++; +  					} else { //if just folding a small piece (by clicking on the minus sign next to the word)  						levelCurrent--;  					}  				} -												 +  				// end the fold for these words before the current line  				if (strcmp(szKeyword,"endif") == 0 || strcmp(szKeyword,"endfor") == 0) {  						levelNext--;  						levelCurrent--;  				} -				// end the fold for these words before the current line and Start new fold  +				// end the fold for these words before the current line and Start new fold  				if (strcmp(szKeyword,"else") == 0 || strcmp(szKeyword,"elseif") == 0 ) {  						levelCurrent--;  				} @@ -513,16 +517,16 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  				// Start of a comment block  				if (!(stylePrev==style) && IsStreamCommentStyle(styleNext) && styleNext==style) {  				    levelNext++; -				}  +				}  				// fold till the last line for normal comment lines -				else if (IsStreamCommentStyle(stylePrev)  +				else if (IsStreamCommentStyle(stylePrev)  						&& !(styleNext == SCE_POWERPRO_COMMENTLINE) -						&& stylePrev == SCE_POWERPRO_COMMENTLINE  +						&& stylePrev == SCE_POWERPRO_COMMENTLINE  						&& style == SCE_POWERPRO_COMMENTLINE) {  					levelNext--;  				}  				// fold till the one but last line for Blockcomment lines -				else if (IsStreamCommentStyle(stylePrev)  +				else if (IsStreamCommentStyle(stylePrev)  						&& !(styleNext == SCE_POWERPRO_COMMENTBLOCK)  						&& style == SCE_POWERPRO_COMMENTBLOCK) {  					levelNext--; @@ -547,7 +551,7 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  			style = styleNext;  			levelCurrent = levelNext;  			visibleChars = 0; -			 +  			// if the last characters are ;;+ then don't reset since the line continues on the next line.  			if (chPrev == '+' && chPrevPrev == ';' && chPrevPrevPrev == ';') {  				//do nothing @@ -573,7 +577,7 @@ static void FoldPowerProDoc(unsigned int startPos, int length, int, WordList *[]  		}  	} -	//close folds on the last line - without this a 'phantom'  +	//close folds on the last line - without this a 'phantom'  	//fold can appear when an open fold is on the last line  	//this can occur because functions and labels don't have an explicit end  	if (lineCurrent >= lastLine) {  | 
