[wxPython] Fortran Lexer?

Hi all,

This is my first post to this list. I have just started using wxpython (yesterday) and I really like it. Now in under 2 weeks I need to make a demo editor for Fortran code. I have noticed lexers for various languages but no Fortran.

Anyone knows how to tackle this or if it’s been done already …?

Thanks a lot.

PS: All I need mostly is syntax highlighting. Forget about folding for now!

Hi Hassan,

Now in under 2 weeks I need to make a demo editor
for Fortran code. I have noticed lexers for various
languages but no Fortran.

Anyone knows how to tackle this or if it's been done
already ....?

   There is no Fortran lexer available AFAIK. wxSTC inherits much of its
functionality from Scintilla http://www.scintilla.org

   If you are only interested in modern free-form Fortran then you may be
able to reuse the VB lexer almost completely by just changing the keyword
list. Try this out with SciTE and see how far you get.

   The best way to produce a new lexer is to take one of the current lexers
and modify the C++ code to handle the new language. Then you link your new
lexer into wxSTC. For Fortran, the Visual Basic lexer
scintilla/src/LexVB.cxx would be a good starting point.
   http://www.scintilla.org/Lexer.txt

   It is possible to write a lexer that is located within client code by
responding to EVT_STC_STYLENEEDED and this makes it possible to write the
lexer in Python but there is more example code available for the normal way.
This also allows many other applications to use the lexer. Open Source rulez
:slight_smile:

   Neil

Thanks a lot for this info. Now as I am not very familiar with C++, I might need some basic help before diving in.

As far as I can see from source rpm of wxPython, all I need to do is add a LexFortran.cxx which would be a copy of LexVB.cxx with VB changed to Fortran and then define SCLEX_FORTRAN in an include file. Then I’d rebuild the rpm, right?

All, I’d have to do is replace those keywords inside LexFortran.cxx and I’d be done?

> Hi Hassan,
>
> > Now in under 2 weeks I need to make a demo editor
> > for Fortran code. I have noticed lexers for various
> > languages but no Fortran.
> >
> > Anyone knows how to tackle this or if it's been done
> > already ....?
>
> There is no Fortran lexer available AFAIK. wxSTC inherits much of its
> functionality from Scintilla http://www.scintilla.org
>
> If you are only interested in modern free-form Fortran then you may be
> able to reuse the VB lexer almost completely by just changing the keyword
> list. Try this out with SciTE and see how far you get.
>
> The best way to produce a new lexer is to take one of the current lexers
> and modify the C++ code to handle the new language. Then you link your new
> lexer into wxSTC. For Fortran, the Visual Basic lexer
> scintilla/src/LexVB.cxx would be a good starting point.
> http://www.scintilla.org/Lexer.txt
>
> It is possible to write a lexer that is located within client code by
> responding to EVT_STC_STYLENEEDED and this makes it possible to write the
> lexer in Python but there is more example code available for the normal way.
> This also allows many other applications to use the lexer. Open Source rulez
> :-)
>
> Neil
>
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> [http://lists.wxwindows.org/mailman/listinfo/wxpython-users](http://lists.wxwindows.org/mailman/listinfo/wxpython-users)

···

On 02 Aug 2001 09:07:37 +1000, Neil Hodgson wrote:

Hassan:

As far as I can see from source rpm of wxPython,
all I need to do is add a LexFortran.cxx which would
be a copy of LexVB.cxx with VB changed to Fortran
and then define SCLEX_FORTRAN in an include file.
Then I'd rebuild the rpm, right?

   You'll have to link your lexer in by modifying the wxForceScintillaLexers
function in contrib\stc\contrib\src\stc\stc.cpp.in and add it to
makefile.in. Then run the gen_iface.py script and then make. I've never done
this but it looks right.

All, I'd have to do is replace those keywords inside
LexFortran.cxx and I'd be done?

   Keywords are defined by the caller as you often want to tweak these a bit
without touching the lexer code. So to use the VB lexer with different
keywords, use the SetKeyWords method which takes a keyword set (0 for vb)
and a space separated string of keywords.

   Neil

Ok, after much thought (DUH!), I think I am going to start by highlighting stuff myself.

So now, is there a way to Set a Style to some Text, and how does it work? Ideally, I’d love to do it with regular expressions. So I’d look for some re_exp and then set its style to whatever I wish.

> Hassan:
> > As far as I can see from source rpm of wxPython,
> > all I need to do is add a LexFortran.cxx which would
> > be a copy of LexVB.cxx with VB changed to Fortran
> > and then define SCLEX_FORTRAN in an include file.
> > Then I'd rebuild the rpm, right?
>
> You'll have to link your lexer in by modifying the wxForceScintillaLexers
> function in contrib\stc\contrib\src\stc\stc.cpp.in and add it to
> makefile.in. Then run the gen_iface.py script and then make. I've never done
> this but it looks right.
>
> > All, I'd have to do is replace those keywords inside
> > LexFortran.cxx and I'd be done?
>
> Keywords are defined by the caller as you often want to tweak these a bit
> without touching the lexer code. So to use the VB lexer with different
> keywords, use the SetKeyWords method which takes a keyword set (0 for vb)
> and a space separated string of keywords.
>
> Neil
>
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> [http://lists.wxwindows.org/mailman/listinfo/wxpython-users](http://lists.wxwindows.org/mailman/listinfo/wxpython-users)
···

On 02 Aug 2001 23:44:52 +1000, Neil Hodgson wrote:


H. Aurag
Aircraft Systems Specialist - Host Update Group
Engineering Updates Department
CAE Inc.
Phone: 2500
**Email: **aurag@cae.com


If I had only known, I would have been a locksmith.

-- Albert Einstein


Hassan
I don't really know the answer, but I just remembered that I saw in the
demo files a class called wxPyEditor which inherits from wxEditor
(py_editor.py and editor.py files) that is used for editing python code.
I didn't really read much in that code, but I think that you could do
some changes to their class Tokenizer and get something useful.

Again... I've never really used or read any code there throughly at all,
but I thought I could be useful for you if you haven't taken a look to
it yet.

Raul Cota

···

Hassan Aurag wrote:

Ok, after much thought (DUH!), I think I am going to start by
highlighting stuff myself.

So now, is there a way to Set a Style to some Text, and how does it
work? Ideally, I'd love to do it with regular expressions. So I'd look
for some re_exp and then set its style to whatever I wish.

On 02 Aug 2001 23:44:52 +1000, Neil Hodgson wrote:

> Hassan:
> > As far as I can see from source rpm of wxPython,
> > all I need to do is add a LexFortran.cxx which would
> > be a copy of LexVB.cxx with VB changed to Fortran
> > and then define SCLEX_FORTRAN in an include file.
> > Then I'd rebuild the rpm, right?
>
> You'll have to link your lexer in by modifying the wxForceScintillaLexers
> function in contrib\stc\contrib\src\stc\stc.cpp.in and add it to
> makefile.in. Then run the gen_iface.py script and then make. I've never done
> this but it looks right.
>
> > All, I'd have to do is replace those keywords inside
> > LexFortran.cxx and I'd be done?
>
> Keywords are defined by the caller as you often want to tweak these a bit
> without touching the lexer code. So to use the VB lexer with different
> keywords, use the SetKeyWords method which takes a keyword set (0 for vb)
> and a space separated string of keywords.
>
> Neil
>
>
>
> _______________________________________________
> wxpython-users mailing list
> wxpython-users@lists.wxwindows.org
> http://lists.wxwindows.org/mailman/listinfo/wxpython-users

----------------------------------------------------------------------

H. Aurag
Aircraft Systems Specialist - Host Update Group
Engineering Updates Department
CAE Inc.
Phone: 2500
Email: aurag@cae.com
----------------------------------------------------------------------

If I had only known, I would have been a locksmith.
-- Albert Einstein
----------------------------------------------------------------------

[Please don't send html mail messages to this list.]

So now, is there a way to Set a Style to some Text, and how does it
work? Ideally, I'd love to do it with regular expressions. So I'd look for
some re_exp and then set its style to whatever I wish.

The way it is designed to be done is to catch the EVT_STC_STYLENEEDED event.
Then, IIRC, the position in the event object is how far you need to set the
style info, and you can call GetEndStyled to find out where to start from.
Then you can use StartStyling and SetStyling to set the styles in your
document for that range.

···

--
Robin Dunn
Software Craftsman
robin@AllDunn.com Java give you jitters?
http://wxPython.org Relax with wxPython!