diff options
| -rw-r--r-- | src/CharacterSet.h | 58 | ||||
| -rw-r--r-- | src/LexCPP.cxx | 48 | ||||
| -rw-r--r-- | src/LexHTML.cxx | 35 | 
3 files changed, 83 insertions, 58 deletions
| diff --git a/src/CharacterSet.h b/src/CharacterSet.h new file mode 100644 index 000000000..4e8ffbdf6 --- /dev/null +++ b/src/CharacterSet.h @@ -0,0 +1,58 @@ +// Scintilla source code edit control +/** @file CharacterSet.h + ** Encapsulates a set of characters. Used to test if a character is within a set. + **/ +// Copyright 2007 by Neil Hodgson <neilh@scintilla.org> +// The License.txt file describes the conditions under which this software may be distributed. + +class CharacterSet { +	int size; +	bool valueAfter; +	bool *bset; +public: +	enum setBase { +		setNone=0, +		setLower=1, +		setUpper=2, +		setDigits=4, +		setAlpha=setLower|setUpper, +		setAlphaNum=setAlpha|setDigits +	}; +	CharacterSet(setBase base=setNone, const char *initialSet="", int size_=0x80, bool valueAfter_=false) { +		size = size_; +		valueAfter = valueAfter_; +		bset = new bool[size]; +		for (int i=0; i < size; i++) { +			bset[i] = false; +		} +		AddString(initialSet); +		if (base & setLower) +			AddString("abcdefghijklmnopqrstuvwxyz"); +		if (base & setUpper) +			AddString("ABCDEFGHIJKLMNOPQRSTUVWXYZ"); +		if (base & setDigits) +			AddString("0123456789"); +	} +	~CharacterSet() { +		delete []bset; +		bset = 0; +		size = 0; +	} +	void Add(int val) { +		PLATFORM_ASSERT(val >= 0); +		PLATFORM_ASSERT(val < size); +		bset[val] = true; +	} +	void AddString(const char *CharacterSet) { +		for (const char *cp=CharacterSet; *cp; cp++) { +			int val = static_cast<unsigned char>(*cp); +			PLATFORM_ASSERT(val >= 0); +			PLATFORM_ASSERT(val < size); +			bset[val] = true; +		} +	} +	bool Contains(int val) const { +		PLATFORM_ASSERT(val >= 0); +		return (val < size) ? bset[val] : valueAfter; +	} +}; diff --git a/src/LexCPP.cxx b/src/LexCPP.cxx index bc3177cb3..8c00acb7b 100644 --- a/src/LexCPP.cxx +++ b/src/LexCPP.cxx @@ -19,50 +19,12 @@  #include "KeyWords.h"  #include "Scintilla.h"  #include "SciLexer.h" +#include "CharacterSet.h"  #ifdef SCI_NAMESPACE  using namespace Scintilla;  #endif -#define SET_LOWER "abcdefghijklmnopqrstuvwxyz" -#define SET_UPPER "ABCDEFGHIJKLMNOPQRSTUVWXYZ" -#define SET_DIGITS "0123456789" - -class SetOfCharacters { -	int size; -	bool valueAfter; -	bool *bset; -public: -	SetOfCharacters(const char *setOfCharacters, int size_=0x80, bool valueAfter_=false) { -		size = size_; -		valueAfter = valueAfter_; -		bset = new bool[size]; -		for (int i=0; i < size; i++) { -			bset[i] = false; -		} -		for (const char *cp=setOfCharacters; *cp; cp++) { -			int val = static_cast<unsigned char>(*cp); -			PLATFORM_ASSERT(val >= 0); -			PLATFORM_ASSERT(val < size); -			bset[val] = true; -		} -	} -	~SetOfCharacters() { -		delete []bset; -		bset = 0; -		size = 0; -	} -	void Add(int val) { -		PLATFORM_ASSERT(val >= 0); -		PLATFORM_ASSERT(val < size); -		bset[val] = true; -	} -	bool Contains(int val) { -		PLATFORM_ASSERT(val >= 0); -		return (val < size) ? bset[val] : valueAfter; -	} -}; -  static bool IsSpaceEquiv(int state) {  	return (state <= SCE_C_COMMENTDOC) ||  		// including SCE_C_DEFAULT, SCE_C_COMMENT, SCE_C_COMMENTLINE @@ -80,12 +42,12 @@ static void ColouriseCppDoc(unsigned int startPos, int length, int initStyle, Wo  	bool stylingWithinPreprocessor = styler.GetPropertyInt("styling.within.preprocessor") != 0; -	SetOfCharacters setOKBeforeRE("(=,"); +	CharacterSet setOKBeforeRE(CharacterSet::setNone, "(=,"); -	SetOfCharacters setDoxygen("$@\\&<>#{}[]" SET_LOWER); +	CharacterSet setDoxygen(CharacterSet::setLower, "$@\\&<>#{}[]"); -	SetOfCharacters setWordStart("_" SET_LOWER SET_UPPER, 0x80, true); -	SetOfCharacters setWord("._" SET_LOWER SET_UPPER SET_DIGITS, 0x80, true); +	CharacterSet setWordStart(CharacterSet::setAlpha, "_", 0x80, true); +	CharacterSet setWord(CharacterSet::setAlphaNum, "._", 0x80, true);  	if (styler.GetPropertyInt("lexer.cpp.allow.dollars", 1) != 0) {  		setWordStart.Add('$');  		setWord.Add('$'); diff --git a/src/LexHTML.cxx b/src/LexHTML.cxx index 877f0881a..eebf5ca1d 100644 --- a/src/LexHTML.cxx +++ b/src/LexHTML.cxx @@ -19,6 +19,7 @@  #include "KeyWords.h"  #include "Scintilla.h"  #include "SciLexer.h" +#include "CharacterSet.h"  #ifdef SCI_NAMESPACE  using namespace Scintilla; @@ -106,16 +107,16 @@ static script_type ScriptOfState(int state) {  }  static int statePrintForState(int state, script_mode inScriptType) { -	int StateToPrint; - -	if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) { -		StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_PYTHON); -	} else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) { -		StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_VBS); -	} else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_REGEX)) { -		StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_JS); -	} else { -		StateToPrint = state; +	int StateToPrint = state; + +	if (state >= SCE_HJ_START) { +		if ((state >= SCE_HP_START) && (state <= SCE_HP_IDENTIFIER)) { +			StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_PYTHON); +		} else if ((state >= SCE_HB_START) && (state <= SCE_HB_STRINGEOL)) { +			StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_VBS); +		} else if ((state >= SCE_HJ_START) && (state <= SCE_HJ_REGEX)) { +			StateToPrint = state + ((inScriptType == eNonHtmlScript) ? 0 : SCE_HA_JS); +		}  	}  	return StateToPrint; @@ -521,6 +522,10 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty  	const bool foldCompact = styler.GetPropertyInt("fold.compact", 1) != 0;  	const bool caseSensitive = styler.GetPropertyInt("html.tags.case.sensitive", 0) != 0; +	const CharacterSet setHTMLWord(CharacterSet::setAlphaNum, ".-_:!#", 0x80, true); +	const CharacterSet setTagContinue(CharacterSet::setAlphaNum, ".-_:!#[", 0x80, true); +	const CharacterSet setAttributeContinue(CharacterSet::setAlphaNum, ".-_:!#/", 0x80, true); +  	int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;  	int levelCurrent = levelPrev;  	int visibleChars = 0; @@ -932,7 +937,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty  				}  				// find the length of the word  				int size = 1; -				while (ishtmlwordchar(styler.SafeGetCharAt(i + size))) +				while (setHTMLWord.Contains(styler.SafeGetCharAt(i + size)))  					size++;  				styler.ColourTo(i + size - 1, StateToPrint);  				i += size - 1; @@ -1020,7 +1025,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty  			}  			break;  		case SCE_H_TAGUNKNOWN: -			if (!ishtmlwordchar(ch) && !((ch == '/') && (chPrev == '<')) && ch != '[') { +			if (!setTagContinue.Contains(ch) && !((ch == '/') && (chPrev == '<'))) {  				int eClass = classifyTagHTML(styler.GetStartSegment(),  					i - 1, keywords, styler, tagDontFold, caseSensitive, isXml);  				if (eClass == SCE_H_SCRIPT) { @@ -1072,7 +1077,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty  			}  			break;  		case SCE_H_ATTRIBUTE: -			if (!ishtmlwordchar(ch) && ch != '/' && ch != '-') { +			if (!setAttributeContinue.Contains(ch)) {  				if (inScriptType == eNonHtmlScript) {  					int scriptLanguagePrev = scriptLanguage;  					clientScript = segIsScriptingIndicator(styler, styler.GetStartSegment(), i - 1, scriptLanguage); @@ -1145,7 +1150,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty  				i++;  				ch = chNext;  				state = SCE_H_DEFAULT; -			} else if (ishtmlwordchar(ch)) { +			} else if (setHTMLWord.Contains(ch)) {  				styler.ColourTo(i - 1, StateToPrint);  				state = SCE_H_ATTRIBUTE;  			} @@ -1169,7 +1174,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty  			}  			break;  		case SCE_H_VALUE: -			if (!ishtmlwordchar(ch)) { +			if (!setHTMLWord.Contains(ch)) {  				if (ch == '\"' && chPrev == '=') {  					// Should really test for being first character  					state = SCE_H_DOUBLESTRING; | 
