1 // Scintilla source code edit control
\r
3 ** Colourise for particular languages.
\r
5 // Copyright 1998-2001 by Neil Hodgson <neilh@scintilla.org>
\r
6 // The License.txt file describes the conditions under which this software may be distributed.
\r
9 namespace Scintilla {
\r
12 typedef void (*LexerFunction)(unsigned int startPos, int lengthDoc, int initStyle,
\r
13 WordList *keywordlists[], Accessor &styler);
\r
16 * A LexerModule is responsible for lexing and folding a particular language.
\r
17 * The class maintains a list of LexerModules which can be searched to find a
\r
18 * module appropriate to a particular language.
\r
22 const LexerModule *next;
\r
24 LexerFunction fnLexer;
\r
25 LexerFunction fnFolder;
\r
26 const char * const * wordListDescriptions;
\r
29 static const LexerModule *base;
\r
30 static int nextLanguage;
\r
33 const char *languageName;
\r
34 LexerModule(int language_,
\r
35 LexerFunction fnLexer_,
\r
36 const char *languageName_=0,
\r
37 LexerFunction fnFolder_=0,
\r
38 const char * const wordListDescriptions_[] = NULL,
\r
40 virtual ~LexerModule() {
\r
42 int GetLanguage() const { return language; }
\r
44 // -1 is returned if no WordList information is available
\r
45 int GetNumWordLists() const;
\r
46 const char *GetWordListDescription(int index) const;
\r
48 int GetStyleBitsNeeded() const;
\r
50 virtual void Lex(unsigned int startPos, int lengthDoc, int initStyle,
\r
51 WordList *keywordlists[], Accessor &styler) const;
\r
52 virtual void Fold(unsigned int startPos, int lengthDoc, int initStyle,
\r
53 WordList *keywordlists[], Accessor &styler) const;
\r
54 static const LexerModule *Find(int language);
\r
55 static const LexerModule *Find(const char *languageName);
\r
58 #ifdef SCI_NAMESPACE
\r
63 * Check if a character is a space.
\r
64 * This is ASCII specific but is safe with chars >= 0x80.
\r
66 inline bool isspacechar(unsigned char ch) {
\r
67 return (ch == ' ') || ((ch >= 0x09) && (ch <= 0x0d));
\r
70 inline bool iswordchar(char ch) {
\r
71 return isascii(ch) && (isalnum(ch) || ch == '.' || ch == '_');
\r
74 inline bool iswordstart(char ch) {
\r
75 return isascii(ch) && (isalnum(ch) || ch == '_');
\r
78 inline bool isoperator(char ch) {
\r
79 if (isascii(ch) && isalnum(ch))
\r
81 // '.' left out as it is used to make up numbers
\r
82 if (ch == '%' || ch == '^' || ch == '&' || ch == '*' ||
\r
83 ch == '(' || ch == ')' || ch == '-' || ch == '+' ||
\r
84 ch == '=' || ch == '|' || ch == '{' || ch == '}' ||
\r
85 ch == '[' || ch == ']' || ch == ':' || ch == ';' ||
\r
86 ch == '<' || ch == '>' || ch == ',' || ch == '/' ||
\r
87 ch == '?' || ch == '!' || ch == '.' || ch == '~')
\r