Forth language spec

This forum should be used for all code folding problems, questions or suggestions. You can also use this forum to request folding support for a new language.
Post Reply
TonyMc
Posts: 8
Joined: Sat Apr 16, 2005 6:51 pm
Location: Birmingham

Forth language spec

Post by TonyMc »

Dear Jussij,

here is a possible spec for ANS Forth. It covers loops, conditionals and colon definitions (the Forth equivalent of functions, where : starts a definition and ; completes it) as well as block comments. I hope this helps.

Tony

Extension: .f .fth
Line Comment: \ (backslash followed by whitespace)
Block Comment: ( ) (opening parenth followed by whitespace)
Block Comment: { } (opening brace followed by whitespace)
Begin: :
End: ;

Begin: BEGIN
End: REPEAT

Begin: IF
End: THEN

Begin: DO
End: LOOP

Begin: ?DO
End: LOOP

Begin: DO
End: +LOOP

Begin: ?DO
End: +LOOP

Begin: BEGIN
End: UNTIL

Begin: BEGIN
End: AGAIN

Sample Code:

Code: Select all

      : sample  ( -- )
        xxx xxx xxx
        yyy yyy
        zzz zzz ;

      : sample2  ( -- )
        0 > if
            xxx xxx xxx
        else
            yyy yyy yyy
        then ;


      : sample3  ( -- )
        begin
            0 < while
            xxx xx xxx
            yyy yyy yyy
        repeat ;

      : sample4  ( -- )
        100 0 ?do
            xxx xxx xxx
        loop ;

      : sample5  ( -- )
        begin
            xxx xxx xxx
        0= until ;

      : sample6  ( -- )
        begin
            xxx xxx xxx
            yyy yyy yyy
        again
        zz zzz zzz ;
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

Hi Tony,

The code folding for Forth has been implemented and the new xFolder.dll can be found here:

http://www.zeusedit.com/z300/xfolder.zip

The Forth specification you provided could only be partially implemented in that the above DLL has the following limitations:
(1) Whitespace
The xFolder ignores all whitespace, thus all the comments specifications where implemented but the "followed by whitespace" clause was not. Basicaly this means all (, ), {, } and \ characters are identified as a comment character.

If this is going to cause a problem just post a bug report to this thread and I will see if this limitation is easily fixed.

(2) Lines Containing Multiple End of Fold Markers
Your specification also highlighted a folding bug specific to all languages. :(

For any situation where two end of folds occur on the same line the second end of fold is lost, resulting in a folding error. For example this will code will fold incorrectly:

Code: Select all

: sample1  ( -- )
  begin
  repeat ;

: sample2  ( -- )
  begin
  repeat ;
but this code will fold correctly:

Code: Select all

: sample1  ( -- )
  begin
  repeat
  ;

: sample2  ( -- )
  begin
  repeat
  ;
This bug requires further investigation and will most likely require a change to the folding model. This means the editor itself will need to be changed so if this is the case the fixed will only be available in the next Zeus release.

Jussi
Last edited by jussij on Tue Jun 14, 2005 12:11 am, edited 1 time in total.
TonyMc
Posts: 8
Joined: Sat Apr 16, 2005 6:51 pm
Location: Birmingham

Post by TonyMc »

The code folding for Forth has been implemented and the new xFolder.dll can be found here:
Hi Jussi,

thanks for implementing this so quickly. I am really impressed by the quality of your support for Zeus. And thanks for the warning about two fold closings on the same line. That shouldn't be hard for me to work around, but it's great that you are also looking into this.

Best wishes,
Tony
Post Reply