Author Topic: Adding Language Support questions  (Read 14932 times)

stansch

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
Adding Language Support questions
« on: May 29, 2016, 07:15:13 PM »
Hi,
As many other people in this forum i found this tutorial on how to add language support:
http://blog.slickedit.com/2008/05/tutorial-adding-language-support-to-slickedit/
I followed the tutorial and got a very basic tagging support to work, even though i don't really know what i'm doing  ;D
But i have the follow problem that i have no idea how it could be solved, maybe someone could give me an input.

1. like in the tutorial i do search for keywords... then there's a switch case. for instance "case integer" where i would do something like this:
proc_name = temp_word2; //the name of the capurted integer
proc_name = tag_tree_compose_tag(proc_name,"","gvar",0,"","variable " :+ lowcase(kw) :+ str_dimension);
So this would find all my integers. I do the same thing with chars etc.

Now the language (netlinx) i am trying to write a language support file has what's called structures.
In the DEFINE_TYPE section you define a structure. this could look like this:
structure STRUC_TEST
   {
   integer intTest1             
   char     charTest2[30]
   }

And later in the define_variable section you can create Structures like this: STRUC_TEST myStruc

So the problem i am having, is that to recognize created structures the macro has to search for names that the programmer creates in the source code. Unlike when you define an integer or a character.

Does anyone know an easy way to do something like this?  :)

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Adding Language Support questions
« Reply #1 on: May 29, 2016, 10:37:47 PM »
You probably should find the structure name. Then create a selection and match the braces. Then do a recursive search within the selection passing the outer stricter name as an argument. It's pretty involved.

I don't know of a much easier way to do this. The above method could support nested structure. If you don't need that, you could avoid recursion and compare line numbers to see if subsequent variables are members

stansch

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
Re: Adding Language Support questions
« Reply #2 on: May 30, 2016, 06:41:31 PM »
if i understand you correctly, you're talking about finding the members of a structure, right? (comparing line numbers)
But how do i recognize myStruc as Variable of type "STRUC_TEST"? If i find find the keyword "structure" then i know that the next word would be the name of a user created Type defintion. So, now all the source code files have to be searched for that new keyword. The only way i can think of how i could do that would be saving all of the found structures definitions in a string array and then test each and every word in all of the source code files against each and every word in that string array. Or is it possible to define STRUC_TEST as structure name and then tell slickedit to search all the source code files for the occurrence of a previously added structure name?

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Adding Language Support questions
« Reply #3 on: May 30, 2016, 07:10:24 PM »
What I've described doing is to make sure your proc search function calls tag_tree_compose_tag and passes the correct class_name argument for members of the structure.

When a find-tag is done, the user may get prompted which symbol to go to -- the one in the structure or possibly one that is not. Then your proc search function is called with a proc_name argument which may also contain the specific structure name it is from. Your code needs to parse out the structure name and separate the tag_name from the class_name. The calling code takes care of opening the correct source file. Your proc search function just needs to find that specify tag.

stansch

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
Re: Adding Language Support questions
« Reply #4 on: May 31, 2016, 08:03:09 PM »
This might just be a little above my skills. (right now)
Can you mabye give me a little example so i can play around with it?

To add a member to a class you would do something like this??
proc_name = "member1";
proc_name = tag_tree_compose_tag(proc_name,"class1","class",0,"","");

now if you have an instance "myClass" in your code and you would want to "auto list members" what do you have to do that slickedit knows myClass is an instance of class "class1"?

Thanks for your patience!  :)

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Adding Language Support questions
« Reply #5 on: May 31, 2016, 08:15:09 PM »
The instance part is a lot more work than what I've mentioned. What I've mentioned will support find tag very well because all possible definitions will be listed (like the one in the structure). It won't support listing members without a lot more work.

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Adding Language Support questions
« Reply #6 on: June 01, 2016, 03:29:23 PM »
When we add the auto list members feature which requires scope and instance expression analysis, we write a full parser for the language and also implement the additional callbacks for scope and instance expression analysis. The full parser has more call backs than just a proc search which is really intended to just pick up global symbols (not locals, parameters, etc.).

Even for us, it takes between 2 weeks to 2 months to implement all of this. For us, the proc search function takes us only hours to write. In other words, the proc search function gives you a lot of bang for the buck.

stansch

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
Re: Adding Language Support questions
« Reply #7 on: June 01, 2016, 08:04:56 PM »
Too bad the good stuff always has to be complicated  ;D I believe you that professional language support is a hard piece of work. Your code analysis has to "think" pretty much like a compiler. The language support i'm writing is far far far from being professional. Nevertheless, it's great help in everyday programming. There are many ways you can make it not work correctly and still be able to compile. I just started avoiding what i know my language support wouldn't recognize  ;D Not recognizing structures is the biggest downside at the moment. Since Netlinx is not object oriented recoginzing those structure types is the only thing really complicated there is. And it's actually very static since there are no constructors or anything. i thought if i knew how to define captured words as a structure object and how to define the structure members i would eventually figure out something that at least partially works.  ;)
Chances that slickedit ever officially supports netlinx (http://www.amx.com//assets/manuals/NetLinx.LanguageReferenceGuide.pdf) are probably down to 0, eh?
Right now i have a question that is possibly easier to answer: i do capture lines with get_line(variable) but this also captures comments. Can you do a get_line that ignores comments?
« Last Edit: June 01, 2016, 08:07:27 PM by stansch »

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Adding Language Support questions
« Reply #8 on: June 01, 2016, 08:57:03 PM »
There isn't a get_line() option to skip comments but there's a better way. The search() functions takes color coding arguments.

Example:

   status=search('abc','xcs');

The second argument of "xcs" specifies to exclude matches where the first character is comment or string color.

stansch

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
Re: Adding Language Support questions
« Reply #9 on: July 03, 2016, 02:05:47 PM »
how about if i just wanted to capture the names of globally defined structure instances and forget about its members for now.
my proc search already captures structure definitions. i do a search for the keyword "structure" and then tag_tree_compose the next full word like this:
proc_name = curstrucname; //let's say this structures name is "STRUC_TEST"
proc_name = tag_tree_compose_tag(proc_name,"","struct",0,"","");
now to find structure instances of type "STRUC_TEST" i would have to do a search for "STRUC_TEST" (but that name is created by the programmer).
Is there an easy way to do this? Maybe like doing a search for all keywords of type "struct"?


Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Adding Language Support questions
« Reply #10 on: July 03, 2016, 04:46:09 PM »
What happens if you do Ctrl+/ to search for references? It might just do a simple string search in the workspace. I'm not sure what it does in this case.

stansch

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
Re: Adding Language Support questions
« Reply #11 on: July 03, 2016, 06:04:53 PM »
if my cursor is above STRUC_TEST and i do a Ctrl+/ i get a reference list showing me all lines in all files where I used the word "STRUC_TEST" to declare a Structure variable of type STRUC_TEST. That's good. But what i wish it would do is to tag the following word of each reference as a symbol. 

Clark

  • SlickEdit Team Member
  • Senior Community Member
  • *
  • Posts: 6826
  • Hero Points: 526
Re: Adding Language Support questions
« Reply #12 on: July 03, 2016, 08:31:29 PM »
You would have to add them as tags which can be very difficult to do without writing a pretty full parser.  Can't realistically do locals right with a proc search function.

stansch

  • Junior Community Member
  • Posts: 7
  • Hero Points: 0
Re: Adding Language Support questions
« Reply #13 on: July 05, 2016, 07:28:49 PM »
I thought it would be hard to do.. but you never know... writing that basic proc search was easier than i thought it would be, too  ;)
Thanks anyways!

rgloden

  • Senior Community Member
  • Posts: 169
  • Hero Points: 5
Re: Adding Language Support questions
« Reply #14 on: April 01, 2020, 04:02:43 AM »
Is the original link still active?  I can seem to get to it anymore?