1 // Scintilla source code edit control
5 // Copyright 1998-2005 by Neil Hodgson <neilh@scintilla.org>
6 // The License.txt file describes the conditions under which this software may be distributed.
16 #include "Scintilla.h"
19 #include "StringCopy.h"
21 #include "LexAccessor.h"
23 #include "StyleContext.h"
24 #include "CharacterSet.h"
25 #include "LexerModule.h"
28 using namespace Scintilla
;
31 #define SCE_HA_JS (SCE_HJA_START - SCE_HJ_START)
32 #define SCE_HA_VBS (SCE_HBA_START - SCE_HB_START)
33 #define SCE_HA_PYTHON (SCE_HPA_START - SCE_HP_START)
35 enum script_type
{ eScriptNone
= 0, eScriptJS
, eScriptVBS
, eScriptPython
, eScriptPHP
, eScriptXML
, eScriptSGML
, eScriptSGMLblock
, eScriptComment
};
36 enum script_mode
{ eHtml
= 0, eNonHtmlScript
, eNonHtmlPreProc
, eNonHtmlScriptPreProc
};
38 static inline bool IsAWordChar(const int ch
) {
39 return (ch
< 0x80) && (isalnum(ch
) || ch
== '.' || ch
== '_');
42 static inline bool IsAWordStart(const int ch
) {
43 return (ch
< 0x80) && (isalnum(ch
) || ch
== '_');
46 inline bool IsOperator(int ch
) {
47 if (IsASCII(ch
) && isalnum(ch
))
49 // '.' left out as it is used to make up numbers
50 if (ch
== '%' || ch
== '^' || ch
== '&' || ch
== '*' ||
51 ch
== '(' || ch
== ')' || ch
== '-' || ch
== '+' ||
52 ch
== '=' || ch
== '|' || ch
== '{' || ch
== '}' ||
53 ch
== '[' || ch
== ']' || ch
== ':' || ch
== ';' ||
54 ch
== '<' || ch
== '>' || ch
== ',' || ch
== '/' ||
55 ch
== '?' || ch
== '!' || ch
== '.' || ch
== '~')
60 static void GetTextSegment(Accessor
&styler
, unsigned int start
, unsigned int end
, char *s
, size_t len
) {
62 for (; (i
< end
- start
+ 1) && (i
< len
-1); i
++) {
63 s
[i
] = static_cast<char>(MakeLowerCase(styler
[start
+ i
]));
68 static const char *GetNextWord(Accessor
&styler
, unsigned int start
, char *s
, size_t sLen
) {
71 for (; i
< sLen
-1; i
++) {
72 char ch
= static_cast<char>(styler
.SafeGetCharAt(start
+ i
));
73 if ((i
== 0) && !IsAWordStart(ch
))
75 if ((i
> 0) && !IsAWordChar(ch
))
84 static script_type
segIsScriptingIndicator(Accessor
&styler
, unsigned int start
, unsigned int end
, script_type prevValue
) {
86 GetTextSegment(styler
, start
, end
, s
, sizeof(s
));
87 //Platform::DebugPrintf("Scripting indicator [%s]\n", s);
88 if (strstr(s
, "src")) // External script
92 if (strstr(s
, "pyth"))
94 if (strstr(s
, "javas"))
96 if (strstr(s
, "jscr"))
100 if (strstr(s
, "xml")) {
101 const char *xml
= strstr(s
, "xml");
102 for (const char *t
=s
; t
<xml
; t
++) {
113 static int PrintScriptingIndicatorOffset(Accessor
&styler
, unsigned int start
, unsigned int end
) {
116 GetTextSegment(styler
, start
, end
, s
, sizeof(s
));
117 if (0 == strncmp(s
, "php", 3)) {
124 static script_type
ScriptOfState(int state
) {
125 if ((state
>= SCE_HP_START
) && (state
<= SCE_HP_IDENTIFIER
)) {
126 return eScriptPython
;
127 } else if ((state
>= SCE_HB_START
) && (state
<= SCE_HB_STRINGEOL
)) {
129 } else if ((state
>= SCE_HJ_START
) && (state
<= SCE_HJ_REGEX
)) {
131 } else if ((state
>= SCE_HPHP_DEFAULT
) && (state
<= SCE_HPHP_COMMENTLINE
)) {
133 } else if ((state
>= SCE_H_SGML_DEFAULT
) && (state
< SCE_H_SGML_BLOCK_DEFAULT
)) {
135 } else if (state
== SCE_H_SGML_BLOCK_DEFAULT
) {
136 return eScriptSGMLblock
;
142 static int statePrintForState(int state
, script_mode inScriptType
) {
143 int StateToPrint
= state
;
145 if (state
>= SCE_HJ_START
) {
146 if ((state
>= SCE_HP_START
) && (state
<= SCE_HP_IDENTIFIER
)) {
147 StateToPrint
= state
+ ((inScriptType
== eNonHtmlScript
) ? 0 : SCE_HA_PYTHON
);
148 } else if ((state
>= SCE_HB_START
) && (state
<= SCE_HB_STRINGEOL
)) {
149 StateToPrint
= state
+ ((inScriptType
== eNonHtmlScript
) ? 0 : SCE_HA_VBS
);
150 } else if ((state
>= SCE_HJ_START
) && (state
<= SCE_HJ_REGEX
)) {
151 StateToPrint
= state
+ ((inScriptType
== eNonHtmlScript
) ? 0 : SCE_HA_JS
);
158 static int stateForPrintState(int StateToPrint
) {
161 if ((StateToPrint
>= SCE_HPA_START
) && (StateToPrint
<= SCE_HPA_IDENTIFIER
)) {
162 state
= StateToPrint
- SCE_HA_PYTHON
;
163 } else if ((StateToPrint
>= SCE_HBA_START
) && (StateToPrint
<= SCE_HBA_STRINGEOL
)) {
164 state
= StateToPrint
- SCE_HA_VBS
;
165 } else if ((StateToPrint
>= SCE_HJA_START
) && (StateToPrint
<= SCE_HJA_REGEX
)) {
166 state
= StateToPrint
- SCE_HA_JS
;
168 state
= StateToPrint
;
174 static inline bool IsNumber(unsigned int start
, Accessor
&styler
) {
175 return IsADigit(styler
[start
]) || (styler
[start
] == '.') ||
176 (styler
[start
] == '-') || (styler
[start
] == '#');
179 static inline bool isStringState(int state
) {
183 case SCE_HJ_DOUBLESTRING
:
184 case SCE_HJ_SINGLESTRING
:
185 case SCE_HJA_DOUBLESTRING
:
186 case SCE_HJA_SINGLESTRING
:
190 case SCE_HP_CHARACTER
:
192 case SCE_HP_TRIPLEDOUBLE
:
194 case SCE_HPA_CHARACTER
:
196 case SCE_HPA_TRIPLEDOUBLE
:
197 case SCE_HPHP_HSTRING
:
198 case SCE_HPHP_SIMPLESTRING
:
199 case SCE_HPHP_HSTRING_VARIABLE
:
200 case SCE_HPHP_COMPLEX_VARIABLE
:
210 static inline bool stateAllowsTermination(int state
) {
211 bool allowTermination
= !isStringState(state
);
212 if (allowTermination
) {
214 case SCE_HB_COMMENTLINE
:
215 case SCE_HPHP_COMMENT
:
216 case SCE_HP_COMMENTLINE
:
217 case SCE_HPA_COMMENTLINE
:
218 allowTermination
= false;
221 return allowTermination
;
224 // not really well done, since it's only comments that should lex the %> and <%
225 static inline bool isCommentASPState(int state
) {
230 case SCE_HJ_COMMENTLINE
:
231 case SCE_HJ_COMMENTDOC
:
232 case SCE_HB_COMMENTLINE
:
233 case SCE_HP_COMMENTLINE
:
234 case SCE_HPHP_COMMENT
:
235 case SCE_HPHP_COMMENTLINE
:
245 static void classifyAttribHTML(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
246 bool wordIsNumber
= IsNumber(start
, styler
);
247 char chAttr
= SCE_H_ATTRIBUTEUNKNOWN
;
249 chAttr
= SCE_H_NUMBER
;
252 GetTextSegment(styler
, start
, end
, s
, sizeof(s
));
253 if (keywords
.InList(s
))
254 chAttr
= SCE_H_ATTRIBUTE
;
256 if ((chAttr
== SCE_H_ATTRIBUTEUNKNOWN
) && !keywords
)
257 // No keywords -> all are known
258 chAttr
= SCE_H_ATTRIBUTE
;
259 styler
.ColourTo(end
, chAttr
);
262 static int classifyTagHTML(unsigned int start
, unsigned int end
,
263 WordList
&keywords
, Accessor
&styler
, bool &tagDontFold
,
264 bool caseSensitive
, bool isXml
, bool allowScripts
) {
265 char withSpace
[30 + 2] = " ";
266 const char *s
= withSpace
+ 1;
267 // Copy after the '<'
269 for (unsigned int cPos
= start
; cPos
<= end
&& i
< 30; cPos
++) {
270 char ch
= styler
[cPos
];
271 if ((ch
!= '<') && (ch
!= '/')) {
272 withSpace
[i
++] = caseSensitive
? ch
: static_cast<char>(MakeLowerCase(ch
));
276 //The following is only a quick hack, to see if this whole thing would work
277 //we first need the tagname with a trailing space...
279 withSpace
[i
+1] = '\0';
281 // if the current language is XML, I can fold any tag
282 // if the current language is HTML, I don't want to fold certain tags (input, meta, etc.)
283 //...to find it in the list of no-container-tags
284 tagDontFold
= (!isXml
) && (NULL
!= strstr(" area base basefont br col command embed frame hr img input isindex keygen link meta param source track wbr ", withSpace
));
286 //now we can remove the trailing space
289 // No keywords -> all are known
290 char chAttr
= SCE_H_TAGUNKNOWN
;
292 chAttr
= SCE_H_SGML_DEFAULT
;
293 } else if (!keywords
|| keywords
.InList(s
)) {
296 styler
.ColourTo(end
, chAttr
);
297 if (chAttr
== SCE_H_TAG
) {
298 if (allowScripts
&& 0 == strcmp(s
, "script")) {
299 // check to see if this is a self-closing tag by sniffing ahead
300 bool isSelfClose
= false;
301 for (unsigned int cPos
= end
; cPos
<= end
+ 200; cPos
++) {
302 char ch
= styler
.SafeGetCharAt(cPos
, '\0');
303 if (ch
== '\0' || ch
== '>')
305 else if (ch
== '/' && styler
.SafeGetCharAt(cPos
+ 1, '\0') == '>') {
311 // do not enter a script state if the tag self-closed
313 chAttr
= SCE_H_SCRIPT
;
314 } else if (!isXml
&& 0 == strcmp(s
, "comment")) {
315 chAttr
= SCE_H_COMMENT
;
321 static void classifyWordHTJS(unsigned int start
, unsigned int end
,
322 WordList
&keywords
, Accessor
&styler
, script_mode inScriptType
) {
325 for (; i
< end
- start
+ 1 && i
< 30; i
++) {
326 s
[i
] = styler
[start
+ i
];
330 char chAttr
= SCE_HJ_WORD
;
331 bool wordIsNumber
= IsADigit(s
[0]) || ((s
[0] == '.') && IsADigit(s
[1]));
333 chAttr
= SCE_HJ_NUMBER
;
334 } else if (keywords
.InList(s
)) {
335 chAttr
= SCE_HJ_KEYWORD
;
337 styler
.ColourTo(end
, statePrintForState(chAttr
, inScriptType
));
340 static int classifyWordHTVB(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
, script_mode inScriptType
) {
341 char chAttr
= SCE_HB_IDENTIFIER
;
342 bool wordIsNumber
= IsADigit(styler
[start
]) || (styler
[start
] == '.');
344 chAttr
= SCE_HB_NUMBER
;
347 GetTextSegment(styler
, start
, end
, s
, sizeof(s
));
348 if (keywords
.InList(s
)) {
349 chAttr
= SCE_HB_WORD
;
350 if (strcmp(s
, "rem") == 0)
351 chAttr
= SCE_HB_COMMENTLINE
;
354 styler
.ColourTo(end
, statePrintForState(chAttr
, inScriptType
));
355 if (chAttr
== SCE_HB_COMMENTLINE
)
356 return SCE_HB_COMMENTLINE
;
358 return SCE_HB_DEFAULT
;
361 static void classifyWordHTPy(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
, char *prevWord
, script_mode inScriptType
, bool isMako
) {
362 bool wordIsNumber
= IsADigit(styler
[start
]);
365 for (; i
< end
- start
+ 1 && i
< 30; i
++) {
366 s
[i
] = styler
[start
+ i
];
369 char chAttr
= SCE_HP_IDENTIFIER
;
370 if (0 == strcmp(prevWord
, "class"))
371 chAttr
= SCE_HP_CLASSNAME
;
372 else if (0 == strcmp(prevWord
, "def"))
373 chAttr
= SCE_HP_DEFNAME
;
374 else if (wordIsNumber
)
375 chAttr
= SCE_HP_NUMBER
;
376 else if (keywords
.InList(s
))
377 chAttr
= SCE_HP_WORD
;
378 else if (isMako
&& 0 == strcmp(s
, "block"))
379 chAttr
= SCE_HP_WORD
;
380 styler
.ColourTo(end
, statePrintForState(chAttr
, inScriptType
));
384 // Update the word colour to default or keyword
385 // Called when in a PHP word
386 static void classifyWordHTPHP(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
387 char chAttr
= SCE_HPHP_DEFAULT
;
388 bool wordIsNumber
= IsADigit(styler
[start
]) || (styler
[start
] == '.' && start
+1 <= end
&& IsADigit(styler
[start
+1]));
390 chAttr
= SCE_HPHP_NUMBER
;
393 GetTextSegment(styler
, start
, end
, s
, sizeof(s
));
394 if (keywords
.InList(s
))
395 chAttr
= SCE_HPHP_WORD
;
397 styler
.ColourTo(end
, chAttr
);
400 static bool isWordHSGML(unsigned int start
, unsigned int end
, WordList
&keywords
, Accessor
&styler
) {
403 for (; i
< end
- start
+ 1 && i
< 30; i
++) {
404 s
[i
] = styler
[start
+ i
];
407 return keywords
.InList(s
);
410 static bool isWordCdata(unsigned int start
, unsigned int end
, Accessor
&styler
) {
413 for (; i
< end
- start
+ 1 && i
< 30; i
++) {
414 s
[i
] = styler
[start
+ i
];
417 return (0 == strcmp(s
, "[CDATA["));
420 // Return the first state to reach when entering a scripting language
421 static int StateForScript(script_type scriptLanguage
) {
423 switch (scriptLanguage
) {
425 Result
= SCE_HB_START
;
428 Result
= SCE_HP_START
;
431 Result
= SCE_HPHP_DEFAULT
;
434 Result
= SCE_H_TAGUNKNOWN
;
437 Result
= SCE_H_SGML_DEFAULT
;
440 Result
= SCE_H_COMMENT
;
443 Result
= SCE_HJ_START
;
449 static inline bool issgmlwordchar(int ch
) {
450 return !IsASCII(ch
) ||
451 (isalnum(ch
) || ch
== '.' || ch
== '_' || ch
== ':' || ch
== '!' || ch
== '#' || ch
== '[');
454 static inline bool IsPhpWordStart(int ch
) {
455 return (IsASCII(ch
) && (isalpha(ch
) || (ch
== '_'))) || (ch
>= 0x7f);
458 static inline bool IsPhpWordChar(int ch
) {
459 return IsADigit(ch
) || IsPhpWordStart(ch
);
462 static bool InTagState(int state
) {
463 return state
== SCE_H_TAG
|| state
== SCE_H_TAGUNKNOWN
||
464 state
== SCE_H_SCRIPT
||
465 state
== SCE_H_ATTRIBUTE
|| state
== SCE_H_ATTRIBUTEUNKNOWN
||
466 state
== SCE_H_NUMBER
|| state
== SCE_H_OTHER
||
467 state
== SCE_H_DOUBLESTRING
|| state
== SCE_H_SINGLESTRING
;
470 static bool IsCommentState(const int state
) {
471 return state
== SCE_H_COMMENT
|| state
== SCE_H_SGML_COMMENT
;
474 static bool IsScriptCommentState(const int state
) {
475 return state
== SCE_HJ_COMMENT
|| state
== SCE_HJ_COMMENTLINE
|| state
== SCE_HJA_COMMENT
||
476 state
== SCE_HJA_COMMENTLINE
|| state
== SCE_HB_COMMENTLINE
|| state
== SCE_HBA_COMMENTLINE
;
479 static bool isLineEnd(int ch
) {
480 return ch
== '\r' || ch
== '\n';
483 static bool isMakoBlockEnd(const int ch
, const int chNext
, const char *blockType
) {
484 if (strlen(blockType
) == 0) {
485 return ((ch
== '%') && (chNext
== '>'));
486 } else if ((0 == strcmp(blockType
, "inherit")) ||
487 (0 == strcmp(blockType
, "namespace")) ||
488 (0 == strcmp(blockType
, "include")) ||
489 (0 == strcmp(blockType
, "page"))) {
490 return ((ch
== '/') && (chNext
== '>'));
491 } else if (0 == strcmp(blockType
, "%")) {
492 if (ch
== '/' && isLineEnd(chNext
))
495 return isLineEnd(ch
);
496 } else if (0 == strcmp(blockType
, "{")) {
503 static bool isDjangoBlockEnd(const int ch
, const int chNext
, const char *blockType
) {
504 if (strlen(blockType
) == 0) {
506 } else if (0 == strcmp(blockType
, "%")) {
507 return ((ch
== '%') && (chNext
== '}'));
508 } else if (0 == strcmp(blockType
, "{")) {
509 return ((ch
== '}') && (chNext
== '}'));
515 static bool isPHPStringState(int state
) {
517 (state
== SCE_HPHP_HSTRING
) ||
518 (state
== SCE_HPHP_SIMPLESTRING
) ||
519 (state
== SCE_HPHP_HSTRING_VARIABLE
) ||
520 (state
== SCE_HPHP_COMPLEX_VARIABLE
);
523 static int FindPhpStringDelimiter(char *phpStringDelimiter
, const int phpStringDelimiterSize
, int i
, const int lengthDoc
, Accessor
&styler
, bool &isSimpleString
) {
525 const int beginning
= i
- 1;
526 bool isValidSimpleString
= false;
528 while (i
< lengthDoc
&& (styler
[i
] == ' ' || styler
[i
] == '\t'))
531 char ch
= styler
.SafeGetCharAt(i
);
532 const char chNext
= styler
.SafeGetCharAt(i
+ 1);
533 if (!IsPhpWordStart(ch
)) {
534 if (ch
== '\'' && IsPhpWordStart(chNext
)) {
537 isSimpleString
= true;
539 phpStringDelimiter
[0] = '\0';
543 phpStringDelimiter
[0] = ch
;
546 for (j
= i
; j
< lengthDoc
&& !isLineEnd(styler
[j
]); j
++) {
547 if (!IsPhpWordChar(styler
[j
])) {
548 if (isSimpleString
&& (styler
[j
] == '\'') && isLineEnd(styler
.SafeGetCharAt(j
+ 1))) {
549 isValidSimpleString
= true;
553 phpStringDelimiter
[0] = '\0';
557 if (j
- i
< phpStringDelimiterSize
- 2)
558 phpStringDelimiter
[j
-i
+1] = styler
[j
];
562 if (isSimpleString
&& !isValidSimpleString
) {
563 phpStringDelimiter
[0] = '\0';
566 phpStringDelimiter
[j
-i
+1 - (isSimpleString
? 1 : 0)] = '\0';
570 static void ColouriseHyperTextDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
571 Accessor
&styler
, bool isXml
) {
572 WordList
&keywords
= *keywordlists
[0];
573 WordList
&keywords2
= *keywordlists
[1];
574 WordList
&keywords3
= *keywordlists
[2];
575 WordList
&keywords4
= *keywordlists
[3];
576 WordList
&keywords5
= *keywordlists
[4];
577 WordList
&keywords6
= *keywordlists
[5]; // SGML (DTD) keywords
579 styler
.StartAt(startPos
);
582 char phpStringDelimiter
[200]; // PHP is not limited in length, we are
583 phpStringDelimiter
[0] = '\0';
584 int StateToPrint
= initStyle
;
585 int state
= stateForPrintState(StateToPrint
);
586 char makoBlockType
[200];
587 makoBlockType
[0] = '\0';
589 char djangoBlockType
[2];
590 djangoBlockType
[0] = '\0';
592 // If inside a tag, it may be a script tag, so reread from the start of line starting tag to ensure any language tags are seen
593 if (InTagState(state
)) {
594 while ((startPos
> 0) && (InTagState(styler
.StyleAt(startPos
- 1)))) {
595 int backLineStart
= styler
.LineStart(styler
.GetLine(startPos
-1));
596 length
+= startPos
- backLineStart
;
597 startPos
= backLineStart
;
599 state
= SCE_H_DEFAULT
;
601 // String can be heredoc, must find a delimiter first. Reread from beginning of line containing the string, to get the correct lineState
602 if (isPHPStringState(state
)) {
603 while (startPos
> 0 && (isPHPStringState(state
) || !isLineEnd(styler
[startPos
- 1]))) {
606 state
= styler
.StyleAt(startPos
);
609 state
= SCE_H_DEFAULT
;
611 styler
.StartAt(startPos
);
613 int lineCurrent
= styler
.GetLine(startPos
);
615 if (lineCurrent
> 0) {
616 lineState
= styler
.GetLineState(lineCurrent
-1);
618 // Default client and ASP scripting language is JavaScript
619 lineState
= eScriptJS
<< 8;
621 // property asp.default.language
622 // Script in ASP code is initially assumed to be in JavaScript.
623 // To change this to VBScript set asp.default.language to 2. Python is 3.
624 lineState
|= styler
.GetPropertyInt("asp.default.language", eScriptJS
) << 4;
626 script_mode inScriptType
= script_mode((lineState
>> 0) & 0x03); // 2 bits of scripting mode
627 bool tagOpened
= (lineState
>> 2) & 0x01; // 1 bit to know if we are in an opened tag
628 bool tagClosing
= (lineState
>> 3) & 0x01; // 1 bit to know if we are in a closing tag
629 bool tagDontFold
= false; //some HTML tags should not be folded
630 script_type aspScript
= script_type((lineState
>> 4) & 0x0F); // 4 bits of script name
631 script_type clientScript
= script_type((lineState
>> 8) & 0x0F); // 4 bits of script name
632 int beforePreProc
= (lineState
>> 12) & 0xFF; // 8 bits of state
634 script_type scriptLanguage
= ScriptOfState(state
);
635 // If eNonHtmlScript coincides with SCE_H_COMMENT, assume eScriptComment
636 if (inScriptType
== eNonHtmlScript
&& state
== SCE_H_COMMENT
) {
637 scriptLanguage
= eScriptComment
;
639 script_type beforeLanguage
= ScriptOfState(beforePreProc
);
641 // property fold.html
642 // Folding is turned on or off for HTML and XML files with this option.
643 // The fold option must also be on for folding to occur.
644 const bool foldHTML
= styler
.GetPropertyInt("fold.html", 0) != 0;
646 const bool fold
= foldHTML
&& styler
.GetPropertyInt("fold", 0);
648 // property fold.html.preprocessor
649 // Folding is turned on or off for scripts embedded in HTML files with this option.
650 // The default is on.
651 const bool foldHTMLPreprocessor
= foldHTML
&& styler
.GetPropertyInt("fold.html.preprocessor", 1);
653 const bool foldCompact
= styler
.GetPropertyInt("fold.compact", 1) != 0;
655 // property fold.hypertext.comment
656 // Allow folding for comments in scripts embedded in HTML.
657 // The default is off.
658 const bool foldComment
= fold
&& styler
.GetPropertyInt("fold.hypertext.comment", 0) != 0;
660 // property fold.hypertext.heredoc
661 // Allow folding for heredocs in scripts embedded in HTML.
662 // The default is off.
663 const bool foldHeredoc
= fold
&& styler
.GetPropertyInt("fold.hypertext.heredoc", 0) != 0;
665 // property html.tags.case.sensitive
666 // For XML and HTML, setting this property to 1 will make tags match in a case
667 // sensitive way which is the expected behaviour for XML and XHTML.
668 const bool caseSensitive
= styler
.GetPropertyInt("html.tags.case.sensitive", 0) != 0;
670 // property lexer.xml.allow.scripts
671 // Set to 0 to disable scripts in XML.
672 const bool allowScripts
= styler
.GetPropertyInt("lexer.xml.allow.scripts", 1) != 0;
674 // property lexer.html.mako
675 // Set to 1 to enable the mako template language.
676 const bool isMako
= styler
.GetPropertyInt("lexer.html.mako", 0) != 0;
678 // property lexer.html.django
679 // Set to 1 to enable the django template language.
680 const bool isDjango
= styler
.GetPropertyInt("lexer.html.django", 0) != 0;
682 const CharacterSet
setHTMLWord(CharacterSet::setAlphaNum
, ".-_:!#", 0x80, true);
683 const CharacterSet
setTagContinue(CharacterSet::setAlphaNum
, ".-_:!#[", 0x80, true);
684 const CharacterSet
setAttributeContinue(CharacterSet::setAlphaNum
, ".-_:!#/", 0x80, true);
685 // TODO: also handle + and - (except if they're part of ++ or --) and return keywords
686 const CharacterSet
setOKBeforeJSRE(CharacterSet::setNone
, "([{=,:;!%^&*|?~");
688 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
689 int levelCurrent
= levelPrev
;
690 int visibleChars
= 0;
691 int lineStartVisibleChars
= 0;
695 int chPrevNonWhite
= ' ';
696 // look back to set chPrevNonWhite properly for better regex colouring
697 if (scriptLanguage
== eScriptJS
&& startPos
> 0) {
701 style
= styler
.StyleAt(back
);
702 if (style
< SCE_HJ_DEFAULT
|| style
> SCE_HJ_COMMENTDOC
)
703 // includes SCE_HJ_COMMENT & SCE_HJ_COMMENTLINE
706 if (style
== SCE_HJ_SYMBOLS
) {
707 chPrevNonWhite
= static_cast<unsigned char>(styler
.SafeGetCharAt(back
));
711 styler
.StartSegment(startPos
);
712 const int lengthDoc
= startPos
+ length
;
713 for (int i
= startPos
; i
< lengthDoc
; i
++) {
714 const int chPrev2
= chPrev
;
716 if (!IsASpace(ch
) && state
!= SCE_HJ_COMMENT
&&
717 state
!= SCE_HJ_COMMENTLINE
&& state
!= SCE_HJ_COMMENTDOC
)
719 ch
= static_cast<unsigned char>(styler
[i
]);
720 int chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
721 const int chNext2
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 2));
723 // Handle DBCS codepages
724 if (styler
.IsLeadByte(static_cast<char>(ch
))) {
730 if ((!IsASpace(ch
) || !foldCompact
) && fold
)
733 lineStartVisibleChars
++;
735 // decide what is the current state to print (depending of the script tag)
736 StateToPrint
= statePrintForState(state
, inScriptType
);
738 // handle script folding
740 switch (scriptLanguage
) {
743 //not currently supported case eScriptVBS:
745 if ((state
!= SCE_HPHP_COMMENT
) && (state
!= SCE_HPHP_COMMENTLINE
) && (state
!= SCE_HJ_COMMENT
) && (state
!= SCE_HJ_COMMENTLINE
) && (state
!= SCE_HJ_COMMENTDOC
) && (!isStringState(state
))) {
746 //Platform::DebugPrintf("state=%d, StateToPrint=%d, initStyle=%d\n", state, StateToPrint, initStyle);
747 //if ((state == SCE_HPHP_OPERATOR) || (state == SCE_HPHP_DEFAULT) || (state == SCE_HJ_SYMBOLS) || (state == SCE_HJ_START) || (state == SCE_HJ_DEFAULT)) {
750 while ((j
< lengthDoc
) && IsASpaceOrTab(styler
.SafeGetCharAt(j
))) {
753 if (styler
.Match(j
, "region") || styler
.Match(j
, "if")) {
755 } else if (styler
.Match(j
, "end")) {
758 } else if ((ch
== '{') || (ch
== '}') || (foldComment
&& (ch
== '/') && (chNext
== '*'))) {
759 levelCurrent
+= (((ch
== '{') || (ch
== '/')) ? 1 : -1);
761 } else if (((state
== SCE_HPHP_COMMENT
) || (state
== SCE_HJ_COMMENT
)) && foldComment
&& (ch
== '*') && (chNext
== '/')) {
766 if (state
!= SCE_HP_COMMENTLINE
&& !isMako
) {
767 if ((ch
== ':') && ((chNext
== '\n') || (chNext
== '\r' && chNext2
== '\n'))) {
769 } else if ((ch
== '\n') && !((chNext
== '\r') && (chNext2
== '\n')) && (chNext
!= '\n')) {
770 // check if the number of tabs is lower than the level
771 int Findlevel
= (levelCurrent
& ~SC_FOLDLEVELBASE
) * 8;
772 for (int j
= 0; Findlevel
> 0; j
++) {
773 char chTmp
= styler
.SafeGetCharAt(i
+ j
+ 1);
776 } else if (chTmp
== ' ') {
784 levelCurrent
-= Findlevel
/ 8;
796 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
797 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
798 // Avoid triggering two times on Dos/Win
799 // New line -> record any line state onto /next/ line
802 if (visibleChars
== 0)
803 lev
|= SC_FOLDLEVELWHITEFLAG
;
804 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
805 lev
|= SC_FOLDLEVELHEADERFLAG
;
807 styler
.SetLevel(lineCurrent
, lev
);
809 levelPrev
= levelCurrent
;
811 styler
.SetLineState(lineCurrent
,
812 ((inScriptType
& 0x03) << 0) |
813 ((tagOpened
? 1 : 0) << 2) |
814 ((tagClosing
? 1 : 0) << 3) |
815 ((aspScript
& 0x0F) << 4) |
816 ((clientScript
& 0x0F) << 8) |
817 ((beforePreProc
& 0xFF) << 12));
819 lineStartVisibleChars
= 0;
822 // handle start of Mako comment line
823 if (isMako
&& ch
== '#' && chNext
== '#') {
827 // handle end of Mako comment line
828 else if (isMako
&& makoComment
&& (ch
== '\r' || ch
== '\n')) {
830 styler
.ColourTo(i
, SCE_HP_COMMENTLINE
);
831 state
= SCE_HP_DEFAULT
;
834 // Allow falling through to mako handling code if newline is going to end a block
835 if (((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) &&
836 (!isMako
|| (0 != strcmp(makoBlockType
, "%")))) {
839 // generic end of script processing
840 else if ((inScriptType
== eNonHtmlScript
) && (ch
== '<') && (chNext
== '/')) {
841 // Check if it's the end of the script tag (or any other HTML tag)
843 // in these cases, you can embed HTML tags (to confirm !!!!!!!!!!!!!!!!!!!!!!)
844 case SCE_H_DOUBLESTRING
:
845 case SCE_H_SINGLESTRING
:
847 case SCE_HJ_COMMENTDOC
:
848 //case SCE_HJ_COMMENTLINE: // removed as this is a common thing done to hide
849 // the end of script marker from some JS interpreters.
850 case SCE_HB_COMMENTLINE
:
851 case SCE_HBA_COMMENTLINE
:
852 case SCE_HJ_DOUBLESTRING
:
853 case SCE_HJ_SINGLESTRING
:
859 case SCE_HP_TRIPLEDOUBLE
:
860 case SCE_HPHP_HSTRING
:
861 case SCE_HPHP_SIMPLESTRING
:
862 case SCE_HPHP_COMMENT
:
863 case SCE_HPHP_COMMENTLINE
:
866 // check if the closing tag is a script tag
867 if (const char *tag
=
868 state
== SCE_HJ_COMMENTLINE
|| isXml
? "script" :
869 state
== SCE_H_COMMENT
? "comment" : 0) {
873 chr
= static_cast<int>(*tag
++);
874 } while (chr
!= 0 && chr
== MakeLowerCase(styler
.SafeGetCharAt(j
++)));
877 // closing tag of the script (it's a closing HTML tag anyway)
878 styler
.ColourTo(i
- 1, StateToPrint
);
879 state
= SCE_H_TAGUNKNOWN
;
880 inScriptType
= eHtml
;
881 scriptLanguage
= eScriptNone
;
882 clientScript
= eScriptJS
;
890 /////////////////////////////////////
891 // handle the start of PHP pre-processor = Non-HTML
892 else if ((state
!= SCE_H_ASPAT
) &&
893 !isPHPStringState(state
) &&
894 (state
!= SCE_HPHP_COMMENT
) &&
895 (state
!= SCE_HPHP_COMMENTLINE
) &&
898 !IsScriptCommentState(state
)) {
899 beforeLanguage
= scriptLanguage
;
900 scriptLanguage
= segIsScriptingIndicator(styler
, i
+ 2, i
+ 6, isXml
? eScriptXML
: eScriptPHP
);
901 if ((scriptLanguage
!= eScriptPHP
) && (isStringState(state
) || (state
==SCE_H_COMMENT
))) continue;
902 styler
.ColourTo(i
- 1, StateToPrint
);
903 beforePreProc
= state
;
906 i
+= PrintScriptingIndicatorOffset(styler
, styler
.GetStartSegment() + 2, i
+ 6);
907 if (scriptLanguage
== eScriptXML
)
908 styler
.ColourTo(i
, SCE_H_XMLSTART
);
910 styler
.ColourTo(i
, SCE_H_QUESTION
);
911 state
= StateForScript(scriptLanguage
);
912 if (inScriptType
== eNonHtmlScript
)
913 inScriptType
= eNonHtmlScriptPreProc
;
915 inScriptType
= eNonHtmlPreProc
;
916 // Fold whole script, but not if the XML first tag (all XML-like tags in this case)
917 if (foldHTMLPreprocessor
&& (scriptLanguage
!= eScriptXML
)) {
921 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
));
925 // handle the start Mako template Python code
926 else if (isMako
&& scriptLanguage
== eScriptNone
&& ((ch
== '<' && chNext
== '%') ||
927 (lineStartVisibleChars
== 1 && ch
== '%') ||
928 (lineStartVisibleChars
== 1 && ch
== '/' && chNext
== '%') ||
929 (ch
== '$' && chNext
== '{') ||
930 (ch
== '<' && chNext
== '/' && chNext2
== '%'))) {
931 if (ch
== '%' || ch
== '/')
932 StringCopy(makoBlockType
, "%");
934 StringCopy(makoBlockType
, "{");
935 else if (chNext
== '/')
936 GetNextWord(styler
, i
+3, makoBlockType
, sizeof(makoBlockType
));
938 GetNextWord(styler
, i
+2, makoBlockType
, sizeof(makoBlockType
));
939 styler
.ColourTo(i
- 1, StateToPrint
);
940 beforePreProc
= state
;
941 if (inScriptType
== eNonHtmlScript
)
942 inScriptType
= eNonHtmlScriptPreProc
;
944 inScriptType
= eNonHtmlPreProc
;
949 } else if (ch
!= '%') {
953 state
= SCE_HP_START
;
954 scriptLanguage
= eScriptPython
;
955 styler
.ColourTo(i
, SCE_H_ASP
);
957 if (ch
!= '%' && ch
!= '$' && ch
!= '/') {
958 i
+= static_cast<int>(strlen(makoBlockType
));
959 visibleChars
+= static_cast<int>(strlen(makoBlockType
));
960 if (keywords4
.InList(makoBlockType
))
961 styler
.ColourTo(i
, SCE_HP_WORD
);
963 styler
.ColourTo(i
, SCE_H_TAGUNKNOWN
);
966 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
));
970 // handle the start/end of Django comment
971 else if (isDjango
&& state
!= SCE_H_COMMENT
&& (ch
== '{' && chNext
== '#')) {
972 styler
.ColourTo(i
- 1, StateToPrint
);
973 beforePreProc
= state
;
974 beforeLanguage
= scriptLanguage
;
975 if (inScriptType
== eNonHtmlScript
)
976 inScriptType
= eNonHtmlScriptPreProc
;
978 inScriptType
= eNonHtmlPreProc
;
981 scriptLanguage
= eScriptComment
;
982 state
= SCE_H_COMMENT
;
983 styler
.ColourTo(i
, SCE_H_ASP
);
984 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
));
986 } else if (isDjango
&& state
== SCE_H_COMMENT
&& (ch
== '#' && chNext
== '}')) {
987 styler
.ColourTo(i
- 1, StateToPrint
);
990 styler
.ColourTo(i
, SCE_H_ASP
);
991 state
= beforePreProc
;
992 if (inScriptType
== eNonHtmlScriptPreProc
)
993 inScriptType
= eNonHtmlScript
;
995 inScriptType
= eHtml
;
996 scriptLanguage
= beforeLanguage
;
1000 // handle the start Django template code
1001 else if (isDjango
&& scriptLanguage
!= eScriptPython
&& (ch
== '{' && (chNext
== '%' || chNext
== '{'))) {
1003 StringCopy(djangoBlockType
, "%");
1005 StringCopy(djangoBlockType
, "{");
1006 styler
.ColourTo(i
- 1, StateToPrint
);
1007 beforePreProc
= state
;
1008 if (inScriptType
== eNonHtmlScript
)
1009 inScriptType
= eNonHtmlScriptPreProc
;
1011 inScriptType
= eNonHtmlPreProc
;
1015 state
= SCE_HP_START
;
1016 beforeLanguage
= scriptLanguage
;
1017 scriptLanguage
= eScriptPython
;
1018 styler
.ColourTo(i
, SCE_H_ASP
);
1020 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
));
1024 // handle the start of ASP pre-processor = Non-HTML
1025 else if (!isMako
&& !isDjango
&& !isCommentASPState(state
) && (ch
== '<') && (chNext
== '%') && !isPHPStringState(state
)) {
1026 styler
.ColourTo(i
- 1, StateToPrint
);
1027 beforePreProc
= state
;
1028 if (inScriptType
== eNonHtmlScript
)
1029 inScriptType
= eNonHtmlScriptPreProc
;
1031 inScriptType
= eNonHtmlPreProc
;
1033 if (chNext2
== '@') {
1034 i
+= 2; // place as if it was the second next char treated
1036 state
= SCE_H_ASPAT
;
1037 } else if ((chNext2
== '-') && (styler
.SafeGetCharAt(i
+ 3) == '-')) {
1038 styler
.ColourTo(i
+ 3, SCE_H_ASP
);
1039 state
= SCE_H_XCCOMMENT
;
1040 scriptLanguage
= eScriptVBS
;
1043 if (chNext2
== '=') {
1044 i
+= 2; // place as if it was the second next char treated
1047 i
++; // place as if it was the next char treated
1051 state
= StateForScript(aspScript
);
1053 scriptLanguage
= eScriptVBS
;
1054 styler
.ColourTo(i
, SCE_H_ASP
);
1055 // fold whole script
1056 if (foldHTMLPreprocessor
)
1059 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
));
1063 /////////////////////////////////////
1064 // handle the start of SGML language (DTD)
1065 else if (((scriptLanguage
== eScriptNone
) || (scriptLanguage
== eScriptXML
)) &&
1068 (StateToPrint
!= SCE_H_CDATA
) &&
1069 (!IsCommentState(StateToPrint
)) &&
1070 (!IsScriptCommentState(StateToPrint
))) {
1071 beforePreProc
= state
;
1072 styler
.ColourTo(i
- 2, StateToPrint
);
1073 if ((chNext
== '-') && (chNext2
== '-')) {
1074 state
= SCE_H_COMMENT
; // wait for a pending command
1075 styler
.ColourTo(i
+ 2, SCE_H_COMMENT
);
1076 i
+= 2; // follow styling after the --
1077 } else if (isWordCdata(i
+ 1, i
+ 7, styler
)) {
1078 state
= SCE_H_CDATA
;
1080 styler
.ColourTo(i
, SCE_H_SGML_DEFAULT
); // <! is default
1081 scriptLanguage
= eScriptSGML
;
1082 state
= SCE_H_SGML_COMMAND
; // wait for a pending command
1084 // fold whole tag (-- when closing the tag)
1085 if (foldHTMLPreprocessor
|| state
== SCE_H_COMMENT
|| state
== SCE_H_CDATA
)
1090 // handle the end of Mako Python code
1092 ((inScriptType
== eNonHtmlPreProc
) || (inScriptType
== eNonHtmlScriptPreProc
)) &&
1093 (scriptLanguage
!= eScriptNone
) && stateAllowsTermination(state
) &&
1094 isMakoBlockEnd(ch
, chNext
, makoBlockType
)) {
1095 if (state
== SCE_H_ASPAT
) {
1096 aspScript
= segIsScriptingIndicator(styler
,
1097 styler
.GetStartSegment(), i
- 1, aspScript
);
1099 if (state
== SCE_HP_WORD
) {
1100 classifyWordHTPy(styler
.GetStartSegment(), i
- 1, keywords4
, styler
, prevWord
, inScriptType
, isMako
);
1102 styler
.ColourTo(i
- 1, StateToPrint
);
1104 if (0 != strcmp(makoBlockType
, "%") && (0 != strcmp(makoBlockType
, "{")) && ch
!= '>') {
1108 else if (0 == strcmp(makoBlockType
, "%") && ch
== '/') {
1112 if (0 != strcmp(makoBlockType
, "%") || ch
== '/') {
1113 styler
.ColourTo(i
, SCE_H_ASP
);
1115 state
= beforePreProc
;
1116 if (inScriptType
== eNonHtmlScriptPreProc
)
1117 inScriptType
= eNonHtmlScript
;
1119 inScriptType
= eHtml
;
1120 scriptLanguage
= eScriptNone
;
1124 // handle the end of Django template code
1125 else if (isDjango
&&
1126 ((inScriptType
== eNonHtmlPreProc
) || (inScriptType
== eNonHtmlScriptPreProc
)) &&
1127 (scriptLanguage
!= eScriptNone
) && stateAllowsTermination(state
) &&
1128 isDjangoBlockEnd(ch
, chNext
, djangoBlockType
)) {
1129 if (state
== SCE_H_ASPAT
) {
1130 aspScript
= segIsScriptingIndicator(styler
,
1131 styler
.GetStartSegment(), i
- 1, aspScript
);
1133 if (state
== SCE_HP_WORD
) {
1134 classifyWordHTPy(styler
.GetStartSegment(), i
- 1, keywords4
, styler
, prevWord
, inScriptType
, isMako
);
1136 styler
.ColourTo(i
- 1, StateToPrint
);
1140 styler
.ColourTo(i
, SCE_H_ASP
);
1141 state
= beforePreProc
;
1142 if (inScriptType
== eNonHtmlScriptPreProc
)
1143 inScriptType
= eNonHtmlScript
;
1145 inScriptType
= eHtml
;
1146 scriptLanguage
= beforeLanguage
;
1150 // handle the end of a pre-processor = Non-HTML
1151 else if ((!isMako
&& !isDjango
&& ((inScriptType
== eNonHtmlPreProc
) || (inScriptType
== eNonHtmlScriptPreProc
)) &&
1152 (((scriptLanguage
!= eScriptNone
) && stateAllowsTermination(state
))) &&
1153 (((ch
== '%') || (ch
== '?')) && (chNext
== '>'))) ||
1154 ((scriptLanguage
== eScriptSGML
) && (ch
== '>') && (state
!= SCE_H_SGML_COMMENT
))) {
1155 if (state
== SCE_H_ASPAT
) {
1156 aspScript
= segIsScriptingIndicator(styler
,
1157 styler
.GetStartSegment(), i
- 1, aspScript
);
1159 // Bounce out of any ASP mode
1162 classifyWordHTJS(styler
.GetStartSegment(), i
- 1, keywords2
, styler
, inScriptType
);
1165 classifyWordHTVB(styler
.GetStartSegment(), i
- 1, keywords3
, styler
, inScriptType
);
1168 classifyWordHTPy(styler
.GetStartSegment(), i
- 1, keywords4
, styler
, prevWord
, inScriptType
, isMako
);
1171 classifyWordHTPHP(styler
.GetStartSegment(), i
- 1, keywords5
, styler
);
1173 case SCE_H_XCCOMMENT
:
1174 styler
.ColourTo(i
- 1, state
);
1177 styler
.ColourTo(i
- 1, StateToPrint
);
1180 if (scriptLanguage
!= eScriptSGML
) {
1185 styler
.ColourTo(i
, SCE_H_ASP
);
1186 else if (scriptLanguage
== eScriptXML
)
1187 styler
.ColourTo(i
, SCE_H_XMLEND
);
1188 else if (scriptLanguage
== eScriptSGML
)
1189 styler
.ColourTo(i
, SCE_H_SGML_DEFAULT
);
1191 styler
.ColourTo(i
, SCE_H_QUESTION
);
1192 state
= beforePreProc
;
1193 if (inScriptType
== eNonHtmlScriptPreProc
)
1194 inScriptType
= eNonHtmlScript
;
1196 inScriptType
= eHtml
;
1197 // Unfold all scripting languages, except for XML tag
1198 if (foldHTMLPreprocessor
&& (scriptLanguage
!= eScriptXML
)) {
1201 scriptLanguage
= beforeLanguage
;
1204 /////////////////////////////////////
1209 // in HTML, fold on tag open and unfold on tag close
1211 tagClosing
= (chNext
== '/');
1212 styler
.ColourTo(i
- 1, StateToPrint
);
1214 state
= SCE_H_TAGUNKNOWN
;
1215 } else if (ch
== '&') {
1216 styler
.ColourTo(i
- 1, SCE_H_DEFAULT
);
1217 state
= SCE_H_ENTITY
;
1220 case SCE_H_SGML_DEFAULT
:
1221 case SCE_H_SGML_BLOCK_DEFAULT
:
1222 // if (scriptLanguage == eScriptSGMLblock)
1223 // StateToPrint = SCE_H_SGML_BLOCK_DEFAULT;
1226 styler
.ColourTo(i
- 1, StateToPrint
);
1227 state
= SCE_H_SGML_DOUBLESTRING
;
1228 } else if (ch
== '\'') {
1229 styler
.ColourTo(i
- 1, StateToPrint
);
1230 state
= SCE_H_SGML_SIMPLESTRING
;
1231 } else if ((ch
== '-') && (chPrev
== '-')) {
1232 if (static_cast<int>(styler
.GetStartSegment()) <= (i
- 2)) {
1233 styler
.ColourTo(i
- 2, StateToPrint
);
1235 state
= SCE_H_SGML_COMMENT
;
1236 } else if (IsASCII(ch
) && isalpha(ch
) && (chPrev
== '%')) {
1237 styler
.ColourTo(i
- 2, StateToPrint
);
1238 state
= SCE_H_SGML_ENTITY
;
1239 } else if (ch
== '#') {
1240 styler
.ColourTo(i
- 1, StateToPrint
);
1241 state
= SCE_H_SGML_SPECIAL
;
1242 } else if (ch
== '[') {
1243 styler
.ColourTo(i
- 1, StateToPrint
);
1244 scriptLanguage
= eScriptSGMLblock
;
1245 state
= SCE_H_SGML_BLOCK_DEFAULT
;
1246 } else if (ch
== ']') {
1247 if (scriptLanguage
== eScriptSGMLblock
) {
1248 styler
.ColourTo(i
, StateToPrint
);
1249 scriptLanguage
= eScriptSGML
;
1251 styler
.ColourTo(i
- 1, StateToPrint
);
1252 styler
.ColourTo(i
, SCE_H_SGML_ERROR
);
1254 state
= SCE_H_SGML_DEFAULT
;
1255 } else if (scriptLanguage
== eScriptSGMLblock
) {
1256 if ((ch
== '!') && (chPrev
== '<')) {
1257 styler
.ColourTo(i
- 2, StateToPrint
);
1258 styler
.ColourTo(i
, SCE_H_SGML_DEFAULT
);
1259 state
= SCE_H_SGML_COMMAND
;
1260 } else if (ch
== '>') {
1261 styler
.ColourTo(i
- 1, StateToPrint
);
1262 styler
.ColourTo(i
, SCE_H_SGML_DEFAULT
);
1266 case SCE_H_SGML_COMMAND
:
1267 if ((ch
== '-') && (chPrev
== '-')) {
1268 styler
.ColourTo(i
- 2, StateToPrint
);
1269 state
= SCE_H_SGML_COMMENT
;
1270 } else if (!issgmlwordchar(ch
)) {
1271 if (isWordHSGML(styler
.GetStartSegment(), i
- 1, keywords6
, styler
)) {
1272 styler
.ColourTo(i
- 1, StateToPrint
);
1273 state
= SCE_H_SGML_1ST_PARAM
;
1275 state
= SCE_H_SGML_ERROR
;
1279 case SCE_H_SGML_1ST_PARAM
:
1280 // wait for the beginning of the word
1281 if ((ch
== '-') && (chPrev
== '-')) {
1282 if (scriptLanguage
== eScriptSGMLblock
) {
1283 styler
.ColourTo(i
- 2, SCE_H_SGML_BLOCK_DEFAULT
);
1285 styler
.ColourTo(i
- 2, SCE_H_SGML_DEFAULT
);
1287 state
= SCE_H_SGML_1ST_PARAM_COMMENT
;
1288 } else if (issgmlwordchar(ch
)) {
1289 if (scriptLanguage
== eScriptSGMLblock
) {
1290 styler
.ColourTo(i
- 1, SCE_H_SGML_BLOCK_DEFAULT
);
1292 styler
.ColourTo(i
- 1, SCE_H_SGML_DEFAULT
);
1294 // find the length of the word
1296 while (setHTMLWord
.Contains(static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ size
))))
1298 styler
.ColourTo(i
+ size
- 1, StateToPrint
);
1300 visibleChars
+= size
- 1;
1301 ch
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
));
1302 if (scriptLanguage
== eScriptSGMLblock
) {
1303 state
= SCE_H_SGML_BLOCK_DEFAULT
;
1305 state
= SCE_H_SGML_DEFAULT
;
1310 case SCE_H_SGML_ERROR
:
1311 if ((ch
== '-') && (chPrev
== '-')) {
1312 styler
.ColourTo(i
- 2, StateToPrint
);
1313 state
= SCE_H_SGML_COMMENT
;
1316 case SCE_H_SGML_DOUBLESTRING
:
1318 styler
.ColourTo(i
, StateToPrint
);
1319 state
= SCE_H_SGML_DEFAULT
;
1322 case SCE_H_SGML_SIMPLESTRING
:
1324 styler
.ColourTo(i
, StateToPrint
);
1325 state
= SCE_H_SGML_DEFAULT
;
1328 case SCE_H_SGML_COMMENT
:
1329 if ((ch
== '-') && (chPrev
== '-')) {
1330 styler
.ColourTo(i
, StateToPrint
);
1331 state
= SCE_H_SGML_DEFAULT
;
1335 if ((chPrev2
== ']') && (chPrev
== ']') && (ch
== '>')) {
1336 styler
.ColourTo(i
, StateToPrint
);
1337 state
= SCE_H_DEFAULT
;
1342 if ((scriptLanguage
!= eScriptComment
) && (chPrev2
== '-') && (chPrev
== '-') && (ch
== '>')) {
1343 styler
.ColourTo(i
, StateToPrint
);
1344 state
= SCE_H_DEFAULT
;
1348 case SCE_H_SGML_1ST_PARAM_COMMENT
:
1349 if ((ch
== '-') && (chPrev
== '-')) {
1350 styler
.ColourTo(i
, SCE_H_SGML_COMMENT
);
1351 state
= SCE_H_SGML_1ST_PARAM
;
1354 case SCE_H_SGML_SPECIAL
:
1355 if (!(IsASCII(ch
) && isupper(ch
))) {
1356 styler
.ColourTo(i
- 1, StateToPrint
);
1358 state
= SCE_H_SGML_ERROR
;
1360 state
= SCE_H_SGML_DEFAULT
;
1364 case SCE_H_SGML_ENTITY
:
1366 styler
.ColourTo(i
, StateToPrint
);
1367 state
= SCE_H_SGML_DEFAULT
;
1368 } else if (!(IsASCII(ch
) && isalnum(ch
)) && ch
!= '-' && ch
!= '.') {
1369 styler
.ColourTo(i
, SCE_H_SGML_ERROR
);
1370 state
= SCE_H_SGML_DEFAULT
;
1375 styler
.ColourTo(i
, StateToPrint
);
1376 state
= SCE_H_DEFAULT
;
1378 if (ch
!= '#' && !(IsASCII(ch
) && isalnum(ch
)) // Should check that '#' follows '&', but it is unlikely anyway...
1379 && ch
!= '.' && ch
!= '-' && ch
!= '_' && ch
!= ':') { // valid in XML
1380 if (!IsASCII(ch
)) // Possibly start of a multibyte character so don't allow this byte to be in entity style
1381 styler
.ColourTo(i
-1, SCE_H_TAGUNKNOWN
);
1383 styler
.ColourTo(i
, SCE_H_TAGUNKNOWN
);
1384 state
= SCE_H_DEFAULT
;
1387 case SCE_H_TAGUNKNOWN
:
1388 if (!setTagContinue
.Contains(ch
) && !((ch
== '/') && (chPrev
== '<'))) {
1389 int eClass
= classifyTagHTML(styler
.GetStartSegment(),
1390 i
- 1, keywords
, styler
, tagDontFold
, caseSensitive
, isXml
, allowScripts
);
1391 if (eClass
== SCE_H_SCRIPT
|| eClass
== SCE_H_COMMENT
) {
1393 inScriptType
= eNonHtmlScript
;
1394 scriptLanguage
= eClass
== SCE_H_SCRIPT
? clientScript
: eScriptComment
;
1396 scriptLanguage
= eScriptNone
;
1401 styler
.ColourTo(i
, eClass
);
1402 if (inScriptType
== eNonHtmlScript
) {
1403 state
= StateForScript(scriptLanguage
);
1405 state
= SCE_H_DEFAULT
;
1416 } else if (ch
== '/' && chNext
== '>') {
1417 if (eClass
== SCE_H_TAGUNKNOWN
) {
1418 styler
.ColourTo(i
+ 1, SCE_H_TAGUNKNOWN
);
1420 styler
.ColourTo(i
- 1, StateToPrint
);
1421 styler
.ColourTo(i
+ 1, SCE_H_TAGEND
);
1425 state
= SCE_H_DEFAULT
;
1428 if (eClass
!= SCE_H_TAGUNKNOWN
) {
1429 if (eClass
== SCE_H_SGML_DEFAULT
) {
1430 state
= SCE_H_SGML_DEFAULT
;
1432 state
= SCE_H_OTHER
;
1438 case SCE_H_ATTRIBUTE
:
1439 if (!setAttributeContinue
.Contains(ch
)) {
1440 if (inScriptType
== eNonHtmlScript
) {
1441 int scriptLanguagePrev
= scriptLanguage
;
1442 clientScript
= segIsScriptingIndicator(styler
, styler
.GetStartSegment(), i
- 1, scriptLanguage
);
1443 scriptLanguage
= clientScript
;
1444 if ((scriptLanguagePrev
!= scriptLanguage
) && (scriptLanguage
== eScriptNone
))
1445 inScriptType
= eHtml
;
1447 classifyAttribHTML(styler
.GetStartSegment(), i
- 1, keywords
, styler
);
1449 styler
.ColourTo(i
, SCE_H_TAG
);
1450 if (inScriptType
== eNonHtmlScript
) {
1451 state
= StateForScript(scriptLanguage
);
1453 state
= SCE_H_DEFAULT
;
1464 } else if (ch
== '=') {
1465 styler
.ColourTo(i
, SCE_H_OTHER
);
1466 state
= SCE_H_VALUE
;
1468 state
= SCE_H_OTHER
;
1474 styler
.ColourTo(i
- 1, StateToPrint
);
1475 styler
.ColourTo(i
, SCE_H_TAG
);
1476 if (inScriptType
== eNonHtmlScript
) {
1477 state
= StateForScript(scriptLanguage
);
1479 state
= SCE_H_DEFAULT
;
1490 } else if (ch
== '\"') {
1491 styler
.ColourTo(i
- 1, StateToPrint
);
1492 state
= SCE_H_DOUBLESTRING
;
1493 } else if (ch
== '\'') {
1494 styler
.ColourTo(i
- 1, StateToPrint
);
1495 state
= SCE_H_SINGLESTRING
;
1496 } else if (ch
== '=') {
1497 styler
.ColourTo(i
, StateToPrint
);
1498 state
= SCE_H_VALUE
;
1499 } else if (ch
== '/' && chNext
== '>') {
1500 styler
.ColourTo(i
- 1, StateToPrint
);
1501 styler
.ColourTo(i
+ 1, SCE_H_TAGEND
);
1504 state
= SCE_H_DEFAULT
;
1506 } else if (ch
== '?' && chNext
== '>') {
1507 styler
.ColourTo(i
- 1, StateToPrint
);
1508 styler
.ColourTo(i
+ 1, SCE_H_XMLEND
);
1511 state
= SCE_H_DEFAULT
;
1512 } else if (setHTMLWord
.Contains(ch
)) {
1513 styler
.ColourTo(i
- 1, StateToPrint
);
1514 state
= SCE_H_ATTRIBUTE
;
1517 case SCE_H_DOUBLESTRING
:
1519 if (inScriptType
== eNonHtmlScript
) {
1520 scriptLanguage
= segIsScriptingIndicator(styler
, styler
.GetStartSegment(), i
, scriptLanguage
);
1522 styler
.ColourTo(i
, SCE_H_DOUBLESTRING
);
1523 state
= SCE_H_OTHER
;
1526 case SCE_H_SINGLESTRING
:
1528 if (inScriptType
== eNonHtmlScript
) {
1529 scriptLanguage
= segIsScriptingIndicator(styler
, styler
.GetStartSegment(), i
, scriptLanguage
);
1531 styler
.ColourTo(i
, SCE_H_SINGLESTRING
);
1532 state
= SCE_H_OTHER
;
1536 if (!setHTMLWord
.Contains(ch
)) {
1537 if (ch
== '\"' && chPrev
== '=') {
1538 // Should really test for being first character
1539 state
= SCE_H_DOUBLESTRING
;
1540 } else if (ch
== '\'' && chPrev
== '=') {
1541 state
= SCE_H_SINGLESTRING
;
1543 if (IsNumber(styler
.GetStartSegment(), styler
)) {
1544 styler
.ColourTo(i
- 1, SCE_H_NUMBER
);
1546 styler
.ColourTo(i
- 1, StateToPrint
);
1549 styler
.ColourTo(i
, SCE_H_TAG
);
1550 if (inScriptType
== eNonHtmlScript
) {
1551 state
= StateForScript(scriptLanguage
);
1553 state
= SCE_H_DEFAULT
;
1565 state
= SCE_H_OTHER
;
1570 case SCE_HJ_DEFAULT
:
1572 case SCE_HJ_SYMBOLS
:
1573 if (IsAWordStart(ch
)) {
1574 styler
.ColourTo(i
- 1, StateToPrint
);
1575 state
= SCE_HJ_WORD
;
1576 } else if (ch
== '/' && chNext
== '*') {
1577 styler
.ColourTo(i
- 1, StateToPrint
);
1579 state
= SCE_HJ_COMMENTDOC
;
1581 state
= SCE_HJ_COMMENT
;
1582 if (chNext2
== '/') {
1583 // Eat the * so it isn't used for the end of the comment
1586 } else if (ch
== '/' && chNext
== '/') {
1587 styler
.ColourTo(i
- 1, StateToPrint
);
1588 state
= SCE_HJ_COMMENTLINE
;
1589 } else if (ch
== '/' && setOKBeforeJSRE
.Contains(chPrevNonWhite
)) {
1590 styler
.ColourTo(i
- 1, StateToPrint
);
1591 state
= SCE_HJ_REGEX
;
1592 } else if (ch
== '\"') {
1593 styler
.ColourTo(i
- 1, StateToPrint
);
1594 state
= SCE_HJ_DOUBLESTRING
;
1595 } else if (ch
== '\'') {
1596 styler
.ColourTo(i
- 1, StateToPrint
);
1597 state
= SCE_HJ_SINGLESTRING
;
1598 } else if ((ch
== '<') && (chNext
== '!') && (chNext2
== '-') &&
1599 styler
.SafeGetCharAt(i
+ 3) == '-') {
1600 styler
.ColourTo(i
- 1, StateToPrint
);
1601 state
= SCE_HJ_COMMENTLINE
;
1602 } else if ((ch
== '-') && (chNext
== '-') && (chNext2
== '>')) {
1603 styler
.ColourTo(i
- 1, StateToPrint
);
1604 state
= SCE_HJ_COMMENTLINE
;
1606 } else if (IsOperator(ch
)) {
1607 styler
.ColourTo(i
- 1, StateToPrint
);
1608 styler
.ColourTo(i
, statePrintForState(SCE_HJ_SYMBOLS
, inScriptType
));
1609 state
= SCE_HJ_DEFAULT
;
1610 } else if ((ch
== ' ') || (ch
== '\t')) {
1611 if (state
== SCE_HJ_START
) {
1612 styler
.ColourTo(i
- 1, StateToPrint
);
1613 state
= SCE_HJ_DEFAULT
;
1618 if (!IsAWordChar(ch
)) {
1619 classifyWordHTJS(styler
.GetStartSegment(), i
- 1, keywords2
, styler
, inScriptType
);
1620 //styler.ColourTo(i - 1, eHTJSKeyword);
1621 state
= SCE_HJ_DEFAULT
;
1622 if (ch
== '/' && chNext
== '*') {
1624 state
= SCE_HJ_COMMENTDOC
;
1626 state
= SCE_HJ_COMMENT
;
1627 } else if (ch
== '/' && chNext
== '/') {
1628 state
= SCE_HJ_COMMENTLINE
;
1629 } else if (ch
== '\"') {
1630 state
= SCE_HJ_DOUBLESTRING
;
1631 } else if (ch
== '\'') {
1632 state
= SCE_HJ_SINGLESTRING
;
1633 } else if ((ch
== '-') && (chNext
== '-') && (chNext2
== '>')) {
1634 styler
.ColourTo(i
- 1, StateToPrint
);
1635 state
= SCE_HJ_COMMENTLINE
;
1637 } else if (IsOperator(ch
)) {
1638 styler
.ColourTo(i
, statePrintForState(SCE_HJ_SYMBOLS
, inScriptType
));
1639 state
= SCE_HJ_DEFAULT
;
1643 case SCE_HJ_COMMENT
:
1644 case SCE_HJ_COMMENTDOC
:
1645 if (ch
== '/' && chPrev
== '*') {
1646 styler
.ColourTo(i
, StateToPrint
);
1647 state
= SCE_HJ_DEFAULT
;
1651 case SCE_HJ_COMMENTLINE
:
1652 if (ch
== '\r' || ch
== '\n') {
1653 styler
.ColourTo(i
- 1, statePrintForState(SCE_HJ_COMMENTLINE
, inScriptType
));
1654 state
= SCE_HJ_DEFAULT
;
1658 case SCE_HJ_DOUBLESTRING
:
1660 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1663 } else if (ch
== '\"') {
1664 styler
.ColourTo(i
, statePrintForState(SCE_HJ_DOUBLESTRING
, inScriptType
));
1665 state
= SCE_HJ_DEFAULT
;
1666 } else if ((inScriptType
== eNonHtmlScript
) && (ch
== '-') && (chNext
== '-') && (chNext2
== '>')) {
1667 styler
.ColourTo(i
- 1, StateToPrint
);
1668 state
= SCE_HJ_COMMENTLINE
;
1670 } else if (isLineEnd(ch
)) {
1671 styler
.ColourTo(i
- 1, StateToPrint
);
1672 state
= SCE_HJ_STRINGEOL
;
1675 case SCE_HJ_SINGLESTRING
:
1677 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1680 } else if (ch
== '\'') {
1681 styler
.ColourTo(i
, statePrintForState(SCE_HJ_SINGLESTRING
, inScriptType
));
1682 state
= SCE_HJ_DEFAULT
;
1683 } else if ((inScriptType
== eNonHtmlScript
) && (ch
== '-') && (chNext
== '-') && (chNext2
== '>')) {
1684 styler
.ColourTo(i
- 1, StateToPrint
);
1685 state
= SCE_HJ_COMMENTLINE
;
1687 } else if (isLineEnd(ch
)) {
1688 styler
.ColourTo(i
- 1, StateToPrint
);
1689 if (chPrev
!= '\\' && (chPrev2
!= '\\' || chPrev
!= '\r' || ch
!= '\n')) {
1690 state
= SCE_HJ_STRINGEOL
;
1694 case SCE_HJ_STRINGEOL
:
1695 if (!isLineEnd(ch
)) {
1696 styler
.ColourTo(i
- 1, StateToPrint
);
1697 state
= SCE_HJ_DEFAULT
;
1698 } else if (!isLineEnd(chNext
)) {
1699 styler
.ColourTo(i
, StateToPrint
);
1700 state
= SCE_HJ_DEFAULT
;
1704 if (ch
== '\r' || ch
== '\n' || ch
== '/') {
1706 while (IsASCII(chNext
) && islower(chNext
)) { // gobble regex flags
1709 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
1712 styler
.ColourTo(i
, StateToPrint
);
1713 state
= SCE_HJ_DEFAULT
;
1714 } else if (ch
== '\\') {
1715 // Gobble up the quoted character
1716 if (chNext
== '\\' || chNext
== '/') {
1719 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
1723 case SCE_HB_DEFAULT
:
1725 if (IsAWordStart(ch
)) {
1726 styler
.ColourTo(i
- 1, StateToPrint
);
1727 state
= SCE_HB_WORD
;
1728 } else if (ch
== '\'') {
1729 styler
.ColourTo(i
- 1, StateToPrint
);
1730 state
= SCE_HB_COMMENTLINE
;
1731 } else if (ch
== '\"') {
1732 styler
.ColourTo(i
- 1, StateToPrint
);
1733 state
= SCE_HB_STRING
;
1734 } else if ((ch
== '<') && (chNext
== '!') && (chNext2
== '-') &&
1735 styler
.SafeGetCharAt(i
+ 3) == '-') {
1736 styler
.ColourTo(i
- 1, StateToPrint
);
1737 state
= SCE_HB_COMMENTLINE
;
1738 } else if (IsOperator(ch
)) {
1739 styler
.ColourTo(i
- 1, StateToPrint
);
1740 styler
.ColourTo(i
, statePrintForState(SCE_HB_DEFAULT
, inScriptType
));
1741 state
= SCE_HB_DEFAULT
;
1742 } else if ((ch
== ' ') || (ch
== '\t')) {
1743 if (state
== SCE_HB_START
) {
1744 styler
.ColourTo(i
- 1, StateToPrint
);
1745 state
= SCE_HB_DEFAULT
;
1750 if (!IsAWordChar(ch
)) {
1751 state
= classifyWordHTVB(styler
.GetStartSegment(), i
- 1, keywords3
, styler
, inScriptType
);
1752 if (state
== SCE_HB_DEFAULT
) {
1754 state
= SCE_HB_STRING
;
1755 } else if (ch
== '\'') {
1756 state
= SCE_HB_COMMENTLINE
;
1757 } else if (IsOperator(ch
)) {
1758 styler
.ColourTo(i
, statePrintForState(SCE_HB_DEFAULT
, inScriptType
));
1759 state
= SCE_HB_DEFAULT
;
1766 styler
.ColourTo(i
, StateToPrint
);
1767 state
= SCE_HB_DEFAULT
;
1768 } else if (ch
== '\r' || ch
== '\n') {
1769 styler
.ColourTo(i
- 1, StateToPrint
);
1770 state
= SCE_HB_STRINGEOL
;
1773 case SCE_HB_COMMENTLINE
:
1774 if (ch
== '\r' || ch
== '\n') {
1775 styler
.ColourTo(i
- 1, StateToPrint
);
1776 state
= SCE_HB_DEFAULT
;
1779 case SCE_HB_STRINGEOL
:
1780 if (!isLineEnd(ch
)) {
1781 styler
.ColourTo(i
- 1, StateToPrint
);
1782 state
= SCE_HB_DEFAULT
;
1783 } else if (!isLineEnd(chNext
)) {
1784 styler
.ColourTo(i
, StateToPrint
);
1785 state
= SCE_HB_DEFAULT
;
1788 case SCE_HP_DEFAULT
:
1790 if (IsAWordStart(ch
)) {
1791 styler
.ColourTo(i
- 1, StateToPrint
);
1792 state
= SCE_HP_WORD
;
1793 } else if ((ch
== '<') && (chNext
== '!') && (chNext2
== '-') &&
1794 styler
.SafeGetCharAt(i
+ 3) == '-') {
1795 styler
.ColourTo(i
- 1, StateToPrint
);
1796 state
= SCE_HP_COMMENTLINE
;
1797 } else if (ch
== '#') {
1798 styler
.ColourTo(i
- 1, StateToPrint
);
1799 state
= SCE_HP_COMMENTLINE
;
1800 } else if (ch
== '\"') {
1801 styler
.ColourTo(i
- 1, StateToPrint
);
1802 if (chNext
== '\"' && chNext2
== '\"') {
1804 state
= SCE_HP_TRIPLEDOUBLE
;
1807 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
1809 // state = statePrintForState(SCE_HP_STRING,inScriptType);
1810 state
= SCE_HP_STRING
;
1812 } else if (ch
== '\'') {
1813 styler
.ColourTo(i
- 1, StateToPrint
);
1814 if (chNext
== '\'' && chNext2
== '\'') {
1816 state
= SCE_HP_TRIPLE
;
1819 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
1821 state
= SCE_HP_CHARACTER
;
1823 } else if (IsOperator(ch
)) {
1824 styler
.ColourTo(i
- 1, StateToPrint
);
1825 styler
.ColourTo(i
, statePrintForState(SCE_HP_OPERATOR
, inScriptType
));
1826 } else if ((ch
== ' ') || (ch
== '\t')) {
1827 if (state
== SCE_HP_START
) {
1828 styler
.ColourTo(i
- 1, StateToPrint
);
1829 state
= SCE_HP_DEFAULT
;
1834 if (!IsAWordChar(ch
)) {
1835 classifyWordHTPy(styler
.GetStartSegment(), i
- 1, keywords4
, styler
, prevWord
, inScriptType
, isMako
);
1836 state
= SCE_HP_DEFAULT
;
1838 state
= SCE_HP_COMMENTLINE
;
1839 } else if (ch
== '\"') {
1840 if (chNext
== '\"' && chNext2
== '\"') {
1842 state
= SCE_HP_TRIPLEDOUBLE
;
1845 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
1847 state
= SCE_HP_STRING
;
1849 } else if (ch
== '\'') {
1850 if (chNext
== '\'' && chNext2
== '\'') {
1852 state
= SCE_HP_TRIPLE
;
1855 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
1857 state
= SCE_HP_CHARACTER
;
1859 } else if (IsOperator(ch
)) {
1860 styler
.ColourTo(i
, statePrintForState(SCE_HP_OPERATOR
, inScriptType
));
1864 case SCE_HP_COMMENTLINE
:
1865 if (ch
== '\r' || ch
== '\n') {
1866 styler
.ColourTo(i
- 1, StateToPrint
);
1867 state
= SCE_HP_DEFAULT
;
1872 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1875 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
1877 } else if (ch
== '\"') {
1878 styler
.ColourTo(i
, StateToPrint
);
1879 state
= SCE_HP_DEFAULT
;
1882 case SCE_HP_CHARACTER
:
1884 if (chNext
== '\"' || chNext
== '\'' || chNext
== '\\') {
1887 chNext
= static_cast<unsigned char>(styler
.SafeGetCharAt(i
+ 1));
1889 } else if (ch
== '\'') {
1890 styler
.ColourTo(i
, StateToPrint
);
1891 state
= SCE_HP_DEFAULT
;
1895 if (ch
== '\'' && chPrev
== '\'' && chPrev2
== '\'') {
1896 styler
.ColourTo(i
, StateToPrint
);
1897 state
= SCE_HP_DEFAULT
;
1900 case SCE_HP_TRIPLEDOUBLE
:
1901 if (ch
== '\"' && chPrev
== '\"' && chPrev2
== '\"') {
1902 styler
.ColourTo(i
, StateToPrint
);
1903 state
= SCE_HP_DEFAULT
;
1906 ///////////// start - PHP state handling
1908 if (!IsAWordChar(ch
)) {
1909 classifyWordHTPHP(styler
.GetStartSegment(), i
- 1, keywords5
, styler
);
1910 if (ch
== '/' && chNext
== '*') {
1912 state
= SCE_HPHP_COMMENT
;
1913 } else if (ch
== '/' && chNext
== '/') {
1915 state
= SCE_HPHP_COMMENTLINE
;
1916 } else if (ch
== '#') {
1917 state
= SCE_HPHP_COMMENTLINE
;
1918 } else if (ch
== '\"') {
1919 state
= SCE_HPHP_HSTRING
;
1920 StringCopy(phpStringDelimiter
, "\"");
1921 } else if (styler
.Match(i
, "<<<")) {
1922 bool isSimpleString
= false;
1923 i
= FindPhpStringDelimiter(phpStringDelimiter
, sizeof(phpStringDelimiter
), i
+ 3, lengthDoc
, styler
, isSimpleString
);
1924 if (strlen(phpStringDelimiter
)) {
1925 state
= (isSimpleString
? SCE_HPHP_SIMPLESTRING
: SCE_HPHP_HSTRING
);
1926 if (foldHeredoc
) levelCurrent
++;
1928 } else if (ch
== '\'') {
1929 state
= SCE_HPHP_SIMPLESTRING
;
1930 StringCopy(phpStringDelimiter
, "\'");
1931 } else if (ch
== '$' && IsPhpWordStart(chNext
)) {
1932 state
= SCE_HPHP_VARIABLE
;
1933 } else if (IsOperator(ch
)) {
1934 state
= SCE_HPHP_OPERATOR
;
1936 state
= SCE_HPHP_DEFAULT
;
1940 case SCE_HPHP_NUMBER
:
1941 // recognize bases 8,10 or 16 integers OR floating-point numbers
1943 && strchr(".xXabcdefABCDEF", ch
) == NULL
1944 && ((ch
!= '-' && ch
!= '+') || (chPrev
!= 'e' && chPrev
!= 'E'))) {
1945 styler
.ColourTo(i
- 1, SCE_HPHP_NUMBER
);
1947 state
= SCE_HPHP_OPERATOR
;
1949 state
= SCE_HPHP_DEFAULT
;
1952 case SCE_HPHP_VARIABLE
:
1953 if (!IsPhpWordChar(chNext
)) {
1954 styler
.ColourTo(i
, SCE_HPHP_VARIABLE
);
1955 state
= SCE_HPHP_DEFAULT
;
1958 case SCE_HPHP_COMMENT
:
1959 if (ch
== '/' && chPrev
== '*') {
1960 styler
.ColourTo(i
, StateToPrint
);
1961 state
= SCE_HPHP_DEFAULT
;
1964 case SCE_HPHP_COMMENTLINE
:
1965 if (ch
== '\r' || ch
== '\n') {
1966 styler
.ColourTo(i
- 1, StateToPrint
);
1967 state
= SCE_HPHP_DEFAULT
;
1970 case SCE_HPHP_HSTRING
:
1971 if (ch
== '\\' && (phpStringDelimiter
[0] == '\"' || chNext
== '$' || chNext
== '{')) {
1972 // skip the next char
1974 } else if (((ch
== '{' && chNext
== '$') || (ch
== '$' && chNext
== '{'))
1975 && IsPhpWordStart(chNext2
)) {
1976 styler
.ColourTo(i
- 1, StateToPrint
);
1977 state
= SCE_HPHP_COMPLEX_VARIABLE
;
1978 } else if (ch
== '$' && IsPhpWordStart(chNext
)) {
1979 styler
.ColourTo(i
- 1, StateToPrint
);
1980 state
= SCE_HPHP_HSTRING_VARIABLE
;
1981 } else if (styler
.Match(i
, phpStringDelimiter
)) {
1982 if (phpStringDelimiter
[0] == '\"') {
1983 styler
.ColourTo(i
, StateToPrint
);
1984 state
= SCE_HPHP_DEFAULT
;
1985 } else if (isLineEnd(chPrev
)) {
1986 const int psdLength
= static_cast<int>(strlen(phpStringDelimiter
));
1987 const char chAfterPsd
= styler
.SafeGetCharAt(i
+ psdLength
);
1988 const char chAfterPsd2
= styler
.SafeGetCharAt(i
+ psdLength
+ 1);
1989 if (isLineEnd(chAfterPsd
) ||
1990 (chAfterPsd
== ';' && isLineEnd(chAfterPsd2
))) {
1991 i
+= (((i
+ psdLength
) < lengthDoc
) ? psdLength
: lengthDoc
) - 1;
1992 styler
.ColourTo(i
, StateToPrint
);
1993 state
= SCE_HPHP_DEFAULT
;
1994 if (foldHeredoc
) levelCurrent
--;
1999 case SCE_HPHP_SIMPLESTRING
:
2000 if (phpStringDelimiter
[0] == '\'') {
2002 // skip the next char
2004 } else if (ch
== '\'') {
2005 styler
.ColourTo(i
, StateToPrint
);
2006 state
= SCE_HPHP_DEFAULT
;
2008 } else if (isLineEnd(chPrev
) && styler
.Match(i
, phpStringDelimiter
)) {
2009 const int psdLength
= static_cast<int>(strlen(phpStringDelimiter
));
2010 const char chAfterPsd
= styler
.SafeGetCharAt(i
+ psdLength
);
2011 const char chAfterPsd2
= styler
.SafeGetCharAt(i
+ psdLength
+ 1);
2012 if (isLineEnd(chAfterPsd
) ||
2013 (chAfterPsd
== ';' && isLineEnd(chAfterPsd2
))) {
2014 i
+= (((i
+ psdLength
) < lengthDoc
) ? psdLength
: lengthDoc
) - 1;
2015 styler
.ColourTo(i
, StateToPrint
);
2016 state
= SCE_HPHP_DEFAULT
;
2017 if (foldHeredoc
) levelCurrent
--;
2021 case SCE_HPHP_HSTRING_VARIABLE
:
2022 if (!IsPhpWordChar(chNext
)) {
2023 styler
.ColourTo(i
, StateToPrint
);
2024 state
= SCE_HPHP_HSTRING
;
2027 case SCE_HPHP_COMPLEX_VARIABLE
:
2029 styler
.ColourTo(i
, StateToPrint
);
2030 state
= SCE_HPHP_HSTRING
;
2033 case SCE_HPHP_OPERATOR
:
2034 case SCE_HPHP_DEFAULT
:
2035 styler
.ColourTo(i
- 1, StateToPrint
);
2036 if (IsADigit(ch
) || (ch
== '.' && IsADigit(chNext
))) {
2037 state
= SCE_HPHP_NUMBER
;
2038 } else if (IsAWordStart(ch
)) {
2039 state
= SCE_HPHP_WORD
;
2040 } else if (ch
== '/' && chNext
== '*') {
2042 state
= SCE_HPHP_COMMENT
;
2043 } else if (ch
== '/' && chNext
== '/') {
2045 state
= SCE_HPHP_COMMENTLINE
;
2046 } else if (ch
== '#') {
2047 state
= SCE_HPHP_COMMENTLINE
;
2048 } else if (ch
== '\"') {
2049 state
= SCE_HPHP_HSTRING
;
2050 StringCopy(phpStringDelimiter
, "\"");
2051 } else if (styler
.Match(i
, "<<<")) {
2052 bool isSimpleString
= false;
2053 i
= FindPhpStringDelimiter(phpStringDelimiter
, sizeof(phpStringDelimiter
), i
+ 3, lengthDoc
, styler
, isSimpleString
);
2054 if (strlen(phpStringDelimiter
)) {
2055 state
= (isSimpleString
? SCE_HPHP_SIMPLESTRING
: SCE_HPHP_HSTRING
);
2056 if (foldHeredoc
) levelCurrent
++;
2058 } else if (ch
== '\'') {
2059 state
= SCE_HPHP_SIMPLESTRING
;
2060 StringCopy(phpStringDelimiter
, "\'");
2061 } else if (ch
== '$' && IsPhpWordStart(chNext
)) {
2062 state
= SCE_HPHP_VARIABLE
;
2063 } else if (IsOperator(ch
)) {
2064 state
= SCE_HPHP_OPERATOR
;
2065 } else if ((state
== SCE_HPHP_OPERATOR
) && (IsASpace(ch
))) {
2066 state
= SCE_HPHP_DEFAULT
;
2069 ///////////// end - PHP state handling
2072 // Some of the above terminated their lexeme but since the same character starts
2073 // the same class again, only reenter if non empty segment.
2075 bool nonEmptySegment
= i
>= static_cast<int>(styler
.GetStartSegment());
2076 if (state
== SCE_HB_DEFAULT
) { // One of the above succeeded
2077 if ((ch
== '\"') && (nonEmptySegment
)) {
2078 state
= SCE_HB_STRING
;
2079 } else if (ch
== '\'') {
2080 state
= SCE_HB_COMMENTLINE
;
2081 } else if (IsAWordStart(ch
)) {
2082 state
= SCE_HB_WORD
;
2083 } else if (IsOperator(ch
)) {
2084 styler
.ColourTo(i
, SCE_HB_DEFAULT
);
2086 } else if (state
== SCE_HBA_DEFAULT
) { // One of the above succeeded
2087 if ((ch
== '\"') && (nonEmptySegment
)) {
2088 state
= SCE_HBA_STRING
;
2089 } else if (ch
== '\'') {
2090 state
= SCE_HBA_COMMENTLINE
;
2091 } else if (IsAWordStart(ch
)) {
2092 state
= SCE_HBA_WORD
;
2093 } else if (IsOperator(ch
)) {
2094 styler
.ColourTo(i
, SCE_HBA_DEFAULT
);
2096 } else if (state
== SCE_HJ_DEFAULT
) { // One of the above succeeded
2097 if (ch
== '/' && chNext
== '*') {
2098 if (styler
.SafeGetCharAt(i
+ 2) == '*')
2099 state
= SCE_HJ_COMMENTDOC
;
2101 state
= SCE_HJ_COMMENT
;
2102 } else if (ch
== '/' && chNext
== '/') {
2103 state
= SCE_HJ_COMMENTLINE
;
2104 } else if ((ch
== '\"') && (nonEmptySegment
)) {
2105 state
= SCE_HJ_DOUBLESTRING
;
2106 } else if ((ch
== '\'') && (nonEmptySegment
)) {
2107 state
= SCE_HJ_SINGLESTRING
;
2108 } else if (IsAWordStart(ch
)) {
2109 state
= SCE_HJ_WORD
;
2110 } else if (IsOperator(ch
)) {
2111 styler
.ColourTo(i
, statePrintForState(SCE_HJ_SYMBOLS
, inScriptType
));
2118 classifyWordHTJS(styler
.GetStartSegment(), lengthDoc
- 1, keywords2
, styler
, inScriptType
);
2121 classifyWordHTVB(styler
.GetStartSegment(), lengthDoc
- 1, keywords3
, styler
, inScriptType
);
2124 classifyWordHTPy(styler
.GetStartSegment(), lengthDoc
- 1, keywords4
, styler
, prevWord
, inScriptType
, isMako
);
2127 classifyWordHTPHP(styler
.GetStartSegment(), lengthDoc
- 1, keywords5
, styler
);
2130 StateToPrint
= statePrintForState(state
, inScriptType
);
2131 if (static_cast<int>(styler
.GetStartSegment()) < lengthDoc
)
2132 styler
.ColourTo(lengthDoc
- 1, StateToPrint
);
2136 // Fill in the real level of the next line, keeping the current flags as they will be filled in later
2138 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
2139 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
2143 static void ColouriseXMLDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
2145 // Passing in true because we're lexing XML
2146 ColouriseHyperTextDoc(startPos
, length
, initStyle
, keywordlists
, styler
, true);
2149 static void ColouriseHTMLDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
2151 // Passing in false because we're notlexing XML
2152 ColouriseHyperTextDoc(startPos
, length
, initStyle
, keywordlists
, styler
, false);
2155 static void ColourisePHPScriptDoc(unsigned int startPos
, int length
, int initStyle
, WordList
*keywordlists
[],
2158 initStyle
= SCE_HPHP_DEFAULT
;
2159 ColouriseHTMLDoc(startPos
, length
, initStyle
, keywordlists
, styler
);
2162 static const char * const htmlWordListDesc
[] = {
2163 "HTML elements and attributes",
2164 "JavaScript keywords",
2165 "VBScript keywords",
2168 "SGML and DTD keywords",
2172 static const char * const phpscriptWordListDesc
[] = {
2182 LexerModule
lmHTML(SCLEX_HTML
, ColouriseHTMLDoc
, "hypertext", 0, htmlWordListDesc
);
2183 LexerModule
lmXML(SCLEX_XML
, ColouriseXMLDoc
, "xml", 0, htmlWordListDesc
);
2184 LexerModule
lmPHPSCRIPT(SCLEX_PHPSCRIPT
, ColourisePHPScriptDoc
, "phpscript", 0, phpscriptWordListDesc
);