Hello,
I would like geany to support the cython [1] programming language. The Cython language is very close to the Python language, but Cython additionally supports calling C functions and declaring C types on variables and class attributes. It is really useful when wrapping C libraries into python. Cython is built upon Pyrex, they both uses the same filename extension and a compatible to a certain extent.
I had a look at [2] but I'm still not sure of what should be done. Here is my first attempt:
- I added GEANY_FILETYPES_CYTHON to filetypes.{c,h}. I choosed ft->lang = 7, but I'm not sure about it means ([2] doesn't mention it) - I added data/filetypes.cython, copied from the cython one with additional keywords (I still need to change the build options) - I think we can use the Python lexer, but I don't know how to explain it to geany, so I did nothing yet.
These modifications are in the attached patch (against trunk). It compiles and works: I now have a cython filetype in geany. However, I still have no folding nor syntax highlighting. Can you guide me a little bit for the next step?
Regards -- Sébastien Barthélemy
[1] http://www.cython.org/ [2] http://www.geany.org/manual/hacking.html#adding-a-filetype
On Tue, 20 Jan 2009 16:20:48 +0100, Sebastien Barthelemy barthelemy@crans.org wrote:
Hello,
I would like geany to support the cython [1] programming language. The Cython language is very close to the Python language, but Cython additionally supports calling C functions and declaring C types on variables and class attributes. It is really useful when wrapping C libraries into python. Cython is built upon Pyrex, they both uses the same filename extension and a compatible to a certain extent.
I had a look at [2] but I'm still not sure of what should be done. Here is my first attempt:
- I added GEANY_FILETYPES_CYTHON to filetypes.{c,h}. I choosed
ft->lang = 7, but I'm not sure about it means ([2] doesn't mention it)
src/filetypes.h line 128
These modifications are in the attached patch (against trunk). It compiles and works: I now have a cython filetype in geany. However, I still have no folding nor syntax highlighting. Can you guide me a little bit for the next step?
From what I have read in the IRC backlog, I don't see why another
filetype is necessary at least for syntax highlighting. Either you want to reuse the Python lexer for highlighting(a), that would be pretty easy in src/highlighting.c or you have to write a new Scintilla lexer for Cython first(b).
In case of (a): why would we need a new filetype at all?
Some example files would be helpful (something more complex than the snippet mentioned in IRC).
Regards, Enrico
2009/1/21 Enrico Tröger enrico.troeger@uvena.de:
On Tue, 20 Jan 2009 16:20:48 +0100, Sebastien Barthelemy barthelemy@crans.org wrote:
- I added GEANY_FILETYPES_CYTHON to filetypes.{c,h}. I choosed
ft->lang = 7, but I'm not sure about it means ([2] doesn't mention it)
src/filetypes.h line 128
/** Represents the langType of tagmanager (see the table * in tagmanager/parsers.h), -1 represents all, -2 none. */
I saw this comment but I do not know what the tagmanager does yet.
From what I have read in the IRC backlog, I don't see why another filetype is necessary at least for syntax highlighting. Either you want to reuse the Python lexer for highlighting(a), that would be pretty easy in src/highlighting.c or you have to write a new Scintilla lexer for Cython first(b).
In case of (a): why would we need a new filetype at all?
there are keywords in Cython that are not keywords in Python. For instance, "cdef int a = 0" is valid Cython but invalid Python. On the contrary "cdef = 0" is valid python (where cdef is a regular var) but invalid cython.
Yet, they are very similar, so the Python lexer should be ok, with additionnal keywords. (I never wrote one, nor heard of them before yesterday, so I might be wrong).
Some example files would be helpful (something more complex than the snippet mentioned in IRC).
The sage project uses Cython a lot. For instance http://www.sagemath.org/hg/sage-main/file/b0aa7ef45b3c/sage/rings/rational.p...
regards
On Wed, 21 Jan 2009 15:21:44 +0100, Sebastien Barthelemy barthelemy@crans.org wrote:
2009/1/21 Enrico Tröger enrico.troeger@uvena.de:
On Tue, 20 Jan 2009 16:20:48 +0100, Sebastien Barthelemy barthelemy@crans.org wrote:
- I added GEANY_FILETYPES_CYTHON to filetypes.{c,h}. I choosed
ft->lang = 7, but I'm not sure about it means ([2] doesn't mention it)
src/filetypes.h line 128
/** Represents the langType of tagmanager (see the table * in tagmanager/parsers.h), -1 represents all, -2 none. */
I saw this comment but I do not know what the tagmanager does yet.
Mainly, the tagmanager creates the data for the symbol list in the sidebar. For your needs, setting langType to 7 is the best as this parses symbols using the existing Python parser.
From what I have read in the IRC backlog, I don't see why another filetype is necessary at least for syntax highlighting. Either you want to reuse the Python lexer for highlighting(a), that would be pretty easy in src/highlighting.c or you have to write a new Scintilla lexer for Cython first(b).
In case of (a): why would we need a new filetype at all?
there are keywords in Cython that are not keywords in Python. For instance, "cdef int a = 0" is valid Cython but invalid Python. On the contrary "cdef = 0" is valid python (where cdef is a regular var) but invalid cython.
Yet, they are very similar, so the Python lexer should be ok, with additionnal keywords. (I never wrote one, nor heard of them before yesterday, so I might be wrong).
Well, if you don't need a different lexer (the code for syntax highlighting) nor a different parser, it's really just about a set of different keywords. In this case I doubt whether it is reasonable to add just another filetype only for different keywords.
Maybe we can find a solution without creating another filetype but I definetely won't work on this during the next two or three weeks. There are too many other, important things on the road.
Regards, Enrico
2009/1/21 Enrico Tröger enrico.troeger@uvena.de:
On Wed, 21 Jan 2009 15:21:44 +0100, Sebastien Barthelemy Mainly, the tagmanager creates the data for the symbol list in the sidebar. For your needs, setting langType to 7 is the best as this parses symbols using the existing Python parser.
Ok, thank you for the explanation. Sadly the python parser fails to identify many of the cython symbols.
Maybe we can find a solution without creating another filetype but I definetely won't work on this during the next two or three weeks. There are too many other, important things on the road.
Ok, thank you for making this clear.
Regards
On Thu, 22 Jan 2009 11:42:44 +0100, Sebastien Barthelemy barthelemy@crans.org wrote:
2009/1/21 Enrico Tröger enrico.troeger@uvena.de:
On Wed, 21 Jan 2009 15:21:44 +0100, Sebastien Barthelemy Mainly, the tagmanager creates the data for the symbol list in the sidebar. For your needs, setting langType to 7 is the best as this parses symbols using the existing Python parser.
Ok, thank you for the explanation. Sadly the python parser fails to identify many of the cython symbols.
You have two possibilites: a) improve the existing Python parser (tagmanager/python.c) while keeping the current functionality at 100% b) write a new one based on the current Python parser which does the job better
Obviously, (a) would be preferred because of reusing existing code and not unnecessarily increasing code size. But only if it's worth it and the existing Python parser must stay working in any case.
Regards, Enrico