diff options
| author | nyamatongwe <unknown> | 2005-04-09 03:20:30 +0000 | 
|---|---|---|
| committer | nyamatongwe <unknown> | 2005-04-09 03:20:30 +0000 | 
| commit | 35f9e91489cb858fd78aa7e04db88b3eda46d4f4 (patch) | |
| tree | d0eee1334b9db79f67346f445322976f23ead645 | |
| parent | 3431815cd0f1686d5bea88f3be8a3d419fc6dc79 (diff) | |
| download | scintilla-mirror-35f9e91489cb858fd78aa7e04db88b3eda46d4f4.tar.gz | |
TADS3 support from Michael Cartmell.
| -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 | 33 | ||||
| -rw-r--r-- | include/Scintilla.iface | 35 | ||||
| -rw-r--r-- | src/KeyWords.cxx | 1 | ||||
| -rw-r--r-- | src/LexTADS3.cxx | 724 | ||||
| -rw-r--r-- | win32/makefile | 4 | ||||
| -rw-r--r-- | win32/scintilla.mak | 3 | ||||
| -rw-r--r-- | win32/scintilla_vc6.mak | 3 | 
10 files changed, 807 insertions, 4 deletions
| diff --git a/doc/ScintillaHistory.html b/doc/ScintillaHistory.html index ebabcbf81..57b3c1efc 100644 --- a/doc/ScintillaHistory.html +++ b/doc/ScintillaHistory.html @@ -197,6 +197,7 @@  	<li>Josepmaria Roca</li>  	<li>Tobias Engvall</li>  	<li>Suzumizaki Kimitaka</li> +	<li>Michael Cartmell</li>      </ul>      <p>         Images used in GTK+ version diff --git a/gtk/makefile b/gtk/makefile index 71a3375bc..a03e76f3e 100644 --- a/gtk/makefile +++ b/gtk/makefile @@ -69,8 +69,8 @@ LexCSS.o LexEiffel.o LexErlang.o LexEScript.o LexForth.o LexFortran.o \  LexGui4Cli.o LexHaskell.o LexHTML.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 \ -LexRuby.o LexScriptol.o LexSpecman.o LexSQL.o LexTeX.o LexVB.o LexVerilog.o \ -LexVHDL.o LexYAML.o +LexRuby.o LexScriptol.o LexSpecman.o LexSQL.o LexTADS3.o LexTeX.o LexVB.o \ +LexVerilog.o LexVHDL.o LexYAML.o  #--Autogenerated -- end of automatically generated section  all: $(COMPLIB) diff --git a/gtk/scintilla.mak b/gtk/scintilla.mak index 269bb73b2..5ed09f4a3 100644 --- a/gtk/scintilla.mak +++ b/gtk/scintilla.mak @@ -184,6 +184,7 @@ LEXOBJS=\  	$(DIR_O)\LexScriptol.obj \  	$(DIR_O)\LexSpecman.obj \  	$(DIR_O)\LexSQL.obj \ +	$(DIR_O)\LexTADS3.obj \  	$(DIR_O)\LexTeX.obj \  	$(DIR_O)\LexVB.obj \  	$(DIR_O)\LexVerilog.obj \ @@ -395,6 +396,8 @@ $(DIR_O)\LexSpecman.obj: ..\src\LexSpecman.cxx $(LEX_HEADERS)  $(DIR_O)\LexSQL.obj: ..\src\LexSQL.cxx $(LEX_HEADERS) +$(DIR_O)\LexTADS3.obj: ..\src\LexTADS3.cxx $(LEX_HEADERS) +  $(DIR_O)\LexTeX.obj: ..\src\LexTeX.cxx $(LEX_HEADERS)  $(DIR_O)\LexVB.obj: ..\src\LexVB.cxx $(LEX_HEADERS) diff --git a/include/SciLexer.h b/include/SciLexer.h index 11533b552..4dd041417 100644 --- a/include/SciLexer.h +++ b/include/SciLexer.h @@ -82,6 +82,7 @@  #define SCLEX_PUREBASIC 67  #define SCLEX_HASKELL 68  #define SCLEX_PHPSCRIPT 69 +#define SCLEX_TADS3 70  #define SCLEX_AUTOMATIC 1000  #define SCE_P_DEFAULT 0  #define SCE_P_COMMENTLINE 1 @@ -830,6 +831,38 @@  #define SCE_HA_COMMENTBLOCK 14  #define SCE_HA_COMMENTBLOCK2 15  #define SCE_HA_COMMENTBLOCK3 16 +#define SCE_T3_DEFAULT 0 +#define SCE_T3_PREPROCESSOR 1 +#define SCE_T3_BLOCK_COMMENT 2 +#define SCE_T3_LINE_COMMENT 3 +#define SCE_T3_OPERATOR 4 +#define SCE_T3_KEYWORD 5 +#define SCE_T3_NUMBER 6 +#define SCE_T3_BRACKET 7 +#define SCE_T3_HTML_TAG 8 +#define SCE_T3_HTML_STRING 9 +#define SCE_T3_S_STRING 10 +#define SCE_T3_S_LIB_DIRECTIVE 11 +#define SCE_T3_S_MSG_PARAM 12 +#define SCE_T3_S_H_DEFAULT 13 +#define SCE_T3_D_STRING 14 +#define SCE_T3_D_LIB_DIRECTIVE 15 +#define SCE_T3_D_MSG_PARAM 16 +#define SCE_T3_D_H_DEFAULT 17 +#define SCE_T3_X_DEFAULT 18 +#define SCE_T3_X_PREPROCESSOR 19 +#define SCE_T3_X_BLOCK_COMMENT 20 +#define SCE_T3_X_LINE_COMMENT 21 +#define SCE_T3_X_S_STRING 22 +#define SCE_T3_X_S_LIB_DIRECTIVE 23 +#define SCE_T3_X_S_MSG_PARAM 24 +#define SCE_T3_X_S_H_DEFAULT 25 +#define SCE_T3_X_D_STRING 26 +#define SCE_T3_X_D_LIB_DIRECTIVE 27 +#define SCE_T3_X_D_MSG_PARAM 28 +#define SCE_T3_X_D_H_DEFAULT 29 +#define SCE_T3_USER1 30 +#define SCE_T3_USER2 31  #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 4a5a9e901..64f674110 100644 --- a/include/Scintilla.iface +++ b/include/Scintilla.iface @@ -1782,6 +1782,7 @@ val SCLEX_BLITZBASIC=66  val SCLEX_PUREBASIC=67  val SCLEX_HASKELL=68  val SCLEX_PHPSCRIPT=69 +val SCLEX_TADS3=70  # When a lexer specifies its language as SCLEX_AUTOMATIC it receives a  # value assigned in sequence from SCLEX_AUTOMATIC+1. @@ -2656,6 +2657,40 @@ val SCE_HA_COMMENTLINE=13  val SCE_HA_COMMENTBLOCK=14  val SCE_HA_COMMENTBLOCK2=15  val SCE_HA_COMMENTBLOCK3=16 +# Lexical states of SCLEX_TADS3 +lex TADS3=SCLEX_TADS3 SCE_T3_ +val SCE_T3_DEFAULT=0 +val SCE_T3_PREPROCESSOR=1 +val SCE_T3_BLOCK_COMMENT=2 +val SCE_T3_LINE_COMMENT=3 +val SCE_T3_OPERATOR=4 +val SCE_T3_KEYWORD=5 +val SCE_T3_NUMBER=6 +val SCE_T3_BRACKET=7 +val SCE_T3_HTML_TAG=8 +val SCE_T3_HTML_STRING=9 +val SCE_T3_S_STRING=10 +val SCE_T3_S_LIB_DIRECTIVE=11 +val SCE_T3_S_MSG_PARAM=12 +val SCE_T3_S_H_DEFAULT=13 +val SCE_T3_D_STRING=14 +val SCE_T3_D_LIB_DIRECTIVE=15 +val SCE_T3_D_MSG_PARAM=16 +val SCE_T3_D_H_DEFAULT=17 +val SCE_T3_X_DEFAULT=18 +val SCE_T3_X_PREPROCESSOR=19 +val SCE_T3_X_BLOCK_COMMENT=20 +val SCE_T3_X_LINE_COMMENT=21 +val SCE_T3_X_S_STRING=22 +val SCE_T3_X_S_LIB_DIRECTIVE=23 +val SCE_T3_X_S_MSG_PARAM=24 +val SCE_T3_X_S_H_DEFAULT=25 +val SCE_T3_X_D_STRING=26 +val SCE_T3_X_D_LIB_DIRECTIVE=27 +val SCE_T3_X_D_MSG_PARAM=28 +val SCE_T3_X_D_H_DEFAULT=29 +val SCE_T3_USER1=30 +val SCE_T3_USER2=31  # Events diff --git a/src/KeyWords.cxx b/src/KeyWords.cxx index 6498c87a0..126be7736 100644 --- a/src/KeyWords.cxx +++ b/src/KeyWords.cxx @@ -191,6 +191,7 @@ int Scintilla_LinkLexers() {  	LINK_LEXER(lmScriptol);  	LINK_LEXER(lmSpecman);  	LINK_LEXER(lmSQL); +	LINK_LEXER(lmTADS3);  	LINK_LEXER(lmTeX);  	LINK_LEXER(lmVB);  	LINK_LEXER(lmVBScript); diff --git a/src/LexTADS3.cxx b/src/LexTADS3.cxx new file mode 100644 index 000000000..2ef6f1323 --- /dev/null +++ b/src/LexTADS3.cxx @@ -0,0 +1,724 @@ +// Scintilla source code edit control +/** @file LexTADS3.cxx + ** Lexer for TADS3. + **/ +/* Copyright 2005 by Michael Cartmell + * Parts copyright 1998-2002 by Neil Hodgson <neilh@scintilla.org> + * In particular FoldTADS3Doc is derived from FoldCppDoc + * The License.txt file describes the conditions under which this software may + * be distributed. + */ + +/* + * TADS3 is a language designed by Michael J. Roberts for the writing of text + * based games.  TADS comes from Text Adventure Development System.  It has good + * support for the processing and outputting of formatted text and much of a + * TADS program listing consists of strings. + * + * TADS has two types of strings, those enclosed in single quotes (') and those + * enclosed in double quotes (").  These strings have different symantics and + * can be given different highlighting if desired. + * + * There can be embedded within both types of strings html tags + * ( <tag key=value> ), library directives ( <.directive> ), and message + * parameters ( {The doctor's/his} ). + * + * Double quoted strings can also contain interpolated expressions + * ( << rug.moved ? ' and a hole in the floor. ' : nil >> ).  These expressions + * may themselves contain single or double quoted strings, although the double + * quoted strings may not contain interpolated expressions. + * + * These embedded constructs influence the output and formatting and are an + * important part of a program and require highlighting. + * + * Because strings, html tags, library directives, message parameters, and + * interpolated expressions may span multiple lines it is necessary to have + * multiple states for a single construct so that the surrounding context can be + * known.  This is important if scanning starts part way through a source file. + * + * States that have a Single quoted string context have _S_ in the name + * States that have a Double quoted string context have _D_ in the name + * States that have an interpolated eXpression context have _X_ in the name + * eg SCE_T3_X_S_MSG_PARAM is a message parameter in a single quoted string + * that is part of an interpolated expression. + * "You see << isKnown? '{iobj/him} lying' : 'nothing' >> on the ground. " + *                       ---------- + * + * TO DO + * + * top level blocks can have one of two forms + * + * cave : DarkRoom 'small cave' 'small cave' + *     "There is barely enough room to stand in this small cave. " + * ; + * + * or + * + * cave : DarkRoom { + *     'small cave' + *     'small cave' + *     "There is barely enough room to stand in this small cave. " + * } + * + * currently only the latter form is folded. + * + * LINKS + * http://www.tads.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 "StyleContext.h" +#include "KeyWords.h" +#include "Scintilla.h" +#include "SciLexer.h" + +static unsigned int endPos; + +static inline bool IsEOL(const int ch) { +	return ch == '\r' || ch == '\n'; +} + +static inline bool IsASpaceOrTab(const int ch) { +	return ch == ' ' || ch == '\t'; +} + +static inline bool IsATADS3Operator(const int ch) { +	return ch == '+' || ch == '-' || ch == '*' || ch == '/' || ch == '|' +		|| ch == '!' || ch == ':' || ch == '?' || ch == '@' || ch == ';' +		|| ch == '&' || ch == '<' || ch == '>' || ch == '='; +} + +static inline bool IsAWordChar(const int ch) { +	return isalnum(ch) || ch == '_'; +} + +static inline bool IsAWordStart(const int ch) { +	return isalpha(ch) || ch == '_'; +} + +static inline bool IsAHexDigit(const int ch) { +	int lch = tolower(ch); +	return isdigit(lch) || lch == 'a' || lch == 'b' || lch == 'c' +		|| lch == 'd' || lch == 'e' || lch == 'f'; +} + +static inline bool IsABracket(const int ch) { +	return ch == '(' || ch == '{' || ch == '[' +		|| ch == ')' || ch == '}' || ch == ']'; +} + +static inline bool IsAMsgParamChar(int ch) { +	return isalpha(ch) || isspace(ch) || ch == '/' || ch == '\'' || ch == '\\'; +} + +static inline bool IsAnHTMLChar(int ch) { +	return isalnum(ch) || ch == '-' || ch == '_' || ch == '.'; +} + +static inline bool IsADirectiveChar(int ch) { +	return isalnum(ch) || isspace(ch) || ch == '-'; +} + +static inline bool IsANumberStart(StyleContext &sc) { +	return isdigit(sc.ch) +		|| (!isdigit(sc.chPrev) && sc.ch == '.' && isdigit(sc.chNext)); +} + +inline static void ColouriseTADS3Operator(StyleContext &sc) { +	int initState = sc.state; +	sc.SetState(SCE_T3_OPERATOR); +	sc.ForwardSetState(initState); +} + +inline static void ColouriseTADS3Bracket(StyleContext &sc) { +	int initState = sc.state; +	sc.SetState(SCE_T3_BRACKET); +	sc.ForwardSetState(initState); +} + +static void ColouriseTADSHTMLString(StyleContext &sc) { +	int initState = sc.state; +	int quoteChar = sc.ch; +	sc.SetState(SCE_T3_HTML_STRING); +	sc.Forward(); + +	while (sc.More()) { +		if (sc.Match('\\', static_cast<char>(quoteChar))) { +			sc.Forward(2); +		} +		if (sc.ch == quoteChar || IsEOL(sc.ch)) { +			sc.ForwardSetState(initState); +			return; +		} +		sc.Forward(); +	} +} + +static void ColouriseTADS3HTMLTagStart(StyleContext &sc) { +	sc.SetState(SCE_T3_HTML_TAG); +	sc.Forward(); +	if (sc.ch == '/') { +		sc.Forward(); +	} +	while (IsAnHTMLChar(sc.ch)) { +		sc.Forward(); +	} +} + +static void ColouriseTADS3HTMLTag(StyleContext &sc) { +	int initState = sc.state; +	switch (initState) { +		case SCE_T3_S_STRING: +			ColouriseTADS3HTMLTagStart(sc); +			sc.SetState(SCE_T3_S_H_DEFAULT); +			break; +		case SCE_T3_D_STRING: +			ColouriseTADS3HTMLTagStart(sc); +			sc.SetState(SCE_T3_S_H_DEFAULT); +			break; +		case SCE_T3_X_S_STRING: +			ColouriseTADS3HTMLTagStart(sc); +			sc.SetState(SCE_T3_X_S_H_DEFAULT); +			break; +		case SCE_T3_X_D_STRING: +			ColouriseTADS3HTMLTagStart(sc); +			sc.SetState(SCE_T3_X_D_H_DEFAULT); +			break; +		case SCE_T3_S_H_DEFAULT: +			initState = SCE_T3_S_STRING; +			break; +		case SCE_T3_D_H_DEFAULT: +			initState = SCE_T3_D_STRING; +			break; +		case SCE_T3_X_S_H_DEFAULT: +			initState = SCE_T3_X_S_STRING; +			break; +		case SCE_T3_X_D_H_DEFAULT: +			initState = SCE_T3_X_D_STRING; +			break; +	} + +	while (sc.More()) { +		if (sc.Match('/', '>')) { +			sc.SetState(SCE_T3_HTML_TAG); +			sc.Forward(2); +			sc.SetState(initState); +			return; +		} else if (sc.ch == '>') { +			sc.SetState(SCE_T3_HTML_TAG); +			sc.ForwardSetState(initState); +			return; +		} +		if (sc.ch == '\'' || sc.ch == '"') { +			ColouriseTADSHTMLString(sc); +		} else if (sc.ch == '=') { +			ColouriseTADS3Operator(sc); +		} else { +			sc.Forward(); +		} +	} +} + +static void ColouriseTADS3Keyword(StyleContext &sc, +										 WordList *keywordlists[]) { +	static char s[250]; +	WordList &keywords = *keywordlists[0]; +	WordList &userwords1 = *keywordlists[1]; +	WordList &userwords2 = *keywordlists[2]; +	int initState = sc.state; +	sc.SetState(SCE_T3_KEYWORD); +	while (sc.More() && (IsAWordChar(sc.ch) || sc.ch == '.')) { +		sc.Forward(); +	} +	sc.GetCurrent(s, sizeof(s)); +	if (userwords1.InList(s)) { +		sc.ChangeState(SCE_T3_USER1); +	} else if (userwords2.InList(s)) { +		sc.ChangeState(SCE_T3_USER2); +	} else if (keywords.InList(s)) { +		// state already correct +	} else if ( strcmp(s, "is") == 0 || strcmp(s, "not") == 0) { +		// have to find if "in" is next +		int n = 1; +		while (n + sc.currentPos < endPos && IsASpaceOrTab(sc.GetRelative(n))) +			n++; +		if (sc.GetRelative(n) == 'i' && sc.GetRelative(n+1) == 'n') { +			sc.Forward(n+2); +		} else { +			sc.ChangeState(initState); +		} +	} else { +		sc.ChangeState(initState); +	} + +	sc.SetState(initState); +} + +static void ColouriseTADS3MsgParam(StyleContext &sc) { +	int initState = sc.state; +	switch (initState) { +		case SCE_T3_S_STRING: +			sc.SetState(SCE_T3_S_MSG_PARAM); +			sc.Forward(); +			break; +		case SCE_T3_D_STRING: +			sc.SetState(SCE_T3_D_MSG_PARAM); +			sc.Forward(); +			break; +		case SCE_T3_X_S_STRING: +			sc.SetState(SCE_T3_X_S_MSG_PARAM); +			sc.Forward(); +			break; +		case SCE_T3_X_D_STRING: +			sc.SetState(SCE_T3_X_D_MSG_PARAM); +			sc.Forward(); +			break; +		case SCE_T3_S_MSG_PARAM: +			initState = SCE_T3_S_STRING; +			break; +		case SCE_T3_D_MSG_PARAM: +			initState = SCE_T3_D_STRING; +			break; +		case SCE_T3_X_S_MSG_PARAM: +			initState = SCE_T3_X_S_STRING; +			break; +		case SCE_T3_X_D_MSG_PARAM: +			initState = SCE_T3_X_D_STRING; +			break; +	} +	while (sc.More() && IsAMsgParamChar(sc.ch)) { +		if (sc.ch == '\\') { +			if (initState == SCE_T3_D_STRING) { +				break; +			} else if (sc.chNext != '\'') { +				break; +			} +		} +		sc.Forward(); +	} +	if (sc.ch == '}' || !sc.More()) { +		sc.ForwardSetState(initState); +	} else { +		sc.ChangeState(initState); +		sc.Forward(); +	} +} + +static void ColouriseTADS3LibDirective(StyleContext &sc) { +	int initState = sc.state; +	switch (initState) { +		case SCE_T3_S_STRING: +			sc.SetState(SCE_T3_S_LIB_DIRECTIVE); +			sc.Forward(2); +			break; +		case SCE_T3_D_STRING: +			sc.SetState(SCE_T3_D_LIB_DIRECTIVE); +			sc.Forward(2); +			break; +		case SCE_T3_X_S_STRING: +			sc.SetState(SCE_T3_X_S_LIB_DIRECTIVE); +			sc.Forward(2); +			break; +		case SCE_T3_X_D_STRING: +			sc.SetState(SCE_T3_X_D_LIB_DIRECTIVE); +			sc.Forward(2); +			break; +		case SCE_T3_S_LIB_DIRECTIVE: +			initState = SCE_T3_S_STRING; +			break; +		case SCE_T3_D_LIB_DIRECTIVE: +			initState = SCE_T3_D_STRING; +			break; +		case SCE_T3_X_S_LIB_DIRECTIVE: +			initState = SCE_T3_X_S_STRING; +			break; +		case SCE_T3_X_D_LIB_DIRECTIVE: +			initState = SCE_T3_X_D_STRING; +			break; +	} +	while (sc.More() && IsADirectiveChar(sc.ch)) { +		sc.Forward(); +	}; +	if (sc.ch == '>' || !sc.More()) { +		sc.ForwardSetState(initState); +	} else { +		sc.ChangeState(initState); +		sc.Forward(); +	} +} + +static void ColouriseTADS3String(StyleContext &sc) { +	int quoteChar = sc.ch; +	int initState = sc.state; +	switch (sc.state) { +		case SCE_T3_DEFAULT: +			if (quoteChar == '"') { +				sc.SetState(SCE_T3_D_STRING); +			} else { +				sc.SetState(SCE_T3_S_STRING); +			} +			sc.Forward(); +			break; +		case SCE_T3_X_DEFAULT: +			if (quoteChar == '"') { +				sc.SetState(SCE_T3_X_D_STRING); +			} else { +				sc.SetState(SCE_T3_X_S_STRING); +			} +			sc.Forward(); +			break; +		case SCE_T3_S_STRING: +			quoteChar = '\''; +			initState = SCE_T3_DEFAULT; +			break; +		case SCE_T3_D_STRING: +			quoteChar = '"'; +			initState = SCE_T3_DEFAULT; +			break; +		case SCE_T3_X_S_STRING: +			quoteChar = '\''; +			initState = SCE_T3_X_DEFAULT; +			break; +		case SCE_T3_X_D_STRING: +			quoteChar = '"'; +			initState = SCE_T3_X_DEFAULT; +			break; +	} +	while (sc.More()) { +		if (sc.Match('\\', static_cast<char>(quoteChar))) { +			sc.Forward(2); +		} +		if (sc.ch == quoteChar) { +			sc.ForwardSetState(initState); +			return; +		} +		if (sc.ch == '{') { +			ColouriseTADS3MsgParam(sc); +		} else if (sc.state == SCE_T3_D_STRING && sc.Match('<', '<')) { +			sc.SetState(SCE_T3_X_DEFAULT); +			sc.Forward(2); +			return; +		} else if (sc.Match('<', '.')) { +			ColouriseTADS3LibDirective(sc); +		} else if (sc.ch == '<') { +			ColouriseTADS3HTMLTag(sc); +		} else { +			sc.Forward(); +		} +	} +} + +static void ColouriseTADS3Comment(StyleContext &sc, const int initState, +								  const int endState) { +	if (sc.state != initState) { +		sc.SetState(initState); +	} +	for (; sc.More(); sc.Forward()) { +		if (sc.Match('*', '/')) { +			sc.Forward(2); +			sc.SetState(endState); +			return; +		} +	} +} + +static void ColouriseToEndOfLine(StyleContext &sc, const int initState, +								 const int endState) { +	if (sc.state != initState) { +		sc.SetState(initState); +	} +	for (; sc.More(); sc.Forward()) { +		if (sc.ch == '\\') { +			if (IsEOL(sc.chNext)) { +				sc.Forward(); +				if (sc.ch == '\r' && sc.chNext == '\n') { +					sc.Forward(); +				} +				continue; +			} +		} +		if (IsEOL(sc.ch)) { +			sc.SetState(endState); +			return; +		} +	} +} + +static void ColouriseTADS3Number(StyleContext &sc) { +	int initState = sc.state; +	bool inHexNumber = false; +	bool seenE = false; +	bool seenDot = sc.ch == '.'; +	sc.SetState(SCE_T3_NUMBER); +	if (sc.More()) { +		sc.Forward(); +	} +	if (sc.chPrev == '0' && tolower(sc.ch) == 'x') { +		inHexNumber = true; +		sc.Forward(); +	} +	for (; sc.More(); sc.Forward()) { +		if (inHexNumber) { +			if (!IsAHexDigit(sc.ch)) { +				break; +			} +		} else if (!isdigit(sc.ch)) { +			if (!seenE && tolower(sc.ch) == 'e') { +				seenE = true; +				seenDot = true; +				if (sc.chNext == '+' || sc.chNext == '-') { +					sc.Forward(); +				} +			} else if (!seenDot && sc.ch == '.') { +				seenDot = true; +			} else { +				break; +			} +		} +	} +	sc.SetState(initState); +} + +static void ColouriseTADS3Doc(unsigned int startPos, int length, int initStyle, +							   WordList *keywordlists[], Accessor &styler) { +	int visibleChars = 0; +	int bracketLevel = 0; +	endPos = startPos + length; +	StyleContext sc(startPos, length, initStyle, styler); + +	while (sc.More()) { + +		if (IsEOL(sc.ch)) { +			visibleChars = 0; +			sc.Forward(); +			continue; +		} + +		switch(sc.state) { +			case SCE_T3_PREPROCESSOR: +			case SCE_T3_LINE_COMMENT: +				ColouriseToEndOfLine(sc, sc.state, SCE_T3_DEFAULT); +				break; +			case SCE_T3_X_PREPROCESSOR: +			case SCE_T3_X_LINE_COMMENT: +				ColouriseToEndOfLine(sc, sc.state, SCE_T3_X_DEFAULT); +				break; +			case SCE_T3_S_STRING: +			case SCE_T3_D_STRING: +			case SCE_T3_X_S_STRING: +			case SCE_T3_X_D_STRING: +				ColouriseTADS3String(sc); +				visibleChars++; +				break; +			case SCE_T3_S_MSG_PARAM: +			case SCE_T3_D_MSG_PARAM: +			case SCE_T3_X_S_MSG_PARAM: +			case SCE_T3_X_D_MSG_PARAM: +				ColouriseTADS3MsgParam(sc); +				break; +			case SCE_T3_S_LIB_DIRECTIVE: +			case SCE_T3_D_LIB_DIRECTIVE: +			case SCE_T3_X_S_LIB_DIRECTIVE: +			case SCE_T3_X_D_LIB_DIRECTIVE: +				ColouriseTADS3LibDirective(sc); +				break; +			case SCE_T3_S_H_DEFAULT: +			case SCE_T3_D_H_DEFAULT: +			case SCE_T3_X_S_H_DEFAULT: +			case SCE_T3_X_D_H_DEFAULT: +				ColouriseTADS3HTMLTag(sc); +				break; +			case SCE_T3_BLOCK_COMMENT: +				ColouriseTADS3Comment(sc, SCE_T3_BLOCK_COMMENT, SCE_T3_DEFAULT); +				break; +			case SCE_T3_X_BLOCK_COMMENT: +				ColouriseTADS3Comment(sc, SCE_T3_X_BLOCK_COMMENT, SCE_T3_X_DEFAULT); +				break; +			case SCE_T3_DEFAULT: +				if (IsASpaceOrTab(sc.ch)) { +					sc.Forward(); +				} else if (sc.ch == '#' && visibleChars == 0) { +					ColouriseToEndOfLine(sc, SCE_T3_PREPROCESSOR, SCE_T3_DEFAULT); +				} else if (sc.Match('/', '*')) { +					ColouriseTADS3Comment(sc, SCE_T3_BLOCK_COMMENT, SCE_T3_DEFAULT); +					visibleChars++; +				} else if (sc.Match('/', '/')) { +					ColouriseToEndOfLine(sc, SCE_T3_LINE_COMMENT, SCE_T3_DEFAULT); +				} else if (sc.ch == '\'' || sc.ch == '"') { +					ColouriseTADS3String(sc); +					visibleChars++; +				} else if (IsATADS3Operator(sc.ch)) { +					ColouriseTADS3Operator(sc); +					visibleChars++; +				} else if (IsANumberStart(sc)) { +					ColouriseTADS3Number(sc); +					visibleChars++; +				} else if (IsABracket(sc.ch)) { +					ColouriseTADS3Bracket(sc); +					visibleChars++; +				} else if (IsAWordStart(sc.ch)) { +					ColouriseTADS3Keyword(sc, keywordlists); +					visibleChars++; +				} else { +					sc.Forward(); +					visibleChars++; +				} +				break; +			case SCE_T3_X_DEFAULT: +				if (IsASpaceOrTab(sc.ch)) { +					sc.Forward(); +				} else if (sc.ch == '#' && visibleChars == 0) { +					ColouriseToEndOfLine(sc, SCE_T3_X_PREPROCESSOR, SCE_T3_X_DEFAULT); +				} else if (sc.Match('/', '*')) { +					ColouriseTADS3Comment(sc, SCE_T3_X_BLOCK_COMMENT, SCE_T3_X_DEFAULT); +					visibleChars++; +				} else if (sc.Match('/', '/')) { +					ColouriseToEndOfLine(sc, SCE_T3_X_LINE_COMMENT, SCE_T3_X_DEFAULT); +				} else if (sc.ch == '\'' || sc.ch == '"') { +					ColouriseTADS3String(sc); +					visibleChars++; +				} else if (bracketLevel == 0 && sc.Match('>', '>')) { +					sc.Forward(2); +					sc.SetState(SCE_T3_D_STRING); +				} else if (IsATADS3Operator(sc.ch)) { +					ColouriseTADS3Operator(sc); +					visibleChars++; +				} else if (IsANumberStart(sc)) { +					ColouriseTADS3Number(sc); +					visibleChars++; +				} else if (IsABracket(sc.ch)) { +					if (sc.ch == '(') { +						bracketLevel++; +					} else if (sc.ch == ')') { +						bracketLevel && bracketLevel--; +					} +					ColouriseTADS3Bracket(sc); +					visibleChars++; +				} else if (IsAWordStart(sc.ch)) { +					ColouriseTADS3Keyword(sc, keywordlists); +					visibleChars++; +				} else { +					sc.Forward(); +					visibleChars++; +				} +				break; +			default: +				sc.SetState(SCE_T3_DEFAULT); +				sc.Forward(); +		} +	} +	sc.Complete(); +} + +static inline bool IsStreamCommentStyle(int style) { +	return style == SCE_T3_BLOCK_COMMENT +		|| style == SCE_T3_X_BLOCK_COMMENT; +} + +static inline bool IsStringTransition(int s1, int s2) { +	switch (s1) { +		case SCE_T3_S_STRING: +			return s2 != s1 +				&& s2 != SCE_T3_S_LIB_DIRECTIVE +				&& s2 != SCE_T3_S_MSG_PARAM +				&& s2 != SCE_T3_HTML_TAG; +		case SCE_T3_D_STRING: +			return s2 != s1 +				&& s2 != SCE_T3_D_LIB_DIRECTIVE +				&& s2 != SCE_T3_D_MSG_PARAM +				&& s2 != SCE_T3_HTML_TAG +				&& s2 != SCE_T3_X_DEFAULT; +		case SCE_T3_X_S_STRING: +			return s2 != s1 +				&& s2 != SCE_T3_X_S_LIB_DIRECTIVE +				&& s2 != SCE_T3_X_S_MSG_PARAM +				&& s2 != SCE_T3_HTML_TAG; +		case SCE_T3_X_D_STRING: +			return s2 != s1 +				&& s2 != SCE_T3_X_D_LIB_DIRECTIVE +				&& s2 != SCE_T3_X_D_MSG_PARAM +				&& s2 != SCE_T3_HTML_TAG; +		default: +			return false; +	} +} + +static void FoldTADS3Doc(unsigned int startPos, int length, int initStyle, +                            WordList *[], Accessor &styler) { +	unsigned int endPos = startPos + length; +	int lineCurrent = styler.GetLine(startPos); +	int levelCurrent = SC_FOLDLEVELBASE; +	if (lineCurrent > 0) +		levelCurrent = styler.LevelAt(lineCurrent-1) >> 16; +	int levelMinCurrent = levelCurrent; +	int levelNext = levelCurrent; +	char chNext = styler[startPos]; +	int styleNext = styler.StyleAt(startPos); +	int style = initStyle; +	for (unsigned int i = startPos; i < endPos; i++) { +		char ch = chNext; +		chNext = styler.SafeGetCharAt(i + 1); +		int stylePrev = style; +		style = styleNext; +		styleNext = styler.StyleAt(i + 1); +		bool atEOL = (ch == '\r' && chNext != '\n') || (ch == '\n'); +		if (IsStreamCommentStyle(style)) { +			if (!IsStreamCommentStyle(stylePrev)) { +				levelNext++; +			} else if (!IsStreamCommentStyle(styleNext) && !atEOL) { +				// Comments don't end at end of line and the next character may be unstyled. +				levelNext--; +			} +		} else if (style == SCE_T3_BRACKET) { +			if (ch == '{' || ch == '[') { +				// Measure the minimum before a '{' to allow +				// folding on "} else {" +				if (levelMinCurrent > levelNext) { +					levelMinCurrent = levelNext; +				} +				levelNext++; +			} else if (ch == '}' || ch == ']') { +				levelNext--; +			} +		} else if ((ch == '\'' || ch == '"')) { +			if (IsStringTransition(style, stylePrev)) { +				if (levelMinCurrent > levelNext) { +					levelMinCurrent = levelNext; +				} +				levelNext++; +			} else if (IsStringTransition(style, styleNext)) { +				levelNext--; +			} +		} + +		if (atEOL) { +			int lev = levelMinCurrent | levelNext << 16; +			if (levelMinCurrent < levelNext) +				lev |= SC_FOLDLEVELHEADERFLAG; +			if (lev != styler.LevelAt(lineCurrent)) { +				styler.SetLevel(lineCurrent, lev); +			} +			lineCurrent++; +			levelCurrent = levelNext; +			levelMinCurrent = levelCurrent; +		} +	} +} + +static const char * const tads3WordList[] = { +	"TADS3 Keywords", +	"User defined 1", +	"User defined 2", +	0 +}; + +LexerModule lmTADS3(SCLEX_TADS3, ColouriseTADS3Doc, "tads3", FoldTADS3Doc, tads3WordList); diff --git a/win32/makefile b/win32/makefile index abbb35150..e0786a2cf 100644 --- a/win32/makefile +++ b/win32/makefile @@ -57,8 +57,8 @@ LexCSS.o LexEiffel.o LexErlang.o LexEScript.o LexForth.o LexFortran.o \  LexGui4Cli.o LexHaskell.o LexHTML.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 \ -LexRuby.o LexScriptol.o LexSpecman.o LexSQL.o LexTeX.o LexVB.o LexVerilog.o \ -LexVHDL.o LexYAML.o +LexRuby.o LexScriptol.o LexSpecman.o LexSQL.o LexTADS3.o LexTeX.o LexVB.o \ +LexVerilog.o LexVHDL.o LexYAML.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 72b18705c..3e061d872 100644 --- a/win32/scintilla.mak +++ b/win32/scintilla.mak @@ -154,6 +154,7 @@ LEXOBJS=\  	$(DIR_O)\LexScriptol.obj \  	$(DIR_O)\LexSpecman.obj \  	$(DIR_O)\LexSQL.obj \ +	$(DIR_O)\LexTADS3.obj \  	$(DIR_O)\LexTeX.obj \  	$(DIR_O)\LexVB.obj \  	$(DIR_O)\LexVerilog.obj \ @@ -358,6 +359,8 @@ $(DIR_O)\LexSpecman.obj: ..\src\LexSpecman.cxx $(LEX_HEADERS)  $(DIR_O)\LexSQL.obj: ..\src\LexSQL.cxx $(LEX_HEADERS) +$(DIR_O)\LexTADS3.obj: ..\src\LexTADS3.cxx $(LEX_HEADERS) +  $(DIR_O)\LexTeX.obj: ..\src\LexTeX.cxx $(LEX_HEADERS)  $(DIR_O)\LexVB.obj: ..\src\LexVB.cxx $(LEX_HEADERS) diff --git a/win32/scintilla_vc6.mak b/win32/scintilla_vc6.mak index 7756dfef6..bcc1d38af 100644 --- a/win32/scintilla_vc6.mak +++ b/win32/scintilla_vc6.mak @@ -156,6 +156,7 @@ LEXOBJS=\  	$(DIR_O)\LexScriptol.obj \  	$(DIR_O)\LexSpecman.obj \  	$(DIR_O)\LexSQL.obj \ +	$(DIR_O)\LexTADS3.obj \  	$(DIR_O)\LexTeX.obj \  	$(DIR_O)\LexVB.obj \  	$(DIR_O)\LexVerilog.obj \ @@ -360,6 +361,8 @@ $(DIR_O)\LexSpecman.obj: ..\src\LexSpecman.cxx $(LEX_HEADERS)  $(DIR_O)\LexSQL.obj: ..\src\LexSQL.cxx $(LEX_HEADERS) +$(DIR_O)\LexTADS3.obj: ..\src\LexTADS3.cxx $(LEX_HEADERS) +  $(DIR_O)\LexTeX.obj: ..\src\LexTeX.cxx $(LEX_HEADERS)  $(DIR_O)\LexVB.obj: ..\src\LexVB.cxx $(LEX_HEADERS) | 
