aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authornyamatongwe <devnull@localhost>2001-09-14 10:14:40 +0000
committernyamatongwe <devnull@localhost>2001-09-14 10:14:40 +0000
commit062eda353f0a9060c8c262d698c66b1b5d8030e2 (patch)
treee970c1c7e8b99c294c4fe90ccb23edf66eaf8f70
parent1f43915c138cff8dbb3da48a81fdccce63abb181 (diff)
downloadscintilla-mirror-062eda353f0a9060c8c262d698c66b1b5d8030e2.tar.gz
Addition of more SGML styles from Steve.
-rw-r--r--include/SciLexer.h7
-rw-r--r--include/Scintilla.h1
-rw-r--r--include/Scintilla.iface10
-rw-r--r--src/LexHTML.cxx105
-rw-r--r--src/ScintillaBase.h2
5 files changed, 109 insertions, 16 deletions
diff --git a/include/SciLexer.h b/include/SciLexer.h
index 49ca762ae..9d3b000b8 100644
--- a/include/SciLexer.h
+++ b/include/SciLexer.h
@@ -94,7 +94,12 @@
#define SCE_H_QUESTION 18
#define SCE_H_VALUE 19
#define SCE_H_XCCOMMENT 20
-#define SCE_H_SGML 21
+#define SCE_H_SGML_DEFAULT 21
+#define SCE_H_SGML_COMMAND 22
+#define SCE_H_SGML_1ST_PARAM 23
+#define SCE_H_SGML_STRING 24
+#define SCE_H_SGML_COMMENT 25
+#define SCE_H_SGML_ERROR 26
#define SCE_HJ_START 40
#define SCE_HJ_DEFAULT 41
#define SCE_HJ_COMMENT 42
diff --git a/include/Scintilla.h b/include/Scintilla.h
index 9d5edb70a..abe1581a4 100644
--- a/include/Scintilla.h
+++ b/include/Scintilla.h
@@ -132,6 +132,7 @@ typedef sptr_t (*SciFnDirect)(sptr_t ptr, unsigned int iMessage, uptr_t wParam,
#define STYLE_BRACEBAD 35
#define STYLE_CONTROLCHAR 36
#define STYLE_INDENTGUIDE 37
+#define STYLE_LASTPREDEFINED 39
#define STYLE_MAX 127
#define SC_CHARSET_ANSI 0
#define SC_CHARSET_DEFAULT 1
diff --git a/include/Scintilla.iface b/include/Scintilla.iface
index b96958039..1d1d17074 100644
--- a/include/Scintilla.iface
+++ b/include/Scintilla.iface
@@ -294,12 +294,15 @@ set void SetMarginSensitiveN=2246(int margin, bool sensitive)
# Retrieve the mouse click sensitivity of a margin.
get bool GetMarginSensitiveN=2247(int margin,)
+# Styles in range 32..37 are predefined for parts of the UI and are not used as normal styles.
+# Styles 38 and 39 are for future use.
val STYLE_DEFAULT=32
val STYLE_LINENUMBER=33
val STYLE_BRACELIGHT=34
val STYLE_BRACEBAD=35
val STYLE_CONTROLCHAR=36
val STYLE_INDENTGUIDE=37
+val STYLE_LASTPREDEFINED=39
val STYLE_MAX=127
# Character set identifiers are used in StyleSetCharacterSet.
@@ -1331,7 +1334,12 @@ val SCE_H_VALUE=19
# X-Code
val SCE_H_XCCOMMENT=20
# SGML
-val SCE_H_SGML=21
+val SCE_H_SGML_DEFAULT=21
+val SCE_H_SGML_COMMAND=22
+val SCE_H_SGML_1ST_PARAM=23
+val SCE_H_SGML_STRING=24
+val SCE_H_SGML_COMMENT=25
+val SCE_H_SGML_ERROR=26
# Embedded Javascript
val SCE_HJ_START=40
val SCE_HJ_DEFAULT=41
diff --git a/src/LexHTML.cxx b/src/LexHTML.cxx
index a918ebf38..6e061e821 100644
--- a/src/LexHTML.cxx
+++ b/src/LexHTML.cxx
@@ -23,7 +23,7 @@
#define SCE_HA_VBS (SCE_HBA_START - SCE_HB_START)
#define SCE_HA_PYTHON (SCE_HPA_START - SCE_HP_START)
-enum { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScriptPHP, eScriptXML };
+enum { eScriptNone = 0, eScriptJS, eScriptVBS, eScriptPython, eScriptPHP, eScriptXML, eScriptSGML };
enum { eHtml = 0, eNonHtmlScript, eNonHtmlPreProc, eNonHtmlScriptPreProc };
static int segIsScriptingIndicator(Accessor &styler, unsigned int start, unsigned int end, int prevValue) {
@@ -76,6 +76,8 @@ static int ScriptOfState(int state) {
return eScriptJS;
} else if ((state >= SCE_HPHP_DEFAULT) && (state <= SCE_HPHP_COMMENTLINE)) {
return eScriptPHP;
+ } else if ((state >= SCE_H_SGML_DEFAULT) && (state <= SCE_H_SGML_ERROR)) {
+ return eScriptSGML;
} else {
return eScriptNone;
}
@@ -201,7 +203,7 @@ static int classifyTagHTML(unsigned int start, unsigned int end,
} else if (strcmp(s, "![cdata[") == 0) { // In lower case because already converted
chAttr = SCE_H_CDATA;
} else if (s[0] == '!') {
- chAttr = SCE_H_SGML;
+ chAttr = SCE_H_SGML_DEFAULT;
} else if (s[0] == '/') { // Closing tag
if (keywords.InList(s + 1))
chAttr = SCE_H_TAG;
@@ -299,6 +301,15 @@ static void classifyWordHTPHP(unsigned int start, unsigned int end, WordList &ke
styler.ColourTo(end, chAttr);
}
+static bool isWordHSGML(unsigned int start, unsigned int end, WordList &keywords, Accessor &styler) {
+ char s[30 + 1];
+ for (unsigned int i = 0; i < end - start + 1 && i < 30; i++) {
+ s[i] = styler[start + i];
+ s[i + 1] = '\0';
+ }
+ return keywords.InList(s);
+}
+
// Return the first state to reach when entering a scripting language
static int StateForScript(int scriptLanguage) {
int Result;
@@ -315,6 +326,9 @@ static int StateForScript(int scriptLanguage) {
case eScriptXML:
Result = SCE_H_TAGUNKNOWN;
break;
+ case eScriptSGML:
+ Result = SCE_H_SGML_DEFAULT;
+ break;
default :
Result = SCE_HJ_START;
break;
@@ -357,9 +371,10 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
WordList &keywords3 = *keywordlists[2];
WordList &keywords4 = *keywordlists[3];
WordList &keywords5 = *keywordlists[4];
+ WordList &keywords6 = *keywordlists[5]; // SGML (DTD) keywords
// Lexer for HTML requires more lexical states (7 bits worth) than most lexers
- styler.StartAt(startPos, 127);
+ styler.StartAt(startPos, STYLE_MAX);
char prevWord[200];
prevWord[0] = '\0';
int StateToPrint = initStyle;
@@ -373,7 +388,7 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
}
state = SCE_H_DEFAULT;
}
- styler.StartAt(startPos, 127);
+ styler.StartAt(startPos, STYLE_MAX);
int lineCurrent = styler.GetLine(startPos);
int lineState;
@@ -593,14 +608,31 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
continue;
}
+ /////////////////////////////////////
+ // handle the start of SGML language (DTD)
+ else if (((scriptLanguage == eScriptNone) || (scriptLanguage == eScriptXML)) &&
+ (chPrev == '<') &&
+ (ch == '!') &&
+ (chNext != '[')) {
+ styler.ColourTo(i - 2, StateToPrint);
+ styler.ColourTo(i, SCE_H_SGML_DEFAULT);
+ scriptLanguage = eScriptSGML;
+ state = SCE_H_SGML_COMMAND; // wait for a pending command
+ // fold whole tag (-- when closing the tag)
+ levelCurrent++;
+ continue;
+ }
+
// handle the end of a pre-processor = Non-HTML
- else if (
+ else if ((
((inScriptType == eNonHtmlPreProc)
|| (inScriptType == eNonHtmlScriptPreProc)) && (
((scriptLanguage == eScriptPHP) && (ch == '?') && !isPHPStringState(state) && (state != SCE_HPHP_COMMENT)) ||
+ ((scriptLanguage == eScriptSGML) && (ch == '>')) ||
((scriptLanguage != eScriptNone) && !isStringState(state) &&
(ch == '%'))
- ) && (chNext == '>')) {
+ ) && (chNext == '>')) ||
+ ((scriptLanguage == eScriptSGML) && (ch == '>'))) {
if (state == SCE_H_ASPAT) {
aspScript = segIsScriptingIndicator(styler,
styler.GetStartSegment(), i - 1, aspScript);
@@ -631,6 +663,8 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
styler.ColourTo(i, SCE_H_ASP);
else if (scriptLanguage == eScriptXML)
styler.ColourTo(i, SCE_H_XMLEND);
+ else if (scriptLanguage == eScriptSGML)
+ styler.ColourTo(i, SCE_H_SGML_DEFAULT);
else
styler.ColourTo(i, SCE_H_QUESTION);
state = beforePreProc;
@@ -662,8 +696,11 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
i += 3;
levelCurrent++;
state = SCE_H_COMMENT;
- } else
+ } else if ((chNext == '!') && (chNext2 != '[')) {
+ state = SCE_H_SGML_DEFAULT;
+ } else {
state = SCE_H_TAGUNKNOWN;
+ }
} else if (ch == '&') {
styler.ColourTo(i - 1, SCE_H_DEFAULT);
state = SCE_H_ENTITY;
@@ -685,14 +722,57 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
tagOpened = false;
}
break;
- case SCE_H_SGML:
- if (ch == '>') {
- levelCurrent--;
+ case SCE_H_SGML_DEFAULT:
+/* if (ch == '!' && chPrev == '<') {
+ styler.ColourTo(i, StateToPrint);
+ state = SCE_H_SGML_COMMAND; // wait for the command
+ } else */if (ch == '\"') {
+ styler.ColourTo(i-1, StateToPrint);
+ state = SCE_H_SGML_STRING; // wait for the command
+ } else if ((ch == '-') && (chPrev == '-')) {
+ styler.ColourTo(i-2, StateToPrint);
+ state = SCE_H_SGML_COMMENT;
+ } else if (ch == '>') {
styler.ColourTo(i, StateToPrint);
state = SCE_H_DEFAULT;
tagOpened = false;
}
break;
+ case SCE_H_SGML_COMMAND:
+ if (!ishtmlwordchar(ch)) {
+ if (isWordHSGML(styler.GetStartSegment(), i - 1, keywords6, styler)) {
+ styler.ColourTo(i - 1, StateToPrint);
+ state = SCE_H_SGML_1ST_PARAM;
+ } else {
+ styler.ColourTo(i - 1, SCE_H_SGML_ERROR);
+ state = SCE_H_SGML_1ST_PARAM;
+ }
+ }
+ break;
+ case SCE_H_SGML_1ST_PARAM:
+ // wait for the beginning of the word
+ if (ishtmlwordchar(ch)) {
+ styler.ColourTo(i - 1, SCE_H_SGML_DEFAULT);
+ // find the length of the word
+ int size = 1;
+ while (ishtmlwordchar(styler.SafeGetCharAt(i+size)))
+ size++;
+ styler.ColourTo(i + size - 1, StateToPrint);
+ state = SCE_H_SGML_DEFAULT;
+ }
+ break;
+ case SCE_H_SGML_STRING:
+ if (ch == '\"') {
+ styler.ColourTo(i, StateToPrint);
+ state = SCE_H_SGML_DEFAULT;
+ }
+ break;
+ case SCE_H_SGML_COMMENT:
+ if ((ch == '-') && (chPrev == '-')) {
+ styler.ColourTo(i, StateToPrint);
+ state = SCE_H_SGML_DEFAULT;
+ }
+ break;
case SCE_H_ENTITY:
if (ch == ';') {
styler.ColourTo(i, StateToPrint);
@@ -745,8 +825,8 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
if (eClass != SCE_H_TAGUNKNOWN) {
if (eClass == SCE_H_CDATA) {
state = SCE_H_CDATA;
- } else if (eClass == SCE_H_SGML) {
- state = SCE_H_SGML;
+ } else if (eClass == SCE_H_SGML_DEFAULT) {
+ state = SCE_H_SGML_DEFAULT;
} else {
state = SCE_H_OTHER;
}
@@ -1366,4 +1446,3 @@ static void ColouriseHyperTextDoc(unsigned int startPos, int length, int initSty
LexerModule lmHTML(SCLEX_HTML, ColouriseHyperTextDoc, "hypertext");
LexerModule lmXML(SCLEX_XML, ColouriseHyperTextDoc, "xml");
-
diff --git a/src/ScintillaBase.h b/src/ScintillaBase.h
index acf70e000..ca4695355 100644
--- a/src/ScintillaBase.h
+++ b/src/ScintillaBase.h
@@ -43,7 +43,7 @@ protected:
int lexLanguage;
LexerModule *lexCurrent;
PropSet props;
- enum {numWordLists=5};
+ enum {numWordLists=6};
WordList *keyWordLists[numWordLists+1];
void SetLexer(uptr_t wParam);
void SetLexerLanguage(const char *languageName);