]>
Commit | Line | Data |
---|---|---|
65ec6247 RD |
1 | // Scintilla source code edit control |
2 | /** @file KeyWords.h | |
3 | ** Colourise for particular languages. | |
4 | **/ | |
5 | // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org> | |
9ce192d4 RD |
6 | // The License.txt file describes the conditions under which this software may be distributed. |
7 | ||
7e0c58e9 RD |
8 | #ifdef SCI_NAMESPACE |
9 | namespace Scintilla { | |
10 | #endif | |
11 | ||
f6bcfd97 BP |
12 | typedef void (*LexerFunction)(unsigned int startPos, int lengthDoc, int initStyle, |
13 | WordList *keywordlists[], Accessor &styler); | |
88a8b04e | 14 | |
65ec6247 RD |
15 | /** |
16 | * A LexerModule is responsible for lexing and folding a particular language. | |
17 | * The class maintains a list of LexerModules which can be searched to find a | |
18 | * module appropriate to a particular language. | |
19 | */ | |
f6bcfd97 | 20 | class LexerModule { |
65ec6247 | 21 | protected: |
1a2fb4cd | 22 | const LexerModule *next; |
f6bcfd97 | 23 | int language; |
65ec6247 RD |
24 | LexerFunction fnLexer; |
25 | LexerFunction fnFolder; | |
a834585d | 26 | const char * const * wordListDescriptions; |
1e9bafca | 27 | int styleBits; |
a834585d | 28 | |
1a2fb4cd | 29 | static const LexerModule *base; |
65ec6247 RD |
30 | static int nextLanguage; |
31 | ||
f6bcfd97 | 32 | public: |
1a2fb4cd | 33 | const char *languageName; |
1e9bafca RD |
34 | LexerModule(int language_, |
35 | LexerFunction fnLexer_, | |
36 | const char *languageName_=0, | |
37 | LexerFunction fnFolder_=0, | |
38 | const char * const wordListDescriptions_[] = NULL, | |
39 | int styleBits_=5); | |
40 | virtual ~LexerModule() { | |
41 | } | |
1a2fb4cd | 42 | int GetLanguage() const { return language; } |
a834585d RD |
43 | |
44 | // -1 is returned if no WordList information is available | |
45 | int GetNumWordLists() const; | |
46 | const char *GetWordListDescription(int index) const; | |
47 | ||
1e9bafca RD |
48 | int GetStyleBitsNeeded() const; |
49 | ||
65ec6247 | 50 | virtual void Lex(unsigned int startPos, int lengthDoc, int initStyle, |
1a2fb4cd | 51 | WordList *keywordlists[], Accessor &styler) const; |
65ec6247 | 52 | virtual void Fold(unsigned int startPos, int lengthDoc, int initStyle, |
1a2fb4cd RD |
53 | WordList *keywordlists[], Accessor &styler) const; |
54 | static const LexerModule *Find(int language); | |
55 | static const LexerModule *Find(const char *languageName); | |
f6bcfd97 BP |
56 | }; |
57 | ||
7e0c58e9 RD |
58 | #ifdef SCI_NAMESPACE |
59 | } | |
60 | #endif | |
61 | ||
65ec6247 RD |
62 | /** |
63 | * Check if a character is a space. | |
64 | * This is ASCII specific but is safe with chars >= 0x80. | |
65 | */ | |
66 | inline bool isspacechar(unsigned char ch) { | |
67 | return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); | |
68 | } | |
69 | ||
f6bcfd97 | 70 | inline bool iswordchar(char ch) { |
65ec6247 | 71 | return isascii(ch) && (isalnum(ch) || ch == '.' || ch == '_'); |
f6bcfd97 BP |
72 | } |
73 | ||
74 | inline bool iswordstart(char ch) { | |
65ec6247 | 75 | return isascii(ch) && (isalnum(ch) || ch == '_'); |
f6bcfd97 BP |
76 | } |
77 | ||
78 | inline bool isoperator(char ch) { | |
65ec6247 | 79 | if (isascii(ch) && isalnum(ch)) |
f6bcfd97 BP |
80 | return false; |
81 | // '.' left out as it is used to make up numbers | |
82 | if (ch == '%' || ch == '^' || ch == '&' || ch == '*' || | |
83 | ch == '(' || ch == ')' || ch == '-' || ch == '+' || | |
84 | ch == '=' || ch == '|' || ch == '{' || ch == '}' || | |
85 | ch == '[' || ch == ']' || ch == ':' || ch == ';' || | |
86 | ch == '<' || ch == '>' || ch == ',' || ch == '/' || | |
87 | ch == '?' || ch == '!' || ch == '.' || ch == '~') | |
88 | return true; | |
89 | return false; | |
90 | } |