LexerModule.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. // Scintilla source code edit control
  2. /** @file LexerModule.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. #ifndef LEXERMODULE_H
  8. #define LEXERMODULE_H
  9. #ifdef SCI_NAMESPACE
  10. namespace Scintilla {
  11. #endif
  12. class Accessor;
  13. class WordList;
  14. typedef void (*LexerFunction)(Sci_PositionU startPos, Sci_Position lengthDoc, int initStyle,
  15. WordList *keywordlists[], Accessor &styler);
  16. typedef ILexer *(*LexerFactoryFunction)();
  17. /**
  18. * A LexerModule is responsible for lexing and folding a particular language.
  19. * The class maintains a list of LexerModules which can be searched to find a
  20. * module appropriate to a particular language.
  21. */
  22. class LexerModule {
  23. protected:
  24. int language;
  25. LexerFunction fnLexer;
  26. LexerFunction fnFolder;
  27. LexerFactoryFunction fnFactory;
  28. const char * const * wordListDescriptions;
  29. public:
  30. const char *languageName;
  31. LexerModule(int language_,
  32. LexerFunction fnLexer_,
  33. const char *languageName_=0,
  34. LexerFunction fnFolder_=0,
  35. const char * const wordListDescriptions_[] = NULL);
  36. LexerModule(int language_,
  37. LexerFactoryFunction fnFactory_,
  38. const char *languageName_,
  39. const char * const wordListDescriptions_[] = NULL);
  40. virtual ~LexerModule() {
  41. }
  42. int GetLanguage() const { return language; }
  43. // -1 is returned if no WordList information is available
  44. int GetNumWordLists() const;
  45. const char *GetWordListDescription(int index) const;
  46. ILexer *Create() const;
  47. virtual void Lex(Sci_PositionU startPos, Sci_Position length, int initStyle,
  48. WordList *keywordlists[], Accessor &styler) const;
  49. virtual void Fold(Sci_PositionU startPos, Sci_Position length, int initStyle,
  50. WordList *keywordlists[], Accessor &styler) const;
  51. friend class Catalogue;
  52. };
  53. inline int Maximum(int a, int b) {
  54. return (a > b) ? a : b;
  55. }
  56. // Shut up annoying Visual C++ warnings:
  57. #ifdef _MSC_VER
  58. #pragma warning(disable: 4244 4456 4457)
  59. #endif
  60. // Turn off shadow warnings for lexers as may be maintained by others
  61. #if defined(__GNUC__)
  62. #pragma GCC diagnostic ignored "-Wshadow"
  63. #endif
  64. #ifdef SCI_NAMESPACE
  65. }
  66. #endif
  67. #endif