[Qt-interest] Syntax Highlighter State Stack
Scott Aron Bloom
Scott.Bloom at sabgroup.com
Fri Jan 2 21:02:00 CET 2009
Im completely confused by your response...
Your original question was
"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 ??"
And then went on to talk about keeping track of the previou state, so
you could "pop" (my word) into it...
You were looking for a stack class... and the "QT" way of doing things.
I pointed you the NON-GUI container classes, there happens to be one
called.... QStack, with a push and pop mechanism, which will give you
the LIFO system your looking for... But only for the stack of states
you were talking about...
Now, your talking about the QTextBlockUserData which is used in
conjunction with the QTextBlock being worked on... And has nothing to
do with your original question.... Now you are correct, you can not
get the previous blocks user data. The reason why there isn't... I
don't know... But I can say, when I have used it, I used it for the
QTextDocument and QSyntaxHighlighter to get and set special information
on the blocks, not for the highlighter to use as part of its analysis.
All that said, is neither here nor there...
The problem you said you were trying to solve was this:
"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
variable"
Now, if you don't care about which happened first, someone suggested use
bitwise OR'ing the attributes... My recommendation... every time you
enter a block, push it to the stack. When you leave the block, pop it
from the stack.
Then when you go to set the color, you can set the code in a
multicomment that's in a function, differently then code that's in a
multicomment that is not in a function...
Again.. a simple stack solves the problem...
Scott
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> bounces at trolltech.com] On Behalf Of Alan M. Carroll
> Sent: Friday, January 02, 2009 10:55 AM
> To: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] Syntax Highlighter State Stack
>
> I think this illustrates what to me is a design flaw in
QSyntaxHighlighter
> that renders it unusable for any of my projects. The flaw is that you
cannot
> access the user data for the previous block. You can get the state,
which is
> just an int, but not an instance of a generic class. Therefore, it's
pointless
> to ask "What container would you use?" because you can't use a
container, only
> an int. Clearly, the API can find the previous block because
> previousBlockState() does it. Why there isn't a parallel
> previousBlockUserData() is incomprehensible to me.
>
> So my advice is that if your parse engine has any non-trivial state,
write
> your own and ignore QSyntaxHighlighter.
>
> At 12:16 PM 12/30/2008, Scott Aron Bloom wrote:
> >Did you look at the QT syntax highlighter example?
> >
> >Did you look at the non-gui datatstructures given to you by QT in the
> >docs?
> >http://doc.trolltech.com/4.3/tools.html
> >
> >First, think of it in a Non-QT way?? What container would you use?
> >
> >
> >> -----Original Message-----
> >> From: Neel Basu [mailto:neel.basu.z at gmail.com]
> >> Sent: Tuesday, December 30, 2008 10:08 AM
> >> To: qt-interest at trolltech.com
> >> Cc: Scott Aron Bloom
> >> Subject: Re: [Qt-interest] Syntax Highlighter State Stack
> >>
> >> No The reason for which I am asking is QSyntaxHighlighter provides
> >> int previousBlockState () const
> >> void setCurrentBlockState ( int newState )
> >> int currentBlockState () const
> >> function which seems to keep track of state data in two integer
> >variables.
> >>
> >> But what I am trying to do is keeping a stack of states.
> >> So I'll not make mush use of these Qt methods rather I'll use mine.
> >>
> >> Thanks why I am asking to make sure am I running through a wrong
track
> >??
> >>
> >> On Tuesday 30 Dec 2008 11:29:42 pm Scott Aron Bloom wrote:
> >> > What does this have to do with QT? This is simple C++ data
> >structure
> >> > theory.
> >> >
> >> > Scott
> >> >
> >> > > -----Original Message-----
> >> > > From: qt-interest-bounces at trolltech.com [mailto:qt-interest-
> >> > > bounces at trolltech.com] On Behalf Of Neel Basu
> >> > > Sent: Tuesday, December 30, 2008 9:51 AM
> >> > > To: Qt Interest
> >> > > Subject: [Qt-interest] Syntax Highlighter State Stack
> >> > >
> >> > > 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
> >> > > _______________________________________________
> >> > > Qt-interest mailing list
> >> > > Qt-interest at trolltech.com
> >> > > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >> >
> >> > _______________________________________________
> >> > Qt-interest mailing list
> >> > Qt-interest at trolltech.com
> >> > http://lists.trolltech.com/mailman/listinfo/qt-interest
> >> >
> >>
> >>
> >>
> >> --
> >> Zigmoyd PHP Framework http://zigmoyd.net
> >
> >_______________________________________________
> >Qt-interest mailing list
> >Qt-interest at trolltech.com
> >http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list