]> git.saurik.com Git - wxWidgets.git/blob - src/stc/scintilla/include/KeyWords.h
Use the data scheme to load resources in the WebKitGTK+ implementation, rather than...
[wxWidgets.git] / src / stc / scintilla / include / KeyWords.h
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 /**
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
35 typedef void (*LexerFunction)(unsigned int startPos, int lengthDoc, int initStyle,
36 WordList *keywordlists[], Accessor &styler);
37
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 */
43 class LexerModule {
44 protected:
45 const LexerModule *next;
46 int language;
47 LexerFunction fnLexer;
48 LexerFunction fnFolder;
49 const char * const * wordListDescriptions;
50 int styleBits;
51
52 static const LexerModule *base;
53 static int nextLanguage;
54
55 public:
56 const char *languageName;
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 }
65 int GetLanguage() const { return language; }
66
67 // -1 is returned if no WordList information is available
68 int GetNumWordLists() const;
69 const char *GetWordListDescription(int index) const;
70
71 int GetStyleBitsNeeded() const;
72
73 virtual void Lex(unsigned int startPos, int lengthDoc, int initStyle,
74 WordList *keywordlists[], Accessor &styler) const;
75 virtual void Fold(unsigned int startPos, int lengthDoc, int initStyle,
76 WordList *keywordlists[], Accessor &styler) const;
77 static const LexerModule *Find(int language);
78 static const LexerModule *Find(const char *languageName);
79 };
80
81 #ifdef SCI_NAMESPACE
82 }
83 #endif
84
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
93 inline bool iswordchar(char ch) {
94 return isascii(ch) && (isalnum(ch) || ch == '.' || ch == '_');
95 }
96
97 inline bool iswordstart(char ch) {
98 return isascii(ch) && (isalnum(ch) || ch == '_');
99 }
100
101 inline bool isoperator(char ch) {
102 if (isascii(ch) && isalnum(ch))
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 }