]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/lexers/LexSML.cxx
1 // Scintilla source code edit control
5 // Copyright 2009 by James Moffatt and Yuzhou Xin
6 // Modified from LexCaml.cxx by Robert Roessler <robertr@rftp.com> Copyright 2005
7 // The License.txt file describes the conditions under which this software may be distributed.
17 #include "Scintilla.h"
21 #include "LexAccessor.h"
23 #include "StyleContext.h"
24 #include "CharacterSet.h"
25 #include "LexerModule.h"
27 inline int issml(int c
) {return isalnum(c
) || c
== '_';}
28 inline int issmlf(int c
) {return isalpha(c
) || c
== '_';}
29 inline int issmld(int c
) {return isdigit(c
) || c
== '_';}
33 using namespace Scintilla
;
37 unsigned int startPos
, int length
,
39 WordList
*keywordlists
[],
42 StyleContext
sc(startPos
, length
, initStyle
, styler
);
44 if (sc
.state
< SCE_SML_STRING
)
45 sc
.state
= SCE_SML_DEFAULT
;
46 if (sc
.state
>= SCE_SML_COMMENT
)
47 nesting
= (sc
.state
& 0x0f) - SCE_SML_COMMENT
;
49 int chBase
= 0, chToken
= 0, chLit
= 0;
50 WordList
& keywords
= *keywordlists
[0];
51 WordList
& keywords2
= *keywordlists
[1];
52 WordList
& keywords3
= *keywordlists
[2];
53 const int useMagic
= styler
.GetPropertyInt("lexer.caml.magic", 0);
57 int chColor
= sc
.currentPos
- 1;
60 switch (sc
.state
& 0x0f) {
62 chToken
= sc
.currentPos
;
64 state2
= SCE_SML_IDENTIFIER
;
65 else if (sc
.Match('`') && issmlf(sc
.chNext
))
66 state2
= SCE_SML_TAGNAME
;
67 else if (sc
.Match('#')&&isdigit(sc
.chNext
))
68 state2
= SCE_SML_LINENUM
;
69 else if (sc
.Match('#','\"')){
70 state2
= SCE_SML_CHAR
,chLit
= 0;
74 else if (isdigit(sc
.ch
)) {
75 state2
= SCE_SML_NUMBER
, chBase
= 10;
76 if (sc
.Match('0') && strchr("xX", sc
.chNext
))
77 chBase
= 16, sc
.Forward();}
78 else if (sc
.Match('\"')&&sc
.chPrev
!='#')
79 state2
= SCE_SML_STRING
;
80 else if (sc
.Match('(', '*')){
81 state2
= SCE_SML_COMMENT
,
87 state2
= SCE_SML_OPERATOR
;
90 case SCE_SML_IDENTIFIER
:
91 if (!(issml(sc
.ch
) || sc
.Match('\''))) {
92 const int n
= sc
.currentPos
- chToken
;
95 for (int i
= -n
; i
< 0; i
++)
96 t
[n
+ i
] = static_cast<char>(sc
.GetRelative(i
));
98 if ((n
== 1 && sc
.chPrev
== '_') || keywords
.InList(t
))
99 sc
.ChangeState(SCE_SML_KEYWORD
);
100 else if (keywords2
.InList(t
))
101 sc
.ChangeState(SCE_SML_KEYWORD2
);
102 else if (keywords3
.InList(t
))
103 sc
.ChangeState(SCE_SML_KEYWORD3
);
105 state2
= SCE_SML_DEFAULT
, advance
= false;
109 case SCE_SML_TAGNAME
:
110 if (!(issml(sc
.ch
) || sc
.Match('\'')))
111 state2
= SCE_SML_DEFAULT
, advance
= false;
114 case SCE_SML_LINENUM
:
116 state2
= SCE_SML_DEFAULT
, advance
= false;
119 case SCE_SML_OPERATOR
: {
121 if (issml(sc
.ch
) || isspace(sc
.ch
)
122 || (o
= strchr(")]};,\'\"`#", sc
.ch
),o
)
123 || !strchr("!$%&*+-./:<=>?@^|~", sc
.ch
)) {
124 if (o
&& strchr(")]};,", sc
.ch
)) {
125 if ((sc
.Match(')') && sc
.chPrev
== '(')
126 || (sc
.Match(']') && sc
.chPrev
== '['))
127 sc
.ChangeState(SCE_SML_KEYWORD
);
131 state2
= SCE_SML_DEFAULT
;
137 if (issmld(sc
.ch
) || IsADigit(sc
.ch
, chBase
))
139 if ((sc
.Match('l') || sc
.Match('L') || sc
.Match('n'))
140 && (issmld(sc
.chPrev
) || IsADigit(sc
.chPrev
, chBase
)))
143 if (sc
.Match('.') && issmld(sc
.chPrev
))
145 if ((sc
.Match('e') || sc
.Match('E'))
146 && (issmld(sc
.chPrev
) || sc
.chPrev
== '.'))
148 if ((sc
.Match('+') || sc
.Match('-'))
149 && (sc
.chPrev
== 'e' || sc
.chPrev
== 'E'))
152 state2
= SCE_SML_DEFAULT
, advance
= false;
156 if (sc
.Match('\\')) {
158 if (sc
.chPrev
== '\\')
160 } else if ((sc
.Match('\"') && sc
.chPrev
!= '\\') || sc
.atLineEnd
) {
161 state2
= SCE_SML_DEFAULT
;
166 sc
.ChangeState(SCE_SML_IDENTIFIER
);
167 } else if (chLit
< 1 && sc
.currentPos
- chToken
>= 3)
168 sc
.ChangeState(SCE_SML_IDENTIFIER
), advance
= false;
172 if (sc
.Match('\\') && sc
.chPrev
== '\\')
174 else if (sc
.Match('\"') && sc
.chPrev
!= '\\')
175 state2
= SCE_SML_DEFAULT
, chColor
++;
178 case SCE_SML_COMMENT
:
179 case SCE_SML_COMMENT1
:
180 case SCE_SML_COMMENT2
:
181 case SCE_SML_COMMENT3
:
182 if (sc
.Match('(', '*'))
183 state2
= sc
.state
+ 1, chToken
= sc
.currentPos
,
185 sc
.Forward(), nesting
++;
186 else if (sc
.Match(')') && sc
.chPrev
== '*') {
188 state2
= (sc
.state
& 0x0f) - 1, chToken
= 0, nesting
--;
190 state2
= SCE_SML_DEFAULT
;
192 } else if (useMagic
&& sc
.currentPos
- chToken
== 4
193 && sc
.Match('c') && sc
.chPrev
== 'r' && sc
.GetRelative(-2) == '@')
199 styler
.ColourTo(chColor
, sc
.state
), sc
.ChangeState(state2
);
215 static const char * const SMLWordListDesc
[] = {
222 LexerModule
lmSML(SCLEX_SML
, ColouriseSMLDoc
, "SML", FoldSMLDoc
, SMLWordListDesc
);