[QScintilla] Unable to add new keywords into already existing lexers.

Phil Thompson phil at riverbankcomputing.com
Thu Feb 23 17:11:27 GMT 2012


On Wed, 22 Feb 2012 12:04:56 +0530, Sarbojit Sarkar
<sarkar.iitr at gmail.com>
wrote:
> Hi,
>   I have started playing with QScintilla few days back and I am quite
happy
> to see broad range of already existing lexers. Now I have a requirement
> where I am planning to add few keywords into existing lexer. By googling
it
> seems that I have to create a subclass and need to redefine "const char*
> keywords(int set) const" function. I did that but did not observer any
> change. Here is my code,
> 
> class myLex : public QsciLexerCPP
> {
> public:
>     const char* keywords(int set) const;
> };
> 
> const char* myLex::keywords(int set) const
> {
>     if (set == 1)
>         return
>             "and and_eq asm auto bitand bitor bool break case "
>             "catch char class compl const const_cast continue "
>             "default delete do double dynamic_cast else enum "
>             "explicit export extern false float for friend goto if "
>             "inline int long mutable namespace new not not_eq "
>             "operator or or_eq private protected public register "
>             "reinterpret_cast return short signed sizeof static "
>             "static_cast struct switch template this throw true "
>             "try typedef typeid typename union unsigned using "
>             "virtual void volatile wchar_t while xor xor_eq"
>             "mov";* // my new keyword*

You are missing a space - you've replaced "xor_eq" with "xor_eqmov".

>     if (set == 3)
>         return
>             "a addindex addtogroup anchor arg attention author b "
>             "brief bug c class code date def defgroup deprecated "
>             "dontinclude e em endcode endhtmlonly endif "
>             "endlatexonly endlink endverbatim enum example "
>             "exception f$ f[ f] file fn hideinitializer "
>             "htmlinclude htmlonly if image include ingroup "
>             "internal invariant interface latexonly li line link "
>             "mainpage name namespace nosubgrouping note overload "
>             "p page par param post pre ref relates remarks return "
>             "retval sa section see showinitializer since skip "
>             "skipline struct subsection test throw todo typedef "
>             "union until var verbatim verbinclude version warning "
>             "weakgroup $ @ \\ & < > # { }";
> 
>     if (set == 16)
>         return "mdef mend"; *// my new keywords*
>     return 0;
> }

The lexer only supports sets 1 to 4. I've updated the docs to reflect
this.

> Please let me know in case I have missed something.
> 
> Also I wanted to play with existing colour scheme that lexer is
following.
> wondering if it is possible.

Reimplement defaultPaper(), defaultColor() etc in your sub-class, or just
call setPaper(), setColor().

> Any help, link or suggestion will help a lot.
> 
> thanks

Phil


More information about the QScintilla mailing list