]>
Commit | Line | Data |
---|---|---|
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> | |
6 | // The License.txt file describes the conditions under which this software may be distributed. | |
7 | ||
8 | #ifdef SCI_NAMESPACE | |
9 | namespace Scintilla { | |
10 | #endif | |
11 | ||
12 | typedef void (*LexerFunction)(unsigned int startPos, int lengthDoc, int initStyle, | |
13 | WordList *keywordlists[], Accessor &styler); | |
14 | ||
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 | */ | |
20 | class LexerModule { | |
21 | protected: | |
22 | const LexerModule *next; | |
23 | int language; | |
24 | LexerFunction fnLexer; | |
25 | LexerFunction fnFolder; | |
26 | const char * const * wordListDescriptions; | |
27 | int styleBits; | |
28 | ||
29 | static const LexerModule *base; | |
30 | static int nextLanguage; | |
31 | ||
32 | public: | |
33 | const char *languageName; | |
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 | } | |
42 | int GetLanguage() const { return language; } | |
43 | ||
44 | // -1 is returned if no WordList information is available | |
45 | int GetNumWordLists() const; | |
46 | const char *GetWordListDescription(int index) const; | |
47 | ||
48 | int GetStyleBitsNeeded() const; | |
49 | ||
50 | virtual void Lex(unsigned int startPos, int lengthDoc, int initStyle, | |
51 | WordList *keywordlists[], Accessor &styler) const; | |
52 | virtual void Fold(unsigned int startPos, int lengthDoc, int initStyle, | |
53 | WordList *keywordlists[], Accessor &styler) const; | |
54 | static const LexerModule *Find(int language); | |
55 | static const LexerModule *Find(const char *languageName); | |
56 | }; | |
57 | ||
58 | #ifdef SCI_NAMESPACE | |
59 | } | |
60 | #endif | |
61 | ||
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 | ||
70 | inline bool iswordchar(char ch) { | |
71 | return isascii(ch) && (isalnum(ch) || ch == '.' || ch == '_'); | |
72 | } | |
73 | ||
74 | inline bool iswordstart(char ch) { | |
75 | return isascii(ch) && (isalnum(ch) || ch == '_'); | |
76 | } | |
77 | ||
78 | inline bool isoperator(char ch) { | |
79 | if (isascii(ch) && isalnum(ch)) | |
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 | } |