On Sun, Jun 26, 2011 at 5:34 PM, Reiner Pope <reiner.p...@gmail.com> wrote:
> On a similar note, would it be acceptable to join the 'hlRun' and 'hlFocus'
> fields. Currently they are:
>
> hlRun :: Scanner Point Char -> Point -> cache -> cache,
> hlFocus :: Map WindowRef Region -> cache -> cache

I am not sure... However, maybe you would enjoy the following
explanation on what "focusing" is all about -- I don't think I have
documented it anywhere. Focusing on a particular point allows better
asymptotic performance.

The idea is that focusing is called when a window is "scrolled", so
that the AST does not have to be re-traversed from the root every time
a display is needed. Otherwise, the AST has to be traversed in
pre-order to find the portion that corresponds to the windows, at
every refresh.

You may retort: "Why don't you cache the beginning/end of the regions
corresponding to each node in the AST?" Otherwise, it would break the
"online" properties of the parser. (See
www.cse.chalmers.se/~bernardy/FunctionalIncrementalParsing.pdf for the
explanation of the online parsing)

> It seems that we could allow simpler parsers (more on this later)

I dare say that a sensible overall plan about parsers should be well
thought out before putting the current code under the knife :). I am
curious to hear your plans! I could also let you know about mine if
you are interested.

> if we combined them into one:
>
> hlRun :: Scanner Point Char -> Point -> Map WindowRef Region -> cache ->
> cache
>
> After my brief search through the code, it appears that these are run in the
> main loop as follows
>
> (in Yi.Core.refreshEditor):
> pureM clearAllSyntaxAndHideSelection >>=
> ... (do layout stuff)
> pureM focusAllSyntax >>=
> ... (display everything)
>
> I don't see any reason why this couldn't be changed to
>
> ... (do layout stuff)
> pureM runAndFocusAllSyntax >>=
> ... (display everything

I cannot recall why these two calls are separated. Perhaps I just
wanted the focusing to be easily removable. That's the last
non-trivial thing I implemented, and I wasn't sure the asymptotic
performance gain was worth the trouble.

> which would allow merging hlRun and hlFocus as described above. In fact, I
> tested this by moving the calls to 'pureM clearAllSyntaxAndHideSelection'
> and 'pureM focusAllSyntax' next to each other, and nothing appears to have
> been broken.

Did you also test asymptotic performance as hinted above?
(Quite a pain to do, I'll grant you that much).

> The reason for merging hlRun and hlFocus is as follows. For example, suppose
> I have a simple parser which just recognises keywords based on
> regexp-matching (I know it's bad, but it's just an example).

Do you have any good example?

> If hlRun and
> hlFocus were combined, my cache could be
>
> type Cache = Map WindowRef [(Keyword, Point)]

At the moment, the parsers are optimized for a single window showing a
given buffer (that's another way to say that I ignored the case of a
buffer shown in multiple windows).
I'd much prefer a solution that handles multiple windows in a generic
way rather than to hack it withing the cache of a specific parser.
Maybe that's what you want to do though?

Cheers,
JP.

-- 
Yi development mailing list
yi-devel@googlegroups.com
http://groups.google.com/group/yi-devel

Reply via email to