Help to configure a new language

Get help with the installation and running of the Zeus IDE. Please do not post bug reports or feature requests here. When in doubt post your question here.
Post Reply
Allanon
Posts: 6
Joined: Sun Aug 03, 2014 8:18 am

Help to configure a new language

Post by Allanon »

Hello :)
I'm evaluating to purchase Zeus Ide that seems to have almost all features I need but I'm not able to configure it the way I like, so I'm asking help :)

I'm using the trial version for Windows, my OS is Windows 7.

I'd like to configure a custom language that is similar to Lua, there are just some differences I've already figured out, like comments and keywords.

What I'm still missing are:

** Function browsing : in my language functions are defined using the following template:

Code: Select all

Function foo()
   ...
EndFunction
The same for While ... Wend, Repeat ... Until, and some other statemenents.
So my language differs from Lua because instead of "end" there is a specific closing command like "EndFunction", "Wend" and so on...

** Classes/Tables/Methods browsing : it works exactly as Lua, classes are defined into tables, tables/classes members are accessed with a single dot <.> and methods are invoked using a colon <:>

** Code folding : can be configured by hand or it must be implemented into the xFolder.dll?

I've already read some posts about .ctags files but I've not clear where this file should be saved and with which name, and how I've to link the .ctag file with my own custom language definition.

Can someone help me to configure Zeus if it's possible?

P.S.: the language I'm trying to configure is Hollywood, it's a crossplatform language available for Linux, Windows, AmigaOS, MorphOS, AROS and a few more.

Thanks for any help you may provide :)
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

** Function browsing : in my language functions are defined using the following template:

To get the function browsing to work requires the ctags to be configured.

Here is a link to an example on how this is done: http://www.zeusedit.com/zforum/viewtopic.php?t=3367
** Classes/Tables/Methods browsing : it works exactly as Lua, classes are defined into tables, tables/classes members are accessed with a single dot <.> and methods are invoked using a colon <:>
The class section of the Navigator panel is also filled by the information generated by ctags.

The level of auto-complete in Zeus is language dependent.

Basically the auto-complete in some of the languages work better than others.
** Code folding : can be configured by hand or it must be implemented into the xFolder.dll?
For some simple languages it can be hand configured via the xFolder.ini file.

But in this case I suspect a change will need to be made to the xFolder.dll itself.

Details on this can be found here: http://www.zeusedit.com/zforum/viewtopic.php?t=103
I've already read some posts about .ctags files but I've not clear where this file should be saved and with which name, and how I've to link the .ctag file with my own custom language definition.

Did you see this link mention earlier: http://www.zeusedit.com/zforum/viewtopic.php?t=3367

It has a complete example of how to add a language to the .ctags file.

As described in the link you basically tell the ctags.exe where the .ctags file is located using a few environment variables.
Here are more informations if needed : http://www.hollywood-mal.com/
Thanks for the link. I'll be taking a closer look ;)

Cheers Jussi
Allanon
Posts: 6
Joined: Sun Aug 03, 2014 8:18 am

Post by Allanon »

Hello Jussi! Thank you for your quick reply!

I was able to move my first steps into ctags and Zeus after reading tons of webpages about ctags and regexp :D

Now I'm able to see functions with this regex:

Code: Select all

--regex-hw=/^[ \t]*(Local)*[ \t]*Function[ \t]+([a-zA-Z0-9_]+)[(]/\2/f,function/i
Functions are global if the keyword "Local" is not used.

Now I'm trying to trap anonymous functions, methods and table items but as I'm totally new to regular expression seems I've to study a lot before being able to achieve what I need.

Using the following regexp

Code: Select all

--regex-hw=/^[ \t]*(Local)*[ \t]*Function[ \t]+([a-zA-Z0-9_]+)(:)+([a-zA-Z0-9_]+)[(]/\2\3\4/m,method/i
I was able to have a method definition listed under the functions group, but I'd like to group methods under its object.

Here is a snippet:

Code: Select all

myObject = { a = 0, b = 0 }

Function myObject:new()
   Return(CopyTable(myObject))
EndFunction

Function myObject:addition()
   Return(self.a+self.b)
EndFunction

Local instance = myObject:new()
instance.a = 5
instance.b = 6
Print(instance:addition())
This seems to be a huge job for a totally regexp newbie like me :?
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

I dont know a lot about Hollywood but I'm assuming these are the items you are trying to identify:

Code: Select all

    -- a anonymous classs 
    myObject = { a = 0, b = 0 } 

    -- a method
    Function myObject:new() 
       Return(CopyTable(myObject)) 
    EndFunction 
    
    -- a method
    Function myObject:addition() 
       Return(self.a+self.b) 
    EndFunction 
    
    -- function
    Function myFunction() 
       Return(CopyTable(myObject)) 
    EndFunction 
Looking at the code the first thing you notice is that excluding white space, the thing you are looking for must be the first item of that line.

That means all the regular expressions will need to start with this pattern:

Code: Select all

^[\t ]*
So now we can write the regular expression for these constructs.

Here is the class regular expression where the match is \1 item.

Code: Select all

^[\t ]*([a-zA-Z0-9]+)+[\t ]*=[\t ]*{
Here is the method regular expression where the match is \1 item.

Code: Select all

^[\t ]*Function [a-zA-Z0-9]+:(.*)\(
Here is the function regular expression where the match is \1 item.

Code: Select all

^[\t ]*Function [^:]+([a-zA-Z0-9]+)\(
I was able to have a method definition listed under the functions group, but I'd like to group methods under its object.
I'm not sure if that is possible via the .ctags config approach.

But it should be possble by changing the ctags code directly.

If you send me same Hollywood sample code containing classes, methods, function aand annonymouns functions I take a look at this ;)
This seems to be a huge job for a totally regexp newbie like me
Never too soon to start learning ;)

FYI there are some simple examples of regexps in the help file. Just search for Regular Expression in the help index.

There is also an option in the Find dilaog that can help to debug the regexp search string.

In all seriousness, I'm always reading that regexps are hard and I just don't get that :?

I can understand how someone who's never seen a regexp before might think that, but to actully start writing regexps only requires learning a dozen or so rules, so it is not really that hard.

Cheers Jussi
Allanon
Posts: 6
Joined: Sun Aug 03, 2014 8:18 am

Post by Allanon »

Hi Jussi and thank you for your time :)

I have made some progresses, now I'm able to correctly display functions (with arguments) and classes with the following regexp:

Code: Select all

--regex-hw=/^[ \t]*(Local)*[ \t]*Function[ \t]+([a-zA-Z0-9_]+)(\(.*\))/\2\3/f,function/i
--regex-hw=/^[ \t]*(Local|Global)*[ \t]*([a-zA-Z0-9]+)[ \t]*=[ \t]*Function[ \t]+(\(.*\))/\2=Function\3/f,function/i
--regex-hw=/^[ \t]*(Local)*[ \t]*([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)[ \t]*=[ \t]*Function[ \t](\(.*\))/\2.\3=Function\4/f,function/i

--regex-hw=/^[ \t]*(Local|Global)*[ \t]*([a-zA-Z0-9]+)[ \t]*=[ \t]*{/\2/c,class/i
--regex-hw=/^[ \t]*(Local)*[ \t]*Function[ \t]+([a-zA-Z0-9_]+)(:)+([a-zA-Z0-9_]+)(\(.*\))/\2\3\4\5/c,class/i 
--regex-hw=/^[ \t]*(Local)*[ \t]*([a-zA-Z0-9_]+)\.([a-zA-Z0-9_]+)[ \t]*=[ \t]*Function[ \t](\(.*\))/\2.\3=Function\4/c,class/i 

--regex-hw=/^[ \t]*(Local|Global)*[ \t]*([a-zA-Z0-9]+)[ \t]*=[ \t]*Function[ \t]+(\(.*\))/\2/v,variable/i
--regex-hw=/^[ \t]*(Local|Global)*[ \t]*([a-zA-Z0-9]+)[ \t]*=[ \t]*{/\2/v,variable/i

--regex-hw=/^[ \t]*(Const)+[ \t]*#([a-zA-Z0-9]+)[ \t]*=/#\2/v,variable/i
I'm able to trap all the following constructs:

Code: Select all

; comment on a single line

/* comment on multiple
   lines */

;----- OBJECTS and TABLES -----
; -  global -
Obj1 = { a = 0, b = 0 }
Global Obj2 = { a = 1 }

; - local -
Local Obj3 = { d = 1, e = 2 }

; Object definition on multiple lines
; - global -
Obj4 = {
    f = 0,
    e = 0 }

Global ObjA = {
    f = 1,
    e = 9 }

; - local -
Local Obj5 = {
    g = 0,
    h = 0 }


;----- METHODS -----
; - global -
Function Obj1:meth1()
    Return
EndFunction

; - local -
Local Function Obj1:meth2(a)
    Return(self.a + self.b + a)
EndFunction

; - anonymous functions -
Obj5.meth3 = Function (a)
                 return
             EndFunction


;----- FUNCTIONS -----
; - global -
Function func1()
    Return
EndFunction

; - local -
Function func2(a, b)
    Return
EndFunction

;----- ANONYMOUS FUNCTIONS -----
; - on global variable -
aFunc1 = Function (a)
            return
         EndFunction

;----- CONSTANTS ------
Const #CIAO = 10
But now I have a problem I'm not able to solve: how can I add table members/methods to the class?
For example, a table/object declaration:

Code: Select all

;--- global ---
myTable = { message = "hello", name = "Allanon" }
OR

Code: Select all

myTable = {}
myTable.message = "hello"
myTable.name = "Allanon"
The same concept applies to methods declaration using anonymous functions (rarely) or standard declaration like:

Code: Select all

Function myTable:printMessage()
   Print(self.message)
   Print(self.name)
EndFunction
I wuold like to know if it's possible to group object/table members in the class browser like:

Code: Select all

CLASSES
   +- myTable
    |     +- message
    |     +- name
    |     +- printMessage()
I'd like to know also if it's possible with Zeus to have suggestions on object's instances, for example if I do:

Code: Select all

Instance = myTable:new()
There is a chance for the ide to suggest me the 'myTable''s members when I'm writing properties:

Code: Select all

Instance.
and methods:

Code: Select all

Instance:
It's all very similar to Lua in tables/objects handling...

It's a lot of things I know :D
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

how can I add table members/methods to the class?

To group the tags requires the ctags.exe to be changed. I have made changes to the ctags.exe so that it better understand Hollywood code and those changes also implements this grouping.

I have also added a Hollywood folding to the xFolder.dll file.

Those new binaries can be found here: http://www.zeusedit.com/z300/xFolder.zip

The ctags source code changes can be found here: http://www.zeusedit.com/z300/ctags_src.zip

Cheers Jussi
Allanon
Posts: 6
Joined: Sun Aug 03, 2014 8:18 am

Post by Allanon »

Hello Jussi, that was faaast! Thank you for your support, your IDE seems to be what I was looking for years :D

Now all seems almost fine, but, if possible, I'd have some things to be adjusted
---
Constants defined with

Code: Select all

Const #MYCONSTANTS = 10
are grouped under "Macros", I know I can change the label, so it's not a problem, I was wondering if it's correct or not. If possible I'd like to see the assigned value along the constant's name.
---
Some variables declaration are not recognized, for example:

Code: Select all

Local aFunc2 = Function (b)
                  Return
               EndFunction

Code: Select all

abc = 1
Global def = 2
Local ghi = 3

test = "Hello"
multiple, assignment, thirdval = 0, 1, 2
Global a, b, c = 0, 1, 2
Local d, e, f = 3, 4, 5
---
Functions are detected except his construct:

Code: Select all

HGui = {}
HGui.Theme = {}
Function HGui.Theme.WindowBGColor(value)
    ...some stuff...
EndFunction
I also like to see parameters along the function's name :)
---
Classes are detected, but as for the functions, I'd like to see their parameters, this way I suppose that when Zeus suggest me available methods they are returned with parameters to speed up even more code writing.
---
What I'm asking now I think could be difficult, it's a really step forward for me what you have done and it will be wonderful if you could implement the above requests, but asking costs nothing so here it is my latest questions :)
- Is it possible to detected class instances?

Code: Select all

myClass = { a = 0 }
Function myClass:print()
   Print(self.a)
EndFunction

yourClass = myClass
yourClass.
or, more common form:

Code: Select all

yourClass = CopyTable(myClass)
yourClass.
Now Zeus should suggest me MyClass methods

- Is it possible to show properties (variables) inside classes? In the above example 'a' is a property, so writing myClass. Zeus should suggest me 'a' and 'print' as possible results.
Tables and objects can be declared on multiple lines like

Code: Select all

myObj = { a = 0,
          b = 1,
          c = "hello" }
- Am I still able to fine-tune the ide using the .ctags file?


That's all and thanks again for your great support!
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

are grouped under "Macros", I know I can change the label, so it's not a problem
Zeus is fairly old and dates back to the days of c/c++ and as such the ctags understands these name:

Code: Select all

class     Tag_Class 
function  Tag_Function 
method    Tag_Method 
macro     Tag_Macro 
procedure Tag_Procedure 
variable  Tag_Variable
As such I just mapped the constant values to the macro tag.
I was wondering if it's correct or not. If possible I'd like to see the assigned value along the constant's name.

I think this is possible by just changing the regexp :?

If you look at the source code link you will see the regexp used defines what is displayed and I suspect by just changing that regexp the resulting display will be different.

Give me an example of the code you have and the result you expect to see and I will see if it is possible to make it work as expected ;)
Some variables declaration are not recognized, for example:
I will see if this can be improved.
Functions are detected except his construct:
As you can see that function has lots of dots. I'll see if the regexp can be tweaked to detect this ;)

Code: Select all

yourClass = CopyTable(myClass) 
yourClass.
I'm not sure what this CopyTable does?

As you can see from the one day of tweaking that I have done, for a language that I've never used, it is actually fairly easy to get Zeus to display some sort of information in the Classes section of the Navigator panel.

As to whether that information is correct, that can only be answered by people that actually know the language, which is you ;)
Tables and objects can be declared on multiple lines like
myObj = { a = 0,
b = 1,
c = "hello" }
I can't answer this as I'm note really sure what that code means or what you are expecting to see in the navigator panel.

The ctags is just doing regexp matches so it will never be 100% correct but with the right regexp it can get pretty close :)

Cheers Jussi
Allanon
Posts: 6
Joined: Sun Aug 03, 2014 8:18 am

Post by Allanon »

Hi Jussi,
so constants are mapped to the 'macro' group, that's fine ::)
If I'm understanding correclty I could use the 'procedure' group to map something else since the language I'm using have no procedure definitions.

About the source code, yes I have looked at it and I've seen how you have defined the regexp to match the needed groups, unfortunatly I'm not a C programmer but I can try to extend it with the content I need since the source code is easy to understand. I've seen you have used the 's,scope' string, have you used it to group items?
Give me an example of the code you have and the result you expect to see and I will see if it is possible to make it work as expected
I don't want to bother you too much, I will try to make the needed changes by myself :)
I'm not sure what this CopyTable does?
'CopyTable' is a rought way to instantiate a class creating a copy of the object, that is 100% a table, a table with members that can be functions (methods), variables (properties) and even subtables, like in the Lua language.

As to whether that information is correct, that can only be answered by people that actually know the language, which is you Quote:
Tables and objects can be declared on multiple lines like

Code: Select all

myObj = { a = 0, 
 b = 1, 
 c = "hello" } 
I can't answer this as I'm note really sure what that code means or what you are expecting to see in the navigator panel.
The code mentioned defines a table with 3 items at index 'a', 'b' and 'c'.
It's an alternative to:

Code: Select all

myObj = {}
myObj.a = 0
myObj.b = 1
myObj.c = "hello"
Anyway I will experiment a bit with regexp tweaking the source code and playing with the .ctags file.
Thank you for your time, I will post here again to let you know how is going :)
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

If I'm understanding correctly I could use the 'procedure' group to map something else since the language I'm using have no procedure definitions.

Correct.

The structure and interface tags act a lot like the class tag in that they can group other tags.

The procedure and macro tags are just a single items.
I've seen you have used the 's,scope' string, have you used it to group items?

That scope tag is just used to group the items into the class.

You can see the this code sets the class details for the item and it uses the scope:

Code: Select all

        // set the current scope and the default add will add it
        e->extensionFields.scope [0] = "class";
        e->extensionFields.scope [1] = vStringValue (scope);
I don't want to bother you too much, I will try to make the needed changes by myself
I'm happy enough to help, as making the changes is actually very easy.

But you are going to have to do the testing ;)
'CopyTable' is a rought way to instantiate a class creating a copy of the object
Ok.

Cheers Jussi
jussij
Site Admin
Posts: 2650
Joined: Fri Aug 13, 2004 5:10 pm

Post by jussij »

- Am I still able to fine-tune the ide using the .ctags file?

No. The way the ctags.exe works is either/or but not both.

Code: Select all

myObj = { a = 0, 
           b = 1, 
           c = "hello" }
The latest code detects this construct.

But this change might cause other issues as it has to try an detect the end of scope and it might not always get this correct :?

Code: Select all

yourClass = CopyTable(myClass)

The latest code detects this construct.

But the actual member details of yourClass is not populated (i.e. the members of myClass) as it doesn't know those details.

Code: Select all

HGui = {} 
HGui.Theme = {} 
Function HGui.Theme.WindowBGColor(value) 
    other stuff
EndFunction

The latest code detects this construct.

Those new binaries can be found here: http://www.zeusedit.com/z300/xFolder.zip

The ctags source code changes can be found here: http://www.zeusedit.com/z300/ctags_src.zip

NOTE: That xFolder.zip contains a new improved folder, new keywords information, a new code comment macro and some templates. See the readme.txt for details.

Cheers Jussi
Allanon
Posts: 6
Joined: Sun Aug 03, 2014 8:18 am

Post by Allanon »

Thank you Jussi for your work, I'm goin' to try it right now :)
Post Reply