Using Flags on a State?

29 views
Skip to first unread message

RaptorX

unread,
Nov 4, 2012, 6:17:24 PM11/4/12
to scintilla...@googlegroups.com
Hi!

I have been reading the CPP lexer and i have noticed sometimes the author passes a new state with a flag, and after checking the definition of StyleContext I noticed that there is a parameter where you can indicate a value from where to start clearing flags off.

So I tried the following:

void SCI_METHOD Lexer::Lex(unsigned int startPos, int length, int initStyle, IDocument *pAccess)
{
    LexAccessor styler(pAccess);
    StyleContext sc(startPos, length, initStyle, styler, invSyntax-1);
    
    for (; sc.More(); sc.Forward()) {

        if (sc.atLineStart) {
        }

        // Exit current State
        switch (sc.state) {
            case COMMENT|fBlock:
                if (sc.Match("*/")) {
                    sc.Forward(2);
                    sc.SetState(DEFAULT);
                }
            break;
        }

        // Enter a new State
        if (sc.state == DEFAULT) {
            if (sc.Match("/*"))
                sc.SetState(COMMENT|fBlock);
        }
    }
    sc.Complete(); 
}

I am sure fBlock is lower than invSyntax-1 so according to the definition that bit wont be reset and that is exactly like that when scintilla reads a whole file and renders it for the first time... as soon as one starts typing the flag is lost.

I am a bit of new on all this so please explain me why is it not working according to what i think is logical?
I know that when i start typing the Lex function gets called again and a new StyleContext object gets created but i thought that initStyle will still have the flag set and thus be passed to the new object as is!

Thanks for your support!

Neil Hodgson

unread,
Dec 30, 2012, 3:50:39 AM12/30/12
to scintilla...@googlegroups.com
RaptorX:

I have been reading the CPP lexer and i have noticed sometimes the author passes a new state with a flag, and after checking the definition of StyleContext I noticed that there is a parameter where you can indicate a value from where to start clearing flags off.

   Flags are a rarely used feature in LexAccessor. The idea was that you could determine an error such as a bad character in a literal and have an error indicator show until the end of the literal.

So I tried the following:
...
I am sure fBlock is lower than invSyntax-1 so according to the definition that bit wont be reset and that is exactly like that when scintilla reads a whole file and renders it for the first time... as soon as one starts typing the flag is lost.

   That code doesn't appear to use flags and I don't understand the point.

I am a bit of new on all this so please explain me why is it not working according to what i think is logical?
I know that when i start typing the Lex function gets called again and a new StyleContext object gets created but i thought that initStyle will still have the flag set and thus be passed to the new object as is!

   initStyle is anded with the style mask before going to the lexer. See the initialisation of styleStart in LexInterface::Colourise.

   Neil

Reply all
Reply to author
Forward
0 new messages