ActiveState Community

Fortran syntax highlighting and/or adding a new language

Posted by sourish.basu on 2009-10-21 02:43
OS: OS X

Hi,

Is there an existing extension to add fortran syntax highlighting to Komodo Edit? I use Komodo Edit for my python code all the time, and would like to use it for fortran as well.

Else, is there a tutorial somewhere to demonstrate how to add support for a new language to Komodo Edit? I don't want autocompletion etc., just syntax highlighting and indenting. I found a tutorial at http://blogs.activestate.com/2007/01/kid_adding_a_ne but if it doesn't work for Komodo 4.2, I doubt it will work for version 5.2.1. Is there a more updated tutorial somewhere?

Thanks,

Sourish

ericp | Wed, 2009-10-21 11:49

You could try running [koext help] and [koext gettingstarted]
(koext is in the sdk folder of your Komodo install directory.

I imagine that Fortran colorizing might be non-trivial, given
everything else I've heard about the language (white-space is
ignored everywhere, to the point that it isn't used for
delimiting tokens).

UDL focuses on colorizing, but it also gives you the a
skeleton language service, in which you would implement
code like indentation. Most of Komodo's indentation is
table-driven, but again from what I know about Fortran
(in particular that C and Algol were structured reactions
against it), I expect Fortran auto-indentation to be
non-trivial. You could look at koRubyLanguage.py to see
how to do keyword-based indentation (as opposed to brace-driven).

- Eric

sourish.basu | Thu, 2009-10-22 00:59

Having a sample would really help. For example, I think I could take the syntax highlighting rules of C/C++ and modify them for Fortran (instead of starting from scratch). I mention C/C++ because there too white spaces are ignored, indentation is purely for visual clarity, etc. (just like Fortran).

So is there a UDL definition for C/C++ that I can copy and modify?

-Sourish

ericp | Thu, 2009-10-22 09:45

Komodo includes a colorizer for Fortran (actually "Fortran 77"),
and by default maps *.f and *.for files to it. We don't do any kind
of auto-indentation though.

What extension are you using?

- Eric

toddw | Thu, 2009-10-22 11:14

The maya extension is based on C/C++ rules, so you may find that an easy extension to modify, see:
http://svn.openkomodo.com/openkomodo/browse/addons/maya/

You can checkout this code using:

svn co http://svn.openkomodo.com/repos/addons/maya maya

Cheers,
Todd

sourish.basu | Fri, 2009-10-23 02:30

Then perhaps I won't need to write my own colorizer.

Alternatively, how can I copy the colorizing rules for Fortran 77, modify them, and associate them with a new file extension?

-Sourish

ericp | Fri, 2009-10-23 09:39

See [Preferences|File Associations|New Association]

There are no "rules" for the Fortran colorizer -- it's done
in C++ code. You *could* write a new colorizer and submit
it to the scintilla project, but I think that would be overkill.

On the other hand, if you have some thoughts on how indentation
should work for Fortran, that will take some Python code, in
koFortranLanguage.py.

- Eric