Page 1 of 1

Request for new language support - Clarion

Posted: Thu Feb 23, 2006 10:13 am
by Turotulco
Clarion actually has two languages. There is the Source Generation (or Template) language, and then there is the Clarion source language itself.

This is an example of the Clarion source language. It produces a clean compile but otherwise is total nonsense. It is very badly formated by design, to facilitate testing. It parses clean.

I'm not sure if the "OMIT" structure can be accomodated, it's kind of weird. Basically it will omit all code up to and including the supplied string.

Code: Select all

    Extension: .clw ; .cla
 Line Comment: ! 
Block Comment: none 
        Begin: Program
          End: none
        Begin: Module
          End: End
        Begin: File       (has a label in column 1)
          End: End
        Begin: Record     (has a label in column 1)
          End: End
        Begin: Procedure  (has a label in column 1)
          End: none 
        Begin: Function   (has a label in column 1)
          End: none 
        Begin: Routine    (has a label in column 1)
          End: none
        Begin: Data
          End: Code
        Begin: Code
          End: none
        Begin: Loop       (Can have a label in column 1. Optional)
          End: End
        Begin: If
          End: End
        Begin: Case
          End: End
        Begin: Execute
          End: End
        Begin: OMIT
          End: (The string specified in the OMIT statement)

Note: END keyword can also be represented by a period (.)

  Sample Code: 

  PROGRAM

Taglines             FILE,DRIVER('TOPSPEED'),RECLAIM,PRE(TAG),BINDABLE,CREATE,THREAD
Key_MD5                  KEY(TAG:MD5),DUP,NOCASE,OPT
Key_ID                   KEY(TAG:TAG_ID),NOCASE,OPT,PRIMARY
Record                   RECORD,PRE()
TAG_ID                      LONG
Tagline                     STRING(4096)
MD5                         CSTRING(32)
                         END
                     END
  MAP
Main      PROCEDURE
Dis       Function(STRING p:linein),STRING

   MODULE('WinAPI')
  AttachThreadToClarion (BOOL Full),PASCAL
   END ! Module
  END !Map

  CODE
  Main()

Main  PROCeDURE
                     
StartDay             LONG
Of_Beer              String(20)
Got_Beer             BYTE(20)
UnLooped             LONG
Hell_Freezes_Over    LONG

  CoDE
  ! This is a single line comment

  If TODAY() = StartDay
     Do something_daring
  EnD ! IF    -    (I usually end my structures with a comment)

  Case Of_Beer
     OF 'Ringnes'
     OF 'Budweiser'
     OF 'Hansa'
     OF 'Tuborg'
  End ! Case Of_Beer

  Loop UnTiL NoT Got_Beer
     Got_Beer -= 1
  END ! Loop

  OMIT('This code')
  Rollover()
  Reboot() 
  PlayDead()
  'This code'  ! String comparisons are case sensitive even if the 
               ! language isn't              
 
  OPEN(Taglines)
FirstLoop LOOP until Unlooped
   TAG:TAG_ID += 1
   SET(TAG:Key_ID,TAG:Key_ID)
SecondLoop LOOP Until Hell_Freezes_Over
      Next(Taglines)
      IF ERRORCODE()
         Break FirstLoop
      END ! IF
      Hell_Freezes_Over -= 1
    End ! SecondLoop
  END ! FirstLoop 
  Close(Taglines)

Something_Daring ROUTINE
  DaTA
A_Number   LONG
  Code
  A_Number = Random(1,4)
  EXECUTE(A_Number)
     Of_Beer = 'Ringnes'
     Of_Beer = 'Budweiser'
     Of_Beer = 'Hansa'
     Of_Beer = 'Tuborg'
  END ! Execute

Dis  Function(STRING p:linein)
Somevar        LONG
AnyOfThisMakesSense  LONG
ReturnString   STRING(120)
   CODE
   IF Somevar
      ReturnString = 'Yep!'
   Else
      ReturnString = 'nope'
   END !IF

   IF AnyOfThisMakesSense THEN RETURN('0').  !This is a valid variation of an if statement

   RETURN(ReturnString)

Notes:

This example code produces a clean compile and demonstrates every
keyword structure in the Clarion source language.

Clarion is case insensitive. procedure, Procedure and PROCEDURE
are all considered the same. This example code is difficult to
read because I have intentionally mixed the case of the keywords
for testing purposes.


Column 1 in all Clarion source is reserved to indicate a label.
Procedure names, variable names, all begin in column 1. So the
structure names that have labels will always be the second word
on the line, with the exception of Loop which may or may not have
a label. This exception is useful for breaking an inner loop when
you really want to break out of the topmost loop. I have provided
examples of both.


The END keyword can have a period (.) used as an indicator. i.e.

Map
.

Or

Map.

This is probably going to be removed in the future but there is
20 years of legacy code that still use this syntax. I hate it.
But I didn't design the language. I have provided examples of
this structure in the source code.


*.clw is the windows source file suffix, *.cla is the older DOS
suffix. The code is substantially the same. This folding scheme
should support Clarion source code written in the 1980's

If you are interested, I have syntax highlighting keyword
lists available for adding as a supported language.

Posted: Thu Feb 23, 2006 10:32 am
by jussij
Thank you for posting such a detail Clarion folding definition. Check back here in a few days time and there should be a replacement folding dll available.
If you are interested, I have syntax highlighting keyword lists available for adding as a supported language.
That would be great :)

Could you send the keyword list to info@zeusedit.com with the subject of Clarion Zeus Keywords.

Cheers Jussi

Posted: Thu Feb 23, 2006 12:27 pm
by Turotulco
I wondered what happened. :) Here's the additional folds and a new copy of the sample code with the structures in place.

Code: Select all

    Extension: .clw ; .cla
 Line Comment: !
Block Comment: none
        Begin: Program
          End: none
        Begin: Module
          End: End
        Begin: File       (has a label in column 1)
          End: End
        Begin: Record     (has a label in column 1)
          End: End
        Begin: Procedure  (has a label in column 1)
          End: none
        Begin: Function   (has a label in column 1)
          End: none
        Begin: Routine    (has a label in column 1)
          End: none
        Begin: Data
          End: Code
        Begin: Code
          End: none
        Begin: Loop       (Can have a label in column 1. Optional)
          End: End
        Begin: If
          End: End
        Begin: Case
          End: End
        Begin: Execute
          End: End
        Begin: OMIT
          End: (The string specified in the OMIT statement) 
        Begin: Queue
          End: End
        Begin: Group
          End: End
        Begin: Class
          End: End
        Begin: Interface
          End: End
        Begin: Itemize
          End: End

  Sample Code: 

  PROGRAM

Taglines             FILE,DRIVER('TOPSPEED'),RECLAIM,PRE(TAG),BINDABLE,CREATE,THREAD
Key_MD5                  KEY(TAG:MD5),DUP,NOCASE,OPT
Key_ID                   KEY(TAG:TAG_ID),NOCASE,OPT,PRIMARY
Record                   RECORD,PRE()
TAG_ID                      LONG
Tagline                     STRING(4096)
MD5                         CSTRING(32)
                         END
                     END
  MAP
Main      PROCEDURE
Dis       Function(STRING p:linein),STRING


   MODULE('WinAPI')
  AttachThreadToClarion (BOOL Full),PASCAL
   END ! Module
  END !Map





  CODE
  Main()


Main  PROCeDURE

Example              QUEUE
AVar                    STRING(120)
BVar                    LONG
                     END


Color                Group
Red                     LONG
Blue                    LONG
Green                   LONG
                     END

Classify             CLASS
Var                  LONG 
! Just fold these. If I define the procedures here I'll have to write them too!
                     END

                     ITEMIZE(1)
AConstant              EQUATE
BConstant              EQUATE
                     END

Another              INTERFACE
! Another fold
! I don't want to write any interfaces either!
                     END

                     
StartDay             LONG
Of_Beer              String(20)
Got_Beer             BYTE(20)
UnLooped             LONG
Hell_Freezes_Over    LONG

  CoDE
  ! This is a single line comment

  If TODAY() = StartDay
     Do something_daring
  EnD ! IF    -    (I usually end my structures with a comment)

  Case Of_Beer
     OF 'Ringnes'
     OF 'Budweiser'
     OF 'Hansa'
     OF 'Tuborg'
  End ! Case Of_Beer

  Loop UnTiL NoT Got_Beer
     Got_Beer -= 1
  END ! Loop

  OMIT('This code')
  Rollover()
  Reboot()
  PlayDead()
  'This code'


  OPEN(Taglines)
FirstLoop LOOP until Unlooped
   TAG:TAG_ID += 1
   SET(TAG:Key_ID,TAG:Key_ID)
SecondLoop LOOP Until Hell_Freezes_Over
      Next(Taglines)
      IF ERRORCODE()
         Break FirstLoop
      END ! IF
      Hell_Freezes_Over -= 1
    End ! SecondLoop
  END ! FirstLoop 
  Close(Taglines)

Something_Daring ROUTINE
  DaTA
A_Number   LONG
  Code
  A_Number = Random(1,4)
  EXECUTE(A_Number)
     Of_Beer = 'Ringnes'
     Of_Beer = 'Budweiser'
     Of_Beer = 'Hansa'
     Of_Beer = 'Tuborg'
  END ! Execute

Dis  Function(STRING p:linein)
Somevar        LONG
AnyOfThisMakesSense  LONG
ReturnString   STRING(120)
   CODE
   IF Somevar
      ReturnString = 'Yep!'
   Else
      ReturnString = 'nope'
   END !IF

   IF AnyOfThisMakesSense THEN RETURN('0').  !This is a valid variation of an if statement

   RETURN(ReturnString)


Posted: Thu Feb 23, 2006 9:07 pm
by jussij
Thanks :)

Jussi

Posted: Mon Feb 27, 2006 8:23 am
by jussij
The Clarion code folding for changes have been made and the new xFolder.dll can be found here:

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

To install this new dll backup the current dll and replace it with the one contained in the zip file.

To complete the install you will need to create a Clarion document type and enable the code folding option.

The fold options for Procedure, Code, Data and Function where not be added.

The reason being the current Zeus folder needs either a matching pair of start and end fold keywords or otherwise an indent level to identify the fold points. From the specification provided, none of these fold points fit this current model :(

Cheers Jussi

Posted: Mon Feb 27, 2006 8:50 am
by Turotulco
Thanks Jussi!

I just installed it and it works like a charm.

On the end words, can their be multiple choices?

If so, PROCEDURE will always end with either another PROCEDURE or FUNCTION. Same for FUNCTION

DATA will always end with CODE

CODE will always end with PROCEDURE, ROUTINE or FUNCTION

It might be a problem because the end word then becomes the begin word of the next block. Since I don't know how the parser keeps track of itself, I'm only guessing.

Just a thought.

I'm desk checking my keyword lists and a description of the Template language. I want to be certain all of the info is precisely correct before passing it over to you.

b. rgds.
Richard

Posted: Mon Feb 27, 2006 12:09 pm
by jussij
On the end words, can their be multiple choices?

Unfortunately this is notcurrently possible :(

The fold parser design is very primitive and is even fooled by certain coding styles (ie multiple end or start folds per line). But for well formated code it dows seem to work suprisingly well :)
If so, PROCEDURE will always end with either another PROCEDURE or FUNCTION. Same for FUNCTION DATA will always end with CODE CODE will always end with PROCEDURE, ROUTINE or FUNCTION
Using indenting it could be made to fold code that looks like this:

Code: Select all

Something_Daring ROUTINE
  DaTA
  A_Number   LONG
  Code
  A_Number = Random(1,4)
  EXECUTE(A_Number)
     Of_Beer = 'Ringnes'
     Of_Beer = 'Budweiser'
     Of_Beer = 'Hansa'
     Of_Beer = 'Tuborg'
  END ! Execute
but note this only works because of the indent levels. This is exactly how the Python folder also works.

Alternatively the Function code could also be made to fold if Return is used as the matching end of fold, but unfortunately since the Return is optional, this is not an ideal solution :(

I suspect that with some redesign, it should be possible to enhance the folding engine to achieve this sort of folding result, but for now this is the best it can do ;)

Cheers Jussi

Posted: Mon Feb 27, 2006 12:53 pm
by Turotulco
I have no problem with enforcing good code formatting. <g>

Actually, the parser does work suprisingly well as you say. It even understood this weird construct (not my code):

Code: Select all

If Something
   !some code
Else ; If somethingelse
 exit end
   !More code
End
It catches and correctly processes the inner if.

In working over the Template language I find the same parsing problem exists. A section begins with, say... #EXTENSION which starts an extension template. The way it knows it should end is by encountering another #EXTENSION or #CODE or #GROUP or... well, you get the idea. Same problem.

I'll finish the spec and send it along. Maybe someday an answer will appear.