On Dec 5, 3:15 pm, "Edward K. Ream" <[EMAIL PROTECTED]> wrote:

> In essence we must hack a resolution of the difference between
> scanning lines and tokens.

Yesterday I saw that this isn't necessary.  Indeed, there is a clever
way of re-imagining what QSyntaxHighlighter.highlightBlock is doing
that makes everything easier.  The Qt docs are quite misleading in
suggesting complexity where none actually exist.

In essence, one can think of the highlightBlock method as *suggesting*
that a range of text be colored.  But there is no requirement that
this suggestion be followed!!!  Therefore, subclasses of
QSyntaxHighlighter are free to highlight any range of text whenever
they like.

This collapses all the complexity.  For example, here is the present
highlightBlock::

def highlightBlock (self,s):
    i = self.i
    s = unicode(s)
    # self.s is the entire string.
    # s is the portion to be colored now.
    self.i = self.colorer.recolor(self.s,i,i+len(s))

And here is the recolor main loop (simplified)::

def recolor (self,s,i,j):
    '''Recolor s from i to j.'''
    j = min(j,len(s))
    while i < j:
        functions = self.rulesDict.get(s[i],[])
        for f in functions:
            if trace: g.trace('i',i,'f',f)
            n = f(self,s,i)
            if n is None or n < 0:
                g.trace('Can not happen'); break
            elif n > 0:
                i += n ; break
        else:
            i += 1
    return i

This is almost identical to the main loop in the threading colorizer!

> There are examples of this kind of hacking
> athttp://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qsyntaxhig...

I plan to point out that there is no need whatsoever to colorize
tokens line-by-line.

> Considerable repackaging will also be needed.  

Done at rev. 1293.  The colorizer should work as soon as
jeditColorizer.setTag calls QSyntaxHighlighter.setFormat.  We are
close.  In particular, setTag is being called with the proper tags and
index ranges.

Edward

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/leo-editor?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to