Still working on LexAHK.cxx, doing a major refactoring...

In AutoHotkey language, there is no reserved words, so even as Send or MsgBox are official commands, you can use these names as variable names.
Ie. I can write Send = Foo or MsgBox = String
When lexing, I first see them as identifiers then as commands (classical method). But upon seeing a = or a :=, I must change their state back to identifier. I have some other similar cases, like label handling.

I thought of making a bookmark class, which would record the start and end position of the word that can change, then change its state if I meet a modifier:
        void ChangeState(int state) {
                styler.StartSegment(markedPosStart);
                styler.ColourTo(markedPosEnd, state);
        }
I was hoping it wouldn't alter the StyleContext, which would be able to continue.

Alas, it doesn't work, because DocumentAccessor::ColourTo not only use the positions, but also a validLen counter, pointing in the style buffer, and this one doesn't go back upon a call to StartSegment...
So I end by triggering the
PLATFORM_ASSERT((startPosStyling + validLen) < Length());

My question is: what is the best way to handle this?

I saw LexPerl, but it is really doing backtracking, ie., if I understood correctly, it goes back in the source using it finds the start of the HereDoc or other multi-line constructs, memorize the ending string, then it starts lexing from this point. Same for other lexers like the Fortran one (and languages with this HereDoc feature: Bash, Ruby, PHP...).

So, is there already some clean way to change the style of an arbitrary text segment? If no, is there a clean way to implement it in DocumentAccessor? Or do I have to mess at lower level?

--
Philippe Lhoste
--  (near) Paris -- France
--  http://Phi.Lho.free.fr
--  --  --  --  --  --  --  --  --  --  --  --  --  --
_______________________________________________
Scintilla-interest mailing list
[email protected]
http://mailman.lyra.org/mailman/listinfo/scintilla-interest

Reply via email to