[Qt-interest] Syntax Highlighter State Stack
Robert Hairgrove
evorgriahr at hispeed.ch
Tue Dec 30 19:05:39 CET 2008
Neel Basu wrote:
> I am Making a Syntax Highlighter for PHP
> there are a lot of states such as
> enum State{
> NormalState = -1,
> InPHPCodeBlock,
> InFunction,
> InClass,
> InMultiComment,
> InCurlyBraces
> };
> Now Its possible that some code block is in InMultiComment which is in InFnction which is in InPHPCodeBlock
> It is not possible to keep informations about these states in a single integer variable.
> (Is it ??)
> So I thought to keep a vector for this enum values which will be used as a StateStack
>
> Now the question is am I on the right Track ?? or there are easier or safer or more standard alternatives ??
>
> Neel
If you define your enum values like this:
enum State{
NormalState = 0,
InPHPCodeBlock = 1,
InFunction = 2,
InClass = 4,
InMultiComment = 8,
InCurlyBraces = 16
};
then you could keep them in an unsigned integer by OR'ing the values
together. However, it would be impossible to keep the information as to
the order of the values, i.e. if you had to unwind the "stack".
The STL has std::stack<>. If you really need LIFO semantics, this is
probably a good choice. Otherwise, look into std::deque<> which is
insertable at both ends. I've never programmed syntax highlighting
before, so I can't make any recommendations here.
More information about the Qt-interest-old
mailing list