ActiveState Community

Django lexer incomplete

Posted by zgoda on 2008-06-25 04:07
OS: All / Any

I'm working on Django-based project with KomodoEdit and I found Django template language lexer is incomplete (and buggy to some extent) -- it does not recognize {# #} comment tags, some keywords are missing (i.e. blocktrans) and using construction like value="{% trans "Save" %}" causes wrong highlighting of the rest of line due to invalid treatment of double quotes inside tags.

I could fix this by myself (I did things like this for other editors eg. for jEdit) but could anybody point me to any documentation for Komodo lexers?

ericp | Wed, 2008-06-25 09:57

UDL (for User-defined languages) was designed to support the creation
of readable lexer specs for complex, multi-part languages. It
looks straightforward to add/fix the parts you identified, but you're
welcome to take a stab at it. Patches welcome.

I wrote an intro to UDL at
http://blogs.activestate.com/ericp/2007/01/kid_adding_a_ne.html

The build part of this document is obsolete. See
http://community.activestate.com/forum-topic/introduction-building-komod...
for instructions there.

You can find the source for django-mainlex.udl and its included
files at <komodo-install>/lib/sdk/udl -- the key file is djangolex.udl

Although Luddite (the name of UDL's language) deals primarily
with regular expressions, it has a few built-in stacks, which
will support nested strings. Have a look at how I handled
Ruby's "... #{puts "nested string"} ..." in rubylex.udl for
an example.

Good luck. Please post any questions to this thread.

- Eric