FORTRAN syntax file

Discuss syntax highlighting or submit new syntax files.
jgodfrey
Posts: 471
Joined: 19 Aug 2011 23:02
Location: Missouri, USA

FORTRAN syntax file

Post by jgodfrey »

I'm attempting to set up a FORTRAN syntax file (yeah, I know... ;)), but am struggling with the column-specific nature of the language.

For instance, in F77, a comment is denoted by either a "C" or an asterisk, but it must specifically be in column 1. Currently, I don't see any way to do that in a syntax definition. I can define the "C" character, and say that it must be the first non-white space character in the line, but then the highlighter thinks the following legitimate code is a comment:

Code: Select all

             CALL INSTR(CUT, FSTR, FN)
because the first non-whitespace character is a "C".

Are there any tricks for accomplishing this?

Jeff
User avatar
pjj
Posts: 2129
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: FORTRAN syntax file

Post by pjj »

jgodfrey wrote:I'm attempting to set up a FORTRAN syntax file (yeah, I know... ;))
Fortran! I first programmed in Fortran, some 25 years ago! We used special sheets to write our (very simple) code, which werre subsequently "compiled" on special perforated cards...
Image
Ahh, memories.

Anyway, Rickard, for some time I've been thinking about similar feature request: similar in the sense that I was going to ask for a support for a very, err, unorthodox file format, namely YAML: http://www.yaml.org/spec/1.2/spec.html Thing is, it has no keywords, just structure (roughly speaking, it is supposed to be a substitute for XML, but better human-readable and easier maintainable). As you can see from samples on the website, it has no tags, or, should I say, its tags have no braces. I haven't attempted to define a syntax file for YAML, but something is telling me that it would be impossible within current specifications, due to the very fluid YAML form. I am writing this because maybe you would need to find completely new way to ensure support for Fortran language (a plugin rather than massive rework of the current code) and if there are more than just one reason to take it into consideration (now it would be two ;)) you would be more inclined to give it some thought?
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
User avatar
Rickard Johansson
Site Admin
Posts: 6627
Joined: 19 Jul 2006 14:29

Re: FORTRAN syntax file

Post by Rickard Johansson »

The syntax option "OnlyLineCommentIfFirstChar" can now have 3 values in v7.63.

OnlyLineCommentIfFirstChar=2 means the line comment start character has to be the first character on the line.
User avatar
Rickard Johansson
Site Admin
Posts: 6627
Joined: 19 Jul 2006 14:29

Re: FORTRAN syntax file

Post by Rickard Johansson »

YAML highlighting may be difficult to accomplice. Using external highlighters is probably not an option. Any external script need an API to work with and that API just doesn't exist.
jgodfrey
Posts: 471
Joined: 19 Aug 2011 23:02
Location: Missouri, USA

Re: FORTRAN syntax file

Post by jgodfrey »

Rickard Johansson wrote:The syntax option "OnlyLineCommentIfFirstChar" can now have 3 values in v7.63.

OnlyLineCommentIfFirstChar=2 means the line comment start character has to be the first character on the line.
Thanks!

I wonder though, with the addition of regex definitions, (my other related post) would I also be able to define my comment character as:

Code: Select all

^C
Jeff

Edit: Reading your other post, I think regex only applies to keywords, correct? So, I guess the above won't work. Though regex would be a nice addition to other areas of syntax definitions... ;)

Edit 2: For instance, the Fortran continuation character can be any character, but must appear in column 6. With regex, I could define that as:

Code: Select all

^      [+*&^]
... or whatever list of chars I wanted...

Edit 3: And, I could define the opening fold character for Tcl as:

Code: Select all

{$
That would resolve this item I think - http://www.rjsoftware.se/Forum/viewtopic.php?f=4&t=1813
Last edited by jgodfrey on 27 Aug 2011 15:30, edited 1 time in total.
jgodfrey
Posts: 471
Joined: 19 Aug 2011 23:02
Location: Missouri, USA

Re: FORTRAN syntax file

Post by jgodfrey »

Rickard,

I added an "Edit" "Edit 2" and "Edit 3" section in my above post in case you missed them.

Jeff
User avatar
Rickard Johansson
Site Admin
Posts: 6627
Joined: 19 Jul 2006 14:29

Re: FORTRAN syntax file

Post by Rickard Johansson »

Using regular expressions for code folding may seem like a good idea, but it actually doesn't help that much. You still need to match the { } characters to find the correct fold ending. So you still need to know the fold start "{" in plain text to match it properly.

It might be helpful with blocks though.

I'll add some more in v7.70.
User avatar
pjj
Posts: 2129
Joined: 13 Oct 2009 13:48
Location: Kraków, Poland

Re: FORTRAN syntax file

Post by pjj »

Rickard Johansson wrote:YAML highlighting may be difficult to accomplice.
Yes, I'm afraid it would require a kind of separate module to do just that.
Rickard Johansson wrote:Using external highlighters is probably not an option.
I pondered a bit about it and came to the same conclusion. They're just highlighters, and have no information about folding. Then, licensing issue comes up...
Alium tibi quaere fratrem; hic, quem tuum putas, meus est. Titus Flāvius Caesar Vespasiānus Augustus
jgodfrey
Posts: 471
Joined: 19 Aug 2011 23:02
Location: Missouri, USA

Re: FORTRAN syntax file

Post by jgodfrey »

Rickard Johansson wrote:The syntax option "OnlyLineCommentIfFirstChar" can now have 3 values in v7.63.

OnlyLineCommentIfFirstChar=2 means the line comment start character has to be the first character on the line.
Rickard,

I just tried this, and it works (mostly) as expected. However, this doesn't work properly:

Code: Select all

CCCCCCCCCCCCCCCCCCCCCCCCC
C SOME DESCRIPTIVE TEXT 
CCCCCCCCCCCCCCCCCCCCCCCCC
Above, the 1st and 3rd lines aren't highlighted as comments, though I'd expect them to be. It seems that the "C" must be followed by a space (or a word delimiter) in order to be seen as a comment. If I include a space as the 2nd character on lines 1 and 3 above, they highlight correctly.

Jeff
User avatar
Rickard Johansson
Site Admin
Posts: 6627
Joined: 19 Jul 2006 14:29

Re: FORTRAN syntax file

Post by Rickard Johansson »

It seems to work on my end using

LineCommentA=C
OnlyLineCommentIfFirstCharA=2

Could you recheck?
jgodfrey
Posts: 471
Joined: 19 Aug 2011 23:02
Location: Missouri, USA

Re: FORTRAN syntax file

Post by jgodfrey »

Rickard Johansson wrote:It seems to work on my end using

LineCommentA=C
OnlyLineCommentIfFirstCharA=2

Could you recheck?
Hmmm... It doesn't seem to work here. Using this syntax definition:

Code: Select all

;{}

[Keywords]
Keywords=allocatable|allocate|assign|backspace|block data|call|case|character|close|common|contains|continue|cycle|data|deallocate|dimension|do|else|else if|elseif|elsewhere|end|enddo|endfile|endif|entry|equivalence|exit|external|format|function|goto|if|implicit|include|inquire|integer|intent|interface|intrinsic|logical|module|namelist|nullify|only|open|operator|optional|parameter|pause|pointer|print|private|procedure|program|public|read|real|recursive|result|return|rewind|rewrite|save|select|sequence|stop|subroutine|taret|then|use|where|while|write|

[Options]
LineCommentA=C 
LineCommentB=!
OnlyLineCommentIfFirstCharA=2
OnlyLineCommentIfFirstCharB=2
String='
StringOnLine=1
Symbols=():*
Numbers=0123456789

[Fold]
1_Id=if
1_Begin=
1_End=endif
1_EndBefore=else
1_Section=
1_NoParentOfId=0
1_NotAlwaysEnded=0
1_ListItem=
2_Id=else
2_Begin=
2_End=endif
2_EndBefore=
2_Section=
2_NoParentOfId=0
2_NotAlwaysEnded=0
2_ListItem=
3_Id=subroutine
3_Begin=
3_End=end
3_EndBefore=
3_Section=
3_NoParentOfId=0
3_NotAlwaysEnded=0
3_ListItem=ceMethod
4_Id=function
4_Begin=
4_End=end
4_EndBefore=
4_Section=
4_NoParentOfId=0
4_NotAlwaysEnded=0
4_ListItem=ceMethod
5_Id=program
5_Begin=
5_End=end
5_EndBefore=
5_Section=
5_NoParentOfId=0
5_NotAlwaysEnded=0
5_ListItem=
I get the highlighting shown in the attached image:

Jeff
Attachments
fortran_highlight.png
fortran_highlight.png (8.33 KiB) Viewed 28146 times
jgodfrey
Posts: 471
Joined: 19 Aug 2011 23:02
Location: Missouri, USA

Re: FORTRAN syntax file

Post by jgodfrey »

Wait... Now it's working! I seem to get tripped up by some kind of highlighting cache that I don't understand. I haven't yet found a guaranteed way to know that highlighter changes I just made are being reflected in the file I'm looking at (short of closing TextEd). Sometimes, the highlight seems to refresh automatically. Sometimes changing the file-type selection to something incorrect and then changing it back shows the recent changes. Other times, closing the current file and reopening it shows the changes.

In the case of the above Fortran, I did all of the above, but still (apparently) got the incorrect highlighting. Finally, I closed TextEd and reopened it, then reopened my file - and all is OK.

What's the proper procedure for testing highlighter changes? Do I need to close the editor each time?

Thanks,

Jeff
jgodfrey
Posts: 471
Joined: 19 Aug 2011 23:02
Location: Missouri, USA

Re: FORTRAN syntax file

Post by jgodfrey »

In addition to the above response, Fortran is not case sensitive, and therefore the "C" comment character can be upper or lowercase. Currently, TextEd seems to only recognize a comment as defined (so, uppercase "C"). Maybe the comment parsing should leverage the CaseSensitive flag of the definition file?

Also, technically Fortran 77 allows the following comment characters (C, c, D, d), while Fortran 90 allows only (!). So, ignoring the upper/lower case differences, there are actually 3 comment chars. I don't suppose I can define multiples on in the same definition, can I? Something like "C|D|!".

Looking through the legacy code I support, I see that all 3 are used, though the "D" variation is only in a few places. So, if I can't define them all, it's not a big problem.

Thanks,

Jeff
User avatar
Rickard Johansson
Site Admin
Posts: 6627
Joined: 19 Jul 2006 14:29

Re: FORTRAN syntax file

Post by Rickard Johansson »

Seems you have an extra space after "C"

LineCommentA=C<space>

Just remove it and it should work.
jgodfrey
Posts: 471
Joined: 19 Aug 2011 23:02
Location: Missouri, USA

Re: FORTRAN syntax file

Post by jgodfrey »

Rickard Johansson wrote:Seems you have an extra space after "C"
Actually, I thought about that, but I don't think that was the case. Anyway, if you haven't seen my 2 previous responses, you might look at them.

Thanks,

Jeff
Post Reply