]>
git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/src/LexPLM.cxx
1 // Copyright (c) 1990-2007, Scientific Toolworks, Inc.
2 // Author: Jason Haslam
3 // The License.txt file describes the conditions under which this software may be distributed.
16 #include "Scintilla.h"
18 #include "StyleContext.h"
21 using namespace Scintilla
;
24 static void GetRange(unsigned int start
,
30 while ((i
< end
- start
+ 1) && (i
< len
-1)) {
31 s
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
37 static void ColourisePlmDoc(unsigned int startPos
,
40 WordList
*keywordlists
[],
43 unsigned int endPos
= startPos
+ length
;
44 int state
= initStyle
;
46 styler
.StartAt(startPos
);
47 styler
.StartSegment(startPos
);
49 for (unsigned int i
= startPos
; i
< endPos
; i
++) {
50 char ch
= styler
.SafeGetCharAt(i
);
51 char chNext
= styler
.SafeGetCharAt(i
+ 1);
53 if (state
== SCE_PLM_DEFAULT
) {
54 if (ch
== '/' && chNext
== '*') {
55 styler
.ColourTo(i
- 1, state
);
56 state
= SCE_PLM_COMMENT
;
57 } else if (ch
== '\'') {
58 styler
.ColourTo(i
- 1, state
);
59 state
= SCE_PLM_STRING
;
60 } else if (isdigit(ch
)) {
61 styler
.ColourTo(i
- 1, state
);
62 state
= SCE_PLM_NUMBER
;
63 } else if (isalpha(ch
)) {
64 styler
.ColourTo(i
- 1, state
);
65 state
= SCE_PLM_IDENTIFIER
;
66 } else if (ch
== '+' || ch
== '-' || ch
== '*' || ch
== '/' ||
67 ch
== '=' || ch
== '<' || ch
== '>' || ch
== ':') {
68 styler
.ColourTo(i
- 1, state
);
69 state
= SCE_PLM_OPERATOR
;
70 } else if (ch
== '$') {
71 styler
.ColourTo(i
- 1, state
);
72 state
= SCE_PLM_CONTROL
;
74 } else if (state
== SCE_PLM_COMMENT
) {
75 if (ch
== '*' && chNext
== '/') {
77 styler
.ColourTo(i
, state
);
78 state
= SCE_PLM_DEFAULT
;
80 } else if (state
== SCE_PLM_STRING
) {
85 styler
.ColourTo(i
, state
);
86 state
= SCE_PLM_DEFAULT
;
89 } else if (state
== SCE_PLM_NUMBER
) {
90 if (!isdigit(ch
) && !isalpha(ch
) && ch
!= '$') {
92 styler
.ColourTo(i
, state
);
93 state
= SCE_PLM_DEFAULT
;
95 } else if (state
== SCE_PLM_IDENTIFIER
) {
96 if (!isdigit(ch
) && !isalpha(ch
) && ch
!= '$') {
97 // Get the entire identifier.
99 int segmentStart
= styler
.GetStartSegment();
100 GetRange(segmentStart
, i
- 1, styler
, word
, sizeof(word
));
103 if (keywordlists
[0]->InList(word
))
104 styler
.ColourTo(i
, SCE_PLM_KEYWORD
);
106 styler
.ColourTo(i
, state
);
107 state
= SCE_PLM_DEFAULT
;
109 } else if (state
== SCE_PLM_OPERATOR
) {
110 if (ch
!= '=' && ch
!= '>') {
112 styler
.ColourTo(i
, state
);
113 state
= SCE_PLM_DEFAULT
;
115 } else if (state
== SCE_PLM_CONTROL
) {
116 if (ch
== '\r' || ch
== '\n') {
117 styler
.ColourTo(i
- 1, state
);
118 state
= SCE_PLM_DEFAULT
;
122 styler
.ColourTo(endPos
- 1, state
);
125 static void FoldPlmDoc(unsigned int startPos
,
131 bool foldComment
= styler
.GetPropertyInt("fold.comment") != 0;
132 bool foldCompact
= styler
.GetPropertyInt("fold.compact", 1) != 0;
133 unsigned int endPos
= startPos
+ length
;
134 int visibleChars
= 0;
135 int lineCurrent
= styler
.GetLine(startPos
);
136 int levelPrev
= styler
.LevelAt(lineCurrent
) & SC_FOLDLEVELNUMBERMASK
;
137 int levelCurrent
= levelPrev
;
138 char chNext
= styler
[startPos
];
139 int styleNext
= styler
.StyleAt(startPos
);
140 int style
= initStyle
;
141 int startKeyword
= 0;
143 for (unsigned int i
= startPos
; i
< endPos
; i
++) {
145 chNext
= styler
.SafeGetCharAt(i
+ 1);
146 int stylePrev
= style
;
148 styleNext
= styler
.StyleAt(i
+ 1);
149 bool atEOL
= (ch
== '\r' && chNext
!= '\n') || (ch
== '\n');
151 if (stylePrev
!= SCE_PLM_KEYWORD
&& style
== SCE_PLM_KEYWORD
)
154 if (style
== SCE_PLM_KEYWORD
&& styleNext
!= SCE_PLM_KEYWORD
) {
156 GetRange(startKeyword
, i
, styler
, word
, sizeof(word
));
158 if (strcmp(word
, "procedure") == 0 || strcmp(word
, "do") == 0)
160 else if (strcmp(word
, "end") == 0)
165 if (stylePrev
!= SCE_PLM_COMMENT
&& style
== SCE_PLM_COMMENT
)
167 else if (stylePrev
== SCE_PLM_COMMENT
&& style
!= SCE_PLM_COMMENT
)
173 if (visibleChars
== 0 && foldCompact
)
174 lev
|= SC_FOLDLEVELWHITEFLAG
;
175 if ((levelCurrent
> levelPrev
) && (visibleChars
> 0))
176 lev
|= SC_FOLDLEVELHEADERFLAG
;
177 if (lev
!= styler
.LevelAt(lineCurrent
)) {
178 styler
.SetLevel(lineCurrent
, lev
);
181 levelPrev
= levelCurrent
;
185 if (!isspacechar(ch
))
189 int flagsNext
= styler
.LevelAt(lineCurrent
) & ~SC_FOLDLEVELNUMBERMASK
;
190 styler
.SetLevel(lineCurrent
, levelPrev
| flagsNext
);
193 static const char *const plmWordListDesc
[] = {
198 LexerModule
lmPLM(SCLEX_PLM
, ColourisePlmDoc
, "PL/M", FoldPlmDoc
, plmWordListDesc
);