Syntax highlighting for Forth?
Syntax highlighting for Forth?
How do I set up syntax highlighting for the Forth language? Does anyone have a wordlist for this, especially for the Forth-83 style?
Zeus does come with a Forth document type defined for the following file extensions:
but as I am not a Forth programmer it is hard to say how accurate the definition actually is 
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
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
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
Code: Select all
f;fs;fs8;fsg;fsw;fsz;fsh;fse;fsy;fsp;fsu;fsf;fsa;fsx

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

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

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
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?
(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?
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]+).What is being done in the above string? How does it work?
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: Select all
0x01af
0x02bfh
0x03CF
0x03CFH
In this case something like this would work better:I ask, because the above string does not work for syntax coloring of numbers in my Forth language
Code: Select all
[0-9]+[.]*[e0-9]*
Code: Select all
[0-9]+
[0-9]+[.]*
[0-9]+[.]*[e0-9]*
Cheers Jussi
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)
[.]*[+]*[-]*[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)
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?
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?
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: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.
Code: Select all
"a string"
" a string"
" a string "
I found the following way to do this:Is there a way to specify that ." is also a string function, so that the whole thing is displayed in the string-color?
- Define the strings as per usual using the " character
- Select the user "1: defined words" option
- In the pattern section enter the following characters: ."*"
- Change to the coloring section and set the color for the user defined words to match the color of the strings.

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.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.
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

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.But if I add a space within the comment, then the second line is colored correctly, as in:
Do you have some example code that has the comments colored incorrectly as soon as the file is loadedIs there a way to fix this, so that I do not have to go through all my previous code, adding and subtracting spaces?

Cheers Jussi
Last edited by jussij on Tue Dec 07, 2010 4:53 am, edited 1 time in total.
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
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
Hi Tony,
All document types are limited to one and only block comment and two line comments.
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
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
Cheers Jussi
Unfortunately there is no way to do thisMy 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.

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.I can't figure out a pattern to allow the brace delimited block comments.
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

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

Cheers Jussi
I too would like to see the word files. Please send to robert1111@starcenter.com