]>
git.saurik.com Git - wxWidgets.git/blob - contrib/src/stc/scintilla/src/LexAda.cxx
0d8fb9d5dd7148fd42b792ca6927e3dd4595684e
1 // SciTE - Scintilla based Text Editor
2 // LexAda.cxx - lexer for Ada95
3 // by Tahir Karaca <tahir@bigfoot.de>
4 // The License.txt file describes the conditions under which this software may be distributed.
17 #include "Scintilla.h"
20 inline void classifyWordAda(unsigned int start
, unsigned int end
,
21 WordList
&keywords
, Accessor
&styler
) {
23 static const unsigned KEWORD_LEN_MAX
= 30;
25 char wordLower
[KEWORD_LEN_MAX
+ 1];
27 for(i
= 0; ( i
< KEWORD_LEN_MAX
) && ( i
< end
- start
+ 1 ); i
++) {
28 wordLower
[i
] = static_cast<char>(tolower(styler
[start
+ i
]));
32 // int levelChange = 0;
33 char chAttr
= SCE_ADA_IDENTIFIER
;
34 if (keywords
.InList(wordLower
)) {
35 chAttr
= SCE_ADA_WORD
;
37 // Folding doesn't work this way since the semantics of some keywords depends
38 // on the current context.
39 // E.g. - "cond1 and THEN cond2" <-> "if ... THEN ..."
40 // - "procedure X IS ... end X;" <-> "procedure X IS new Y;"
41 // if (strcmp(wordLower, "is") == 0 || strcmp(wordLower, "then") == 0)
43 // else if (strcmp(wordLower, "end") == 0)
46 styler
.ColourTo(end
, chAttr
);
48 // return levelChange;
52 static inline bool isAdaOperator(char ch
) {
54 if (ch
== '&' || ch
== '\'' || ch
== '(' || ch
== ')' ||
55 ch
== '*' || ch
== '+' || ch
== ',' || ch
== '-' ||
56 ch
== '.' || ch
== '/' || ch
== ':' || ch
== ';' ||
57 ch
== '<' || ch
== '=' || ch
== '>')
63 inline void styleTokenBegin(char beginChar
, unsigned int pos
, int &state
,
66 if (isalpha(beginChar
)) {
67 styler
.ColourTo(pos
-1, state
);
68 state
= SCE_ADA_IDENTIFIER
;
69 } else if (isdigit(beginChar
)) {
70 styler
.ColourTo(pos
-1, state
);
71 state
= SCE_ADA_NUMBER
;
72 } else if (beginChar
== '-' && styler
.SafeGetCharAt(pos
+ 1) == '-') {
73 styler
.ColourTo(pos
-1, state
);
74 state
= SCE_ADA_COMMENT
;
75 } else if (beginChar
== '\"') {
76 styler
.ColourTo(pos
-1, state
);
77 state
= SCE_ADA_STRING
;
78 } else if (beginChar
== '\'' && styler
.SafeGetCharAt(pos
+ 2) == '\'') {
79 styler
.ColourTo(pos
-1, state
);
80 state
= SCE_ADA_CHARACTER
;
81 } else if (isAdaOperator(beginChar
)) {
82 styler
.ColourTo(pos
-1, state
);
83 styler
.ColourTo(pos
, SCE_ADA_OPERATOR
);
88 static void ColouriseAdaDoc(unsigned int startPos
, int length
, int initStyle
,
89 WordList
*keywordlists
[], Accessor
&styler
) {
91 WordList
&keywords
= *keywordlists
[0];
93 styler
.StartAt(startPos
);
95 // bool fold = styler.GetPropertyInt("fold");
96 // int lineCurrent = styler.GetLine(startPos);
97 // int levelPrev = styler.LevelAt(lineCurrent) & SC_FOLDLEVELNUMBERMASK;
98 // int levelCurrent = levelPrev;
100 int state
= initStyle
;
101 if (state
== SCE_ADA_STRINGEOL
) // Does not leak onto next line
102 state
= SCE_ADA_DEFAULT
;
103 char chNext
= styler
[startPos
];
104 const unsigned int lengthDoc
= startPos
+ length
;
105 //int visibleChars = 0;
106 styler
.StartSegment(startPos
);
107 for (unsigned int i
= startPos
; i
< lengthDoc
; i
++) {
109 chNext
= styler
.SafeGetCharAt(i
+ 1);
111 if ((ch
== '\r' && chNext
!= '\n') || (ch
== '\n')) {
112 // Trigger on CR only (Mac style) or either on LF from CR+LF (Dos/Win) or on LF alone (Unix)
113 // Avoid triggering two times on Dos/Win
114 if (state
== SCE_ADA_STRINGEOL
) {
115 styler
.ColourTo(i
, state
);
116 state
= SCE_ADA_DEFAULT
;
119 // int lev = levelPrev;
120 // if (visibleChars == 0)
121 // lev |= SC_FOLDLEVELWHITEFLAG;
122 // if ((levelCurrent > levelPrev) && (visibleChars > 0))
123 // lev |= SC_FOLDLEVELHEADERFLAG;
124 // styler.SetLevel(lineCurrent, lev);
126 // levelPrev = levelCurrent;
130 //if (!isspacechar(ch))
133 if (styler
.IsLeadByte(ch
)) {
134 chNext
= styler
.SafeGetCharAt(i
+ 2);
139 if (state
== SCE_ADA_DEFAULT
) {
140 styleTokenBegin(ch
, i
, state
, styler
);
141 } else if (state
== SCE_ADA_IDENTIFIER
) {
142 if (!iswordchar(ch
)) {
143 classifyWordAda(styler
.GetStartSegment(),
147 state
= SCE_ADA_DEFAULT
;
148 styleTokenBegin(ch
, i
, state
, styler
);
150 } else if (state
== SCE_ADA_COMMENT
) {
151 if (ch
== '\r' || ch
== '\n') {
152 styler
.ColourTo(i
-1, state
);
153 state
= SCE_ADA_DEFAULT
;
155 } else if (state
== SCE_ADA_STRING
) {
157 if( chNext
== '"' ) {
159 chNext
= styler
.SafeGetCharAt(i
+ 1);
161 styler
.ColourTo(i
, state
);
162 state
= SCE_ADA_DEFAULT
;
164 } else if (chNext
== '\r' || chNext
== '\n') {
165 styler
.ColourTo(i
-1, SCE_ADA_STRINGEOL
);
166 state
= SCE_ADA_STRINGEOL
;
168 } else if (state
== SCE_ADA_CHARACTER
) {
169 if (ch
== '\r' || ch
== '\n') {
170 styler
.ColourTo(i
-1, SCE_ADA_STRINGEOL
);
171 state
= SCE_ADA_STRINGEOL
;
172 } else if (ch
== '\'' && styler
.SafeGetCharAt(i
- 2) == '\'') {
173 styler
.ColourTo(i
, state
);
174 state
= SCE_ADA_DEFAULT
;
176 } else if (state
== SCE_ADA_NUMBER
) {
177 if ( !( isdigit(ch
) || ch
== '.' || ch
== '_' || ch
== '#'
178 || ch
== 'A' || ch
== 'B' || ch
== 'C' || ch
== 'D'
179 || ch
== 'E' || ch
== 'F'
180 || ch
== 'a' || ch
== 'b' || ch
== 'c' || ch
== 'd'
181 || ch
== 'e' || ch
== 'f' ) ) {
182 styler
.ColourTo(i
-1, SCE_ADA_NUMBER
);
183 state
= SCE_ADA_DEFAULT
;
184 styleTokenBegin(ch
, i
, state
, styler
);
189 styler
.ColourTo(lengthDoc
- 1, state
);
191 // // Fill in the real level of the next line, keeping the current flags as they will be filled in later
193 // int flagsNext = styler.LevelAt(lineCurrent) & ~SC_FOLDLEVELNUMBERMASK;
194 // styler.SetLevel(lineCurrent, levelPrev | flagsNext);
198 LexerModule
lmAda(SCLEX_ADA
, ColouriseAdaDoc
, "ada");