]>
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 | ||
9e96e16f RD |
12 | /** |
13 | */ | |
14 | class WordList { | |
15 | public: | |
16 | // Each word contains at least one character - a empty word acts as sentinel at the end. | |
17 | char **words; | |
18 | char *list; | |
19 | int len; | |
20 | bool onlyLineEnds; ///< Delimited by any white space or only line ends | |
21 | bool sorted; | |
22 | int starts[256]; | |
23 | WordList(bool onlyLineEnds_ = false) : | |
24 | words(0), list(0), len(0), onlyLineEnds(onlyLineEnds_), | |
25 | sorted(false) | |
26 | {} | |
27 | ~WordList() { Clear(); } | |
28 | operator bool() { return len ? true : false; } | |
29 | void Clear(); | |
30 | void Set(const char *s); | |
31 | bool InList(const char *s); | |
32 | bool InListAbbreviated(const char *s, const char marker); | |
33 | }; | |
34 | ||
f6bcfd97 BP |
35 | typedef void (*LexerFunction)(unsigned int startPos, int lengthDoc, int initStyle, |
36 | WordList *keywordlists[], Accessor &styler); | |
88a8b04e | 37 | |
65ec6247 RD |
38 | /** |
39 | * A LexerModule is responsible for lexing and folding a particular language. | |
40 | * The class maintains a list of LexerModules which can be searched to find a | |
41 | * module appropriate to a particular language. | |
42 | */ | |
f6bcfd97 | 43 | class LexerModule { |
65ec6247 | 44 | protected: |
1a2fb4cd | 45 | const LexerModule *next; |
f6bcfd97 | 46 | int language; |
65ec6247 RD |
47 | LexerFunction fnLexer; |
48 | LexerFunction fnFolder; | |
a834585d | 49 | const char * const * wordListDescriptions; |
1e9bafca | 50 | int styleBits; |
a834585d | 51 | |
1a2fb4cd | 52 | static const LexerModule *base; |
65ec6247 RD |
53 | static int nextLanguage; |
54 | ||
f6bcfd97 | 55 | public: |
1a2fb4cd | 56 | const char *languageName; |
1e9bafca RD |
57 | LexerModule(int language_, |
58 | LexerFunction fnLexer_, | |
59 | const char *languageName_=0, | |
60 | LexerFunction fnFolder_=0, | |
61 | const char * const wordListDescriptions_[] = NULL, | |
62 | int styleBits_=5); | |
63 | virtual ~LexerModule() { | |
64 | } | |
1a2fb4cd | 65 | int GetLanguage() const { return language; } |
a834585d RD |
66 | |
67 | // -1 is returned if no WordList information is available | |
68 | int GetNumWordLists() const; | |
69 | const char *GetWordListDescription(int index) const; | |
70 | ||
1e9bafca RD |
71 | int GetStyleBitsNeeded() const; |
72 | ||
65ec6247 | 73 | virtual void Lex(unsigned int startPos, int lengthDoc, int initStyle, |
1a2fb4cd | 74 | WordList *keywordlists[], Accessor &styler) const; |
65ec6247 | 75 | virtual void Fold(unsigned int startPos, int lengthDoc, int initStyle, |
1a2fb4cd RD |
76 | WordList *keywordlists[], Accessor &styler) const; |
77 | static const LexerModule *Find(int language); | |
78 | static const LexerModule *Find(const char *languageName); | |
f6bcfd97 BP |
79 | }; |
80 | ||
7e0c58e9 RD |
81 | #ifdef SCI_NAMESPACE |
82 | } | |
83 | #endif | |
84 | ||
65ec6247 RD |
85 | /** |
86 | * Check if a character is a space. | |
87 | * This is ASCII specific but is safe with chars >= 0x80. | |
88 | */ | |
89 | inline bool isspacechar(unsigned char ch) { | |
90 | return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d)); | |
91 | } | |
92 | ||
f6bcfd97 | 93 | inline bool iswordchar(char ch) { |
65ec6247 | 94 | return isascii(ch) && (isalnum(ch) || ch == '.' || ch == '_'); |
f6bcfd97 BP |
95 | } |
96 | ||
97 | inline bool iswordstart(char ch) { | |
65ec6247 | 98 | return isascii(ch) && (isalnum(ch) || ch == '_'); |
f6bcfd97 BP |
99 | } |
100 | ||
101 | inline bool isoperator(char ch) { | |
65ec6247 | 102 | if (isascii(ch) && isalnum(ch)) |
f6bcfd97 BP |
103 | return false; |
104 | // '.' left out as it is used to make up numbers | |
105 | if (ch == '%' || ch == '^' || ch == '&' || ch == '*' || | |
106 | ch == '(' || ch == ')' || ch == '-' || ch == '+' || | |
107 | ch == '=' || ch == '|' || ch == '{' || ch == '}' || | |
108 | ch == '[' || ch == ']' || ch == ':' || ch == ';' || | |
109 | ch == '<' || ch == '>' || ch == ',' || ch == '/' || | |
110 | ch == '?' || ch == '!' || ch == '.' || ch == '~') | |
111 | return true; | |
112 | return false; | |
113 | } |