I think the specifics of the syntax highlighting could work a little
better, if changed a bit.

Let me start off with TextMate, for which I really like the syntax
highlighting and scoping features. TextMate's bundles define languages
using a hierarchical regular expressions, which is a pretty good
system. The file becomes scoped, in that any part of the file can be
described in various ways. For example (in Python, because the Haskell
bundle doesn't really use this to the fullest potential), the name of
the function in the definition for a class's `__init__` method has
these scopes:

    source.python
    meta.function.python
    entity.name.function.python
    support.function.magic.python

Syntax highlighting can then be based on all these levels of scope. I
could, for example, define a background by referring to
`source.python` (which would apply a background to the text of the
entire file), or `source.python meta.function.python` (applies to all
of "def ...(...):"). But when writing the style, I usually don't want
to write for a specific language, so I'd write something like
`meta.function` and it would style all functions, no matter the
language.

I don't think this is quite the right solution for Yi, though. It does
work very well, but it uses regular expressions heavily, and I agree
that lexing with Alex is a smarter solution. I think that is not a
complete solution, though, because it does not provide the
hierarchical scoping that is essential to a good system.

I know Parsec is used somewhere in Yi, but I'm not exactly sure for
what it is used. If the syntax highlighters could work with the AST of
a parsed file, I believe this would lead to much more precise and
powerful parsing.

Moreover, the advantages of using Parsec to parse in every mode would
allow commands to act differently depending on the context. Say, for
example (again, not in Haskell because I can't think of as good an
example), that I have a documentation string in Python or a similar
language. I expect the commands I execute to behave as though I'm
writing restructedText (the docstring format for Python) when I'm
inside the context of a docstring, but as though I'm writing Python
for the rest of the file.

Regardless, I think the highlighting in Yi is problematic, currently,
because the specific tokens are odd and very Haskell-specific. "cpp",
etc. seem very much out-of-place in this context.

Jeff Wheeler
--~--~---------~--~----~------------~-------~--~----~
Yi development mailing list
[email protected]
http://groups.google.com/group/yi-devel
-~----------~----~----~----~------~----~------~--~---

Reply via email to