Zeus IDE Forum Index Zeus IDE
Use this forum to ask for help, submit a bug report or make a suggestion.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Syntax highlighting for Forth?

 
Post new topic   Reply to topic    Zeus IDE Forum Index -> General
View previous topic :: View next topic  
Author Message
robert37
Guest





PostPosted: Wed Jan 19, 2005 8:12 am    Post subject: Syntax highlighting for Forth? Reply with quote

How do I set up syntax highlighting for the Forth language? Does anyone have a wordlist for this, especially for the Forth-83 style?
Back to top
jussij
Site Admin


Joined: 13 Aug 2004
Posts: 2201

PostPosted: Wed Jan 19, 2005 2:07 pm    Post subject: Reply with quote

Zeus does come with a Forth document type defined for the following file extensions:
Code:
f;fs;fs8;fsg;fsw;fsz;fsh;fse;fsy;fsp;fsu;fsf;fsa;fsx

but as I am not a Forth programmer it is hard to say how accurate the definition actually is Sad

In an effort to test the validity of the definition I found this web page: http://astro.pas.rochester.edu/Forth/forth-words.html
and saved the text to a dummy forth file and then loaded the file in Zeus.

The first thing I noticed was none of the keywords where highlighted so I went to the Zeus document type and turned off the case sensitivity.

Now some of the keywords where highligted but many where missing, so I added the missing words to the existing forth keywords file. After importing this new keyword list into the document type, from what I could tell all the keywords listed where now highlighted Smile

The new keywords file can be found here: http://www.zeusedit.com/fwords.txt

But I must stress this does mean the highlighting is actually correct Sad

Since my understand of the Forth language it is very limited it is hard to tell if the highlighting is in fact correct. If this new keyword list does seem to work could you please post back here as I will then update the current installer.

Cheers Jussi
Back to top
View user's profile Send private message Send e-mail
robert37



Joined: 19 Jan 2005
Posts: 17

PostPosted: Thu Jan 20, 2005 12:57 am    Post subject: Reply with quote

Thank you for this work that you have done. I will try out the wordlist immediately.

Can I somehow include the extension .fth in your list of Forth extensions? How would I do this?
Back to top
View user's profile Send private message
jussij
Site Admin


Joined: 13 Aug 2004
Posts: 2201

PostPosted: Thu Jan 20, 2005 6:37 am    Post subject: Reply with quote

Sure. Just edit the Forth document type using the Options, Document Types menu and add fth; to the list of file extensions.

Cheers Jussi
Back to top
View user's profile Send private message Send e-mail
robert37



Joined: 19 Jan 2005
Posts: 17

PostPosted: Thu Feb 10, 2005 6:50 am    Post subject: Reply with quote

I do not understand the numbers string for syntax highlighting. For instance, you have provided a default string of:
(0x*[0-9A-Fa-f]+[Hh]*)|([0-9]+)

What is being done in the above string? How does it work?

I ask, because the above string does not work for syntax coloring of numbers in my Forth language setup. I use only decimal numbers, such as:

1
123
+45
-222
1.23E0
-2.222e-4
-0.174e2
etc. Just the symbols 0-9 + - . E

I would like for any and all of the above number types to be highlighted with the number-color specified in Zeus. How would I create a number-string to accomplish this?
Back to top
View user's profile Send private message
jussij
Site Admin


Joined: 13 Aug 2004
Posts: 2201

PostPosted: Thu Feb 10, 2005 12:59 pm    Post subject: Reply with quote

Quote:
What is being done in the above string? How does it work?

This is a two part regular expression which reads a number is defined as this (0x*[0-9A-Fa-f.]+[Hh]*) or as this ([0-9]+).

If you take the second part ([0-9]+) first it says search for a set (ie []) of characters in the range of 0-9. The + sign means at least one. Thus in English the expression reads find one or more characters in the range 0 thru 9.

Next consider the first part (0x*[0-9A-Fa-f]+[Hh]*) of the string.

The 0x* reads search for the optional characters 0x where the presence of the * makes this part optional. The next part [0-9A-Fa-f]+ reads find one or more of the characters in the set of 0 thru 9 or the letters a thru f or the letters A thru F. The final part again is an optional match for the characters h or H.

Hence this pattern is designed to match these type of hexidecimal numbers:

Code:
0x01af
0x02bfh
0x03CF
0x03CFH


Quote:
I ask, because the above string does not work for syntax coloring of numbers in my Forth language


In this case something like this would work better:

Code:
[0-9]+[.]*[e0-9]*

I find writing regular expression always involves a bit of trial and error. I start with a small expression and just keep adding to it, for example to come up with this pattern I would build it in these steps:
Code:

[0-9]+
[0-9]+[.]*
[0-9]+[.]*[e0-9]*

At each step I can test the expression using the Find Dialog and turning on the regular expression option.

Cheers Jussi
Back to top
View user's profile Send private message Send e-mail
robert37



Joined: 19 Jan 2005
Posts: 17

PostPosted: Mon Feb 21, 2005 2:37 am    Post subject: Reply with quote

Thank you. For the Forth language, I have made the following number string, which seems to work:

[.]*[+]*[-]*[0-9]+[.]*[0-9]*[eE]*[+]*[-]*[0-9]*

Now, I have another question. In Forth, strings are compiled by enclosing them in quotes with a leading space, as in:

" THIS IS A QUOTE"

The first " must be followed by a space, and the last " needs no space.

Putting a " in the Zeus string keyword box, this seems to work fine. All such quoted strings are displayed in the chosen string color.

However, there is another word, used within a Forth word, that prints a string. It is .", as in:

." THIS IS A STRING"

The point-quote must be followed by a space, and the closing quote needs no space.

At present, the point part of the above is colored in text-color, while the quotes and the string are displayed in the string color. Is there a way to specify that ." is also a string function, so that the whole thing is displayed in the string-color? I tried adding ." to the string-keyword box, but then Zeus colored all periods in the string color. Is there a way to include ." and " as string functions, while . is not?

Another question: in Forth, comments begin with parenthesis-space and end with parenthesis, as in:

( THIS IS A COMMENT)
Back to top
View user's profile Send private message
robert37



Joined: 19 Jan 2005
Posts: 17

PostPosted: Mon Feb 21, 2005 2:48 am    Post subject: Reply with quote

Somehow, my previous message got sent before I finished it. Here is the complete message:

Thank you. For the Forth language, I have made the following number string, which seems to work:

[.]*[+]*[-]*[0-9]+[.]*[0-9]*[eE]*[+]*[-]*[0-9]*

Now, I have another question. In Forth, strings are compiled by enclosing them in quotes with a leading space, as in:

" THIS IS A QUOTE"

The first " must be followed by a space, and the last " needs no space.

Putting a " in the Zeus string keyword box, this seems to work fine. All such quoted strings are displayed in the chosen string color.

However, there is another word, used within a Forth word, that prints a string. It is .", as in:

." THIS IS A STRING"

The point-quote must be followed by a space, and the closing quote needs no space.

At present, the point part of the above is colored in text-color, while the quotes and the string are displayed in the string color. Is there a way to specify that ." is also a string function, so that the whole thing is displayed in the string-color? I tried adding ." to the string-keyword box, but then Zeus colored all periods in the string color. Is there a way to include ." and " as string functions, while . is not?

Another question: in Forth, comments begin with parenthesis-space and end with parenthesis, as in:

( THIS IS A COMMENT)

In Zeus, I have entered ( for the comment-start and ) for the comment-end. This works fine, and the comment text and the parentheses are collored in the chosen comment-color.

However, a strange thing happens. Sometimes, the code following the comment is also colored in the comment-color, as if the closing ) were not there. But I can stop this by adding or subtracting a space within the comment line.

For instance, in the following code, the second line is erroneously colored in the comment-color:

: POLY2 ( A B C T X: X=A+BT+CT^2)

FDUP 2 FROLL F* 2 FROLL F+ F* F+ ;

But if I add a space within the comment, then the second line is colored correctly, as in:

: POLY2 ( A B C T X: X=A+BT+CT^2)

FDUP 2 FROLL F* 2 FROLL F+ F* F+ ;

Please note, that I have added an extra space between the A and the B within the comment.

Is there a way to fix this, so that I do not have to go through all my previous code, adding and subtracting spaces?
Back to top
View user's profile Send private message
jussij
Site Admin


Joined: 13 Aug 2004
Posts: 2201

PostPosted: Mon Feb 21, 2005 3:36 am    Post subject: Reply with quote

Quote:
The first " must be followed by a space, and the last " needs no space. Putting a " in the Zeus string keyword box, this seems to work fine.

One thing you will have noticed is that the numbers field is the only field that is a regular expression. Thus putting a '' in the quotes field will work but Zeus will highlight all of these as strings:

Code:
"a string"
" a string"
" a string "

Quote:
Is there a way to specify that ." is also a string function, so that the whole thing is displayed in the string-color?

I found the following way to do this:

  1. Define the strings as per usual using the " character
  2. Select the user "1: defined words" option
  3. In the pattern section enter the following characters: ."*"
  4. Change to the coloring section and set the color for the user defined words to match the color of the strings.

From the little testing that I did, this seemed to work just fine Smile

Quote:
However, a strange thing happens. Sometimes, the code following the comment is also colored in the comment-color, as if the closing ) were not there.

As a test I created a new, empty forth file and pasted your 4 lines of code into the file but for me the comment block coloring seemed to work fine.

So I can only guess is that since the ) is both a comment and a delimiter the Zeus coloring might be getting a bit confused. Does Forth need () defined as delimiters Confused If not I would try removing these characters from the list of delimiters. Also, one way to re-synch the coloring would be to File Save the file and then use the File Reload menu. If the coloring is confused, running these to commands should get it back on track.

Quote:
But if I add a space within the comment, then the second line is colored correctly, as in:

I am guessing the action of adding the character triggered a the coloring re-sysnch similar to the File Save command I described earlier and this results in the comments being pained correctly.

Quote:
Is there a way to fix this, so that I do not have to go through all my previous code, adding and subtracting spaces?

Do you have some example code that has the comments colored incorrectly as soon as the file is loaded Confused If so post a small sample of code here, and I will try to replicate the bug at this end.

Cheers Jussi


Last edited by jussij on Tue Dec 07, 2010 4:53 am; edited 1 time in total
Back to top
View user's profile Send private message Send e-mail
TonyMc



Joined: 16 Apr 2005
Posts: 8
Location: Birmingham

PostPosted: Sun Apr 17, 2005 2:42 pm    Post subject: Reply with quote

Hello,

I have put together a syntax highlighting definition for SwiftForth which may be helpful to others. I have treated all words in the ANS Forth CORE wordset as keywords, words in other ANS Forth wordsets as User defined (set 1) and words specific to SwiftForth as User defined (set 2). This works well.

My only difficulty is that I would like to specify block comments in two ways. The ANS Forth standard uses ( blah blah ... ) comments and SwiftForth uses { blah blah .. } as an extension. I can't figure out a pattern to allow the brace delimited block comments. As a regular expression it would be { [^}]*} but patterns seem to be more limited than regexps. Can anyone help?

I removed all the characters from the delimites input field. Only whitespace delimits Forth words.

I can send the various wordsets as txt files ready for import using the keywords dialog if others are interested.

Best,
Tony
Back to top
View user's profile Send private message
Guest






PostPosted: Mon Apr 18, 2005 3:02 am    Post subject: Reply with quote

Hi Tony,

Quote:
My only difficulty is that I would like to specify block comments in two ways. The ANS Forth standard uses ( blah blah ... ) comments and SwiftForth uses { blah blah .. } as an extension.

Unfortunately there is no way to do this Sad All document types are limited to one and only block comment and two line comments.

Quote:
I can't figure out a pattern to allow the brace delimited block comments.

The comment entries can not be defined as regular expressions. In fact you will notice the comment entry fields only accepts up to a maximum of three characters. This is done for performance reason.

Lots of the code in Zeus (including the syntax highlighting) was originally written to run on 80386 machines and these 60-100 Mhz machine had no where near the power todays GHz machines So lots of the code in Zeus had to be highly optimized for performance and not flexibility Sad

Quote:
I can send the various wordsets as txt files ready for import using the keywords dialog if others are interested.

If you send the files to jussij@zeusedit.com I will be more than happy to update the Forth document type of the Zeus installer Smile

Cheers Jussi
Back to top
robert37



Joined: 19 Jan 2005
Posts: 17

PostPosted: Mon Apr 18, 2005 8:02 am    Post subject: Reply with quote

I too would like to see the word files. Please send to robert1111@starcenter.com
Back to top
View user's profile Send private message
jussij
Site Admin


Joined: 13 Aug 2004
Posts: 2201

PostPosted: Fri Feb 24, 2012 4:14 am    Post subject: Reply with quote

Quote:
All document types are limited to one and only block comment and two line comments.

The later versions of Zeus now have room for two block comments and two line comments so it is now possible to specify block comments in two ways Wink

Cheers Jussi
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    Zeus IDE Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group