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 | 11 | ||||
| -rw-r--r-- | include/Scintilla.iface | 13 | ||||
| -rw-r--r-- | src/KeyWords.cxx | 1 | ||||
| -rw-r--r-- | src/LexOpal.cxx | 518 | ||||
| -rw-r--r-- | win32/makefile | 4 | ||||
| -rw-r--r-- | win32/scintilla.mak | 3 | ||||
| -rw-r--r-- | win32/scintilla_vc6.mak | 3 | 
10 files changed, 557 insertions, 4 deletions
| diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index 0234d85cb..bc686e424 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -214,6 +214,7 @@  	<li>Armel Asselin</li>  	<li>Jim Pattee</li>  	<li>Friedrich Vedder</li> +	<li>Sebastian Pipping</li>      </ul>      <p>         Images used in GTK+ version diff --git a/gtk/makefile b/gtk/makefile index a3372d88a..487f19508 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -68,8 +68,8 @@ LexBasic.o LexBullant.o LexCaml.o LexCLW.o LexConf.o LexCPP.o LexCrontab.o \  LexCsound.o LexCSS.o LexEiffel.o LexErlang.o LexEScript.o LexFlagship.o \  LexForth.o LexFortran.o LexGui4Cli.o LexHaskell.o LexHTML.o LexInno.o LexKix.o \  LexLisp.o LexLout.o LexLua.o LexMatlab.o LexMetapost.o LexMMIXAL.o LexMPT.o \ -LexMSSQL.o LexNsis.o LexOthers.o LexPascal.o LexPB.o LexPerl.o LexPOV.o \ -LexPS.o LexPython.o LexRebol.o LexRuby.o LexScriptol.o LexSmalltalk.o \ +LexMSSQL.o LexNsis.o LexOpal.o LexOthers.o LexPascal.o LexPB.o LexPerl.o \ +LexPOV.o LexPS.o LexPython.o LexRebol.o LexRuby.o LexScriptol.o LexSmalltalk.o \  LexSpecman.o LexSQL.o LexTADS3.o LexTeX.o LexVB.o LexVerilog.o LexVHDL.o \  LexYAML.o  #--Autogenerated -- end of automatically generated section diff --git a/gtk/scintilla.mak b/gtk/scintilla.mak index 3337fb583..a42e07bf5 100644 --- a/gtk/scintilla.mak +++ b/gtk/scintilla.mak @@ -176,6 +176,7 @@ LEXOBJS=\  	$(DIR_O)\LexMPT.obj \  	$(DIR_O)\LexMSSQL.obj \  	$(DIR_O)\LexNsis.obj \ +	$(DIR_O)\LexOpal.obj \  	$(DIR_O)\LexOthers.obj \  	$(DIR_O)\LexPascal.obj \  	$(DIR_O)\LexPB.obj \ @@ -385,6 +386,8 @@ $(DIR_O)\LexMSSQL.obj: ..\src\LexMSSQL.cxx $(LEX_HEADERS)  $(DIR_O)\LexNsis.obj: ..\src\LexNsis.cxx $(LEX_HEADERS) +$(DIR_O)\LexOpal.obj: ..\src\LexOpal.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 204349ce4..d72f55642 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -89,6 +89,7 @@  #define SCLEX_CSOUND 74  #define SCLEX_FREEBASIC 75  #define SCLEX_INNOSETUP 76 +#define SCLEX_OPAL 77  #define SCLEX_AUTOMATIC 1000  #define SCE_P_DEFAULT 0  #define SCE_P_COMMENTLINE 1 @@ -1022,6 +1023,16 @@  #define SCE_INNO_STRING_DOUBLE 10  #define SCE_INNO_STRING_SINGLE 11  #define SCE_INNO_IDENTIFIER 12 +#define SCE_OPAL_SPACE 0 +#define SCE_OPAL_COMMENT_BLOCK 1 +#define SCE_OPAL_COMMENT_LINE 2 +#define SCE_OPAL_INTEGER 3 +#define SCE_OPAL_KEYWORD 4 +#define SCE_OPAL_SORT 5 +#define SCE_OPAL_STRING 6 +#define SCE_OPAL_PAR 7 +#define SCE_OPAL_BOOL_CONST 8 +#define SCE_OPAL_DEFAULT 32  #define SCLEX_ASP 29  #define SCLEX_PHP 30  //--Autogenerated -- end of section automatically generated from Scintilla.iface diff --git a/include/Scintilla.iface b/include/Scintilla.iface index 0a38ad2e1..9a3a94d77 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1819,6 +1819,7 @@ val SCLEX_FLAGSHIP=73  val SCLEX_CSOUND=74  val SCLEX_FREEBASIC=75  val SCLEX_INNOSETUP=76 +val SCLEX_OPAL=77  # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a  # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -2892,6 +2893,18 @@ val SCE_INNO_KEYWORD_USER=9  val SCE_INNO_STRING_DOUBLE=10  val SCE_INNO_STRING_SINGLE=11  val SCE_INNO_IDENTIFIER=12 +# Lexical states for SCLEX_OPAL +lex Opal=SCLEX_OPAL SCE_OPAL_ +val SCE_OPAL_SPACE=0 +val SCE_OPAL_COMMENT_BLOCK=1 +val SCE_OPAL_COMMENT_LINE=2 +val SCE_OPAL_INTEGER=3 +val SCE_OPAL_KEYWORD=4 +val SCE_OPAL_SORT=5 +val SCE_OPAL_STRING=6 +val SCE_OPAL_PAR=7 +val SCE_OPAL_BOOL_CONST=8 +val SCE_OPAL_DEFAULT=32  # Events diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx index 342d068e4..322a8d84c 100644 --- a/src/KeyWords.cxx +++ b/src/KeyWords.cxx @@ -187,6 +187,7 @@ int Scintilla_LinkLexers() {  	LINK_LEXER(lmNsis);  	LINK_LEXER(lmNull);  	LINK_LEXER(lmOctave); +	LINK_LEXER(lmOpal);  	LINK_LEXER(lmPascal);  	LINK_LEXER(lmPB);  	LINK_LEXER(lmPerl); diff --git a/src/LexOpal.cxx b/src/LexOpal.cxx new file mode 100644 index 000000000..d1d188998 --- /dev/null +++ b/src/LexOpal.cxx @@ -0,0 +1,518 @@ +// Scintilla source code edit control +/** @file LexOpal.cxx + ** Lexer for OPAL (functional language similar to Haskell) + ** Written by Sebastian Pipping <webmaster@hartwork.org> + **/ + +#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" +#include "StyleContext.h" + +inline static void getRange( unsigned int start, unsigned int end, Accessor & styler, char * s, unsigned int len ) +{ +	unsigned int i = 0; +	while( ( i < end - start + 1 ) && ( i < len - 1 ) ) +	{ +		s[i] = static_cast<char>( styler[ start + i ] ); +		i++; +	} +	s[ i ] = '\0'; +} + +inline bool HandleString( unsigned int & cur, unsigned int one_too_much, Accessor & styler ) +{ +	char ch; + +	// Wait for string to close +	bool even_backslash_count = true; // Without gaps in between +	cur++; // Skip initial quote +	for( ; ; ) +	{ +		if( cur >= one_too_much ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_STRING ); +			return false; // STOP +		} + +		ch = styler.SafeGetCharAt( cur ); +		if( ( ch == '\015' ) || ( ch == '\012' ) ) // Deny multi-line strings +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_STRING ); +			styler.StartSegment( cur ); +			return true; +		} +		else +		{ +			if( even_backslash_count ) +			{ +				if( ch == '"' ) +				{ +					styler.ColourTo( cur, SCE_OPAL_STRING ); +					cur++; +					if( cur >= one_too_much ) +					{ +						return false; // STOP +					} +					else +					{ +						styler.StartSegment( cur ); +						return true; +					} +				} +				else if( ch == '\\' ) +				{ +					even_backslash_count = false; +				} +			} +			else +			{ +				even_backslash_count = true; +			} +		} + +		cur++; +	} +} + +inline bool HandleCommentBlock( unsigned int & cur, unsigned int one_too_much, Accessor & styler, bool could_fail ) +{ +	char ch; +	 +	if( could_fail ) +	{ +		cur++; +		if( cur >= one_too_much ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_DEFAULT ); +			return false; // STOP +		} +		 +		ch = styler.SafeGetCharAt( cur ); +		if( ch != '*' ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_DEFAULT ); +			styler.StartSegment( cur ); +			return true; +		} +	} +	 +	// Wait for comment close +	cur++; +	bool star_found = false; +	for( ; ; ) +	{ +		if( cur >= one_too_much ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_COMMENT_BLOCK ); +			return false; // STOP +		} +		 +		ch = styler.SafeGetCharAt( cur ); +		if( star_found ) +		{ +			if( ch == '/' ) +			{ +				styler.ColourTo( cur, SCE_OPAL_COMMENT_BLOCK ); +				cur++; +				if( cur >= one_too_much ) +				{ +					return false; // STOP +				} +				else +				{ +					styler.StartSegment( cur ); +					return true; +				} +			} +			else if( ch != '*' ) +			{ +				star_found = false; +			} +		} +		else if( ch == '*' ) +		{ +			star_found = true; +		} +		cur++; +	} +} + +inline bool HandleCommentLine( unsigned int & cur, unsigned int one_too_much, Accessor & styler, bool could_fail ) +{ +	char ch; +	 +	if( could_fail ) +	{ +		cur++; +		if( cur >= one_too_much ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_DEFAULT ); +			return false; // STOP +		} +		 +		ch = styler.SafeGetCharAt( cur ); +		if( ch != '-' ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_DEFAULT ); +			styler.StartSegment( cur ); +			return true; +		} + +		cur++; +		if( cur >= one_too_much ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_DEFAULT ); +			return false; // STOP +		} +		 +		ch = styler.SafeGetCharAt( cur ); +		if( ( ch != ' ' ) && ( ch != '\t' ) ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_DEFAULT ); +			styler.StartSegment( cur ); +			return true; +		} +	} + +	// Wait for end of line +	bool fifteen_found = false; + +	for( ; ; ) +	{ +		cur++; + +		if( cur >= one_too_much ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_COMMENT_LINE ); +			return false; // STOP +		} + +		ch = styler.SafeGetCharAt( cur ); +		if( fifteen_found ) +		{ +/* +			if( ch == '\012' ) +			{ +				// One newline on Windows (015, 012) +			} +			else +			{ +				// One newline on MAC (015) and another char +			} +*/ +			cur--; +			styler.ColourTo( cur - 1, SCE_OPAL_COMMENT_LINE ); +			styler.StartSegment( cur ); +			return true; +		} +		else +		{ +			if( ch == '\015' ) +			{ +				fifteen_found = true;	 +			} +			else if( ch == '\012' ) +			{ +				// One newline on Linux (012) +				styler.ColourTo( cur - 1, SCE_OPAL_COMMENT_LINE ); +				styler.StartSegment( cur ); +				return true; +			} +		} +	} +} + +inline bool HandlePar( unsigned int & cur, Accessor & styler ) +{ +	styler.ColourTo( cur, SCE_OPAL_PAR ); + +	cur++; + +	styler.StartSegment( cur ); +	return true; +} + +inline bool HandleSpace( unsigned int & cur, unsigned int one_too_much, Accessor & styler ) +{ +	char ch; + +	cur++; +	for( ; ; ) +	{ +		if( cur >= one_too_much ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_SPACE ); +			return false; +		} +		 +		ch = styler.SafeGetCharAt( cur ); +		switch( ch ) +		{ +		case ' ': +		case '\t': +		case '\015': +		case '\012': +			cur++; +			break; +		 +		default: +			styler.ColourTo( cur - 1, SCE_OPAL_SPACE ); +			styler.StartSegment( cur ); +			return true; +		} +	} +} + +inline bool HandleInteger( unsigned int & cur, unsigned int one_too_much, Accessor & styler ) +{ +	char ch; + +	for( ; ; ) +	{ +		cur++; +		if( cur >= one_too_much ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_INTEGER ); +			return false; // STOP +		} + +		ch = styler.SafeGetCharAt( cur ); +		if( !isdigit( ch ) ) +		{ +			styler.ColourTo( cur - 1, SCE_OPAL_INTEGER ); +			styler.StartSegment( cur ); +			return true; +		} +	} +} + +inline bool HandleWord( unsigned int & cur, unsigned int one_too_much, Accessor & styler, WordList * keywordlists[] ) +{ +	char ch; +	const unsigned int beg = cur; + +	cur++; +	for( ; ; ) +	{ +		ch = styler.SafeGetCharAt( cur ); +		if( ( ch != '_' ) && ( ch != '-' ) && +			!islower( ch ) && !isupper( ch ) && !isdigit( ch ) ) break; + +		cur++; +		if( cur >= one_too_much )  +		{ +			break; +		} +	} + +	const int ide_len = cur - beg + 1; +	char * ide = new char[ ide_len ]; +	getRange( beg, cur, styler, ide, ide_len ); +	 +	WordList & keywords    = *keywordlists[ 0 ]; +	WordList & classwords  = *keywordlists[ 1 ]; + +	if( keywords.InList( ide ) ) // Keyword +	{ +		delete [] ide; + +		styler.ColourTo( cur - 1, SCE_OPAL_KEYWORD ); +		if( cur >= one_too_much ) +		{ +			return false; // STOP +		} +		else +		{ +			styler.StartSegment( cur );	 +			return true;			 +		} +	} +	else if( classwords.InList( ide ) ) // Sort +	{ +		delete [] ide; + +		styler.ColourTo( cur - 1, SCE_OPAL_SORT ); +		if( cur >= one_too_much ) +		{ +			return false; // STOP +		} +		else +		{ +			styler.StartSegment( cur );	 +			return true;			 +		} +	} +	else if( !strcmp( ide, "true" ) || !strcmp( ide, "false" ) ) // Bool const +	{ +		delete [] ide; + +		styler.ColourTo( cur - 1, SCE_OPAL_BOOL_CONST ); +		if( cur >= one_too_much ) +		{ +			return false; // STOP +		} +		else +		{ +			styler.StartSegment( cur );	 +			return true;			 +		} +	} +	else // Unknown keyword +	{ +		delete [] ide; + +		styler.ColourTo( cur - 1, SCE_OPAL_DEFAULT ); +		if( cur >= one_too_much ) +		{ +			return false; // STOP +		} +		else +		{ +			styler.StartSegment( cur ); +			return true;			 +		} +	} + +} + +inline bool HandleSkip( unsigned int & cur, unsigned int one_too_much, Accessor & styler ) +{ +	cur++; +	styler.ColourTo( cur - 1, SCE_OPAL_DEFAULT ); +	if( cur >= one_too_much ) +	{ +		return false; // STOP +	} +	else +	{ +		styler.StartSegment( cur );	 +		return true; +	} +} + +static void ColouriseOpalDoc( unsigned int startPos, int length, int initStyle, WordList *keywordlists[], Accessor & styler ) +{ +	styler.StartAt( startPos ); +	styler.StartSegment( startPos ); + +	unsigned int & cur = startPos; +	const unsigned int one_too_much = startPos + length; + +	int state = initStyle; + +	for( ; ; ) +	{ +		switch( state ) +		{ +		case SCE_OPAL_KEYWORD: +		case SCE_OPAL_SORT: +			if( !HandleWord( cur, one_too_much, styler, keywordlists ) ) return; +			state = SCE_OPAL_DEFAULT; +			break; + +		case SCE_OPAL_INTEGER: +			if( !HandleInteger( cur, one_too_much, styler ) ) return; +			state = SCE_OPAL_DEFAULT; +			break; + +		case SCE_OPAL_COMMENT_BLOCK: +			if( !HandleCommentBlock( cur, one_too_much, styler, false ) ) return; +			state = SCE_OPAL_DEFAULT; +			break; + +		case SCE_OPAL_COMMENT_LINE: +			if( !HandleCommentLine( cur, one_too_much, styler, false ) ) return; +			state = SCE_OPAL_DEFAULT; +			break; + +		case SCE_OPAL_STRING: +			if( !HandleString( cur, one_too_much, styler ) ) return; +			state = SCE_OPAL_DEFAULT; +			break; +			 +		default: // SCE_OPAL_DEFAULT: +			{ +				char ch = styler.SafeGetCharAt( cur ); +				 +				switch( ch ) +				{ +				// String +				case '"': +					if( !HandleString( cur, one_too_much, styler ) ) return; +					break; + +				// Comment block +				case '/': +					if( !HandleCommentBlock( cur, one_too_much, styler, true ) ) return; +					break; + +				// Comment line +				case '-': +					if( !HandleCommentLine( cur, one_too_much, styler, true ) ) return; +					break; + +				// Par +				case '(': +				case ')': +				case '[': +				case ']': +				case '{': +				case '}': +					if( !HandlePar( cur, styler ) ) return; +					break; + +				// Whitespace +				case ' ': +				case '\t': +				case '\015': +				case '\012': +					if( !HandleSpace( cur, one_too_much, styler ) ) return; +					break; +				 +				default: +					{ +						// Integer +						if( isdigit( ch ) ) +						{ +							if( !HandleInteger( cur, one_too_much, styler ) ) return; +						} + +						// Keyword +						else if( islower( ch ) || isupper( ch ) ) +						{ +							if( !HandleWord( cur, one_too_much, styler, keywordlists ) ) return; +							 +						} + +						// Skip +						else +						{ +							if( !HandleSkip( cur, one_too_much, styler ) ) return; +						} +					} +				} + +				break; +			} +		} +	} +} + +static const char * const opalWordListDesc[] = { +	"Keywords", +	"Sorts", +	0 +}; + +LexerModule lmOpal(SCLEX_OPAL, ColouriseOpalDoc, "opal", NULL, opalWordListDesc); diff --git a/win32/makefile b/win32/makefile index 60cf9f82e..99e98c13e 100644 --- a/win32/makefile +++ b/win32/makefile @@ -56,8 +56,8 @@ LexBasic.o LexBullant.o LexCaml.o LexCLW.o LexConf.o LexCPP.o LexCrontab.o \  LexCsound.o LexCSS.o LexEiffel.o LexErlang.o LexEScript.o LexFlagship.o \  LexForth.o LexFortran.o LexGui4Cli.o LexHaskell.o LexHTML.o LexInno.o LexKix.o \  LexLisp.o LexLout.o LexLua.o LexMatlab.o LexMetapost.o LexMMIXAL.o LexMPT.o \ -LexMSSQL.o LexNsis.o LexOthers.o LexPascal.o LexPB.o LexPerl.o LexPOV.o \ -LexPS.o LexPython.o LexRebol.o LexRuby.o LexScriptol.o LexSmalltalk.o \ +LexMSSQL.o LexNsis.o LexOpal.o LexOthers.o LexPascal.o LexPB.o LexPerl.o \ +LexPOV.o LexPS.o LexPython.o LexRebol.o LexRuby.o LexScriptol.o LexSmalltalk.o \  LexSpecman.o LexSQL.o LexTADS3.o LexTeX.o LexVB.o LexVerilog.o LexVHDL.o \  LexYAML.o  #--Autogenerated -- end of automatically generated section diff --git a/win32/scintilla.mak b/win32/scintilla.mak index 9cabd6ce0..2248d3513 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -146,6 +146,7 @@ LEXOBJS=\  	$(DIR_O)\LexMPT.obj \  	$(DIR_O)\LexMSSQL.obj \  	$(DIR_O)\LexNsis.obj \ +	$(DIR_O)\LexOpal.obj \  	$(DIR_O)\LexOthers.obj \  	$(DIR_O)\LexPascal.obj \  	$(DIR_O)\LexPB.obj \ @@ -348,6 +349,8 @@ $(DIR_O)\LexMSSQL.obj: ..\src\LexMSSQL.cxx $(LEX_HEADERS)  $(DIR_O)\LexNsis.obj: ..\src\LexNsis.cxx $(LEX_HEADERS) +$(DIR_O)\LexOpal.obj: ..\src\LexOpal.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 3db37af06..dc79cee15 100644 --- a/win32/scintilla_vc6.mak +++ b/win32/scintilla_vc6.mak @@ -148,6 +148,7 @@ LEXOBJS=\  	$(DIR_O)\LexMPT.obj \  	$(DIR_O)\LexMSSQL.obj \  	$(DIR_O)\LexNsis.obj \ +	$(DIR_O)\LexOpal.obj \  	$(DIR_O)\LexOthers.obj \  	$(DIR_O)\LexPascal.obj \  	$(DIR_O)\LexPB.obj \ @@ -350,6 +351,8 @@ $(DIR_O)\LexMSSQL.obj: ..\src\LexMSSQL.cxx $(LEX_HEADERS)  $(DIR_O)\LexNsis.obj: ..\src\LexNsis.cxx $(LEX_HEADERS) +$(DIR_O)\LexOpal.obj: ..\src\LexOpal.cxx $(LEX_HEADERS) +  $(DIR_O)\LexOthers.obj: ..\src\LexOthers.cxx $(LEX_HEADERS)  $(DIR_O)\LexPascal.obj: ..\src\LexPascal.cxx $(LEX_HEADERS) | 
