diff options
| author | nyamatongwe <unknown> | 2003-07-30 12:56:36 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2003-07-30 12:56:36 +0000 | 
| commit | 55f41339841ae4e7bd5bdbccf42af47dd73e8930 (patch) | |
| tree | 92e337c95b3be7e17658876160a3a0ae6cf3de1e | |
| parent | c1eed814fcbb9fdf976fbbaf1204983f3d138e8e (diff) | |
| download | scintilla-mirror-55f41339841ae4e7bd5bdbccf42af47dd73e8930.tar.gz | |
NSIS scripting language support from Angelo Mandato.
| -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 | 15 | ||||
| -rw-r--r-- | include/Scintilla.iface | 17 | ||||
| -rw-r--r-- | src/KeyWords.cxx | 1 | ||||
| -rw-r--r-- | src/LexNsis.cxx | 346 | ||||
| -rw-r--r-- | win32/makefile | 4 | ||||
| -rw-r--r-- | win32/scintilla.mak | 3 | ||||
| -rw-r--r-- | win32/scintilla_vc6.mak | 3 | 
10 files changed, 393 insertions, 4 deletions
| diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index f5b8e36a7..38bd7f982 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -133,6 +133,7 @@  	<li>Hrishikesh Desai</li>  	<li>Sergey Puljajev</li>  	<li>Mathias Rauen</li> +	<li>Angelo Mandato</li>      </ul>      <p>         Images used in GTK+ version diff --git a/gtk/makefile b/gtk/makefile index 9206be86e..c4ec839cc 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -50,8 +50,8 @@ endif  LEXOBJS=\  LexAda.o LexAsm.o LexAVE.o LexBaan.o LexBullant.o LexConf.o LexCPP.o \  LexCrontab.o LexCSS.o LexEiffel.o LexEScript.o LexFortran.o LexHTML.o \ -LexLisp.o LexLout.o LexLua.o LexMatlab.o LexOthers.o LexPascal.o LexPerl.o \ -LexPOV.o LexPS.o LexPython.o LexRuby.o LexSQL.o LexVB.o  +LexLisp.o LexLout.o LexLua.o LexMatlab.o LexNsis.o LexOthers.o LexPascal.o \ +LexPerl.o LexPOV.o LexPS.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 b171986d5..f6db94adf 100644 --- a/gtk/scintilla.mak +++ b/gtk/scintilla.mak @@ -137,6 +137,7 @@ LEXOBJS=\  	$(DIR_O)\LexLout.obj \  	$(DIR_O)\LexLua.obj \  	$(DIR_O)\LexMatlab.obj \ +	$(DIR_O)\LexNsis.obj \  	$(DIR_O)\LexOthers.obj \  	$(DIR_O)\LexPascal.obj \  	$(DIR_O)\LexPerl.obj \ @@ -292,6 +293,8 @@ $(DIR_O)\LexLua.obj: ..\src\LexLua.cxx $(LEX_HEADERS)  $(DIR_O)\LexMatlab.obj: ..\src\LexMatlab.cxx $(LEX_HEADERS) +$(DIR_O)\LexNsis.obj: ..\src\LexNsis.cxx $(LEX_HEADERS) +  $(DIR_O)\LexOthers.obj: ..\src\LexOthers.cxx $(LEX_HEADERS)  $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS) diff --git a/include/SciLexer.h b/include/SciLexer.h index edf63c4f1..009c046fe 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -57,6 +57,7 @@  #define SCLEX_LOUT 40  #define SCLEX_ESCRIPT 41  #define SCLEX_PS 42 +#define SCLEX_NSIS 43  #define SCLEX_AUTOMATIC 1000  #define SCE_P_DEFAULT 0  #define SCE_P_COMMENTLINE 1 @@ -503,6 +504,20 @@  #define SCE_PS_HEXSTRING 13  #define SCE_PS_BASE85STRING 14  #define SCE_PS_BADSTRINGCHAR 15 +#define SCE_NSIS_DEFAULT 0 +#define SCE_NSIS_COMMENT 1 +#define SCE_NSIS_STRINGDQ 2 +#define SCE_NSIS_STRINGLQ 3 +#define SCE_NSIS_STRINGRQ 4 +#define SCE_NSIS_FUNCTION 5 +#define SCE_NSIS_VARIABLE 6 +#define SCE_NSIS_LABEL 7 +#define SCE_NSIS_USERDEFINED 8 +#define SCE_NSIS_SECTIONDEF 9 +#define SCE_NSIS_SUBSECTIONDEF 10 +#define SCE_NSIS_IFDEFINEDEF 11 +#define SCE_NSIS_MACRODEF 12 +#define SCE_NSIS_STRINGVAR 13  //--Autogenerated -- end of section automatically generated from Scintilla.iface  #endif diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 2d61b4d8c..3cb64c15f 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1586,6 +1586,7 @@ val SCLEX_POV=39  val SCLEX_LOUT=40  val SCLEX_ESCRIPT=41  val SCLEX_PS=42 +val SCLEX_NSIS=43  # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a  # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -2113,6 +2114,22 @@ val SCE_PS_TEXT=12  val SCE_PS_HEXSTRING=13  val SCE_PS_BASE85STRING=14  val SCE_PS_BADSTRINGCHAR=15 +# Lexical states for SCLEX_NSIS +lex NSIS=SCLEX_NSIS SCE_NSIS_ +val SCE_NSIS_DEFAULT=0 +val SCE_NSIS_COMMENT=1 +val SCE_NSIS_STRINGDQ=2 +val SCE_NSIS_STRINGLQ=3 +val SCE_NSIS_STRINGRQ=4 +val SCE_NSIS_FUNCTION=5 +val SCE_NSIS_VARIABLE=6 +val SCE_NSIS_LABEL=7 +val SCE_NSIS_USERDEFINED=8 +val SCE_NSIS_SECTIONDEF=9 +val SCE_NSIS_SUBSECTIONDEF=10 +val SCE_NSIS_IFDEFINEDEF=11 +val SCE_NSIS_MACRODEF=12 +val SCE_NSIS_STRINGVAR=13  # Events diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx index 9a2ff0903..a15bae350 100644 --- a/src/KeyWords.cxx +++ b/src/KeyWords.cxx @@ -153,6 +153,7 @@ int Scintilla_LinkLexers() {  	LINK_LEXER(lmLout);  	LINK_LEXER(lmLua);  	LINK_LEXER(lmMatlab); +	LINK_LEXER(lmNsis);  	LINK_LEXER(lmBatch);  	LINK_LEXER(lmDiff);  	LINK_LEXER(lmProps); diff --git a/src/LexNsis.cxx b/src/LexNsis.cxx new file mode 100644 index 000000000..c09a8ae86 --- /dev/null +++ b/src/LexNsis.cxx @@ -0,0 +1,346 @@ +// Scintilla source code edit control +/** @file LexNsis.cxx + ** Lexer for NSIS + **/ +// Copyright 2003 by Angelo Mandato <angelo@spaceblue.com> +// 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 "KeyWords.h" +#include "Scintilla.h" +#include "SciLexer.h" + +/* +// Put in SciLexer.h +#define SCLEX_NSIS 34 + +#define SCE_NSIS_DEFAULT 0 +#define SCE_NSIS_COMMENT 1 +#define SCE_NSIS_STRINGDQ 2 +#define SCE_NSIS_STRINGLQ 3 +#define SCE_NSIS_STRINGRQ 4 +#define SCE_NSIS_FUNCTION 5 +#define SCE_NSIS_VARIABLE 6 +#define SCE_NSIS_LABEL 7 +#define SCE_NSIS_USERDEFINED 8 +#define SCE_NSIS_SECTIONDEF 9 +#define SCE_NSIS_SUBSECTIONDEF 10 +#define SCE_NSIS_IFDEFINEDEF 11 +#define SCE_NSIS_MACRODEF 12 +#define SCE_NSIS_STRINGVAR 13 +*/ + +static int classifyWordNsis(unsigned int start, unsigned int end, WordList *keywordLists[], Accessor &styler) +{ +	char s[100]; + +	WordList &Functions = *keywordLists[0]; +	WordList &Variables = *keywordLists[1]; +	WordList &Lables = *keywordLists[2]; +	WordList &UserDefined = *keywordLists[3]; + +	for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) +	{ +		s[i] = static_cast<char>( styler[ start + i ] ); +		s[i + 1] = '\0'; +	} + +	// Check for special words... + +	if( strcmp(s, "!macro") == 0 || strcmp(s, "!macroend") == 0 ) // Covers !micro and !microend +		return SCE_NSIS_MACRODEF; + +	if( strcmp(s, "!ifdef") == 0 ||  strcmp(s, "!ifndef") == 0 ||  strcmp(s, "!endif") == 0 ) +		return SCE_NSIS_IFDEFINEDEF; + +	if( strcmp(s, "Section") == 0 || strcmp(s, "SectionEnd") == 0 ) // Covers Section and SectionEnd +		return SCE_NSIS_SECTIONDEF; + +	if( strcmp(s, "SubSection") == 0 || strcmp(s, "SubSectionEnd") == 0 ) // Covers SubSection and SubSectionEnd +		return SCE_NSIS_SUBSECTIONDEF; + +	if( strcmp(s, "Function") == 0 || strcmp(s, "FunctionEnd") == 0 ) // Covers SubSection and SubSectionEnd +		return SCE_NSIS_FUNCTION; + +	if ( Functions.InList(s) ) +		return SCE_NSIS_FUNCTION; + +	if ( Variables.InList(s) ) +		return SCE_NSIS_VARIABLE; + +	if ( Lables.InList(s) ) +		return SCE_NSIS_LABEL; + +	if( UserDefined.InList(s) ) +		return SCE_NSIS_USERDEFINED; + +	if( strlen(s) > 2 ) +	{ +		if( s[1] == '{' && s[strlen(s)-1] == '}' ) +			return SCE_NSIS_VARIABLE; +	} + +	return SCE_NSIS_DEFAULT; +} + +static void ColouriseNsisDoc(unsigned int startPos, int length, int, WordList *keywordLists[], Accessor &styler) +{ +	int state = SCE_NSIS_DEFAULT; +	styler.StartAt( startPos ); +	styler.GetLine( startPos ); + +	unsigned int nLengthDoc = startPos + length; +	styler.StartSegment( startPos ); + +	char cCurrChar; +	bool bVarInString = true; + +	unsigned int i; +	for( i = startPos; i < nLengthDoc; i++ ) +	{ +		cCurrChar = styler.SafeGetCharAt( i ); +		char cNextChar = styler.SafeGetCharAt( i+1, EOF ); + + + +		switch(state) +		{ +			case SCE_NSIS_DEFAULT: +        if( cNextChar == EOF ) +        { +          styler.ColourTo(i,SCE_NSIS_DEFAULT); +			    break; +        } +				if( cCurrChar == ';' || cCurrChar == '#' ) // we have a comment line +				{ +					styler.ColourTo(i-1, state ); +					state = SCE_NSIS_COMMENT; +					break; +				} +				if( cCurrChar == '"' ) +				{ +					styler.ColourTo(i-1, state ); +					state = SCE_NSIS_STRINGDQ; +					bVarInString = false; +					break; +				} +				if( cCurrChar == '\'' ) +				{ +					styler.ColourTo(i-1, state ); +					state = SCE_NSIS_STRINGRQ; +					bVarInString = false; +					break; +				} +				if( cCurrChar == '`' ) +				{ +					styler.ColourTo(i-1, state ); +					state = SCE_NSIS_STRINGLQ; +					bVarInString = false; +					break; +				} + +				// NSIS KeyWord,Function, Variable, UserDefined: +				if( cCurrChar == '$' || iswordchar(cCurrChar) || cCurrChar == '!' ) +				{ +					styler.ColourTo(i-1,state); +				  state = SCE_NSIS_FUNCTION; +					break; +				} +				break; +			case SCE_NSIS_COMMENT: +				if( cNextChar == '\n' || cNextChar == '\r' || cNextChar == EOF ) +        { +				  styler.ColourTo(i,state); +          state = SCE_NSIS_DEFAULT; +        } +				break; +			case SCE_NSIS_STRINGDQ: +				if( cCurrChar == '"' || cNextChar == '\r' || cNextChar == '\n' ) +				{ +					styler.ColourTo(i,SCE_NSIS_STRINGDQ); +				  state = SCE_NSIS_DEFAULT; +				} +				break; +			case SCE_NSIS_STRINGLQ: +				if( cCurrChar == '`' || cNextChar == '\r' || cNextChar == '\n' ) +				{ +					styler.ColourTo(i,SCE_NSIS_STRINGLQ); +				  state = SCE_NSIS_DEFAULT; +				} +				break; +			case SCE_NSIS_STRINGRQ: +				if( cCurrChar == '\'' || cNextChar == '\r' || cNextChar == '\n' ) +				{ +					styler.ColourTo(i,SCE_NSIS_STRINGRQ); +				  state = SCE_NSIS_DEFAULT; +				} +				break; +			case SCE_NSIS_FUNCTION: + +				// NSIS KeyWord: +				if( (iswordchar(cCurrChar) && !iswordchar( cNextChar) && cNextChar != '}') || cCurrChar == '}' ) +				{ +					state = classifyWordNsis( styler.GetStartSegment(), i, keywordLists, styler); +					styler.ColourTo( i, state); +					state = SCE_NSIS_DEFAULT; // Everything after goes back to the default state +				} +				else if( !iswordchar( cCurrChar ) && cCurrChar != '{' && cCurrChar != '}' ) +				{ +					state = SCE_NSIS_DEFAULT; + +					if( cCurrChar == '"' ) // Next +					{ +						state = SCE_NSIS_STRINGDQ; +						bVarInString = false; +					} +					if( cCurrChar == '`' ) +					{ +						state = SCE_NSIS_STRINGLQ; +						bVarInString = false; +					} +					if( cCurrChar == '\'' ) +					{ +						state = SCE_NSIS_STRINGRQ; +						bVarInString = false; +					} +					if( cCurrChar == '#' || cCurrChar == ';' ) +						state = SCE_NSIS_COMMENT; + +					styler.ColourTo( i, state); +				} +				break; +		} + +		if( state == SCE_NSIS_COMMENT ) +		{ +			styler.ColourTo(i,state); +		} +		else if( state == SCE_NSIS_STRINGDQ || state == SCE_NSIS_STRINGLQ || state == SCE_NSIS_STRINGRQ ) +		{ +			// Check for var in String.. +			if( bVarInString && (iswordchar(cCurrChar) || cCurrChar == '}') ) // || cCurrChar == '{' ) ) +			{ +				int nWordState = classifyWordNsis( styler.GetStartSegment(), i, keywordLists, styler); +				if( nWordState == SCE_NSIS_VARIABLE ) +				{ +					styler.ColourTo( i, SCE_NSIS_STRINGVAR); +					bVarInString = false; +				} +			} +			if( cCurrChar == '$' ) +			{ +				styler.ColourTo( i-1, state); +				bVarInString = true; +			} +		} +	} +} + + +static void FoldNsisDoc(unsigned int startPos, int length, int, WordList *[], Accessor &styler) +{ +	// No folding enabled, no reason to continue... +	if( styler.GetPropertyInt("fold") == 0 ) +		return; + +	unsigned int endPos = startPos + length; +	int lineCurrent = styler.GetLine(startPos); +	int levelCurrent = SC_FOLDLEVELBASE; +	if (lineCurrent > 0) +		levelCurrent = styler.LevelAt(lineCurrent-1) >> 16; +	int levelNext = levelCurrent; +	char chNext = styler[startPos]; +	int styleNext = styler.StyleAt(startPos); +	int style; + +	for (unsigned int i = startPos; i < endPos; i++) +	{ +		char ch = chNext; +		chNext = styler.SafeGetCharAt(i + 1); +		style = styleNext; +		styleNext = styler.StyleAt(i + 1); +		bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); +		// Functions Start: Function, Section, SubSection +		// Functions End: FunctionEnd, SectionEnd, SubSectionEnd +		// Label Start: !ifdef, !ifndef +		// Label End: !endif + +		if( style == SCE_NSIS_FUNCTION ) +		{ +			if( styler.Match(i, "FunctionEnd") ) +				levelNext--; +			else if( styler.Match(i, "Function") ) +				levelNext++; +		} +		else if( style == SCE_NSIS_SECTIONDEF ) +		{ +			if( styler.Match(i, "SectionEnd") ) +				levelNext--; +			else if( styler.Match(i, "Section") ) +				levelNext++; +		} +		else if( style == SCE_NSIS_SUBSECTIONDEF ) +		{ +			if( styler.Match(i, "SubSectionEnd") ) +				levelNext--; +			else if( styler.Match(i, "SubSection") ) +				levelNext++; +		} +		else if( style == SCE_NSIS_IFDEFINEDEF ) +		{ +			if( styler.Match(i, "!endif") ) +				levelNext--; +			else if( styler.Match(i, "!ifdef") || styler.Match(i, "!ifndef")) +				levelNext++; +		} +		else if( style == SCE_NSIS_MACRODEF ) +		{ +			if( styler.Match(i, "!macroend") ) +				levelNext--; +			else if( styler.Match(i, "!macro") ) +				levelNext++; +		} + +		if( atEOL ) +		{ +			int levelUse = levelCurrent; +			int lev = levelUse | levelNext << 16; +			if (levelUse < levelNext) +				lev |= SC_FOLDLEVELHEADERFLAG; +			if (lev != styler.LevelAt(lineCurrent)) +			{ +				styler.SetLevel(lineCurrent, lev); +			} +			lineCurrent++; +			levelCurrent = levelNext; +		} +	} + +	int levelUse = levelCurrent; +	int lev = levelUse | levelNext << 16; +	if (levelUse < levelNext) +		lev |= SC_FOLDLEVELHEADERFLAG; +	if (lev != styler.LevelAt(lineCurrent)) +	{ +		styler.SetLevel(lineCurrent, lev); +	} +} + +static const char * const nsisWordLists[] = { +	"Functions", +	"Variables", +	"Lables", +	"UserDefined", +	0, }; + + +LexerModule lmNsis(SCLEX_NSIS, ColouriseNsisDoc, "nsis", FoldNsisDoc, nsisWordLists); diff --git a/win32/makefile b/win32/makefile index 08d4060ea..cfdb9f155 100644 --- a/win32/makefile +++ b/win32/makefile @@ -48,8 +48,8 @@ deps:  LEXOBJS=\  LexAda.o LexAsm.o LexAVE.o LexBaan.o LexBullant.o LexConf.o LexCPP.o \  LexCrontab.o LexCSS.o LexEiffel.o LexEScript.o LexFortran.o LexHTML.o \ -LexLisp.o LexLout.o LexLua.o LexMatlab.o LexOthers.o LexPascal.o LexPerl.o \ -LexPOV.o LexPS.o LexPython.o LexRuby.o LexSQL.o LexVB.o  +LexLisp.o LexLout.o LexLua.o LexMatlab.o LexNsis.o LexOthers.o LexPascal.o \ +LexPerl.o LexPOV.o LexPS.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 963de50c3..ab023e178 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -126,6 +126,7 @@ LEXOBJS=\  	$(DIR_O)\LexLout.obj \  	$(DIR_O)\LexLua.obj \  	$(DIR_O)\LexMatlab.obj \ +	$(DIR_O)\LexNsis.obj \  	$(DIR_O)\LexOthers.obj \  	$(DIR_O)\LexPascal.obj \  	$(DIR_O)\LexPerl.obj \ @@ -278,6 +279,8 @@ $(DIR_O)\LexLua.obj: ..\src\LexLua.cxx $(LEX_HEADERS)  $(DIR_O)\LexMatlab.obj: ..\src\LexMatlab.cxx $(LEX_HEADERS) +$(DIR_O)\LexNsis.obj: ..\src\LexNsis.cxx $(LEX_HEADERS) +  $(DIR_O)\LexOthers.obj: ..\src\LexOthers.cxx $(LEX_HEADERS)  $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS) diff --git a/win32/scintilla_vc6.mak b/win32/scintilla_vc6.mak index febcc997b..611163714 100644 --- a/win32/scintilla_vc6.mak +++ b/win32/scintilla_vc6.mak @@ -128,6 +128,7 @@ LEXOBJS=\  	$(DIR_O)\LexLout.obj \  	$(DIR_O)\LexLua.obj \  	$(DIR_O)\LexMatlab.obj \ +	$(DIR_O)\LexNsis.obj \  	$(DIR_O)\LexOthers.obj \  	$(DIR_O)\LexPascal.obj \  	$(DIR_O)\LexPerl.obj \ @@ -280,6 +281,8 @@ $(DIR_O)\LexLua.obj: ..\src\LexLua.cxx $(LEX_HEADERS)  $(DIR_O)\LexMatlab.obj: ..\src\LexMatlab.cxx $(LEX_HEADERS) +$(DIR_O)\LexNsis.obj: ..\src\LexNsis.cxx $(LEX_HEADERS) +  $(DIR_O)\LexOthers.obj: ..\src\LexOthers.cxx $(LEX_HEADERS)  $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS) | 
